int pos = txt.indexOf("<![CDATA[");
boolean hasCDATA = false;
if (pos > -1) { // check the content outside of the limits
String prefix = txt.substring(0, pos);
if (needsEncoding(prefix)) {
throw new SAXException("The content " + txt + " contains CDATA and can not be parsed");
}
else {
// get the posfix
pos = txt.indexOf("]]>");
if (pos < 0)
throw new SAXException("The content " + txt + " must be encoded and can not be wrapped by a CDATA since no ending ]]> found");
String postfix = txt.substring(pos+"]]>".length()+1);
if (needsEncoding(postfix)) {
throw new SAXException("The content " + txt + " contains CDATA and can not be parsed");
}
}
hasCDATA = true;
}