Search in sources :

Example 6 with QName

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

the class RedundentExprEliminator method findAndEliminateRedundant.

/**
   * Look through the vector from start point, looking for redundant occurances.
   * When one or more are found, create a psuedo variable declaration, insert 
   * it into the stylesheet, and replace the occurance with a reference to 
   * the psuedo variable.  When a redundent variable is found, it's slot in 
   * the vector will be replaced by null.
   * 
   * @param start The position to start looking in the vector.
   * @param firstOccuranceIndex The position of firstOccuranceOwner.
   * @param firstOccuranceOwner The owner of the expression we are looking for.
   * @param psuedoVarRecipient Where to put the psuedo variables.
   * 
   * @return The number of expression occurances that were modified.
   */
protected int findAndEliminateRedundant(int start, int firstOccuranceIndex, ExpressionOwner firstOccuranceOwner, ElemTemplateElement psuedoVarRecipient, Vector paths) throws org.w3c.dom.DOMException {
    MultistepExprHolder head = null;
    MultistepExprHolder tail = null;
    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;
    int stepCount = countSteps(lpi);
    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 (null == head) {
                    head = new MultistepExprHolder(firstOccuranceOwner, stepCount, null);
                    tail = head;
                    numPathsFound++;
                }
                tail.m_next = new MultistepExprHolder(owner2, stepCount, null);
                tail = tail.m_next;
                // 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) && isGlobal) {
        head = new MultistepExprHolder(firstOccuranceOwner, stepCount, null);
        numPathsFound++;
    }
    if (null != head) {
        ElemTemplateElement root = isGlobal ? psuedoVarRecipient : findCommonAncestor(head);
        LocPathIterator sharedIter = (LocPathIterator) head.m_exprOwner.getExpression();
        ElemVariable var = createPseudoVarDecl(root, sharedIter, isGlobal);
        if (DIAGNOSE_MULTISTEPLIST)
            System.err.println("Created var: " + var.getName() + (isGlobal ? "(Global)" : ""));
        QName uniquePseudoVarName = var.getName();
        while (null != head) {
            ExpressionOwner owner = head.m_exprOwner;
            if (DIAGNOSE_MULTISTEPLIST)
                diagnoseLineNumber(owner.getExpression());
            changeToVarRef(uniquePseudoVarName, owner, paths, root);
            head = head.m_next;
        }
        // Replace the first occurance with the variable's XPath, so  
        // that further reduction may take place if needed.
        paths.setElementAt(var.getSelect(), firstOccuranceIndex);
    }
    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 7 with QName

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

the class XSLTAttributeDef method processENUM_OR_PQNAME.

/**
   * Process an attribute string of that is either an enumerated value or a qname-but-not-ncname.
   * Returns an AVT, if this attribute support AVT; otherwise returns int or qname.
   *
   * @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 non-null string that represents an enumerated value that is
   * valid for this element.
   * @param owner
   *
   * @return AVT if attribute supports AVT. An Integer representation of the enumerated value if
   *         attribute does not support AVT and an enumerated value was used.  Otherwise a qname
   *         is returned.
   */
Object processENUM_OR_PQNAME(StylesheetHandler handler, String uri, String name, String rawName, String value, ElemTemplateElement owner) throws org.xml.sax.SAXException {
    Object objToReturn = null;
    if (getSupportsAVT()) {
        try {
            AVT avt = new AVT(handler, uri, name, rawName, value, owner);
            if (!avt.isSimple())
                return avt;
            else
                objToReturn = avt;
        } catch (TransformerException te) {
            throw new org.xml.sax.SAXException(te);
        }
    }
    // An avt wasn't used.
    int key = this.getEnum(value);
    if (key != StringToIntTable.INVALID_KEY) {
        if (objToReturn == null)
            objToReturn = new Integer(key);
    } else // enum not used.  Validate qname-but-not-ncname.
    {
        try {
            QName qname = new QName(value, handler, true);
            if (objToReturn == null)
                objToReturn = qname;
            if (qname.getPrefix() == null) {
                StringBuffer enumNamesList = getListOfEnums();
                enumNamesList.append(" <qname-but-not-ncname>");
                handleError(handler, XSLTErrorResources.INVALID_ENUM, new Object[] { name, value, enumNamesList.toString() }, null);
                return null;
            }
        } catch (IllegalArgumentException ie) {
            StringBuffer enumNamesList = getListOfEnums();
            enumNamesList.append(" <qname-but-not-ncname>");
            handleError(handler, XSLTErrorResources.INVALID_ENUM, new Object[] { name, value, enumNamesList.toString() }, ie);
            return null;
        } catch (RuntimeException re) {
            StringBuffer enumNamesList = getListOfEnums();
            enumNamesList.append(" <qname-but-not-ncname>");
            handleError(handler, XSLTErrorResources.INVALID_ENUM, new Object[] { name, value, enumNamesList.toString() }, re);
            return null;
        }
    }
    return objToReturn;
}
Also used : QName(org.apache.xml.utils.QName) TransformerException(javax.xml.transform.TransformerException) AVT(org.apache.xalan.templates.AVT)

