001: /**
002: * org/ozone-db/xml/dom/TextImpl.java
003: *
004: * The contents of this file are subject to the OpenXML Public
005: * License Version 1.0; you may not use this file except in compliance
006: * with the License. You may obtain a copy of the License at
007: * http://www.openxml.org/license.html
008: *
009: * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
010: * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
011: * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
012: * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
013: * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
014: * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
015: *
016: * The Initial Developer of this code under the License is Assaf Arkin.
017: * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
018: * All Rights Reserved.
019: *
020: * The Initial Developer of this code under the License is Assaf Arkin.
021: * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
022: * All Rights Reserved.
023: */
024:
025: /**
026: * Changes for Persistent DOM running with ozone are
027: * Copyright 1999 by SMB GmbH. All rights reserved.
028: */package org.ozoneDB.xml.dom;
029:
030: import org.w3c.dom.*;
031:
032: /**
033: * Implements the textual content (termed character data) of a {@link
034: * org.w3c.dom.Element} or {@link org.w3c.dom.Attr}. If there is no markup
035: * inside an element's content, the text is contained in a single object
036: * implementing the {@link org.w3c.dom.Text} interface; if there is markup,
037: * it is parsed into a list of elements and {@link org.w3c.dom.Text} nodes
038: * that form the list of children of the element.
039: * <P>
040: * Notes:
041: * <OLl>
042: * <LI>Node type is {@link org.w3c.dom.Node#TEXT_NODE}
043: * <LI>Node does not support childern
044: * <LI>Node name is always "#text"
045: * <LI>One of two nodes that may be added to an attribute
046: * </OL>
047: *
048: *
049: * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
050: * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a>
051: * @see org.w3c.dom.Text
052: * @see CharacterDataImpl
053: */
054: public class TextImpl extends CharacterDataImpl implements TextProxy {
055:
056: final static long serialVersionUID = 1;
057:
058: public short getNodeType() {
059: return TEXT_NODE;
060: }
061:
062: public synchronized final Text splitText(int offset)
063: throws DOMException {
064: TextProxy next = null;
065:
066: if (isReadOnly()) {
067: throw new DOMExceptionImpl(
068: DOMException.NO_MODIFICATION_ALLOWED_ERR);
069: }
070: if (offset < 0 || offset > getLength()) {
071: throw new DOMExceptionImpl(DOMException.INDEX_SIZE_ERR,
072: "Offest is negative or greater than text size.");
073: }
074: // Create new Text node, splice the first section and place it in the new
075: // text node, then add it before this node. Splice the second section and
076: // place it in the existing node. Note that this Text node might not have
077: // a parent.
078: try {
079: next = (TextProxy) database().createObject(
080: TextImpl.class.getName());
081: next.init(_ownerDocument, substringData(0, offset));
082: } catch (Exception except) {
083: throw new DOMExceptionImpl(DOMExceptionImpl.PDOM_ERR,
084: except.getMessage());
085: }
086: if (getParentNode() != null) {
087: getParentNode().insertBefore(next, this );
088: }
089: setData(substringData(offset, getLength() - offset));
090: return next;
091: }
092:
093: public String toString() {
094: String value;
095:
096: value = getData();
097: if (value.length() > 64) {
098: value = value.substring(0, 64) + "..";
099: }
100: value = value.replace('\n', '|');
101: return "Text node: [" + value + "]";
102: }
103:
104: public Object clone() {
105: TextProxy clone = null;
106: try {
107: clone = (TextProxy) database().createObject(
108: TextImpl.class.getName());
109: clone.init(_ownerDocument, getNodeValue());
110: cloneInto((NodeProxy) clone, true);
111: } catch (Exception except) {
112: throw new DOMExceptionImpl(DOMExceptionImpl.PDOM_ERR,
113: except.getMessage());
114: }
115: return clone;
116: }
117:
118: public Node cloneNode(boolean deep) {
119: TextProxy clone = null;
120: try {
121: clone = (TextProxy) database().createObject(
122: TextImpl.class.getName());
123: clone.init(_ownerDocument, getNodeValue());
124: cloneInto((NodeProxy) clone, deep);
125: } catch (Exception except) {
126: throw new DOMExceptionImpl(DOMExceptionImpl.PDOM_ERR,
127: except.getMessage());
128: }
129: return clone;
130: }
131:
132: /**
133: * Constructor requires only owner document and initial text.
134: *
135: * @param owner The owner of this document
136: * @param text The initial text
137: */
138: TextImpl(DocumentImpl owner, String text) {
139: super (owner, "#text", text);
140: }
141:
142: /**
143: * Constructor for {@link CDATASectionImpl}.
144: */
145: TextImpl(DocumentImpl owner, String name, String text) {
146: super (owner, name, text);
147: }
148:
149: public TextImpl() {
150: super ();
151: }
152:
153: public void init(DocumentProxy owner, String text) {
154: super .init(owner, "#text", text);
155: }
156: }
|