/** * Create a new empty document. * * @return a new empty document */ public static Document newEmptyDocument() { return newDocumentBuilder().newDocument(); }
/** * Parses the given InputSource after, applying the given XMLFilter. */ private Document parseInputSourceWithFilter(InputSource s, XMLFilter f) throws JspException { try { XMLReader xr = XmlUtil.newXMLReader(entityResolver); // (note that we overwrite the filter's parent. this seems // to be expected usage. we could cache and reset the old // parent, but you can't setParent(null), so this wouldn't // be perfect.) f.setParent(xr); TransformerHandler th = XmlUtil.newTransformerHandler(); Document o = XmlUtil.newEmptyDocument(); th.setResult(new DOMResult(o)); f.setContentHandler(th); f.parse(s); return o; } catch (IOException e) { throw new JspException(e); } catch (SAXException e) { throw new JspException(e); } catch (TransformerConfigurationException e) { throw new JspException(e); } catch (ParserConfigurationException e) { throw new JspException(e); } }
/** * Create a SAXSource from a Reader. Any entities will be resolved using JSTL semantics. * * @param reader the source of the XML * @param systemId the system id * @param entityResolver for resolving using JSTL semamtics * @return a new SAXSource * @throws ParserConfigurationException if there was a configuration problem creating the source * @throws SAXException if there was a problem creating the source */ public static SAXSource newSAXSource(Reader reader, String systemId, JstlEntityResolver entityResolver) throws ParserConfigurationException, SAXException { SAXSource source = new SAXSource(newXMLReader(entityResolver), new InputSource(reader)); source.setSystemId(wrapSystemId(systemId)); return source; }
throw new JspTagException(Resources.getMessage("TRANSFORM_XSLT_IS_EMPTY")); source = XmlUtil.newSAXSource(new StringReader(s), xsltSystemId, entityResolver); } else if (xslt instanceof Reader) { source = XmlUtil.newSAXSource((Reader) xslt, xsltSystemId, entityResolver); } else { throw new JspTagException(Resources.getMessage("TRANSFORM_XSLT_UNSUPPORTED_TYPE", xslt.getClass())); t = XmlUtil.newTransformer(source, uriResolver); t.setURIResolver(uriResolver); } catch (TransformerConfigurationException e) {
throw new JspTagException(Resources.getMessage("TRANSFORM_XML_IS_EMPTY")); return XmlUtil.newSAXSource(new StringReader(s), xmlSystemId, entityResolver); return XmlUtil.newSAXSource((Reader) xml, xmlSystemId, entityResolver);
@Override public int doEndTag() throws JspException { try { Source source = xmlSpecified ? getSourceFromXmlAttribute() : getSourceFromBodyContent(); // Conduct the transformation if (var != null) { // Save the result to var. Document d = XmlUtil.newEmptyDocument(); Result doc = new DOMResult(d); t.transform(source, doc); pageContext.setAttribute(var, d, scope); } else { // Write to out if result is not specified. Result out = result; if (out == null) { out = new StreamResult(new UnclosableWriter(pageContext.getOut())); } t.transform(source, out); } return EVAL_PAGE; } catch (TransformerException ex) { throw new JspException(ex); } catch (SAXException e) { throw new JspException(e); } catch (ParserConfigurationException e) { throw new JspException(e); } finally { t = null; } }
public InputSource resolveEntity(String publicId, String systemId) throws FileNotFoundException { // pass if we don't have a systemId if (systemId == null) { return null; } // strip leading "jstl:" off URL if applicable if (systemId.startsWith("jstl:")) { systemId = systemId.substring(5); } // we're only concerned with relative URLs if (UrlUtil.isAbsoluteUrl(systemId)) { checkProtocol(ALLOWED_PROTOCOLS, systemId); return null; } // for relative URLs, load and wrap the resource. // don't bother checking for 'null' since we specifically want // the parser to fail if the resource doesn't exist String path = systemId; if (!path.startsWith("/")) { String pagePath = ((HttpServletRequest) ctx.getRequest()).getServletPath(); String basePath = pagePath.substring(0, pagePath.lastIndexOf("/")); path = basePath + "/" + systemId; } InputStream s = ctx.getServletContext().getResourceAsStream(path); if (s == null) { throw new FileNotFoundException(Resources.getMessage("UNABLE_TO_RESOLVE_ENTITY", systemId)); } return new InputSource(s); } }
/** * Create an InputSource from a Reader. * * The systemId will be wrapped for use with JSTL's EntityResolver and UriResolver. * * @param reader the source of the XML * @param systemId the system id * @return a configured InputSource */ public static InputSource newInputSource(Reader reader, String systemId) { InputSource source = new InputSource(reader); source.setSystemId(wrapSystemId(systemId)); return source; }
throw new JspTagException(Resources.getMessage("PARSE_INVALID_SOURCE")); InputSource source = XmlUtil.newInputSource(((Reader) xmlText), systemId);
XMLReader xmlReader = XmlUtil.newXMLReader(null); xmlReader.setContentHandler(h); InputStream inputStream = page.getInputStream();
PageParser(boolean namespaceAware) { parserFactory = AccessController.doPrivileged(new PrivilegedAction<SAXParserFactory>() { public SAXParserFactory run() { ClassLoader original = Thread.currentThread().getContextClassLoader(); ClassLoader ours = PageParser.class.getClassLoader(); try { if (original != ours) { Thread.currentThread().setContextClassLoader(ours); } return SAXParserFactory.newInstance(); } finally { if (original != ours) { Thread.currentThread().setContextClassLoader(original); } } } }); try { parserFactory.setNamespaceAware(namespaceAware); parserFactory.setValidating(false); parserFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, XmlUtil.isSecureProcessing()); } catch (ParserConfigurationException e) { throw new ExceptionInInitializerError(e); } catch (SAXNotRecognizedException e) { throw new ExceptionInInitializerError(e); } catch (SAXNotSupportedException e) { throw new ExceptionInInitializerError(e); } }
throw new JspTagException(Resources.getMessage("TRANSFORM_XSLT_IS_EMPTY")); source = XmlUtil.newSAXSource(new StringReader(s), xsltSystemId, entityResolver); } else if (xslt instanceof Reader) { source = XmlUtil.newSAXSource((Reader) xslt, xsltSystemId, entityResolver); } else { throw new JspTagException(Resources.getMessage("TRANSFORM_XSLT_UNSUPPORTED_TYPE", xslt.getClass())); t = XmlUtil.newTransformer(source); t.setURIResolver(uriResolver); } catch (TransformerConfigurationException e) {
throw new JspTagException(Resources.getMessage("TRANSFORM_XML_IS_EMPTY")); return XmlUtil.newSAXSource(new StringReader(s), xmlSystemId, entityResolver); return XmlUtil.newSAXSource((Reader) xml, xmlSystemId, entityResolver);
@Override public int doEndTag() throws JspException { try { Source source = xmlSpecified ? getSourceFromXmlAttribute() : getSourceFromBodyContent(); // Conduct the transformation if (var != null) { // Save the result to var. Document d = XmlUtil.newEmptyDocument(); Result doc = new DOMResult(d); t.transform(source, doc); pageContext.setAttribute(var, d, scope); } else { // Write to out if result is not specified. Result out = result; if (out == null) { out = new StreamResult(new UnclosableWriter(pageContext.getOut())); } t.transform(source, out); } return EVAL_PAGE; } catch (TransformerException ex) { throw new JspException(ex); } catch (SAXException e) { throw new JspException(e); } catch (ParserConfigurationException e) { throw new JspException(e); } finally { t = null; } }
public InputSource resolveEntity(String publicId, String systemId) throws FileNotFoundException { // pass if we don't have a systemId if (systemId == null) { return null; } // strip leading "jstl:" off URL if applicable if (systemId.startsWith("jstl:")) { systemId = systemId.substring(5); } // we're only concerned with relative URLs if (UrlUtil.isAbsoluteUrl(systemId)) { checkProtocol(ALLOWED_PROTOCOLS, systemId); return null; } // for relative URLs, load and wrap the resource. // don't bother checking for 'null' since we specifically want // the parser to fail if the resource doesn't exist String path = systemId; if (!path.startsWith("/")) { String pagePath = ((HttpServletRequest) ctx.getRequest()).getServletPath(); String basePath = pagePath.substring(0, pagePath.lastIndexOf("/")); path = basePath + "/" + systemId; } InputStream s = ctx.getServletContext().getResourceAsStream(path); if (s == null) { throw new FileNotFoundException(Resources.getMessage("UNABLE_TO_RESOLVE_ENTITY", systemId)); } return new InputSource(s); } }
/** * Create an InputSource from a Reader. * * The systemId will be wrapped for use with JSTL's EntityResolver and UriResolver. * * @param reader the source of the XML * @param systemId the system id * @return a configured InputSource */ public static InputSource newInputSource(Reader reader, String systemId) { InputSource source = new InputSource(reader); source.setSystemId(wrapSystemId(systemId)); return source; }
throw new JspTagException(Resources.getMessage("PARSE_INVALID_SOURCE")); InputSource source = XmlUtil.newInputSource(((Reader) xmlText), systemId);
XMLReader xmlReader = XmlUtil.newXMLReader(null); xmlReader.setContentHandler(h); InputStream inputStream = page.getInputStream();
/** * Parses the given InputSource after, applying the given XMLFilter. */ private Document parseInputSourceWithFilter(InputSource s, XMLFilter f) throws JspException { try { XMLReader xr = XmlUtil.newXMLReader(entityResolver); // (note that we overwrite the filter's parent. this seems // to be expected usage. we could cache and reset the old // parent, but you can't setParent(null), so this wouldn't // be perfect.) f.setParent(xr); TransformerHandler th = XmlUtil.newTransformerHandler(); Document o = XmlUtil.newEmptyDocument(); th.setResult(new DOMResult(o)); f.setContentHandler(th); f.parse(s); return o; } catch (IOException e) { throw new JspException(e); } catch (SAXException e) { throw new JspException(e); } catch (TransformerConfigurationException e) { throw new JspException(e); } catch (ParserConfigurationException e) { throw new JspException(e); } }
/** * Create a SAXSource from a Reader. Any entities will be resolved using JSTL semantics. * * @param reader the source of the XML * @param systemId the system id * @param entityResolver for resolving using JSTL semamtics * @return a new SAXSource * @throws ParserConfigurationException if there was a configuration problem creating the source * @throws SAXException if there was a problem creating the source */ public static SAXSource newSAXSource(Reader reader, String systemId, JstlEntityResolver entityResolver) throws ParserConfigurationException, SAXException { SAXSource source = new SAXSource(newXMLReader(entityResolver), new InputSource(reader)); source.setSystemId(wrapSystemId(systemId)); return source; }