1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.xml;
16  
17  import com.liferay.portal.kernel.xml.Branch;
18  import com.liferay.portal.kernel.xml.Comment;
19  import com.liferay.portal.kernel.xml.Element;
20  import com.liferay.portal.kernel.xml.Node;
21  import com.liferay.portal.kernel.xml.ProcessingInstruction;
22  import com.liferay.portal.kernel.xml.QName;
23  
24  import java.util.Iterator;
25  import java.util.List;
26  
27  /**
28   * <a href="BranchImpl.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class BranchImpl extends NodeImpl implements Branch {
33  
34      public BranchImpl(org.dom4j.Branch branch) {
35          super(branch);
36  
37          _branch = branch;
38      }
39  
40      public void add(Comment comment) {
41          CommentImpl commentImpl = (CommentImpl)comment;
42  
43          _branch.add(commentImpl.getWrappedComment());
44      }
45  
46      public void add(Element element) {
47          ElementImpl elementImpl = (ElementImpl)element;
48  
49          _branch.add(elementImpl.getWrappedElement());
50      }
51  
52      public void add(Node node) {
53          NodeImpl nodeImpl = (NodeImpl)node;
54  
55          _branch.add(nodeImpl.getWrappedNode());
56      }
57  
58      public void add(ProcessingInstruction processingInstruction) {
59          ProcessingInstructionImpl processingInstructionImpl =
60              (ProcessingInstructionImpl)processingInstruction;
61  
62          _branch.add(
63              processingInstructionImpl.getWrappedProcessingInstruction());
64      }
65  
66      public Element addElement(QName qName) {
67          QNameImpl qNameImpl = (QNameImpl)qName;
68  
69          return new ElementImpl(_branch.addElement(qNameImpl.getWrappedQName()));
70      }
71  
72      public Element addElement(String name) {
73          return new ElementImpl(_branch.addElement(name));
74      }
75  
76      public Element addElement(String qualifiedName, String namespaceURI) {
77          return new ElementImpl(_branch.addElement(qualifiedName, namespaceURI));
78      }
79  
80      public void appendContent(Branch branch) {
81          BranchImpl branchImpl = (BranchImpl)branch;
82  
83          _branch.appendContent(branchImpl.getWrappedBranch());
84      }
85  
86      public void clearContent() {
87          _branch.clearContent();
88      }
89  
90      public List<Node> content() {
91          return SAXReaderImpl.toNewNodes(_branch.content());
92      }
93  
94      public Element elementByID(String elementID) {
95          return new ElementImpl(_branch.elementByID(elementID));
96      }
97  
98      public boolean equals(Object obj) {
99          org.dom4j.Branch branch = ((BranchImpl)obj).getWrappedBranch();
100 
101         return _branch.equals(branch);
102     }
103 
104     public org.dom4j.Branch getWrappedBranch() {
105         return _branch;
106     }
107 
108     public int hashCode() {
109         return _branch.hashCode();
110     }
111 
112     public int indexOf(Node node) {
113         NodeImpl nodeImpl = (NodeImpl)node;
114 
115         return _branch.indexOf(nodeImpl.getWrappedNode());
116     }
117 
118     public Node node(int index) {
119         org.dom4j.Node node = _branch.node(index);
120 
121         if (node == null) {
122             return null;
123         }
124         else {
125             if (node instanceof org.dom4j.Element) {
126                 return new ElementImpl((org.dom4j.Element)node);
127             }
128             else {
129                 return new NodeImpl(node);
130             }
131         }
132     }
133 
134     public int nodeCount() {
135         return _branch.nodeCount();
136     }
137 
138     public Iterator<Node> nodeIterator() {
139         return content().iterator();
140     }
141 
142     public void normalize() {
143         _branch.normalize();
144     }
145 
146     public ProcessingInstruction processingInstruction(String target) {
147         org.dom4j.ProcessingInstruction processingInstruction =
148             _branch.processingInstruction(target);
149 
150         if (processingInstruction == null) {
151             return null;
152         }
153         else {
154             return new ProcessingInstructionImpl(processingInstruction);
155         }
156     }
157 
158     public List<ProcessingInstruction> processingInstructions() {
159         return SAXReaderImpl.toNewProcessingInstructions(
160             _branch.processingInstructions());
161     }
162 
163     public List<ProcessingInstruction> processingInstructions(String target) {
164         return SAXReaderImpl.toNewProcessingInstructions(
165             _branch.processingInstructions(target));
166     }
167 
168     public boolean remove(Comment comment) {
169         CommentImpl commentImpl = (CommentImpl)comment;
170 
171         return _branch.remove(commentImpl.getWrappedComment());
172     }
173 
174     public boolean remove(Element element) {
175         ElementImpl elementImpl = (ElementImpl)element;
176 
177         return _branch.remove(elementImpl.getWrappedElement());
178     }
179 
180     public boolean remove(Node node) {
181         NodeImpl nodeImpl = (NodeImpl)node;
182 
183         return _branch.remove(nodeImpl.getWrappedNode());
184     }
185 
186     public boolean remove(ProcessingInstruction processingInstruction) {
187         ProcessingInstructionImpl processingInstructionImpl =
188             (ProcessingInstructionImpl)processingInstruction;
189 
190         return _branch.remove(
191             processingInstructionImpl.getWrappedProcessingInstruction());
192     }
193 
194     public boolean removeProcessingInstruction(String target) {
195         return _branch.removeProcessingInstruction(target);
196     }
197 
198     public void setContent(List<Node> content) {
199         _branch.setContent(SAXReaderImpl.toOldNodes(content));
200     }
201 
202     public void setProcessingInstructions(
203         List<ProcessingInstruction> processingInstructions) {
204 
205         _branch.setProcessingInstructions(
206             SAXReaderImpl.toOldProcessingInstructions(processingInstructions));
207     }
208 
209     public String toString() {
210         return _branch.toString();
211     }
212 
213     private org.dom4j.Branch _branch;
214 
215 }