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