View Javadoc

1   /*
2    *  Java HTML Tidy - JTidy
3    *  HTML parser and pretty printer
4    *
5    *  Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
6    *  Institute of Technology, Institut National de Recherche en
7    *  Informatique et en Automatique, Keio University). All Rights
8    *  Reserved.
9    *
10   *  Contributing Author(s):
11   *
12   *     Dave Raggett <dsr@w3.org>
13   *     Andy Quick <ac.quick@sympatico.ca> (translation to Java)
14   *     Gary L Peskin <garyp@firstech.com> (Java development)
15   *     Sami Lempinen <sami@lempinen.net> (release management)
16   *     Fabrizio Giustina <fgiust at users.sourceforge.net>
17   *
18   *  The contributing author(s) would like to thank all those who
19   *  helped with testing, bug fixes, and patience.  This wouldn't
20   *  have been possible without all of you.
21   *
22   *  COPYRIGHT NOTICE:
23   * 
24   *  This software and documentation is provided "as is," and
25   *  the copyright holders and contributing author(s) make no
26   *  representations or warranties, express or implied, including
27   *  but not limited to, warranties of merchantability or fitness
28   *  for any particular purpose or that the use of the software or
29   *  documentation will not infringe any third party patents,
30   *  copyrights, trademarks or other rights. 
31   *
32   *  The copyright holders and contributing author(s) will not be
33   *  liable for any direct, indirect, special or consequential damages
34   *  arising out of any use of the software or documentation, even if
35   *  advised of the possibility of such damage.
36   *
37   *  Permission is hereby granted to use, copy, modify, and distribute
38   *  this source code, or portions hereof, documentation and executables,
39   *  for any purpose, without fee, subject to the following restrictions:
40   *
41   *  1. The origin of this source code must not be misrepresented.
42   *  2. Altered versions must be plainly marked as such and must
43   *     not be misrepresented as being the original source.
44   *  3. This Copyright notice may not be removed or altered from any
45   *     source or altered source distribution.
46   * 
47   *  The copyright holders and contributing author(s) specifically
48   *  permit, without fee, and encourage the use of this source code
49   *  as a component for supporting the Hypertext Markup Language in
50   *  commercial products. If you use this source code in a product,
51   *  acknowledgment is not required but would be appreciated.
52   *
53   */
54  package org.w3c.tidy;
55  
56  import org.w3c.dom.DOMException;
57  
58  
59  /**
60   * Tidy implementation of org.w3c.dom.CharacterData.
61   * @author Dave Raggett <a href="mailto:dsr@w3.org">dsr@w3.org </a>
62   * @author Andy Quick <a href="mailto:ac.quick@sympatico.ca">ac.quick@sympatico.ca </a> (translation to Java)
63   * @author Fabrizio Giustina
64   * @version $Revision: 779 $ ($Author: fgiust $)
65   */
66  public class DOMCharacterDataImpl extends DOMNodeImpl implements org.w3c.dom.CharacterData
67  {
68  
69      /**
70       * Instantiates a new DOMCharacterDataImpl which wraps the given Node.
71       * @param adaptee wrapped node.
72       */
73      protected DOMCharacterDataImpl(Node adaptee)
74      {
75          super(adaptee);
76      }
77  
78      /**
79       * @see org.w3c.dom.CharacterData#getData
80       */
81      public String getData() throws DOMException
82      {
83          return getNodeValue();
84      }
85  
86      /**
87       * @see org.w3c.dom.CharacterData#getLength
88       */
89      public int getLength()
90      {
91          int len = 0;
92          if (adaptee.textarray != null && adaptee.start < adaptee.end)
93          {
94              len = adaptee.end - adaptee.start;
95          }
96          return len;
97      }
98  
99      /**
100      * @see org.w3c.dom.CharacterData#substringData
101      */
102     public String substringData(int offset, int count) throws DOMException
103     {
104         int len;
105         String value = null;
106         if (count < 0)
107         {
108             throw new DOMException(DOMException.INDEX_SIZE_ERR, "Invalid length");
109         }
110         if (adaptee.textarray != null && adaptee.start < adaptee.end)
111         {
112             if (adaptee.start + offset >= adaptee.end)
113             {
114                 throw new DOMException(DOMException.INDEX_SIZE_ERR, "Invalid offset");
115             }
116             len = count;
117             if (adaptee.start + offset + len - 1 >= adaptee.end)
118             {
119                 len = adaptee.end - adaptee.start - offset;
120             }
121 
122             value = TidyUtils.getString(adaptee.textarray, adaptee.start + offset, len);
123         }
124         return value;
125     }
126 
127     /**
128      * Not supported.
129      * @see org.w3c.dom.CharacterData#setData
130      */
131     public void setData(String data) throws DOMException
132     {
133         // NOT SUPPORTED
134         throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Not supported");
135     }
136 
137     /**
138      * Not supported.
139      * @see org.w3c.dom.CharacterData#appendData
140      */
141     public void appendData(String arg) throws DOMException
142     {
143         // NOT SUPPORTED
144         throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Not supported");
145     }
146 
147     /**
148      * Not supported.
149      * @see org.w3c.dom.CharacterData#insertData
150      */
151     public void insertData(int offset, String arg) throws DOMException
152     {
153         // NOT SUPPORTED
154         throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Not supported");
155     }
156 
157     /**
158      * Not supported.
159      * @see org.w3c.dom.CharacterData#deleteData
160      */
161     public void deleteData(int offset, int count) throws DOMException
162     {
163         // NOT SUPPORTED
164         throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Not supported");
165     }
166 
167     /**
168      * Not supported.
169      * @see org.w3c.dom.CharacterData#replaceData
170      */
171     public void replaceData(int offset, int count, String arg) throws DOMException
172     {
173         // NOT SUPPORTED
174         throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "Not supported");
175     }
176 
177 }