use of org.apache.xpath.Expression in project robovm by robovm.
the class FuncExtFunction method callArgVisitors.
/**
* Call the visitors for the function arguments.
*/
public void callArgVisitors(XPathVisitor visitor) {
for (int i = 0; i < m_argVec.size(); i++) {
Expression exp = (Expression) m_argVec.elementAt(i);
exp.callVisitors(new ArgExtOwner(exp), visitor);
}
}
use of org.apache.xpath.Expression in project robovm by robovm.
the class Compiler method compile.
/**
* Execute the XPath object from a given opcode position.
* @param opPos The current position in the xpath.m_opMap array.
* @return The result of the XPath.
*
* @throws TransformerException if there is a syntax or other error.
* @xsl.usage advanced
*/
public Expression compile(int opPos) throws TransformerException {
int op = getOp(opPos);
Expression expr = null;
// System.out.println(getPatternString()+"op: "+op);
switch(op) {
case OpCodes.OP_XPATH:
expr = compile(opPos + 2);
break;
case OpCodes.OP_OR:
expr = or(opPos);
break;
case OpCodes.OP_AND:
expr = and(opPos);
break;
case OpCodes.OP_NOTEQUALS:
expr = notequals(opPos);
break;
case OpCodes.OP_EQUALS:
expr = equals(opPos);
break;
case OpCodes.OP_LTE:
expr = lte(opPos);
break;
case OpCodes.OP_LT:
expr = lt(opPos);
break;
case OpCodes.OP_GTE:
expr = gte(opPos);
break;
case OpCodes.OP_GT:
expr = gt(opPos);
break;
case OpCodes.OP_PLUS:
expr = plus(opPos);
break;
case OpCodes.OP_MINUS:
expr = minus(opPos);
break;
case OpCodes.OP_MULT:
expr = mult(opPos);
break;
case OpCodes.OP_DIV:
expr = div(opPos);
break;
case OpCodes.OP_MOD:
expr = mod(opPos);
break;
// expr = quo(opPos); break;
case OpCodes.OP_NEG:
expr = neg(opPos);
break;
case OpCodes.OP_STRING:
expr = string(opPos);
break;
case OpCodes.OP_BOOL:
expr = bool(opPos);
break;
case OpCodes.OP_NUMBER:
expr = number(opPos);
break;
case OpCodes.OP_UNION:
expr = union(opPos);
break;
case OpCodes.OP_LITERAL:
expr = literal(opPos);
break;
case OpCodes.OP_VARIABLE:
expr = variable(opPos);
break;
case OpCodes.OP_GROUP:
expr = group(opPos);
break;
case OpCodes.OP_NUMBERLIT:
expr = numberlit(opPos);
break;
case OpCodes.OP_ARGUMENT:
expr = arg(opPos);
break;
case OpCodes.OP_EXTFUNCTION:
expr = compileExtension(opPos);
break;
case OpCodes.OP_FUNCTION:
expr = compileFunction(opPos);
break;
case OpCodes.OP_LOCATIONPATH:
expr = locationPath(opPos);
break;
case OpCodes.OP_PREDICATE:
expr = null;
// should never hit this here.
break;
case OpCodes.OP_MATCHPATTERN:
expr = matchPattern(opPos + 2);
break;
case OpCodes.OP_LOCATIONPATHPATTERN:
expr = locationPathPattern(opPos);
break;
case OpCodes.OP_QUO:
error(XPATHErrorResources.ER_UNKNOWN_OPCODE, //"ERROR! Unknown op code: "+m_opMap[opPos]);
new Object[] { "quo" });
break;
default:
error(XPATHErrorResources.ER_UNKNOWN_OPCODE, //"ERROR! Unknown op code: "+m_opMap[opPos]);
new Object[] { Integer.toString(getOp(opPos)) });
}
return expr;
}
use of org.apache.xpath.Expression in project j2objc by google.
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;
}
}
use of org.apache.xpath.Expression in project j2objc by google.
the class FuncDocument method execute.
/**
* Execute the function. The function must return
* a valid object.
* @param xctxt The current execution context.
* @return A valid XObject.
*
* @throws javax.xml.transform.TransformerException
*/
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException {
int context = xctxt.getCurrentNode();
DTM dtm = xctxt.getDTM(context);
int docContext = dtm.getDocumentRoot(context);
XObject arg = (XObject) this.getArg0().execute(xctxt);
String base = "";
Expression arg1Expr = this.getArg1();
if (null != arg1Expr) {
// The URI reference may be relative. The base URI (see [3.2 Base URI])
// of the node in the second argument node-set that is first in document
// order is used as the base URI for resolving the
// relative URI into an absolute URI.
XObject arg2 = arg1Expr.execute(xctxt);
if (XObject.CLASS_NODESET == arg2.getType()) {
int baseNode = arg2.iter().nextNode();
if (baseNode == DTM.NULL) {
// See http://www.w3.org/1999/11/REC-xslt-19991116-errata#E14.
// If the second argument is an empty nodeset, this is an error.
// The processor can recover by returning an empty nodeset.
warn(xctxt, XSLTErrorResources.WG_EMPTY_SECOND_ARG, null);
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
return nodes;
} else {
DTM baseDTM = xctxt.getDTM(baseNode);
base = baseDTM.getDocumentBaseURI();
}
// %REVIEW% This doesn't seem to be a problem with the conformance
// suite, but maybe it's just not doing a good test?
// int baseDoc = baseDTM.getDocument();
//
// if (baseDoc == DTM.NULL /* || baseDoc instanceof Stylesheet -->What to do?? */)
// {
//
// // base = ((Stylesheet)baseDoc).getBaseIdentifier();
// base = xctxt.getNamespaceContext().getBaseIdentifier();
// }
// else
// base = xctxt.getSourceTreeManager().findURIFromDoc(baseDoc);
} else {
//Can not convert other type to a node-set!;
arg2.iter();
}
} else {
// If the second argument is omitted, then it defaults to
// the node in the stylesheet that contains the expression that
// includes the call to the document function. Note that a
// zero-length URI reference is a reference to the document
// relative to which the URI reference is being resolved; thus
// document("") refers to the root node of the stylesheet;
// the tree representation of the stylesheet is exactly
// the same as if the XML document containing the stylesheet
// was the initial source document.
assertion(null != xctxt.getNamespaceContext(), "Namespace context can not be null!");
base = xctxt.getNamespaceContext().getBaseIdentifier();
}
XNodeSet nodes = new XNodeSet(xctxt.getDTMManager());
NodeSetDTM mnl = nodes.mutableNodeset();
DTMIterator iterator = (XObject.CLASS_NODESET == arg.getType()) ? arg.iter() : null;
int pos = DTM.NULL;
while ((null == iterator) || (DTM.NULL != (pos = iterator.nextNode()))) {
XMLString ref = (null != iterator) ? xctxt.getDTM(pos).getStringValue(pos) : arg.xstr();
// member.
if (null == arg1Expr && DTM.NULL != pos) {
DTM baseDTM = xctxt.getDTM(pos);
base = baseDTM.getDocumentBaseURI();
}
if (null == ref)
continue;
if (DTM.NULL == docContext) {
//"context does not have an owner document!");
error(xctxt, XSLTErrorResources.ER_NO_CONTEXT_OWNERDOC, null);
}
// From http://www.ics.uci.edu/pub/ietf/uri/rfc1630.txt
// A partial form can be distinguished from an absolute form in that the
// latter must have a colon and that colon must occur before any slash
// characters. Systems not requiring partial forms should not use any
// unencoded slashes in their naming schemes. If they do, absolute URIs
// will still work, but confusion may result.
int indexOfColon = ref.indexOf(':');
int indexOfSlash = ref.indexOf('/');
if ((indexOfColon != -1) && (indexOfSlash != -1) && (indexOfColon < indexOfSlash)) {
// The url (or filename, for that matter) is absolute.
base = null;
}
int newDoc = getDoc(xctxt, context, ref.toString(), base);
// nodes.mutableNodeset().addNode(newDoc);
if (DTM.NULL != newDoc) {
// TODO: mnl.addNodeInDocOrder(newDoc, true, xctxt); ??
if (!mnl.contains(newDoc)) {
mnl.addElement(newDoc);
}
}
if (null == iterator || newDoc == DTM.NULL)
break;
}
return nodes;
}
use of org.apache.xpath.Expression in project j2objc by google.
the class RedundentExprEliminator method oldFindAndEliminateRedundant.
/**
* To be removed.
*/
protected int oldFindAndEliminateRedundant(int start, int firstOccuranceIndex, ExpressionOwner firstOccuranceOwner, ElemTemplateElement psuedoVarRecipient, Vector paths) throws org.w3c.dom.DOMException {
QName uniquePseudoVarName = null;
boolean foundFirst = false;
int numPathsFound = 0;
int n = paths.size();
Expression expr1 = firstOccuranceOwner.getExpression();
if (DEBUG)
assertIsLocPathIterator(expr1, firstOccuranceOwner);
boolean isGlobal = (paths == m_absPaths);
LocPathIterator lpi = (LocPathIterator) expr1;
for (int j = start; j < n; j++) {
ExpressionOwner owner2 = (ExpressionOwner) paths.elementAt(j);
if (null != owner2) {
Expression expr2 = owner2.getExpression();
boolean isEqual = expr2.deepEquals(lpi);
if (isEqual) {
LocPathIterator lpi2 = (LocPathIterator) expr2;
if (!foundFirst) {
foundFirst = true;
// Insert variable decl into psuedoVarRecipient
// We want to insert this into the first legitimate
// position for a variable.
ElemVariable var = createPseudoVarDecl(psuedoVarRecipient, lpi, isGlobal);
if (null == var)
return 0;
uniquePseudoVarName = var.getName();
changeToVarRef(uniquePseudoVarName, firstOccuranceOwner, paths, psuedoVarRecipient);
// Replace the first occurance with the variable's XPath, so
// that further reduction may take place if needed.
paths.setElementAt(var.getSelect(), firstOccuranceIndex);
numPathsFound++;
}
changeToVarRef(uniquePseudoVarName, owner2, paths, psuedoVarRecipient);
// Null out the occurance, so we don't have to test it again.
paths.setElementAt(null, j);
// foundFirst = true;
numPathsFound++;
}
}
}
// Change all globals in xsl:templates, etc, to global vars no matter what.
if ((0 == numPathsFound) && (paths == m_absPaths)) {
ElemVariable var = createPseudoVarDecl(psuedoVarRecipient, lpi, true);
if (null == var)
return 0;
uniquePseudoVarName = var.getName();
changeToVarRef(uniquePseudoVarName, firstOccuranceOwner, paths, psuedoVarRecipient);
paths.setElementAt(var.getSelect(), firstOccuranceIndex);
numPathsFound++;
}
return numPathsFound;
}
Aggregations