1 | |
package org.jtheque.primary.utils.web.analyzers.generic.value; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
import org.jtheque.primary.utils.web.analyzers.generic.condition.Condition; |
20 | |
import org.jtheque.primary.utils.web.analyzers.generic.operation.ScannerPossessor; |
21 | |
import org.jtheque.primary.utils.web.analyzers.generic.operation.iterator.IteratorOperation; |
22 | |
|
23 | |
import java.util.ArrayList; |
24 | |
import java.util.Collection; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public final class IteratorValue implements ValueGetter, BuilderPossessor { |
32 | |
private final StringBuilder builder; |
33 | |
private final Collection<IteratorOperation> operationsBefore; |
34 | |
private final Collection<IteratorOperation> operationsAfter; |
35 | |
private final Collection<IteratorOperation> operations; |
36 | |
private Condition condition; |
37 | |
|
38 | |
private final ScannerPossessor analyzer; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
IteratorValue(ScannerPossessor analyzer){ |
46 | 0 | super(); |
47 | |
|
48 | 0 | this.analyzer = analyzer; |
49 | |
|
50 | 0 | builder = new StringBuilder(100); |
51 | 0 | operationsBefore = new ArrayList<IteratorOperation>(5); |
52 | 0 | operationsAfter = new ArrayList<IteratorOperation>(5); |
53 | 0 | operations = new ArrayList<IteratorOperation>(5); |
54 | 0 | } |
55 | |
|
56 | |
@Override |
57 | |
public String getValue(String line){ |
58 | 0 | String current = line; |
59 | |
|
60 | 0 | for (IteratorOperation operation : operationsBefore){ |
61 | 0 | current = operation.perform(current, analyzer, this); |
62 | |
} |
63 | |
|
64 | 0 | while (condition.match(current)){ |
65 | 0 | for (IteratorOperation operation : operations){ |
66 | 0 | current = operation.perform(current, analyzer, this); |
67 | |
} |
68 | |
} |
69 | |
|
70 | 0 | for (IteratorOperation operation : operationsAfter){ |
71 | 0 | current = operation.perform(current, analyzer, this); |
72 | |
} |
73 | |
|
74 | 0 | return builder.toString(); |
75 | |
} |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public void addOperationsBefore(IteratorOperation operation){ |
83 | 0 | operationsBefore.add(operation); |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
public void addOperationsAfter(IteratorOperation operation){ |
92 | 0 | operationsAfter.add(operation); |
93 | 0 | } |
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
public void addOperations(IteratorOperation operation){ |
101 | 0 | operations.add(operation); |
102 | 0 | } |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
public void setCondition(Condition condition){ |
110 | 0 | this.condition = condition; |
111 | 0 | } |
112 | |
|
113 | |
@Override |
114 | |
public StringBuilder getBuilder(){ |
115 | 0 | return builder; |
116 | |
} |
117 | |
} |