{
try {
PageContextImpl pageContext = (PageContextImpl) this.pageContext;
BodyContentImpl body = (BodyContentImpl) getBodyContent();
XMLReader xmlReader = null;
Reader reader = null;
InputSource is;
if (_xml != null) {
Object obj = _xml;
if (obj instanceof Reader) {
reader = (Reader) obj;
is = new InputSource(reader);
}
else if (obj instanceof String) {
reader = Vfs.openString((String) obj).getReader();
is = new InputSource(reader);
} else if (obj instanceof XMLReader) {
xmlReader = (XMLReader) obj;
is = new InputSource();
}
else
throw new JspException(L.l("xml must be java.io.Reader, String or org.xml.sax.XMLReader at `{0}'",
obj));
}
else if (body != null) {
TempCharReader tempReader = (TempCharReader) body.getReader();
int ch;
while (Character.isWhitespace((ch = tempReader.read()))) {
}
if (ch >= 0)
tempReader.unread();
reader = tempReader;
is = new InputSource(reader);
}
/*
else if (_filter != null) {
is = null;
}
*/
else {
throw new JspException(L.l("No XML document supplied via a doc attribute or inside the body of <x:parse> tag."));
}
if (_systemId != null && is != null)
is.setSystemId(_systemId);
XMLFilter filter = (XMLFilter) _filter;
if (xmlReader == null) {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
// jsp/1m14
parserFactory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
parserFactory.setFeature("http://xml.org/sax/features/namespaces", true);
xmlReader = parserFactory.newSAXParser().getXMLReader();
}
// jsp/1g05
if (_filter != null && _var == null && _varDom == null) {
filter.setParent(xmlReader);
filter.parse(is);
} else {
DocumentBuilderFactory domFactory
= DocumentBuilderFactory.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.newDocument();
SAXTransformerFactory saxFactory
= (SAXTransformerFactory) SAXTransformerFactory.newInstance();
//saxFactory.setAttribute("http://xml.org/sax/features/namespace-prefixes", false);
// saxFactory.setAttribute("http://xml.org/sax/features/namespaces", false);
//saxFactory.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
// xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
TransformerHandler handler
= saxFactory.newTransformerHandler();
handler.setResult(new DOMResult(doc));
if (filter != null) {
filter.setParent(xmlReader);
filter.setContentHandler(handler);
filter.parse(is);
} else {
xmlReader.setContentHandler(handler);
xmlReader.parse(is);
}
if (_var == null && _varDom == null)
throw new JspException(L.l("x:parse needs either var or varDom"));