001    /**
002     * Copyright (c) 2000-2012 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            public Document addComment(String comment) {
039                    _document.addComment(comment);
040    
041                    return this;
042            }
043    
044            public Document addDocumentType(
045                    String name, String publicId, String systemId) {
046    
047                    _document.addDocType(name, publicId, systemId);
048    
049                    return this;
050            }
051    
052            @Override
053            public boolean equals(Object obj) {
054                    org.dom4j.Document document = ((DocumentImpl)obj).getWrappedDocument();
055    
056                    return _document.equals(document);
057            }
058    
059            public DocumentType getDocumentType() {
060                    return new DocumentTypeImpl(_document.getDocType());
061            }
062    
063            public Element getRootElement() {
064                    return new ElementImpl(_document.getRootElement());
065            }
066    
067            public org.dom4j.Document getWrappedDocument() {
068                    return _document;
069            }
070    
071            public String getXMLEncoding() {
072                    return _document.getXMLEncoding();
073            }
074    
075            @Override
076            public int hashCode() {
077                    return _document.hashCode();
078            }
079    
080            public void setRootElement(Element rootElement) {
081                    ElementImpl rootElementImpl = (ElementImpl)rootElement;
082    
083                    _document.setRootElement(rootElementImpl.getWrappedElement());
084            }
085    
086            public void setXMLEncoding(String encoding) {
087                    _document.setXMLEncoding(encoding);
088            }
089    
090            @Override
091            public String toString() {
092                    return _document.toString();
093            }
094    
095            private org.dom4j.Document _document;
096    
097    }