2
* The Apache Software License, Version 1.1
5
* Copyright (c) 1999-2002 The Apache Software Foundation. All rights
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in
17
* the documentation and/or other materials provided with the
20
* 3. The end-user documentation included with the redistribution,
21
* if any, must include the following acknowledgment:
22
* "This product includes software developed by the
23
* Apache Software Foundation (http://www.apache.org/)."
24
* Alternately, this acknowledgment may appear in the software itself,
25
* if and wherever such third-party acknowledgments normally appear.
27
* 4. The names "Xerces" and "Apache Software Foundation" must
28
* not be used to endorse or promote products derived from this
29
* software without prior written permission. For written
30
* permission, please contact apache@apache.org.
32
* 5. Products derived from this software may not be called "Apache",
33
* nor may "Apache" appear in their name, without prior written
34
* permission of the Apache Software Foundation.
36
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48
* ====================================================================
50
* This software consists of voluntary contributions made by many
51
* individuals on behalf of the Apache Software Foundation and was
52
* originally based on software copyright (c) 1999, International
53
* Business Machines, Inc., http://www.apache.org. For more
54
* information on the Apache Software Foundation, please see
55
* <http://www.apache.org/>.
2
* Copyright 1999-2002,2004 The Apache Software Foundation.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
58
17
package org.apache.xerces.dom;
136
104
* from the high-level functions in CharacterData, and another
137
105
* type if the client simply calls setNodeValue(value).
139
protected void setNodeValueInternal(String value) {
107
protected void setNodeValueInternal(String value, boolean replace) {
109
CoreDocumentImpl ownerDocument = ownerDocument();
111
if (ownerDocument.errorChecking && isReadOnly()) {
141
112
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
142
113
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
144
116
// revisit: may want to set the value in ownerDocument.
145
// Default behavior, overridden in some subclasses
117
// Default behavior, overridden in some subclasses
146
118
if (needsSyncData()) {
147
119
synchronizeData();
150
122
// keep old value for document notification
151
123
String oldvalue = this.data;
153
CoreDocumentImpl ownerDocument = ownerDocument();
156
ownerDocument.modifyingCharacterData(this);
161
ownerDocument.modifiedCharacterData(this, oldvalue, value);
126
ownerDocument.modifyingCharacterData(this, replace);
131
ownerDocument.modifiedCharacterData(this, oldvalue, value, replace);
243
213
public void deleteData(int offset, int count)
244
214
throws DOMException {
247
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
248
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
252
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
253
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
216
internalDeleteData(offset, count, false);
217
} // deleteData(int,int)
220
/** NON-DOM INTERNAL: Within DOM actions, we sometimes need to be able
221
* to control which mutation events are spawned. This version of the
222
* deleteData operation allows us to do so. It is not intended
223
* for use by application programs.
225
void internalDeleteData (int offset, int count, boolean replace)
226
throws DOMException {
228
CoreDocumentImpl ownerDocument = ownerDocument();
229
if (ownerDocument.errorChecking) {
231
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
232
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
236
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
237
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
256
241
if (needsSyncData()) {
257
242
synchronizeData();
259
244
int tailLength = Math.max(data.length() - count - offset, 0);
261
246
String value = data.substring(0, offset) +
263
? data.substring(offset + count, offset + count + tailLength)
266
setNodeValueInternal(value);
247
(tailLength > 0 ? data.substring(offset + count, offset + count + tailLength) : "");
249
setNodeValueInternal(value, replace);
268
251
// notify document
269
ownerDocument().deletedText(this, offset, count);
252
ownerDocument.deletedText(this, offset, count);
271
254
catch (StringIndexOutOfBoundsException e) {
272
255
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
273
256
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
276
} // deleteData(int,int)
259
} // internalDeleteData(int,int,boolean)
279
262
* Insert additional characters into the data stored in this node,
287
270
public void insertData(int offset, String data)
288
271
throws DOMException {
273
internalInsertData(offset, data, false);
275
} // insertData(int,int)
279
/** NON-DOM INTERNAL: Within DOM actions, we sometimes need to be able
280
* to control which mutation events are spawned. This version of the
281
* insertData operation allows us to do so. It is not intended
282
* for use by application programs.
284
void internalInsertData (int offset, String data, boolean replace)
285
throws DOMException {
287
CoreDocumentImpl ownerDocument = ownerDocument();
289
if (ownerDocument.errorChecking && isReadOnly()) {
291
290
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
292
291
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
295
294
if (needsSyncData()) {
296
295
synchronizeData();
300
299
new StringBuffer(this.data).insert(offset, data).toString();
302
setNodeValueInternal(value);
302
setNodeValueInternal(value, replace);
304
304
// notify document
305
ownerDocument().insertedText(this, offset, data.length());
305
ownerDocument.insertedText(this, offset, data.length());
307
307
catch (StringIndexOutOfBoundsException e) {
308
308
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
309
309
throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
312
} // insertData(int,int)
312
} // internalInsertData(int,String,boolean)
315
317
* Replace a series of characters at the specified (zero-based)
316
318
* offset with a new string, NOT necessarily of the same
338
340
public void replaceData(int offset, int count, String data)
339
throws DOMException {
341
throws DOMException {
343
CoreDocumentImpl ownerDocument = ownerDocument();
341
345
// The read-only check is done by deleteData()
342
346
// ***** This could be more efficient w/r/t Mutation Events,
343
347
// specifically by aggregating DOMAttrModified and
344
348
// DOMSubtreeModified. But mutation events are
345
349
// underspecified; I don't feel compelled
346
350
// to deal with it right now.
347
deleteData(offset, count);
348
insertData(offset, data);
351
if (ownerDocument.errorChecking && isReadOnly()) {
352
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
353
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
356
if (needsSyncData()) {
361
ownerDocument.replacingData(this);
363
// keep old value for document notification
364
String oldvalue = this.data;
366
internalDeleteData(offset, count, true);
367
internalInsertData(offset, data, true);
369
ownerDocument.replacedCharacterData(this, oldvalue, this.data);
350
371
} // replaceData(int,int,String)