@Override public XObject getVariableOrParam(XPathContext xctxt, QName qname) throws TransformerException { String prefix = qname.getNamespaceURI(); String name = qname.getLocalPart(); Object value = getValue(prefix, name); if (value == null) { StringBuilder var = new StringBuilder(); var.append('$'); if (prefix != null) { var.append(prefix); var.append(':'); } var.append(name); throw new TransformerException(Resources.getMessage("XPATH_UNABLE_TO_RESOLVE_VARIABLE", var.toString())); } return XObjectFactory.create(value, xctxt); }
/** * 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; }
@Override public XObject getVariableOrParam(XPathContext xctxt, QName qname) throws TransformerException { String prefix = qname.getNamespaceURI(); String name = qname.getLocalPart(); Object value = getValue(prefix, name); if (value == null) { StringBuilder var = new StringBuilder(); var.append('$'); if (prefix != null) { var.append(prefix); var.append(':'); } var.append(name); throw new TransformerException(Resources.getMessage("XPATH_UNABLE_TO_RESOLVE_VARIABLE", var.toString())); } return XObjectFactory.create(value, xctxt); }