Search in sources :

Example 11 with QName

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

the class TransformerImpl method getParameter.

/**
 * Get a parameter that was explicitly set with setParameter
 * or setParameters.
 *
 * NEEDSDOC @param name
 * @return A parameter that has been set with setParameter
 * or setParameters,
 * *not* all the xsl:params on the stylesheet (which require
 * a transformation Source to be evaluated).
 */
public Object getParameter(String name) {
    try {
        // VariableStack varstack = getXPathContext().getVarStack();
        // The first string might be the namespace, or it might be
        // the local name, if the namespace is null.
        QName qname = QName.getQNameFromString(name);
        if (null == m_userParams)
            return null;
        int n = m_userParams.size();
        for (int i = n - 1; i >= 0; i--) {
            Arg arg = (Arg) m_userParams.elementAt(i);
            if (arg.getQName().equals(qname)) {
                return arg.getVal().object();
            }
        }
        return null;
    } catch (java.util.NoSuchElementException nsee) {
        // Should throw some sort of an error.
        return null;
    }
}
Also used : QName(org.apache.xml.utils.QName) Arg(org.apache.xpath.Arg)

Example 12 with QName

use of org.apache.xml.utils.QName 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;
}
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 13 with QName

use of org.apache.xml.utils.QName 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 14 with QName

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

the class XSLTAttributeDef method processQNAMES.

/**
 * Process an attribute string of type T_QNAMES into a vector of QNames where
 * the specification requires that non-prefixed elements not be placed in a
 * namespace.  (See section 2.4 of XSLT 1.0.)
 *
 * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
 * @param uri The Namespace URI, or an empty string.
 * @param name The local name (without prefix), or empty string if not namespace processing.
 * @param rawName The qualified name (with prefix).
 * @param value A whitespace delimited list of qualified names.
 *
 * @return a Vector of QName objects.
 *
 * @throws org.xml.sax.SAXException if the one of the qualified name strings
 * contains a prefix that can not be
 * resolved, or a qualified name contains syntax that is invalid for a qualified name.
 */
Vector processQNAMES(StylesheetHandler handler, String uri, String name, String rawName, String value) throws org.xml.sax.SAXException {
    StringTokenizer tokenizer = new StringTokenizer(value, " \t\n\r\f");
    int nQNames = tokenizer.countTokens();
    Vector qnames = new Vector(nQNames);
    for (int i = 0; i < nQNames; i++) {
        // Fix from Alexander Rudnev
        qnames.addElement(new QName(tokenizer.nextToken(), handler));
    }
    return qnames;
}
Also used : StringTokenizer(java.util.StringTokenizer) QName(org.apache.xml.utils.QName) Vector(java.util.Vector) StringVector(org.apache.xml.utils.StringVector)

Example 15 with QName

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

the class Variable method fixupVariables.

/**
 * This function is used to fixup variables from QNames to stack frame
 * indexes at stylesheet build time.
 * @param vars List of QNames that correspond to variables.  This list
 * should be searched backwards for the first qualified name that
 * corresponds to the variable reference qname.  The position of the
 * QName in the vector from the start of the vector will be its position
 * in the stack frame (but variables above the globalsTop value will need
 * to be offset to the current stack frame).
 */
public void fixupVariables(java.util.Vector vars, int globalsSize) {
    m_fixUpWasCalled = true;
    int sz = vars.size();
    for (int i = vars.size() - 1; i >= 0; i--) {
        QName qn = (QName) vars.elementAt(i);
        // System.out.println("qn: "+qn);
        if (qn.equals(m_qname)) {
            if (i < globalsSize) {
                m_isGlobal = true;
                m_index = i;
            } else {
                m_index = i - globalsSize;
            }
            return;
        }
    }
    java.lang.String msg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_COULD_NOT_FIND_VAR, new Object[] { m_qname.toString() });
    TransformerException te = new TransformerException(msg, this);
    throw new org.apache.xml.utils.WrappedRuntimeException(te);
}
Also used : QName(org.apache.xml.utils.QName) TransformerException(javax.xml.transform.TransformerException)

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