Search in sources :

Example 36 with QName

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

the class FuncExtElementAvailable 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 {
    String prefix;
    String namespace;
    String methName;
    String fullName = m_arg0.execute(xctxt).str();
    int indexOfNSSep = fullName.indexOf(':');
    if (indexOfNSSep < 0) {
        prefix = "";
        namespace = Constants.S_XSLNAMESPACEURL;
        methName = fullName;
    } else {
        prefix = fullName.substring(0, indexOfNSSep);
        namespace = xctxt.getNamespaceContext().getNamespaceForPrefix(prefix);
        if (null == namespace)
            return XBoolean.S_FALSE;
        methName = fullName.substring(indexOfNSSep + 1);
    }
    if (namespace.equals(Constants.S_XSLNAMESPACEURL) || namespace.equals(Constants.S_BUILTIN_EXTENSIONS_URL)) {
        try {
            TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
            return transformer.getStylesheet().getAvailableElements().containsKey(new QName(namespace, methName)) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
        } catch (Exception e) {
            return XBoolean.S_FALSE;
        }
    } else {
        // dml
        ExtensionsProvider extProvider = (ExtensionsProvider) xctxt.getOwnerObject();
        return extProvider.elementAvailable(namespace, methName) ? XBoolean.S_TRUE : XBoolean.S_FALSE;
    }
}
Also used : ExtensionsProvider(org.apache.xpath.ExtensionsProvider) TransformerImpl(org.apache.xalan.transformer.TransformerImpl) QName(org.apache.xml.utils.QName)

Example 37 with QName

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

the class FuncKey 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 {
    // TransformerImpl transformer = (TransformerImpl)xctxt;
    TransformerImpl transformer = (TransformerImpl) xctxt.getOwnerObject();
    XNodeSet nodes = null;
    int context = xctxt.getCurrentNode();
    DTM dtm = xctxt.getDTM(context);
    int docContext = dtm.getDocumentRoot(context);
    if (DTM.NULL == docContext) {
    // path.error(context, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC); //"context does not have an owner document!");
    }
    String xkeyname = getArg0().execute(xctxt).str();
    QName keyname = new QName(xkeyname, xctxt.getNamespaceContext());
    XObject arg = getArg1().execute(xctxt);
    boolean argIsNodeSetDTM = (XObject.CLASS_NODESET == arg.getType());
    KeyManager kmgr = transformer.getKeyManager();
    // Don't bother with nodeset logic if the thing is only one node.
    if (argIsNodeSetDTM) {
        XNodeSet ns = (XNodeSet) arg;
        ns.setShouldCacheNodes(true);
        int len = ns.getLength();
        if (len <= 1)
            argIsNodeSetDTM = false;
    }
    if (argIsNodeSetDTM) {
        Hashtable usedrefs = null;
        DTMIterator ni = arg.iter();
        int pos;
        UnionPathIterator upi = new UnionPathIterator();
        upi.exprSetParent(this);
        while (DTM.NULL != (pos = ni.nextNode())) {
            dtm = xctxt.getDTM(pos);
            XMLString ref = dtm.getStringValue(pos);
            if (null == ref)
                continue;
            if (null == usedrefs)
                usedrefs = new Hashtable();
            if (usedrefs.get(ref) != null) {
                // We already have 'em.
                continue;
            } else {
                // ISTRUE being used as a dummy value.
                usedrefs.put(ref, ISTRUE);
            }
            XNodeSet nl = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
            nl.setRoot(xctxt.getCurrentNode(), xctxt);
            // try
            // {
            upi.addIterator(nl);
        // }
        // catch(CloneNotSupportedException cnse)
        // {
        // // will never happen.
        // }
        // mnodeset.addNodesInDocOrder(nl, xctxt); needed??
        }
        int current = xctxt.getCurrentNode();
        upi.setRoot(current, xctxt);
        nodes = new XNodeSet(upi);
    } else {
        XMLString ref = arg.xstr();
        nodes = kmgr.getNodeSetDTMByKey(xctxt, docContext, keyname, ref, xctxt.getNamespaceContext());
        nodes.setRoot(xctxt.getCurrentNode(), xctxt);
    }
    return nodes;
}
Also used : TransformerImpl(org.apache.xalan.transformer.TransformerImpl) UnionPathIterator(org.apache.xpath.axes.UnionPathIterator) QName(org.apache.xml.utils.QName) Hashtable(java.util.Hashtable) XMLString(org.apache.xml.utils.XMLString) XNodeSet(org.apache.xpath.objects.XNodeSet) DTMIterator(org.apache.xml.dtm.DTMIterator) DTM(org.apache.xml.dtm.DTM) XMLString(org.apache.xml.utils.XMLString) KeyManager(org.apache.xalan.transformer.KeyManager) XObject(org.apache.xpath.objects.XObject)

Example 38 with QName

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

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 39 with QName

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

the class ProcessorOutputElem method addLiteralResultAttribute.

/**
 * Set a foreign property from the attribute value.
 * @param newValue non-null reference to attribute value.
 */
public void addLiteralResultAttribute(String attrUri, String attrLocalName, String attrRawName, String attrValue) {
    QName key = new QName(attrUri, attrLocalName);
    m_outputProperties.setProperty(key, attrValue);
}
Also used : QName(org.apache.xml.utils.QName)

Example 40 with QName

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

the class ProcessorOutputElem method setForeignAttr.

/**
 * Set a foreign property from the attribute value.
 * @param newValue non-null reference to attribute value.
 */
public void setForeignAttr(String attrUri, String attrLocalName, String attrRawName, String attrValue) {
    QName key = new QName(attrUri, attrLocalName);
    m_outputProperties.setProperty(key, attrValue);
}
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