001/*
002 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
003 * 
004 * This software is open source. 
005 * See the bottom of this file for the licence.
006 * 
007 * $Id: AbstractComment.java,v 1.8 2001/07/25 10:51:11 jstrachan Exp $
008 */
009
010package org.dom4j.tree;
011
012import java.io.IOException;
013import java.io.Writer;
014
015import org.dom4j.Comment;
016import org.dom4j.Element;
017import org.dom4j.Visitor;
018
019/** <p><code>AbstractComment</code> is an abstract base class for 
020  * tree implementors to use for implementation inheritence.</p>
021  *
022  * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
023  * @version $Revision: 1.8 $
024  */
025public abstract class AbstractComment extends AbstractCharacterData implements Comment {
026
027    public AbstractComment() {
028    }
029
030    public short getNodeType() {
031        return COMMENT_NODE;
032    }
033
034    public String getPath(Element context) {
035        Element parent = getParent();
036        return ( parent != null && parent != context ) 
037            ? parent.getPath( context ) + "/comment()"
038            : "comment()";
039    }
040
041    public String getUniquePath(Element context) {
042        Element parent = getParent();
043        return ( parent != null && parent != context ) 
044            ? parent.getUniquePath( context ) + "/comment()"
045            : "comment()";
046    }
047
048
049    public String toString() {
050        return super.toString() + " [Comment: \"" + getText() + "\"]";
051    }
052
053    public String asXML() {
054        return "<!--" + getText() + "-->";
055    }
056    
057    public void write(Writer writer) throws IOException {
058        writer.write( "<!--" );
059        writer.write( getText() );
060        writer.write( "-->" );
061    }
062    
063    public void accept(Visitor visitor) {
064        visitor.visit(this);
065    }
066}
067
068
069
070
071/*
072 * Redistribution and use of this software and associated documentation
073 * ("Software"), with or without modification, are permitted provided
074 * that the following conditions are met:
075 *
076 * 1. Redistributions of source code must retain copyright
077 *    statements and notices.  Redistributions must also contain a
078 *    copy of this document.
079 *
080 * 2. Redistributions in binary form must reproduce the
081 *    above copyright notice, this list of conditions and the
082 *    following disclaimer in the documentation and/or other
083 *    materials provided with the distribution.
084 *
085 * 3. The name "DOM4J" must not be used to endorse or promote
086 *    products derived from this Software without prior written
087 *    permission of MetaStuff, Ltd.  For written permission,
088 *    please contact dom4j-info@metastuff.com.
089 *
090 * 4. Products derived from this Software may not be called "DOM4J"
091 *    nor may "DOM4J" appear in their names without prior written
092 *    permission of MetaStuff, Ltd. DOM4J is a registered
093 *    trademark of MetaStuff, Ltd.
094 *
095 * 5. Due credit should be given to the DOM4J Project
096 *    (http://dom4j.org/).
097 *
098 * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
099 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
100 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
101 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
102 * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
103 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
104 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
105 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
106 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
107 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
108 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
109 * OF THE POSSIBILITY OF SUCH DAMAGE.
110 *
111 * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved.
112 *
113 * $Id: AbstractComment.java,v 1.8 2001/07/25 10:51:11 jstrachan Exp $
114 */