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 java.lang.reflect.Method; 022 023import lucee.runtime.exp.PageRuntimeException; 024import lucee.runtime.op.Caster; 025import lucee.runtime.type.Collection; 026import lucee.runtime.type.util.ArrayUtil; 027 028import org.w3c.dom.CDATASection; 029import org.w3c.dom.DOMException; 030import org.w3c.dom.Node; 031import org.w3c.dom.Text; 032 033/** 034 * 035 */ 036public final class XMLCDATASectionStruct extends XMLNodeStruct implements CDATASection { 037 038 private CDATASection section; 039 040 /** 041 * constructor of the class 042 * @param section 043 * @param caseSensitive 044 */ 045 public XMLCDATASectionStruct(CDATASection section, boolean caseSensitive) { 046 super(section,caseSensitive); 047 this.section=section; 048 } 049 050 @Override 051 public Text splitText(int offset) throws DOMException { 052 return section.splitText(offset); 053 } 054 055 @Override 056 public int getLength() { 057 return section.getLength(); 058 } 059 060 @Override 061 public void deleteData(int offset, int count) throws DOMException { 062 section.deleteData(offset,count); 063 } 064 065 @Override 066 public String getData() throws DOMException { 067 return section.getData(); 068 } 069 070 @Override 071 public String substringData(int offset, int count) throws DOMException { 072 return section.substringData(offset,count); 073 } 074 075 @Override 076 public void replaceData(int offset, int count, String arg) 077 throws DOMException { 078 section.replaceData(offset,count,arg); 079 } 080 081 @Override 082 public void insertData(int offset, String arg) throws DOMException { 083 section.insertData(offset,arg); 084 } 085 086 @Override 087 public void appendData(String arg) throws DOMException { 088 section.appendData(arg); 089 } 090 091 @Override 092 public void setData(String data) throws DOMException { 093 section.setData(data); 094 } 095 096 public String getWholeText() { 097 // dynamic load to support jre 1.4 and 1.5 098 try { 099 Method m = section.getClass().getMethod("getWholeText", new Class[]{}); 100 return Caster.toString(m.invoke(section, ArrayUtil.OBJECT_EMPTY)); 101 } 102 catch (Exception e) { 103 throw new PageRuntimeException(Caster.toPageException(e)); 104 } 105 } 106 107 public boolean isElementContentWhitespace() { 108 // dynamic load to support jre 1.4 and 1.5 109 try { 110 Method m = section.getClass().getMethod("isElementContentWhitespace", new Class[]{}); 111 return Caster.toBooleanValue(m.invoke(section, ArrayUtil.OBJECT_EMPTY)); 112 } 113 catch (Exception e) { 114 throw new PageRuntimeException(Caster.toPageException(e)); 115 } 116 } 117 118 public Text replaceWholeText(String arg0) throws DOMException { 119 // dynamic load to support jre 1.4 and 1.5 120 try { 121 Method m = section.getClass().getMethod("replaceWholeText", new Class[]{arg0.getClass()}); 122 return (Text)m.invoke(section, new Object[]{arg0}); 123 } 124 catch (Exception e) { 125 throw new PageRuntimeException(Caster.toPageException(e)); 126 } 127 } 128 129 130 131 @Override 132 public Collection duplicate(boolean deepCopy) { 133 return new XMLCDATASectionStruct((CDATASection)section.cloneNode(deepCopy),caseSensitive); 134 } 135 136 137 @Override 138 public Node cloneNode(boolean deep) { 139 return new XMLCDATASectionStruct((CDATASection)section.cloneNode(deep),caseSensitive); 140 } 141 142}