1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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.util.xml.XMLFormatter;
28  
29  import java.io.IOException;
30  
31  /**
32   * <a href="DocumentImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   *
36   */
37  public class DocumentImpl extends BranchImpl implements Document {
38  
39      public DocumentImpl(org.dom4j.Document document) {
40          super(document);
41  
42          _document = document;
43      }
44  
45      public Document addComment(String comment) {
46          _document.addComment(comment);
47  
48          return this;
49      }
50  
51      public Document addDocType(String name, String publicId, String systemId) {
52          _document.addDocType(name, publicId, systemId);
53  
54          return this;
55      }
56  
57      public boolean equals(Object obj) {
58          org.dom4j.Document document = ((DocumentImpl)obj).getWrappedDocument();
59  
60          return _document.equals(document);
61      }
62  
63      public String formattedString() throws IOException {
64          return XMLFormatter.toString(_document);
65      }
66  
67      public String formattedString(String indent) throws IOException {
68          return XMLFormatter.toString(_document, indent);
69      }
70  
71      public String formattedString(String indent, boolean expandEmptyElements)
72          throws IOException {
73  
74          return XMLFormatter.toString(_document, indent, expandEmptyElements);
75      }
76  
77      public Element getRootElement() {
78          return new ElementImpl(_document.getRootElement());
79      }
80  
81      public org.dom4j.Document getWrappedDocument() {
82          return _document;
83      }
84  
85      public String getXMLEncoding() {
86          return _document.getXMLEncoding();
87      }
88  
89      public int hashCode() {
90          return _document.hashCode();
91      }
92  
93      public void setRootElement(Element rootElement) {
94          ElementImpl rootElementImpl = (ElementImpl)rootElement;
95  
96          _document.setRootElement(rootElementImpl.getWrappedElement());
97      }
98  
99      public void setXMLEncoding(String encoding) {
100         _document.setXMLEncoding(encoding);
101     }
102 
103     private org.dom4j.Document _document;
104 
105 }