| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.apache.commons.configuration.tree.xpath; |
| 18 | |
|
| 19 | |
import java.util.ArrayList; |
| 20 | |
import java.util.Collections; |
| 21 | |
import java.util.Iterator; |
| 22 | |
import java.util.List; |
| 23 | |
|
| 24 | |
import org.apache.commons.configuration.tree.ConfigurationNode; |
| 25 | |
import org.apache.commons.jxpath.ri.Compiler; |
| 26 | |
import org.apache.commons.jxpath.ri.QName; |
| 27 | |
import org.apache.commons.jxpath.ri.compiler.NodeNameTest; |
| 28 | |
import org.apache.commons.jxpath.ri.compiler.NodeTest; |
| 29 | |
import org.apache.commons.jxpath.ri.compiler.NodeTypeTest; |
| 30 | |
import org.apache.commons.jxpath.ri.model.NodePointer; |
| 31 | |
import org.apache.commons.lang.StringUtils; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
class ConfigurationNodeIteratorChildren extends ConfigurationNodeIteratorBase |
| 42 | |
{ |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
public ConfigurationNodeIteratorChildren(NodePointer parent, |
| 53 | |
NodeTest nodeTest, boolean reverse, NodePointer startsWith) |
| 54 | |
{ |
| 55 | 24441 | super(parent, reverse); |
| 56 | 24441 | ConfigurationNode root = (ConfigurationNode) parent.getNode(); |
| 57 | 24441 | List childNodes = createSubNodeList(root, nodeTest); |
| 58 | 24441 | initSubNodeList(childNodes); |
| 59 | 24441 | if (startsWith != null) |
| 60 | |
{ |
| 61 | 5 | setStartOffset(findStartIndex(root, |
| 62 | |
(ConfigurationNode) startsWith.getNode())); |
| 63 | |
} |
| 64 | 24441 | } |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
protected List createSubNodeList(ConfigurationNode node, NodeTest test) |
| 76 | |
{ |
| 77 | 24441 | List children = node.getChildren(); |
| 78 | |
|
| 79 | 24441 | if (test == null) |
| 80 | |
{ |
| 81 | 7816 | return children; |
| 82 | |
} |
| 83 | |
else |
| 84 | |
{ |
| 85 | 16625 | if (test instanceof NodeNameTest) |
| 86 | |
{ |
| 87 | 11936 | NodeNameTest nameTest = (NodeNameTest) test; |
| 88 | 11936 | QName name = nameTest.getNodeName(); |
| 89 | 11936 | if (name.getPrefix() == null) |
| 90 | |
{ |
| 91 | 11935 | if (nameTest.isWildcard()) |
| 92 | |
{ |
| 93 | 30 | return children; |
| 94 | |
} |
| 95 | |
|
| 96 | 11905 | List result = new ArrayList(); |
| 97 | 36260 | for (Iterator it = children.iterator(); it.hasNext();) |
| 98 | |
{ |
| 99 | 12450 | ConfigurationNode child = (ConfigurationNode) it.next(); |
| 100 | 12450 | if (StringUtils.equals(name.getName(), child.getName())) |
| 101 | |
{ |
| 102 | 7169 | result.add(child); |
| 103 | |
} |
| 104 | |
} |
| 105 | 11905 | return result; |
| 106 | |
} |
| 107 | |
} |
| 108 | |
|
| 109 | 4689 | else if (test instanceof NodeTypeTest) |
| 110 | |
{ |
| 111 | 4688 | NodeTypeTest typeTest = (NodeTypeTest) test; |
| 112 | 4688 | if (typeTest.getNodeType() == Compiler.NODE_TYPE_NODE |
| 113 | |
|| typeTest.getNodeType() == Compiler.NODE_TYPE_TEXT) |
| 114 | |
{ |
| 115 | 4687 | return children; |
| 116 | |
} |
| 117 | |
} |
| 118 | |
} |
| 119 | |
|
| 120 | 3 | return Collections.EMPTY_LIST; |
| 121 | |
} |
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
protected int findStartIndex(ConfigurationNode node, |
| 132 | |
ConfigurationNode startNode) |
| 133 | |
{ |
| 134 | 21 | for (int index = 0; index < node.getChildrenCount(); index++) |
| 135 | |
{ |
| 136 | 20 | if (node.getChild(index) == startNode) |
| 137 | |
{ |
| 138 | 4 | return index; |
| 139 | |
} |
| 140 | |
} |
| 141 | |
|
| 142 | 1 | return -1; |
| 143 | |
} |
| 144 | |
} |