/** * <p>Default constructor. Establishes its own {@link XPathContext}, and hence * its own {@link org.apache.xml.dtm.DTMManager}. * Good choice for simple uses.</p> * <p>Note that any particular instance of {@link CachedXPathAPI} must not be * operated upon by multiple threads without synchronization; we do * not currently support multithreaded access to a single * {@link org.apache.xml.dtm.DTM}.</p> */ public CachedXPathAPI() { // Create an XPathContext that doesn't support pushing and popping of // variable resolution scopes. Sufficient for simple XPath 1.0 expressions. xpathSupport = new XPathContext(false); }
/** * Get the value of a node as a number. * @param n Node to be converted to a number. May be null. * @return value of n as a number. */ public double toNumber(org.w3c.dom.Node n) { // %REVIEW% You can't get much uglier than this... int nodeHandle = getDTMHandleFromNode(n); DTM dtm = getDTM(nodeHandle); XString xobj = (XString)dtm.getStringValue(nodeHandle); return xobj.num(); }
/** * Given an select expression and a context, evaluate the XPath * and return the resulting iterator. * * @param xctxt The execution context. * @param contextNode The node that "." expresses. * * * @return A valid DTMIterator. * @throws TransformerException thrown if the active ProblemListener decides * the error condition is severe enough to halt processing. * * @throws javax.xml.transform.TransformerException * @xsl.usage experimental */ public DTMIterator asIterator(XPathContext xctxt, int contextNode) throws javax.xml.transform.TransformerException { try { xctxt.pushCurrentNodeAndExpression(contextNode, contextNode); return execute(xctxt).iter(); } finally { xctxt.popCurrentNodeAndExpression(); } }
private final void initDTM(int root, XPathContext xctxt){ m_dtmRoot = root; final DTM dtm = xctxt.getDTM(root); if(dtm != null){ m_DTMXRTreeFrag = xctxt.getDTMXRTreeFrag(xctxt.getDTMIdentity(dtm)); } }
/** * Get the current context node. * @return The current context node. */ public org.w3c.dom.Node getContextNode() { int context = getCurrentNode(); return getDTM(context).getNode(context); }
/** * Return the first node out of the nodeset, if this expression is * a nodeset expression. This is the default implementation for * nodesets. * <p>WARNING: Do not mutate this class from this function!</p> * @param xctxt The XPath runtime context. * @return the first node out of the nodeset, or DTM.NULL. */ public int asNode(XPathContext xctxt) throws javax.xml.transform.TransformerException { int current = xctxt.getCurrentNode(); DTM dtm = xctxt.getDTM(current); return dtm.getFirstChild(current); }
xctxt.pushNamespaceContext(namespaceContext); xctxt.pushCurrentNodeAndExpression(contextNode, contextNode); te.setLocator(this.getLocator()); ErrorListener el = xctxt.getErrorListener(); if(null != el) // defensive, should never happen. el.error(te); msg = XSLMessages.createXPATHMessage( XPATHErrorResources.ER_XPATH_ERROR, null); TransformerException te = new TransformerException(msg, getLocator(), e); ErrorListener el = xctxt.getErrorListener(); el.fatalError(te); xctxt.popNamespaceContext(); xctxt.popCurrentNodeAndExpression();
int sourceNode = xctxt.getCurrentNode(); XObject value = m_selectExpression.execute(xctxt, sourceNode, this); int type = value.getType(); String s; case XObject.CLASS_NUMBER : case XObject.CLASS_STRING : s = value.str(); handler.characters(s.toCharArray(), 0, s.length()); break; case XObject.CLASS_NODESET : DTMIterator nl = value.iter(); DTM dtm = xctxt.getDTMManager().getDTM(pos); short t = dtm.getNodeType(pos); for (int child = dtm.getFirstChild(pos); child != DTM.NULL; child = dtm.getNextSibling(child)) s = value.str(); handler.characters(s.toCharArray(), 0, s.length()); break; throw new TransformerException(se);
/** * Warn the user of a problem. * * @param xctxt The XPath runtime state. * @param msg Warning message key * @param args Arguments to be used in warning message * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide * the error condition is severe enough to halt processing. * * @throws javax.xml.transform.TransformerException */ public void warn(XPathContext xctxt, String msg, Object args[]) throws javax.xml.transform.TransformerException { String formattedMsg = XSLMessages.createWarning(msg, args); ErrorListener errHandler = xctxt.getErrorListener(); errHandler.warning(new TransformerException(formattedMsg, (SAXSourceLocator)xctxt.getSAXLocator())); }
xctxt.pushNamespaceContext(this); int current = xctxt.getCurrentNode(); xctxt.pushCurrentNodeAndExpression(current, current); rth.processingInstruction( javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, ""); Expression expr = m_selectExpression.getExpression(); rth.processingInstruction( javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, ""); xctxt.popNamespaceContext(); xctxt.popCurrentNodeAndExpression(); throw new TransformerException(se); TransformerException te = new TransformerException(re); te.setLocator(this); throw te;
int sourceNode = xctxt.getCurrentNode(); xctxt.pushCurrentNode(sourceNode); DTM dtm = xctxt.getDTM(sourceNode); short nodeType = dtm.getNodeType(sourceNode); transformer.executeChildTemplates(this, true); String ns = dtm.getNamespaceURI(sourceNode); String localName = dtm.getLocalName(sourceNode); transformer.getResultTreeHandler().endElement(ns, localName, dtm.getNodeName(sourceNode)); throw new TransformerException(se); xctxt.popCurrentNode();
DTM dtm = m_xcontext.getDTM(child); short nodeType = dtm.getNodeType(child); boolean isDefaultTextRule = false; boolean isApplyImports = false; xctxt.pushNamespaceContext(xslInstruction); xctxt.popNamespaceContext(); m_xcontext.pushCurrentNode(child); pushPairCurrentMatched(template, child); DTMIterator cnl = new org.apache.xpath.NodeSetDTM(child, m_xcontext.getDTMManager()); m_xcontext.pushContextNodeList(cnl); m_xcontext.setSAXLocator(template); m_xcontext.getVarStack().link(template.m_frameSize); executeChildTemplates(template, true); throw new TransformerException(se); m_xcontext.getVarStack().unlink(); m_xcontext.popCurrentNode(); if (!isApplyImports) { m_xcontext.popContextNodeList();
/** * Tell the user of an error, and probably throw an * exception. * * @param xctxt The XPath runtime state. * @param msg The error message key * @param args Arguments to be used in the error message * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide * the error condition is severe enough to halt processing. * * @throws javax.xml.transform.TransformerException */ public void error(XPathContext xctxt, String msg, Object args[]) throws javax.xml.transform.TransformerException { String formattedMsg = XSLMessages.createMessage(msg, args); ErrorListener errHandler = xctxt.getErrorListener(); TransformerException spe = new TransformerException(formattedMsg, (SourceLocator)xctxt.getSAXLocator()); if (null != errHandler) errHandler.error(spe); else System.out.println(formattedMsg); }
/** * Warn the user of an problem. * * @param xctxt The XPath runtime context. * @param msg An error msgkey that corresponds to one of the conststants found * in {@link org.apache.xpath.res.XPATHErrorResources}, which is * a key for a format string. * @param args An array of arguments represented in the format string, which * may be null. * * @throws TransformerException if the current ErrorListoner determines to * throw an exception. * * @throws javax.xml.transform.TransformerException */ public void warn(XPathContext xctxt, String msg, Object[] args) throws javax.xml.transform.TransformerException { java.lang.String fmsg = XSLMessages.createXPATHWarning(msg, args); if (null != xctxt) { ErrorListener eh = xctxt.getErrorListener(); // TO DO: Need to get stylesheet Locator from here. eh.warning(new TransformerException(fmsg, xctxt.getSAXLocator())); } }
/** * Tell the user of an assertion error, and probably throw an * exception. * * @param b If false, a TransformerException will be thrown. * @param msg The assertion message, which should be informative. * * @throws javax.xml.transform.TransformerException if b is false. */ private void assertion(boolean b, String msg) throws javax.xml.transform.TransformerException { if (!b) { ErrorListener errorHandler = getErrorListener(); if (errorHandler != null) { errorHandler.fatalError( new TransformerException( XSLMessages.createMessage( XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION, new Object[]{ msg }), (SAXSourceLocator)this.getSAXLocator())); } } }
/** * Execute an xsl:number instruction. The xsl:number element is * used to insert a formatted number into the result tree. * * @param transformer non-null reference to the the current transform-time state. * * @throws TransformerException */ public void execute( TransformerImpl transformer) throws TransformerException { int sourceNode = transformer.getXPathContext().getCurrentNode(); String countString = getCountString(transformer, sourceNode); try { transformer.getResultTreeHandler().characters(countString.toCharArray(), 0, countString.length()); } catch(SAXException se) { throw new TransformerException(se); } }
int sourceNode = xctxt.getCurrentNode(); transformer.getResultTreeHandler().processingInstruction(piName, data); throw new TransformerException(se);
return true; PrefixResolver savedResolver = xctxt.getNamespaceContext(); xctxt.pushSubContextList(this); xctxt.pushNamespaceContext(m_lpi.getPrefixResolver()); xctxt.pushCurrentNode(context); if (XObject.CLASS_NUMBER == pred.getType()) System.out.println("pred.num(): " + pred.num()); int predIndex = (int) pred.num(); if (proxPos != predIndex) xctxt.popCurrentNode(); xctxt.popNamespaceContext(); xctxt.popSubContextList(); m_predicateIndex = -1;
/** * Tell the user of an error, and probably throw an * exception. * * @param xctxt The XPath runtime context. * @param msg An error msgkey that corresponds to one of the constants found * in {@link org.apache.xpath.res.XPATHErrorResources}, which is * a key for a format string. * @param args An array of arguments represented in the format string, which * may be null. * * @throws TransformerException if the current ErrorListoner determines to * throw an exception. * * @throws javax.xml.transform.TransformerException */ public void error(XPathContext xctxt, String msg, Object[] args) throws javax.xml.transform.TransformerException { java.lang.String fmsg = XSLMessages.createXPATHMessage(msg, args); if (null != xctxt) { ErrorListener eh = xctxt.getErrorListener(); TransformerException te = new TransformerException(fmsg, this); eh.fatalError(te); } }
/** * Generate the EXSLT function return value, and assign it to the variable * index slot assigned for it in ElemExsltFunction compose(). * */ public void execute(TransformerImpl transformer) throws TransformerException { XPathContext context = transformer.getXPathContext(); // Verify that result has not already been set by another result // element. Recursion is allowed: intermediate results are cleared // in the owner ElemExsltFunction execute(). if (transformer.currentFuncResultSeen()) { throw new TransformerException("An EXSLT function cannot set more than one result!"); } int sourceNode = context.getCurrentNode(); // Set the return value; XObject var = getValue(transformer, sourceNode); transformer.popCurrentFuncResult(); transformer.pushCurrentFuncResult(var); }