1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.ws.commons.schema;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.w3c.dom.DocumentFragment;
25 import org.w3c.dom.Node;
26 import org.w3c.dom.NodeList;
27
28
29
30
31
32 class DocumentFragmentNodeList implements NodeList {
33 private List nodes;
34 private DocumentFragment fragment;
35
36
37
38
39
40 DocumentFragmentNodeList(Node parentNode) {
41 fragment = parentNode.getOwnerDocument().createDocumentFragment();
42 nodes = new ArrayList();
43 for(Node child = parentNode.getFirstChild(); child != null; child = child.getNextSibling()) {
44 nodes.add(fragment.appendChild(child.cloneNode(true)));
45 }
46 }
47
48
49
50
51
52
53
54 DocumentFragmentNodeList(Node parentNode, String filterUri, String filterLocal) {
55 fragment = parentNode.getOwnerDocument().createDocumentFragment();
56 nodes = new ArrayList();
57 for(Node child = parentNode.getFirstChild(); child != null; child = child.getNextSibling()) {
58 if(child.getNodeType() == Node.ELEMENT_NODE
59 && child.getNamespaceURI().equals(filterUri)
60 && child.getLocalName().equals(filterLocal)) {
61 nodes.add(fragment.appendChild(child.cloneNode(true)));
62 }
63 }
64 }
65
66 public int getLength() {
67 return nodes.size();
68 }
69
70 public Node item(int index) {
71 if(nodes == null) {
72 return null;
73 } else {
74 return (Node) nodes.get(index);
75 }
76 }
77
78 }