1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.xml;
16  
17  import com.liferay.portal.kernel.xml.Document;
18  import com.liferay.portal.kernel.xml.Element;
19  import com.liferay.util.xml.XMLFormatter;
20  
21  import java.io.IOException;
22  
23  /**
24   * <a href="DocumentImpl.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class DocumentImpl extends BranchImpl implements Document {
29  
30      public DocumentImpl(org.dom4j.Document document) {
31          super(document);
32  
33          _document = document;
34      }
35  
36      public Document addComment(String comment) {
37          _document.addComment(comment);
38  
39          return this;
40      }
41  
42      public Document addDocType(String name, String publicId, String systemId) {
43          _document.addDocType(name, publicId, systemId);
44  
45          return this;
46      }
47  
48      public boolean equals(Object obj) {
49          org.dom4j.Document document = ((DocumentImpl)obj).getWrappedDocument();
50  
51          return _document.equals(document);
52      }
53  
54      public String formattedString() throws IOException {
55          return XMLFormatter.toString(_document);
56      }
57  
58      public String formattedString(String indent) throws IOException {
59          return XMLFormatter.toString(_document, indent);
60      }
61  
62      public String formattedString(String indent, boolean expandEmptyElements)
63          throws IOException {
64  
65          return XMLFormatter.toString(_document, indent, expandEmptyElements);
66      }
67  
68      public Element getRootElement() {
69          return new ElementImpl(_document.getRootElement());
70      }
71  
72      public org.dom4j.Document getWrappedDocument() {
73          return _document;
74      }
75  
76      public String getXMLEncoding() {
77          return _document.getXMLEncoding();
78      }
79  
80      public int hashCode() {
81          return _document.hashCode();
82      }
83  
84      public void setRootElement(Element rootElement) {
85          ElementImpl rootElementImpl = (ElementImpl)rootElement;
86  
87          _document.setRootElement(rootElementImpl.getWrappedElement());
88      }
89  
90      public void setXMLEncoding(String encoding) {
91          _document.setXMLEncoding(encoding);
92      }
93  
94      private org.dom4j.Document _document;
95  
96  }