001: /*
002: * Java HTML Tidy - JTidy
003: * HTML parser and pretty printer
004: *
005: * Copyright (c) 1998-2000 World Wide Web Consortium (Massachusetts
006: * Institute of Technology, Institut National de Recherche en
007: * Informatique et en Automatique, Keio University). All Rights
008: * Reserved.
009: *
010: * Contributing Author(s):
011: *
012: * Dave Raggett <dsr@w3.org>
013: * Andy Quick <ac.quick@sympatico.ca> (translation to Java)
014: * Gary L Peskin <garyp@firstech.com> (Java development)
015: * Sami Lempinen <sami@lempinen.net> (release management)
016: * Fabrizio Giustina <fgiust at users.sourceforge.net>
017: *
018: * The contributing author(s) would like to thank all those who
019: * helped with testing, bug fixes, and patience. This wouldn't
020: * have been possible without all of you.
021: *
022: * COPYRIGHT NOTICE:
023: *
024: * This software and documentation is provided "as is," and
025: * the copyright holders and contributing author(s) make no
026: * representations or warranties, express or implied, including
027: * but not limited to, warranties of merchantability or fitness
028: * for any particular purpose or that the use of the software or
029: * documentation will not infringe any third party patents,
030: * copyrights, trademarks or other rights.
031: *
032: * The copyright holders and contributing author(s) will not be
033: * liable for any direct, indirect, special or consequential damages
034: * arising out of any use of the software or documentation, even if
035: * advised of the possibility of such damage.
036: *
037: * Permission is hereby granted to use, copy, modify, and distribute
038: * this source code, or portions hereof, documentation and executables,
039: * for any purpose, without fee, subject to the following restrictions:
040: *
041: * 1. The origin of this source code must not be misrepresented.
042: * 2. Altered versions must be plainly marked as such and must
043: * not be misrepresented as being the original source.
044: * 3. This Copyright notice may not be removed or altered from any
045: * source or altered source distribution.
046: *
047: * The copyright holders and contributing author(s) specifically
048: * permit, without fee, and encourage the use of this source code
049: * as a component for supporting the Hypertext Markup Language in
050: * commercial products. If you use this source code in a product,
051: * acknowledgment is not required but would be appreciated.
052: *
053: */
054: package org.w3c.tidy;
055:
056: import org.w3c.dom.DOMException;
057:
058: /**
059: * Tidy implementation of org.w3c.dom.CharacterData.
060: * @author Dave Raggett <a href="mailto:dsr@w3.org">dsr@w3.org </a>
061: * @author Andy Quick <a href="mailto:ac.quick@sympatico.ca">ac.quick@sympatico.ca </a> (translation to Java)
062: * @author Fabrizio Giustina
063: * @version $Revision: 1.7 $ ($Author: fgiust $)
064: */
065: public class DOMCharacterDataImpl extends DOMNodeImpl implements
066: org.w3c.dom.CharacterData {
067:
068: /**
069: * Instantiates a new DOMCharacterDataImpl which wraps the given Node.
070: * @param adaptee wrapped node.
071: */
072: protected DOMCharacterDataImpl(Node adaptee) {
073: super (adaptee);
074: }
075:
076: /**
077: * @see org.w3c.dom.CharacterData#getData
078: */
079: public String getData() throws DOMException {
080: return getNodeValue();
081: }
082:
083: /**
084: * @see org.w3c.dom.CharacterData#getLength
085: */
086: public int getLength() {
087: int len = 0;
088: if (adaptee.textarray != null && adaptee.start < adaptee.end) {
089: len = adaptee.end - adaptee.start;
090: }
091: return len;
092: }
093:
094: /**
095: * @see org.w3c.dom.CharacterData#substringData
096: */
097: public String substringData(int offset, int count)
098: throws DOMException {
099: int len;
100: String value = null;
101: if (count < 0) {
102: throw new DOMException(DOMException.INDEX_SIZE_ERR,
103: "Invalid length");
104: }
105: if (adaptee.textarray != null && adaptee.start < adaptee.end) {
106: if (adaptee.start + offset >= adaptee.end) {
107: throw new DOMException(DOMException.INDEX_SIZE_ERR,
108: "Invalid offset");
109: }
110: len = count;
111: if (adaptee.start + offset + len - 1 >= adaptee.end) {
112: len = adaptee.end - adaptee.start - offset;
113: }
114:
115: value = TidyUtils.getString(adaptee.textarray,
116: adaptee.start + offset, len);
117: }
118: return value;
119: }
120:
121: /**
122: * Not supported.
123: * @see org.w3c.dom.CharacterData#setData
124: */
125: public void setData(String data) throws DOMException {
126: // NOT SUPPORTED
127: throw new DOMException(
128: DOMException.NO_MODIFICATION_ALLOWED_ERR,
129: "Not supported");
130: }
131:
132: /**
133: * Not supported.
134: * @see org.w3c.dom.CharacterData#appendData
135: */
136: public void appendData(String arg) throws DOMException {
137: // NOT SUPPORTED
138: throw new DOMException(
139: DOMException.NO_MODIFICATION_ALLOWED_ERR,
140: "Not supported");
141: }
142:
143: /**
144: * Not supported.
145: * @see org.w3c.dom.CharacterData#insertData
146: */
147: public void insertData(int offset, String arg) throws DOMException {
148: // NOT SUPPORTED
149: throw new DOMException(
150: DOMException.NO_MODIFICATION_ALLOWED_ERR,
151: "Not supported");
152: }
153:
154: /**
155: * Not supported.
156: * @see org.w3c.dom.CharacterData#deleteData
157: */
158: public void deleteData(int offset, int count) throws DOMException {
159: // NOT SUPPORTED
160: throw new DOMException(
161: DOMException.NO_MODIFICATION_ALLOWED_ERR,
162: "Not supported");
163: }
164:
165: /**
166: * Not supported.
167: * @see org.w3c.dom.CharacterData#replaceData
168: */
169: public void replaceData(int offset, int count, String arg)
170: throws DOMException {
171: // NOT SUPPORTED
172: throw new DOMException(
173: DOMException.NO_MODIFICATION_ALLOWED_ERR,
174: "Not supported");
175: }
176:
177: }
|