@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; } }
@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; } }
/** * 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); } }
/** * 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); } }
/** * Return the XPathContext to be used for evaluating expressions. * * If the child is nested withing a forEach tag its iteration context is used. * Otherwise, a new context is created based on an empty Document. * * @param child the tag whose context should be returned * @param pageContext the current page context * @return the XPath evaluation context */ public static XPathContext getContext(Tag child, PageContext pageContext) { // if within a forEach tag, use its context ForEachTag forEachTag = (ForEachTag) TagSupport.findAncestorWithClass(child, ForEachTag.class); if (forEachTag != null) { return forEachTag.getContext(); } // otherwise, create a new context referring to an empty document XPathContext context = new XPathContext(false); VariableStack variableStack = new JSTLVariableStack(pageContext); context.setVarStack(variableStack); int dtm = context.getDTMHandleFromNode(XmlUtil.newEmptyDocument()); context.pushCurrentNodeAndExpression(dtm, dtm); return context; }
/** * Return the XPathContext to be used for evaluating expressions. * * If the child is nested withing a forEach tag its iteration context is used. * Otherwise, a new context is created based on an empty Document. * * @param child the tag whose context should be returned * @param pageContext the current page context * @return the XPath evaluation context */ public static XPathContext getContext(Tag child, PageContext pageContext) { // if within a forEach tag, use its context ForEachTag forEachTag = (ForEachTag) TagSupport.findAncestorWithClass(child, ForEachTag.class); if (forEachTag != null) { return forEachTag.getContext(); } // otherwise, create a new context referring to an empty document XPathContext context = new XPathContext(false); VariableStack variableStack = new JSTLVariableStack(pageContext); context.setVarStack(variableStack); int dtm = context.getDTMHandleFromNode(XmlUtil.newEmptyDocument()); context.pushCurrentNodeAndExpression(dtm, dtm); return context; }