Search in sources :

Example 1 with KeyDeclaration

use of org.apache.xalan.templates.KeyDeclaration in project j2objc by google.

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 2 with KeyDeclaration

use of org.apache.xalan.templates.KeyDeclaration in project j2objc by google.

the class KeyTable method getKeyDeclarations.

/**
 * @return key declarations for the key associated to this KeyTable
 */
private Vector getKeyDeclarations() {
    int nDeclarations = m_keyDeclarations.size();
    Vector keyDecls = new Vector(nDeclarations);
    // Walk through each of the declarations made with xsl:key
    for (int i = 0; i < nDeclarations; i++) {
        KeyDeclaration kd = (KeyDeclaration) m_keyDeclarations.elementAt(i);
        // matches the name on the iterator for this walker.
        if (kd.getName().equals(getKeyTableName())) {
            keyDecls.add(kd);
        }
    }
    return keyDecls;
}
Also used : KeyDeclaration(org.apache.xalan.templates.KeyDeclaration) Vector(java.util.Vector)

Example 3 with KeyDeclaration

use of org.apache.xalan.templates.KeyDeclaration 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;
}
Also used : Hashtable(java.util.Hashtable) DTMIterator(org.apache.xml.dtm.DTMIterator) XNodeSet(org.apache.xpath.objects.XNodeSet) KeyDeclaration(org.apache.xalan.templates.KeyDeclaration) XPathContext(org.apache.xpath.XPathContext) XMLString(org.apache.xml.utils.XMLString) DTM(org.apache.xml.dtm.DTM) Vector(java.util.Vector) XObject(org.apache.xpath.objects.XObject) TransformerException(javax.xml.transform.TransformerException) WrappedRuntimeException(org.apache.xml.utils.WrappedRuntimeException)

Example 4 with KeyDeclaration

use of org.apache.xalan.templates.KeyDeclaration in project robovm by robovm.

the class KeyTable method getKeyDeclarations.

/**
   * @return key declarations for the key associated to this KeyTable
   */
private Vector getKeyDeclarations() {
    int nDeclarations = m_keyDeclarations.size();
    Vector keyDecls = new Vector(nDeclarations);
    // Walk through each of the declarations made with xsl:key
    for (int i = 0; i < nDeclarations; i++) {
        KeyDeclaration kd = (KeyDeclaration) m_keyDeclarations.elementAt(i);
        // matches the name on the iterator for this walker.
        if (kd.getName().equals(getKeyTableName())) {
            keyDecls.add(kd);
        }
    }
    return keyDecls;
}
Also used : KeyDeclaration(org.apache.xalan.templates.KeyDeclaration) Vector(java.util.Vector)

Example 5 with KeyDeclaration

use of org.apache.xalan.templates.KeyDeclaration 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)

Aggregations

KeyDeclaration (org.apache.xalan.templates.KeyDeclaration)8 Vector (java.util.Vector)6 TransformerException (javax.xml.transform.TransformerException)4 Hashtable (java.util.Hashtable)2 DTM (org.apache.xml.dtm.DTM)2 DTMIterator (org.apache.xml.dtm.DTMIterator)2 QName (org.apache.xml.utils.QName)2 WrappedRuntimeException (org.apache.xml.utils.WrappedRuntimeException)2 XMLString (org.apache.xml.utils.XMLString)2 XPath (org.apache.xpath.XPath)2 XPathContext (org.apache.xpath.XPathContext)2 XNodeSet (org.apache.xpath.objects.XNodeSet)2 XObject (org.apache.xpath.objects.XObject)2