use of org.apache.xpath.XPathContext in project robovm by robovm.
the class KeyTable method getRefsTable.
/**
* @return lazy initialized refs table associating evaluation of key function
* with a XNodeSet
*/
private Hashtable getRefsTable() {
if (m_refsTable == null) {
// initial capacity set to a prime number to improve hash performance
m_refsTable = new Hashtable(89);
KeyIterator ki = (KeyIterator) (m_keyNodes).getContainedIter();
XPathContext xctxt = ki.getXPathContext();
Vector keyDecls = getKeyDeclarations();
int nKeyDecls = keyDecls.size();
int currentNode;
m_keyNodes.reset();
while (DTM.NULL != (currentNode = m_keyNodes.nextNode())) {
try {
for (int keyDeclIdx = 0; keyDeclIdx < nKeyDecls; keyDeclIdx++) {
KeyDeclaration keyDeclaration = (KeyDeclaration) keyDecls.elementAt(keyDeclIdx);
XObject xuse = keyDeclaration.getUse().execute(xctxt, currentNode, ki.getPrefixResolver());
if (xuse.getType() != xuse.CLASS_NODESET) {
XMLString exprResult = xuse.xstr();
addValueInRefsTable(xctxt, exprResult, currentNode);
} else {
DTMIterator i = ((XNodeSet) xuse).iterRaw();
int currentNodeInUseClause;
while (DTM.NULL != (currentNodeInUseClause = i.nextNode())) {
DTM dtm = xctxt.getDTM(currentNodeInUseClause);
XMLString exprResult = dtm.getStringValue(currentNodeInUseClause);
addValueInRefsTable(xctxt, exprResult, currentNode);
}
}
}
} catch (TransformerException te) {
throw new WrappedRuntimeException(te);
}
}
}
return m_refsTable;
}
use of org.apache.xpath.XPathContext in project robovm by robovm.
the class ElemNumber method getCountString.
/**
* Given an XML source node, get the count according to the
* parameters set up by the xsl:number attributes.
* @param transformer non-null reference to the the current transform-time state.
* @param sourceNode The source node being counted.
*
* @return The count of nodes
*
* @throws TransformerException
*/
String getCountString(TransformerImpl transformer, int sourceNode) throws TransformerException {
long[] list = null;
XPathContext xctxt = transformer.getXPathContext();
CountersTable ctable = transformer.getCountersTable();
if (null != m_valueExpr) {
XObject countObj = m_valueExpr.execute(xctxt, sourceNode, this);
//According to Errata E24
double d_count = java.lang.Math.floor(countObj.num() + 0.5);
if (Double.isNaN(d_count))
return "NaN";
else if (d_count < 0 && Double.isInfinite(d_count))
return "-Infinity";
else if (Double.isInfinite(d_count))
return "Infinity";
else if (d_count == 0)
return "0";
else {
long count = (long) d_count;
list = new long[1];
list[0] = count;
}
} else {
if (Constants.NUMBERLEVEL_ANY == m_level) {
list = new long[1];
list[0] = ctable.countNode(xctxt, this, sourceNode);
} else {
NodeVector ancestors = getMatchingAncestors(xctxt, sourceNode, Constants.NUMBERLEVEL_SINGLE == m_level);
int lastIndex = ancestors.size() - 1;
if (lastIndex >= 0) {
list = new long[lastIndex + 1];
for (int i = lastIndex; i >= 0; i--) {
int target = ancestors.elementAt(i);
list[lastIndex - i] = ctable.countNode(xctxt, this, target);
}
}
}
}
return (null != list) ? formatNumberList(transformer, list, sourceNode) : "";
}
use of org.apache.xpath.XPathContext in project robovm by robovm.
the class ElemPI method execute.
/**
* Create a processing instruction in the result tree.
* The content of the xsl:processing-instruction element is a
* template for the string-value of the processing instruction node.
* @see <a href="http://www.w3.org/TR/xslt#section-Creating-Processing-Instructions">section-Creating-Processing-Instructions in XSLT Specification</a>
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
XPathContext xctxt = transformer.getXPathContext();
int sourceNode = xctxt.getCurrentNode();
String piName = m_name_atv == null ? null : m_name_atv.evaluate(xctxt, sourceNode, this);
// Ignore processing instruction if name is null
if (piName == null)
return;
if (piName.equalsIgnoreCase("xml")) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_PROCESSINGINSTRUCTION_NAME_CANT_BE_XML, new Object[] { Constants.ATTRNAME_NAME, piName });
return;
} else // Ignore processing instruction, if invalid
if ((!m_name_atv.isSimple()) && (!XML11Char.isXML11ValidNCName(piName))) {
transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_PROCESSINGINSTRUCTION_NOTVALID_NCNAME, new Object[] { Constants.ATTRNAME_NAME, piName });
return;
}
// Note the content model is:
// <!ENTITY % instructions "
// %char-instructions;
// | xsl:processing-instruction
// | xsl:comment
// | xsl:element
// | xsl:attribute
// ">
String data = transformer.transformToString(this);
try {
transformer.getResultTreeHandler().processingInstruction(piName, data);
} catch (org.xml.sax.SAXException se) {
throw new TransformerException(se);
}
}
use of org.apache.xpath.XPathContext in project robovm by robovm.
the class ElemTemplate method execute.
/**
* Copy the template contents into the result tree.
* The content of the xsl:template element is the template
* that is instantiated when the template rule is applied.
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
XPathContext xctxt = transformer.getXPathContext();
xctxt.pushRTFContext();
// %REVIEW% commenting out of the code below.
// if (null != sourceNode)
// {
transformer.executeChildTemplates(this, true);
// }
// else // if(null == sourceNode)
// {
// transformer.getMsgMgr().error(this,
// this, sourceNode,
// XSLTErrorResources.ER_NULL_SOURCENODE_HANDLEAPPLYTEMPLATES);
//
// //"sourceNode is null in handleApplyTemplatesInstruction!");
// }
xctxt.popRTFContext();
}
use of org.apache.xpath.XPathContext in project robovm by robovm.
the class ElemValueOf method execute.
/**
* Execute the string expression and copy the text to the
* result tree.
* The required select attribute is an expression; this expression
* is evaluated and the resulting object is converted to a string
* as if by a call to the string function. The string specifies
* the string-value of the created text node. If the string is
* empty, no text node will be created. The created text node will
* be merged with any adjacent text nodes.
* @see <a href="http://www.w3.org/TR/xslt#value-of">value-of in XSLT Specification</a>
*
* @param transformer non-null reference to the the current transform-time state.
*
* @throws TransformerException
*/
public void execute(TransformerImpl transformer) throws TransformerException {
XPathContext xctxt = transformer.getXPathContext();
SerializationHandler rth = transformer.getResultTreeHandler();
try {
// Optimize for "."
xctxt.pushNamespaceContext(this);
int current = xctxt.getCurrentNode();
xctxt.pushCurrentNodeAndExpression(current, current);
if (m_disableOutputEscaping)
rth.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
try {
Expression expr = m_selectExpression.getExpression();
expr.executeCharsToContentHandler(xctxt, rth);
} finally {
if (m_disableOutputEscaping)
rth.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
xctxt.popNamespaceContext();
xctxt.popCurrentNodeAndExpression();
}
} catch (SAXException se) {
throw new TransformerException(se);
} catch (RuntimeException re) {
TransformerException te = new TransformerException(re);
te.setLocator(this);
throw te;
}
}
Aggregations