001
014
015 package com.liferay.portal.xml;
016
017 import com.liferay.portal.kernel.xml.Document;
018 import com.liferay.portal.kernel.xml.DocumentType;
019 import com.liferay.portal.kernel.xml.Element;
020 import com.liferay.portal.kernel.xml.Visitor;
021 import com.liferay.util.xml.XMLFormatter;
022
023 import java.io.IOException;
024
025
028 public class DocumentImpl extends BranchImpl implements Document {
029
030 public DocumentImpl(org.dom4j.Document document) {
031 super(document);
032
033 _document = document;
034 }
035
036 @Override
037 public <T, V extends Visitor<T>> T accept(V visitor) {
038 return visitor.visitDocument(this);
039 }
040
041 public Document addComment(String comment) {
042 _document.addComment(comment);
043
044 return this;
045 }
046
047 public Document addDocumentType(
048 String name, String publicId, String systemId) {
049
050 _document.addDocType(name, publicId, systemId);
051
052 return this;
053 }
054
055 @Override
056 public boolean equals(Object obj) {
057 org.dom4j.Document document = ((DocumentImpl)obj).getWrappedDocument();
058
059 return _document.equals(document);
060 }
061
062 @Override
063 public String formattedString() throws IOException {
064 return XMLFormatter.toString(_document);
065 }
066
067 @Override
068 public String formattedString(String indent) throws IOException {
069 return XMLFormatter.toString(_document, indent);
070 }
071
072 @Override
073 public String formattedString(String indent, boolean expandEmptyElements)
074 throws IOException {
075
076 return XMLFormatter.toString(_document, indent, expandEmptyElements);
077 }
078
079 public String formattedString(
080 String indent, boolean expandEmptyElements, boolean trimText)
081 throws IOException {
082
083 return XMLFormatter.toString(
084 _document, indent, expandEmptyElements, trimText);
085 }
086
087 public DocumentType getDocumentType() {
088 return new DocumentTypeImpl(_document.getDocType());
089 }
090
091 public Element getRootElement() {
092 return new ElementImpl(_document.getRootElement());
093 }
094
095 public org.dom4j.Document getWrappedDocument() {
096 return _document;
097 }
098
099 public String getXMLEncoding() {
100 return _document.getXMLEncoding();
101 }
102
103 @Override
104 public int hashCode() {
105 return _document.hashCode();
106 }
107
108 public void setRootElement(Element rootElement) {
109 ElementImpl rootElementImpl = (ElementImpl)rootElement;
110
111 _document.setRootElement(rootElementImpl.getWrappedElement());
112 }
113
114 public void setXMLEncoding(String encoding) {
115 _document.setXMLEncoding(encoding);
116 }
117
118 @Override
119 public String toString() {
120 return _document.toString();
121 }
122
123 private org.dom4j.Document _document;
124
125 }