1
22
23 package com.liferay.portal.xml;
24
25 import com.liferay.portal.kernel.xml.Document;
26 import com.liferay.portal.kernel.xml.Element;
27 import com.liferay.portal.kernel.xml.Node;
28
29 import java.io.IOException;
30 import java.io.Writer;
31
32 import java.util.List;
33
34
40 public class NodeImpl implements Node {
41
42 public NodeImpl(org.dom4j.Node node) {
43 _node = node;
44 }
45
46 public String asXML() {
47 return _node.asXML();
48 }
49
50 public Node asXPathResult(Element parent) {
51 ElementImpl parentImpl = (ElementImpl)parent;
52
53 org.dom4j.Node node = _node.asXPathResult(
54 parentImpl.getWrappedElement());
55
56 if (node == null) {
57 return null;
58 }
59 if (node instanceof org.dom4j.Element) {
60 return new ElementImpl((org.dom4j.Element)node);
61 }
62 else {
63 return new NodeImpl(node);
64 }
65 }
66
67 public Node detach() {
68 org.dom4j.Node node = _node.detach();
69
70 if (node == null) {
71 return null;
72 }
73 if (node instanceof org.dom4j.Element) {
74 return new ElementImpl((org.dom4j.Element)node);
75 }
76 else {
77 return new NodeImpl(node);
78 }
79 }
80
81 public boolean equals(Object obj) {
82 org.dom4j.Node node = ((NodeImpl)obj).getWrappedNode();
83
84 return _node.equals(node);
85 }
86
87 public Document getDocument() {
88 org.dom4j.Document document = _node.getDocument();
89
90 if (document == null) {
91 return null;
92 }
93 else {
94 return new DocumentImpl(document);
95 }
96 }
97
98 public String getName() {
99 return _node.getName();
100 }
101
102 public Element getParent() {
103 org.dom4j.Element element = _node.getParent();
104
105 if (element == null) {
106 return null;
107 }
108 else {
109 return new ElementImpl(element);
110 }
111 }
112
113 public String getPath() {
114 return _node.getPath();
115 }
116
117 public String getPath(Element context) {
118 ElementImpl contextImpl = (ElementImpl)context;
119
120 return _node.getPath(contextImpl.getWrappedElement());
121 }
122
123 public String getStringValue() {
124 return _node.getStringValue();
125 }
126
127 public String getText() {
128 return _node.getText();
129 }
130
131 public String getUniquePath() {
132 return _node.getUniquePath();
133 }
134
135 public String getUniquePath(Element context) {
136 ElementImpl contextImpl = (ElementImpl)context;
137
138 return _node.getUniquePath(contextImpl.getWrappedElement());
139 }
140
141 public org.dom4j.Node getWrappedNode() {
142 return _node;
143 }
144
145 public boolean hasContent() {
146 return _node.hasContent();
147 }
148
149 public int hashCode() {
150 return _node.hashCode();
151 }
152
153 public boolean isReadOnly() {
154 return _node.isReadOnly();
155 }
156
157 public boolean matches(String xpathExpression) {
158 return _node.matches(xpathExpression);
159 }
160
161 public Number numberValueOf(String xpathExpression) {
162 return _node.numberValueOf(xpathExpression);
163 }
164
165 public List<Node> selectNodes(String xpathExpression) {
166 return SAXReaderImpl.toNewNodes(_node.selectNodes(xpathExpression));
167 }
168
169 public List<Node> selectNodes(
170 String xpathExpression, String comparisonXPathExpression) {
171
172 return SAXReaderImpl.toNewNodes(
173 _node.selectNodes(xpathExpression, comparisonXPathExpression));
174 }
175
176 public List<Node> selectNodes(
177 String xpathExpression, String comparisonXPathExpression,
178 boolean removeDuplicates) {
179
180 return SAXReaderImpl.toNewNodes(
181 _node.selectNodes(
182 xpathExpression, comparisonXPathExpression, removeDuplicates));
183 }
184
185 public Object selectObject(String xpathExpression) {
186 Object obj = _node.selectObject(xpathExpression);
187
188 if (obj == null) {
189 return null;
190 }
191 else if (obj instanceof List) {
192 return SAXReaderImpl.toNewNodes((List<org.dom4j.Node>)obj);
193 }
194 else {
195 return obj;
196 }
197 }
198
199 public Node selectSingleNode(String xpathExpression) {
200 org.dom4j.Node node = _node.selectSingleNode(xpathExpression);
201
202 if (node == null) {
203 return null;
204 }
205 if (node instanceof org.dom4j.Element) {
206 return new ElementImpl((org.dom4j.Element)node);
207 }
208 else {
209 return new NodeImpl(node);
210 }
211 }
212
213 public void setName(String name) {
214 _node.setName(name);
215 }
216
217 public void setText(String text) {
218 _node.setText(text);
219 }
220
221 public boolean supportsParent() {
222 return _node.supportsParent();
223 }
224
225 public String valueOf(String xpathExpression) {
226 return _node.valueOf(xpathExpression);
227 }
228
229 public void write(Writer writer) throws IOException {
230 _node.write(writer);
231 }
232
233 private org.dom4j.Node _node;
234
235 }