| 60 | import java.util.ArrayList; |
| 61 | |
| 62 | class NodeListModel extends SimpleSequence implements TemplateHashModel { |
| 63 | |
| 64 | NodeModel contextNode; |
| 65 | XPathSupport xpathSupport; |
| 66 | |
| 67 | private static ObjectWrapper nodeWrapper = new ObjectWrapper() { |
| 68 | public TemplateModel wrap(Object obj) { |
| 69 | if (obj instanceof NodeModel) { |
| 70 | return (NodeModel) obj; |
| 71 | } |
| 72 | return NodeModel.wrap((Node) obj); |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | |
| 77 | NodeListModel(Node node) { |
| 78 | this(NodeModel.wrap(node)); |
| 79 | } |
| 80 | |
| 81 | NodeListModel(NodeModel contextNode) { |
| 82 | super(nodeWrapper); |
| 83 | this.contextNode = contextNode; |
| 84 | } |
| 85 | |
| 86 | NodeListModel(NodeList nodeList, NodeModel contextNode) { |
| 87 | super(nodeWrapper); |
| 88 | for (int i=0; i<nodeList.getLength();i++) { |
| 89 | list.add(nodeList.item(i)); |
| 90 | } |
| 91 | this.contextNode = contextNode; |
| 92 | } |
| 93 | |
| 94 | NodeListModel(NamedNodeMap nodeList, NodeModel contextNode) { |
| 95 | super(nodeWrapper); |
| 96 | for (int i=0; i<nodeList.getLength();i++) { |
| 97 | list.add(nodeList.item(i)); |
| 98 | } |
| 99 | this.contextNode = contextNode; |
| 100 | } |
| 101 | |
| 102 | NodeListModel(List list, NodeModel contextNode) { |
| 103 | super(list, nodeWrapper); |
| 104 | this.contextNode = contextNode; |
| 105 | } |
| 106 | |
| 107 | NodeListModel filterByName(String name) throws TemplateModelException { |
| 108 | NodeListModel result = new NodeListModel(contextNode); |
| 109 | int size = size(); |
| 110 | if (size == 0) { |
| 111 | return result; |
| 112 | } |
| 113 | Environment env = Environment.getCurrentEnvironment(); |
| 114 | for (int i = 0; i<size; i++) { |
| 115 | NodeModel nm = (NodeModel) get(i); |
| 116 | if (nm instanceof ElementModel) { |
| 117 | if (((ElementModel) nm).matchesName(name, env)) { |
| 118 | result.add(nm); |
| 119 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…