1 24 25 29 30 package org.ozoneDB.xml.dom; 31 32 import org.w3c.dom.*; 33 34 35 57 public class TextImpl extends CharacterDataImpl implements TextProxy { 58 59 final static long serialVersionUID = 1; 60 61 62 public short getNodeType() { 63 return TEXT_NODE; 64 } 65 66 67 public synchronized final Text splitText( int offset ) throws DOMException { 68 TextProxy next = null; 69 70 if (isReadOnly()) { 71 throw new DOMExceptionImpl( DOMException.NO_MODIFICATION_ALLOWED_ERR ); 72 } 73 if (offset < 0 || offset > getLength()) { 74 throw new DOMExceptionImpl( DOMException.INDEX_SIZE_ERR, "Offest is negative or greater than text size." ); 75 } 76 try { 81 next = (TextProxy)database().createObject( TextImpl.class.getName() ); 82 next.init( _ownerDocument, substringData( 0, offset ) ); 83 } catch (Exception except) { 84 throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() ); 85 } 86 if (getParentNode() != null) { 87 getParentNode().insertBefore( next, this ); 88 } 89 setData( substringData( offset, getLength() - offset ) ); 90 return next; 91 } 92 93 94 public String toString() { 95 String value; 96 97 value = getData(); 98 if (value.length() > 64) { 99 value = value.substring( 0, 64 ) + ".."; 100 } 101 value = value.replace( '\n', '|' ); 102 return "Text node: [" + value + "]"; 103 } 104 105 106 public Object clone() { 107 TextProxy clone = null; 108 try { 109 clone = (TextProxy)database().createObject( TextImpl.class.getName() ); 110 clone.init( _ownerDocument, getNodeValue() ); 111 cloneInto( clone, true ); 112 } catch (Exception except) { 113 throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() ); 114 } 115 return clone; 116 } 117 118 119 public Node cloneNode( boolean deep ) { 120 TextProxy clone = null; 121 try { 122 clone = (TextProxy)database().createObject( TextImpl.class.getName() ); 123 clone.init( _ownerDocument, getNodeValue() ); 124 cloneInto( clone, deep ); 125 } catch (Exception except) { 126 throw new DOMExceptionImpl( DOMExceptionImpl.PDOM_ERR, except.getMessage() ); 127 } 128 return clone; 129 } 130 131 132 138 TextImpl( DocumentImpl owner, String text ) { 139 super( owner, "#text", text ); 140 } 141 142 143 146 TextImpl( DocumentImpl owner, String name, String text ) { 147 super( owner, name, text ); 148 } 149 150 151 public TextImpl() { 152 super(); 153 } 154 155 156 public void init( DocumentProxy owner, String text ) { 157 super.init( owner, "#text", text ); 158 } 159 } 160 | Popular Tags |