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        @Override
030        public Text splitText(int offset) throws DOMException {
031            return text.splitText(offset);
032        }
033    
034        @Override
035        public int getLength() {
036            return text.getLength();
037        }
038    
039        @Override
040        public void deleteData(int offset, int count) throws DOMException {
041            text.deleteData(offset,count);
042        }
043    
044        @Override
045        public String getData() throws DOMException {
046            return text.getData();
047        }
048    
049        @Override
050        public String substringData(int offset, int count) throws DOMException {
051            return text.substringData(offset,count);
052        }
053    
054        @Override
055        public void replaceData(int offset, int count, String arg)
056                throws DOMException {
057            text.replaceData(offset,count,arg);
058        }
059    
060        @Override
061        public void insertData(int offset, String arg) throws DOMException {
062            text.insertData(offset,arg);
063        }
064    
065        @Override
066        public void appendData(String arg) throws DOMException {
067            text.appendData(arg);
068        }
069    
070        @Override
071        public void setData(String data) throws DOMException {
072            text.setData(data);
073        }
074    
075        public boolean isElementContentWhitespace() {
076            return text.getNodeValue().trim().length()==0;
077        }
078    
079        public String getWholeText() {
080            return text.getNodeValue();
081        }
082    
083        public Text replaceWholeText(String content) throws DOMException {
084            Text oldText = text;
085            Document doc = XMLUtil.getDocument(text);
086            Text newText = doc.createTextNode(content);
087            Node parent = oldText.getParentNode();
088            parent.replaceChild(XMLCaster.toRawNode(newText),XMLCaster.toRawNode(oldText));
089            return oldText;
090        }
091        
092    
093            @Override
094            public Collection duplicate(boolean deepCopy) {
095                    return new XMLTextStruct((Text)text.cloneNode(deepCopy),caseSensitive);
096            }
097            
098    
099            @Override
100            public Node cloneNode(boolean deep) {
101                    return new XMLTextStruct((Text)text.cloneNode(deep),caseSensitive);
102            }
103    
104    
105    }