001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.text.xml.struct; 020 021import lucee.runtime.text.xml.XMLCaster; 022import lucee.runtime.text.xml.XMLUtil; 023import lucee.runtime.type.Collection; 024 025import org.w3c.dom.DOMException; 026import org.w3c.dom.Document; 027import org.w3c.dom.Node; 028import org.w3c.dom.Text; 029 030/** 031 * 032 */ 033public final class XMLTextStruct extends XMLNodeStruct implements Text { 034 035 036 private Text text; 037 038 /** 039 * @param text 040 * @param caseSensitive 041 */ 042 public XMLTextStruct(Text text, boolean caseSensitive) { 043 super(text,caseSensitive); 044 this.text=text; 045 } 046 047 @Override 048 public Text splitText(int offset) throws DOMException { 049 return text.splitText(offset); 050 } 051 052 @Override 053 public int getLength() { 054 return text.getLength(); 055 } 056 057 @Override 058 public void deleteData(int offset, int count) throws DOMException { 059 text.deleteData(offset,count); 060 } 061 062 @Override 063 public String getData() throws DOMException { 064 return text.getData(); 065 } 066 067 @Override 068 public String substringData(int offset, int count) throws DOMException { 069 return text.substringData(offset,count); 070 } 071 072 @Override 073 public void replaceData(int offset, int count, String arg) 074 throws DOMException { 075 text.replaceData(offset,count,arg); 076 } 077 078 @Override 079 public void insertData(int offset, String arg) throws DOMException { 080 text.insertData(offset,arg); 081 } 082 083 @Override 084 public void appendData(String arg) throws DOMException { 085 text.appendData(arg); 086 } 087 088 @Override 089 public void setData(String data) throws DOMException { 090 text.setData(data); 091 } 092 093 public boolean isElementContentWhitespace() { 094 return text.getNodeValue().trim().length()==0; 095 } 096 097 public String getWholeText() { 098 return text.getNodeValue(); 099 } 100 101 public Text replaceWholeText(String content) throws DOMException { 102 Text oldText = text; 103 Document doc = XMLUtil.getDocument(text); 104 Text newText = doc.createTextNode(content); 105 Node parent = oldText.getParentNode(); 106 parent.replaceChild(XMLCaster.toRawNode(newText),XMLCaster.toRawNode(oldText)); 107 return oldText; 108 } 109 110 111 @Override 112 public Collection duplicate(boolean deepCopy) { 113 return new XMLTextStruct((Text)text.cloneNode(deepCopy),caseSensitive); 114 } 115 116 117 @Override 118 public Node cloneNode(boolean deep) { 119 return new XMLTextStruct((Text)text.cloneNode(deep),caseSensitive); 120 } 121 122 123}