001    /**
002     * Copyright (c) 2000-2013 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 boolean equals(Object obj) {
056                    if (this == obj) {
057                            return true;
058                    }
059    
060                    if (!(obj instanceof DocumentImpl)) {
061                            return false;
062                    }
063    
064                    org.dom4j.Document document = ((DocumentImpl)obj).getWrappedDocument();
065    
066                    return _document.equals(document);
067            }
068    
069            @Override
070            public DocumentType getDocumentType() {
071                    return new DocumentTypeImpl(_document.getDocType());
072            }
073    
074            @Override
075            public Element getRootElement() {
076                    return new ElementImpl(_document.getRootElement());
077            }
078    
079            public org.dom4j.Document getWrappedDocument() {
080                    return _document;
081            }
082    
083            @Override
084            public String getXMLEncoding() {
085                    return _document.getXMLEncoding();
086            }
087    
088            @Override
089            public int hashCode() {
090                    return _document.hashCode();
091            }
092    
093            @Override
094            public void setRootElement(Element rootElement) {
095                    ElementImpl rootElementImpl = (ElementImpl)rootElement;
096    
097                    _document.setRootElement(rootElementImpl.getWrappedElement());
098            }
099    
100            @Override
101            public void setXMLEncoding(String encoding) {
102                    _document.setXMLEncoding(encoding);
103            }
104    
105            @Override
106            public String toString() {
107                    return _document.toString();
108            }
109    
110            private org.dom4j.Document _document;
111    
112    }