Search in sources :

Example 16 with QName

use of org.apache.xml.utils.QName in project j2objc by google.

the class Compiler method variable.

/**
 * Compile a variable reference.
 *
 * @param opPos The current position in the m_opMap array.
 *
 * @return reference to {@link org.apache.xpath.operations.Variable} instance.
 *
 * @throws TransformerException if a error occurs creating the Expression.
 */
protected Expression variable(int opPos) throws TransformerException {
    Variable var = new Variable();
    opPos = getFirstChildPos(opPos);
    int nsPos = getOp(opPos);
    java.lang.String namespace = (OpCodes.EMPTY == nsPos) ? null : (java.lang.String) getTokenQueue().elementAt(nsPos);
    java.lang.String localname = (java.lang.String) getTokenQueue().elementAt(getOp(opPos + 1));
    QName qname = new QName(namespace, localname);
    var.setQName(qname);
    return var;
}
Also used : Variable(org.apache.xpath.operations.Variable) QName(org.apache.xml.utils.QName) XString(org.apache.xpath.objects.XString)

Example 17 with QName

use of org.apache.xml.utils.QName in project robovm by robovm.

the class ElemUse method applyAttrSets.

/**
   * Add the attributes from the named attribute sets to the attribute list.
   * TODO: Error handling for: "It is an error if there are two attribute sets
   * with the same expanded-name and with equal import precedence and that both
   * contain the same attribute unless there is a definition of the attribute
   * set with higher import precedence that also contains the attribute."
   *
   * @param transformer non-null reference to the the current transform-time state.
   * @param stylesheet The owning root stylesheet
   * @param attributeSetsNames List of attribute sets names to apply
   *
   * @throws TransformerException
   */
private void applyAttrSets(TransformerImpl transformer, StylesheetRoot stylesheet, QName[] attributeSetsNames) throws TransformerException {
    if (null != attributeSetsNames) {
        int nNames = attributeSetsNames.length;
        for (int i = 0; i < nNames; i++) {
            QName qname = attributeSetsNames[i];
            java.util.List attrSets = stylesheet.getAttributeSetComposed(qname);
            if (null != attrSets) {
                int nSets = attrSets.size();
                // so process it last.
                for (int k = nSets - 1; k >= 0; k--) {
                    ElemAttributeSet attrSet = (ElemAttributeSet) attrSets.get(k);
                    attrSet.execute(transformer);
                }
            } else {
                throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_ATTRIB_SET, new Object[] { qname }), this);
            }
        }
    }
}
Also used : QName(org.apache.xml.utils.QName) TransformerException(javax.xml.transform.TransformerException)

Example 18 with QName

use of org.apache.xml.utils.QName in project robovm by robovm.

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;
}
Also used : Expression(org.apache.xpath.Expression) QName(org.apache.xml.utils.QName) LocPathIterator(org.apache.xpath.axes.LocPathIterator) ExpressionOwner(org.apache.xpath.ExpressionOwner)

Example 19 with QName

use of org.apache.xml.utils.QName in project robovm by robovm.

the class KeyIterator method acceptNode.

/**
   *  Test whether a specified node is visible in the logical view of a
   * TreeWalker or NodeIterator. This function will be called by the
   * implementation of TreeWalker and NodeIterator; it is not intended to
   * be called directly from user code.
   * 
   * @param testNode  The node to check to see if it passes the filter or not.
   *
   * @return  a constant to determine whether the node is accepted,
   *   rejected, or skipped, as defined  above .
   */
public short acceptNode(int testNode) {
    boolean foundKey = false;
    KeyIterator ki = (KeyIterator) m_lpi;
    org.apache.xpath.XPathContext xctxt = ki.getXPathContext();
    Vector keys = ki.getKeyDeclarations();
    QName name = ki.getName();
    try {
        // System.out.println("lookupKey: "+lookupKey);
        int nDeclarations = keys.size();
        // Walk through each of the declarations made with xsl:key
        for (int i = 0; i < nDeclarations; i++) {
            KeyDeclaration kd = (KeyDeclaration) keys.elementAt(i);
            // matches the name on the iterator for this walker. 
            if (!kd.getName().equals(name))
                continue;
            foundKey = true;
            // xctxt.setNamespaceContext(ki.getPrefixResolver());
            // See if our node matches the given key declaration according to 
            // the match attribute on xsl:key.
            XPath matchExpr = kd.getMatch();
            double score = matchExpr.getMatchScore(xctxt, testNode);
            if (score == kd.getMatch().MATCH_SCORE_NONE)
                continue;
            return DTMIterator.FILTER_ACCEPT;
        }
    // end for(int i = 0; i < nDeclarations; i++)
    } catch (TransformerException se) {
    // TODO: What to do?
    }
    if (!foundKey)
        throw new RuntimeException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_XSLKEY_DECLARATION, new Object[] { name.getLocalName() }));
    return DTMIterator.FILTER_REJECT;
}
Also used : XPath(org.apache.xpath.XPath) QName(org.apache.xml.utils.QName) KeyDeclaration(org.apache.xalan.templates.KeyDeclaration) Vector(java.util.Vector) TransformerException(javax.xml.transform.TransformerException)

Example 20 with QName

use of org.apache.xml.utils.QName in project robovm by robovm.

the class ElemApplyTemplates method execute.

/**
   * Apply the context node to the matching templates.
   * @see <a href="http://www.w3.org/TR/xslt#section-Applying-Template-Rules">section-Applying-Template-Rules 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 {
    transformer.pushCurrentTemplateRuleIsNull(false);
    boolean pushMode = false;
    try {
        // %REVIEW% Do we need this check??
        //      if (null != sourceNode)
        //      {
        // boolean needToTurnOffInfiniteLoopCheck = false;
        QName mode = transformer.getMode();
        if (!m_isDefaultTemplate) {
            if (((null == mode) && (null != m_mode)) || ((null != mode) && !mode.equals(m_mode))) {
                pushMode = true;
                transformer.pushMode(m_mode);
            }
        }
        transformSelectedNodes(transformer);
    } finally {
        if (pushMode)
            transformer.popMode();
        transformer.popCurrentTemplateRuleIsNull();
    }
}
Also used : QName(org.apache.xml.utils.QName)

Aggregations

QName (org.apache.xml.utils.QName)47 TransformerException (javax.xml.transform.TransformerException)16 Vector (java.util.Vector)12 XObject (org.apache.xpath.objects.XObject)10 DTM (org.apache.xml.dtm.DTM)6 DTMIterator (org.apache.xml.dtm.DTMIterator)6 Expression (org.apache.xpath.Expression)6 XPathContext (org.apache.xpath.XPathContext)6 StringTokenizer (java.util.StringTokenizer)5 TransformerImpl (org.apache.xalan.transformer.TransformerImpl)4 FastStringBuffer (org.apache.xml.utils.FastStringBuffer)4 StringVector (org.apache.xml.utils.StringVector)4 Arg (org.apache.xpath.Arg)4 ExpressionOwner (org.apache.xpath.ExpressionOwner)4 LocPathIterator (org.apache.xpath.axes.LocPathIterator)4 XString (org.apache.xpath.objects.XString)4 SAXException (org.xml.sax.SAXException)4 VariableStack (org.apache.xpath.VariableStack)3 XPath (org.apache.xpath.XPath)3 Hashtable (java.util.Hashtable)2