001    package railo.runtime.text.xml.struct;
002    
003    import java.lang.reflect.Method;
004    
005    import org.w3c.dom.CDATASection;
006    import org.w3c.dom.DOMException;
007    import org.w3c.dom.Node;
008    import org.w3c.dom.Text;
009    
010    import railo.runtime.exp.PageRuntimeException;
011    import railo.runtime.op.Caster;
012    import railo.runtime.type.Collection;
013    import railo.runtime.type.util.ArrayUtil;
014    
015    /**
016     * 
017     */
018    public final class XMLCDATASectionStruct extends XMLNodeStruct implements CDATASection {
019    
020        private CDATASection section;
021    
022        /**
023         * constructor of the class
024         * @param section
025         * @param caseSensitive
026         */
027        public XMLCDATASectionStruct(CDATASection section, boolean caseSensitive) {
028            super(section,caseSensitive);
029            this.section=section;
030        }
031    
032        /**
033         * @see org.w3c.dom.Text#splitText(int)
034         */
035        public Text splitText(int offset) throws DOMException {
036            return section.splitText(offset);
037        }
038    
039        /**
040         * @see org.w3c.dom.CharacterData#getLength()
041         */
042        public int getLength() {
043            return section.getLength();
044        }
045    
046        /**
047         * @see org.w3c.dom.CharacterData#deleteData(int, int)
048         */
049        public void deleteData(int offset, int count) throws DOMException {
050            section.deleteData(offset,count);
051        }
052    
053        /**
054         * @see org.w3c.dom.CharacterData#getData()
055         */
056        public String getData() throws DOMException {
057            return section.getData();
058        }
059    
060        /**
061         * @see org.w3c.dom.CharacterData#substringData(int, int)
062         */
063        public String substringData(int offset, int count) throws DOMException {
064            return section.substringData(offset,count);
065        }
066    
067        /**
068         * @see org.w3c.dom.CharacterData#replaceData(int, int, java.lang.String)
069         */
070        public void replaceData(int offset, int count, String arg)
071                throws DOMException {
072            section.replaceData(offset,count,arg);
073        }
074    
075        /**
076         * @see org.w3c.dom.CharacterData#insertData(int, java.lang.String)
077         */
078        public void insertData(int offset, String arg) throws DOMException {
079            section.insertData(offset,arg);
080        }
081    
082        /**
083         * @see org.w3c.dom.CharacterData#appendData(java.lang.String)
084         */
085        public void appendData(String arg) throws DOMException {
086            section.appendData(arg);
087        }
088    
089        /**
090         *
091         * @see org.w3c.dom.CharacterData#setData(java.lang.String)
092         */
093        public void setData(String data) throws DOMException {
094            section.setData(data);
095        }
096    
097            /**
098             *
099             * @see org.w3c.dom.Text#getWholeText()
100             */
101            public String getWholeText() {
102            // dynamic load to support jre 1.4 and 1.5
103                    try {
104                            Method m = section.getClass().getMethod("getWholeText", new Class[]{});
105                            return Caster.toString(m.invoke(section, ArrayUtil.OBJECT_EMPTY));
106                    } 
107                    catch (Exception e) {
108                            throw new PageRuntimeException(Caster.toPageException(e));
109                    }
110            }
111    
112            /**
113             *
114             * @see org.w3c.dom.Text#isElementContentWhitespace()
115             */
116            public boolean isElementContentWhitespace() {
117            // dynamic load to support jre 1.4 and 1.5
118                    try {
119                            Method m = section.getClass().getMethod("isElementContentWhitespace", new Class[]{});
120                            return Caster.toBooleanValue(m.invoke(section, ArrayUtil.OBJECT_EMPTY));
121                    } 
122                    catch (Exception e) {
123                            throw new PageRuntimeException(Caster.toPageException(e));
124                    }
125            }
126    
127            /**
128             *
129             * @see org.w3c.dom.Text#replaceWholeText(java.lang.String)
130             */
131            public Text replaceWholeText(String arg0) throws DOMException {
132            // dynamic load to support jre 1.4 and 1.5
133                    try {
134                            Method m = section.getClass().getMethod("replaceWholeText", new Class[]{arg0.getClass()});
135                            return (Text)m.invoke(section, new Object[]{arg0});
136                    } 
137                    catch (Exception e) {
138                            throw new PageRuntimeException(Caster.toPageException(e));
139                    }
140            }
141            
142    
143            
144            /**
145             *
146             * @see railo.runtime.type.Collection#duplicate(boolean)
147             */
148            public Collection duplicate(boolean deepCopy) {
149                    return new XMLCDATASectionStruct((CDATASection)section.cloneNode(deepCopy),caseSensitive);
150            }
151            
152    
153            /**
154             * @see org.w3c.dom.Node#cloneNode(boolean)
155             */
156            public Node cloneNode(boolean deep) {
157                    return new XMLCDATASectionStruct((CDATASection)section.cloneNode(deep),caseSensitive);
158            }
159    
160    }