| 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.jdom.Element; |
| 20 | |
import org.jtheque.core.utils.file.XMLException; |
| 21 | |
import org.jtheque.core.utils.file.XMLReader; |
| 22 | |
import org.jtheque.primary.utils.web.analyzers.generic.Factory; |
| 23 | |
import org.jtheque.primary.utils.web.analyzers.generic.condition.ConditionUtils; |
| 24 | |
import org.jtheque.primary.utils.web.analyzers.generic.operation.iterator.IteratorOperation; |
| 25 | |
import org.jtheque.primary.utils.web.analyzers.generic.operation.iterator.IteratorOperationFactory; |
| 26 | |
|
| 27 | |
import java.util.ArrayList; |
| 28 | |
import java.util.Collection; |
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | 0 | public final class IteratorValueGetterFactory implements Factory<ValueGetter> { |
| 34 | |
@Override |
| 35 | |
public boolean canFactor(Element element, XMLReader reader) throws XMLException{ |
| 36 | 0 | return !reader.getNodes("iterator", element).isEmpty(); |
| 37 | |
} |
| 38 | |
|
| 39 | |
@Override |
| 40 | |
public ValueGetter factor(Element element, XMLReader reader) throws XMLException{ |
| 41 | 0 | Element n = reader.getNode("iterator", element); |
| 42 | |
|
| 43 | 0 | IteratorValue value = new IteratorValue(ValueGetterFactory.getScannerPossessor()); |
| 44 | |
|
| 45 | 0 | for (IteratorOperation operation : getIteratorOperations(n, "before", reader)){ |
| 46 | 0 | value.addOperationsBefore(operation); |
| 47 | |
} |
| 48 | |
|
| 49 | 0 | for (IteratorOperation operation : getIteratorOperations(n, "after", reader)){ |
| 50 | 0 | value.addOperationsAfter(operation); |
| 51 | |
} |
| 52 | |
|
| 53 | 0 | for (IteratorOperation operation : getIteratorOperations(n, "operations", reader)){ |
| 54 | 0 | value.addOperations(operation); |
| 55 | |
} |
| 56 | |
|
| 57 | 0 | value.setCondition(ConditionUtils.getCondition(n, "condition", reader)); |
| 58 | |
|
| 59 | 0 | return value; |
| 60 | |
} |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
private static Iterable<IteratorOperation> getIteratorOperations(Object node, String location, XMLReader reader) throws XMLException{ |
| 74 | 0 | Collection<IteratorOperation> operations = new ArrayList<IteratorOperation>(8); |
| 75 | |
|
| 76 | 0 | for (Element n : reader.getNodes(location + "/*", node)){ |
| 77 | 0 | operations.add(IteratorOperationFactory.getPosition(n, reader)); |
| 78 | |
} |
| 79 | |
|
| 80 | 0 | return operations; |
| 81 | |
} |
| 82 | |
} |