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