View Javadoc

1   /*
2    * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
3    * 
4    * This software is open source. 
5    * See the bottom of this file for the licence.
6    * 
7    * $Id: AbstractCharacterData.java,v 1.10 2004/06/25 08:03:41 maartenc Exp $
8    */
9   
10  package org.dom4j.tree;
11  
12  import org.dom4j.CharacterData;
13  import org.dom4j.Element;
14  
15  /*** <p><code>AbstractCharacterData</code> is an abstract base class for 
16    * tree implementors to use for implementation inheritence.</p>
17    *
18    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
19    * @version $Revision: 1.10 $
20    */
21  public abstract class AbstractCharacterData extends AbstractNode implements CharacterData {
22  
23      public AbstractCharacterData() {
24      }
25      
26      public String getPath(Element context) {
27          Element parent = getParent();
28          return ( parent != null && parent != context ) 
29              ? parent.getPath( context ) + "/text()"
30              : "text()";
31      }
32      
33      public String getUniquePath(Element context) {
34          Element parent = getParent();
35          return ( parent != null && parent != context ) 
36              ? parent.getUniquePath( context ) + "/text()"
37              : "text()";
38      }
39  
40      public void appendText(String text) {
41          setText( getText() + text );
42      }
43  }
44  
45  
46  
47  
48  /*
49   * Redistribution and use of this software and associated documentation
50   * ("Software"), with or without modification, are permitted provided
51   * that the following conditions are met:
52   *
53   * 1. Redistributions of source code must retain copyright
54   *    statements and notices.  Redistributions must also contain a
55   *    copy of this document.
56   *
57   * 2. Redistributions in binary form must reproduce the
58   *    above copyright notice, this list of conditions and the
59   *    following disclaimer in the documentation and/or other
60   *    materials provided with the distribution.
61   *
62   * 3. The name "DOM4J" must not be used to endorse or promote
63   *    products derived from this Software without prior written
64   *    permission of MetaStuff, Ltd.  For written permission,
65   *    please contact dom4j-info@metastuff.com.
66   *
67   * 4. Products derived from this Software may not be called "DOM4J"
68   *    nor may "DOM4J" appear in their names without prior written
69   *    permission of MetaStuff, Ltd. DOM4J is a registered
70   *    trademark of MetaStuff, Ltd.
71   *
72   * 5. Due credit should be given to the DOM4J Project - 
73   *    http://www.dom4j.org
74   *
75   * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS
76   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
77   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
78   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
79   * METASTUFF, LTD. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
80   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
81   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
82   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
83   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
84   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
85   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
86   * OF THE POSSIBILITY OF SUCH DAMAGE.
87   *
88   * Copyright 2001-2004 (C) MetaStuff, Ltd. All Rights Reserved.
89   *
90   * $Id: AbstractCharacterData.java,v 1.10 2004/06/25 08:03:41 maartenc Exp $
91   */