001 package railo.runtime.text.xml.struct; 002 003 import org.w3c.dom.DOMException; 004 import org.w3c.dom.Document; 005 import org.w3c.dom.Node; 006 import org.w3c.dom.Text; 007 008 import railo.runtime.text.xml.XMLCaster; 009 import railo.runtime.text.xml.XMLUtil; 010 import railo.runtime.type.Collection; 011 012 /** 013 * 014 */ 015 public final class XMLTextStruct extends XMLNodeStruct implements Text { 016 017 018 private Text text; 019 020 /** 021 * @param text 022 * @param caseSensitive 023 */ 024 public XMLTextStruct(Text text, boolean caseSensitive) { 025 super(text,caseSensitive); 026 this.text=text; 027 } 028 029 /** 030 * @see org.w3c.dom.Text#splitText(int) 031 */ 032 public Text splitText(int offset) throws DOMException { 033 return text.splitText(offset); 034 } 035 036 /** 037 * @see org.w3c.dom.CharacterData#getLength() 038 */ 039 public int getLength() { 040 return text.getLength(); 041 } 042 043 /** 044 * @see org.w3c.dom.CharacterData#deleteData(int, int) 045 */ 046 public void deleteData(int offset, int count) throws DOMException { 047 text.deleteData(offset,count); 048 } 049 050 /** 051 * @see org.w3c.dom.CharacterData#getData() 052 */ 053 public String getData() throws DOMException { 054 return text.getData(); 055 } 056 057 /** 058 * @see org.w3c.dom.CharacterData#substringData(int, int) 059 */ 060 public String substringData(int offset, int count) throws DOMException { 061 return text.substringData(offset,count); 062 } 063 064 /** 065 * @see org.w3c.dom.CharacterData#replaceData(int, int, java.lang.String) 066 */ 067 public void replaceData(int offset, int count, String arg) 068 throws DOMException { 069 text.replaceData(offset,count,arg); 070 } 071 072 /** 073 * @see org.w3c.dom.CharacterData#insertData(int, java.lang.String) 074 */ 075 public void insertData(int offset, String arg) throws DOMException { 076 text.insertData(offset,arg); 077 } 078 079 /** 080 * @see org.w3c.dom.CharacterData#appendData(java.lang.String) 081 */ 082 public void appendData(String arg) throws DOMException { 083 text.appendData(arg); 084 } 085 086 /** 087 * @see org.w3c.dom.CharacterData#setData(java.lang.String) 088 */ 089 public void setData(String data) throws DOMException { 090 text.setData(data); 091 } 092 093 /** 094 * @see org.w3c.dom.Text#isElementContentWhitespace() 095 */ 096 public boolean isElementContentWhitespace() { 097 return text.getNodeValue().trim().length()==0; 098 } 099 100 /** 101 * @see org.w3c.dom.Text#getWholeText() 102 */ 103 public String getWholeText() { 104 return text.getNodeValue(); 105 } 106 107 /** 108 * @see org.w3c.dom.Text#replaceWholeText(java.lang.String) 109 */ 110 public Text replaceWholeText(String content) throws DOMException { 111 Text oldText = text; 112 Document doc = XMLUtil.getDocument(text); 113 Text newText = doc.createTextNode(content); 114 Node parent = oldText.getParentNode(); 115 parent.replaceChild(XMLCaster.toRawNode(newText),XMLCaster.toRawNode(oldText)); 116 return oldText; 117 } 118 119 120 /** 121 * 122 * @see railo.runtime.type.Collection#duplicate(boolean) 123 */ 124 public Collection duplicate(boolean deepCopy) { 125 return new XMLTextStruct((Text)text.cloneNode(deepCopy),caseSensitive); 126 } 127 128 129 /** 130 * @see org.w3c.dom.Node#cloneNode(boolean) 131 */ 132 public Node cloneNode(boolean deep) { 133 return new XMLTextStruct((Text)text.cloneNode(deep),caseSensitive); 134 } 135 136 137 }