001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class DocumentImpl extends BranchImpl implements Document {
026    
027            public DocumentImpl(org.dom4j.Document document) {
028                    super(document);
029    
030                    _document = document;
031            }
032    
033            @Override
034            public <T, V extends Visitor<T>> T accept(V visitor) {
035                    return visitor.visitDocument(this);
036            }
037    
038            @Override
039            public Document addComment(String comment) {
040                    _document.addComment(comment);
041    
042                    return this;
043            }
044    
045            @Override
046            public Document addDocumentType(
047                    String name, String publicId, String systemId) {
048    
049                    _document.addDocType(name, publicId, systemId);
050    
051                    return this;
052            }
053    
054            @Override
055            public Document clone() {
056                    return new DocumentImpl((org.dom4j.Document)_document.clone());
057            }
058    
059            @Override
060            public boolean equals(Object obj) {
061                    if (this == obj) {
062                            return true;
063                    }
064    
065                    if (!(obj instanceof DocumentImpl)) {
066                            return false;
067                    }
068    
069                    org.dom4j.Document document = ((DocumentImpl)obj).getWrappedDocument();
070    
071                    return _document.equals(document);
072            }
073    
074            @Override
075            public DocumentType getDocumentType() {
076                    return new DocumentTypeImpl(_document.getDocType());
077            }
078    
079            @Override
080            public Element getRootElement() {
081                    return new ElementImpl(_document.getRootElement());
082            }
083    
084            public org.dom4j.Document getWrappedDocument() {
085                    return _document;
086            }
087    
088            @Override
089            public String getXMLEncoding() {
090                    return _document.getXMLEncoding();
091            }
092    
093            @Override
094            public int hashCode() {
095                    return _document.hashCode();
096            }
097    
098            @Override
099            public void setRootElement(Element rootElement) {
100                    ElementImpl rootElementImpl = (ElementImpl)rootElement;
101    
102                    _document.setRootElement(rootElementImpl.getWrappedElement());
103            }
104    
105            @Override
106            public void setXMLEncoding(String encoding) {
107                    _document.setXMLEncoding(encoding);
108            }
109    
110            @Override
111            public String toString() {
112                    return _document.toString();
113            }
114    
115            private final org.dom4j.Document _document;
116    
117    }