Example 8 with QName

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

the class JAXPVariableStack method getVariableOrParam.

public XObject getVariableOrParam(XPathContext xctxt, QName qname) throws TransformerException, IllegalArgumentException {
    if (qname == null) {
        //JAXP 1.3 spec says that if variable name is null then 
        // we need to through IllegalArgumentException
        String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_ARG_CANNOT_BE_NULL, new Object[] { "Variable qname" });
        throw new IllegalArgumentException(fmsg);
    }
    javax.xml.namespace.QName name = new javax.xml.namespace.QName(qname.getNamespace(), qname.getLocalPart());
    Object varValue = resolver.resolveVariable(name);
    if (varValue == null) {
        String fmsg = XSLMessages.createXPATHMessage(XPATHErrorResources.ER_RESOLVE_VARIABLE_RETURNS_NULL, new Object[] { name.toString() });
        throw new TransformerException(fmsg);
    }
    return XObject.create(varValue, xctxt);
}
Also used : QName(org.apache.xml.utils.QName) XObject(org.apache.xpath.objects.XObject) TransformerException(javax.xml.transform.TransformerException)

Example 9 with QName

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

the class TransformerImpl method setParameter.

/**
 * Set a parameter for the templates.
 *
 * @param name The name of the parameter.
 * @param namespace The namespace of the parameter.
 * @param value The value object.  This can be any valid Java object
 * -- it's up to the processor to provide the proper
 * coersion to the object, or simply pass it on for use
 * in extensions.
 */
public void setParameter(String name, String namespace, Object value) {
    VariableStack varstack = getXPathContext().getVarStack();
    QName qname = new QName(namespace, name);
    XObject xobject = XObject.create(value, getXPathContext());
    StylesheetRoot sroot = m_stylesheetRoot;
    Vector vars = sroot.getVariablesAndParamsComposed();
    int i = vars.size();
    while (--i >= 0) {
        ElemVariable variable = (ElemVariable) vars.elementAt(i);
        if (variable.getXSLToken() == Constants.ELEMNAME_PARAMVARIABLE && variable.getName().equals(qname)) {
            varstack.setGlobalVariable(i, xobject);
        }
    }
}
Also used : VariableStack(org.apache.xpath.VariableStack) ElemVariable(org.apache.xalan.templates.ElemVariable) StylesheetRoot(org.apache.xalan.templates.StylesheetRoot) QName(org.apache.xml.utils.QName) Vector(java.util.Vector) NodeVector(org.apache.xml.utils.NodeVector) XObject(org.apache.xpath.objects.XObject)

Example 10 with QName

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

the class TransformerImpl method resetUserParameters.

/**
 * Reset parameters that the user specified for the transformation.
 * Called during transformer.reset() after we have cleared the
 * variable stack. We need to make sure that user params are
 * reset so that the transformer object can be reused.
 */
private void resetUserParameters() {
    try {
        if (null == m_userParams)
            return;
        int n = m_userParams.size();
        for (int i = n - 1; i >= 0; i--) {
            Arg arg = (Arg) m_userParams.elementAt(i);
            QName name = arg.getQName();
            // The first string might be the namespace, or it might be
            // the local name, if the namespace is null.
            String s1 = name.getNamespace();
            String s2 = name.getLocalPart();
            setParameter(s2, s1, arg.getVal().object());
        }
    } catch (java.util.NoSuchElementException nsee) {
    // Should throw some sort of an error.
    }
}
Also used : QName(org.apache.xml.utils.QName) Arg(org.apache.xpath.Arg)

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