Search in sources :

Example 26 with QName

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

the class TransformerImpl method setParameter.

/**
   * Set a parameter for the transformation.
   *
   * @param name The name of the parameter,
   *             which may have a namespace URI.
   * @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, Object value) {
    if (value == null) {
        throw new IllegalArgumentException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_SET_PARAM_VALUE, new Object[] { name }));
    }
    StringTokenizer tokenizer = new StringTokenizer(name, "{}", false);
    try {
        // The first string might be the namespace, or it might be 
        // the local name, if the namespace is null.
        String s1 = tokenizer.nextToken();
        String s2 = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
        if (null == m_userParams)
            m_userParams = new Vector();
        if (null == s2) {
            replaceOrPushUserParam(new QName(s1), XObject.create(value, getXPathContext()));
            setParameter(s1, null, value);
        } else {
            replaceOrPushUserParam(new QName(s1, s2), XObject.create(value, getXPathContext()));
            setParameter(s2, s1, value);
        }
    } catch (java.util.NoSuchElementException nsee) {
    // Should throw some sort of an error.
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) QName(org.apache.xml.utils.QName) XObject(org.apache.xpath.objects.XObject) Vector(java.util.Vector) NodeVector(org.apache.xml.utils.NodeVector)

Example 27 with QName

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

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

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

the class TransformerImpl method applyTemplateToNode.

/**
   * Given an element and mode, find the corresponding
   * template and process the contents.
   *
   * @param xslInstruction The calling element.
   * @param template The template to use if xsl:for-each, current template for apply-imports, or null.
   * @param child The source context node.
   * @throws TransformerException
   * @return true if applied a template, false if not.
   * @xsl.usage advanced
   */
public // xsl:apply-templates or xsl:for-each
boolean applyTemplateToNode(// xsl:apply-templates or xsl:for-each
ElemTemplateElement xslInstruction, ElemTemplate template, int child) throws TransformerException {
    DTM dtm = m_xcontext.getDTM(child);
    short nodeType = dtm.getNodeType(child);
    boolean isDefaultTextRule = false;
    boolean isApplyImports = false;
    isApplyImports = ((xslInstruction == null) ? false : xslInstruction.getXSLToken() == Constants.ELEMNAME_APPLY_IMPORTS);
    if (null == template || isApplyImports) {
        int maxImportLevel, endImportLevel = 0;
        if (isApplyImports) {
            maxImportLevel = template.getStylesheetComposed().getImportCountComposed() - 1;
            endImportLevel = template.getStylesheetComposed().getEndImportCountComposed();
        } else {
            maxImportLevel = -1;
        }
        // We want to match -no- templates. See bugzilla bug 1170.
        if (isApplyImports && (maxImportLevel == -1)) {
            template = null;
        } else {
            // Find the XSL template that is the best match for the 
            // element.        
            XPathContext xctxt = m_xcontext;
            try {
                xctxt.pushNamespaceContext(xslInstruction);
                QName mode = this.getMode();
                if (isApplyImports)
                    template = m_stylesheetRoot.getTemplateComposed(xctxt, child, mode, maxImportLevel, endImportLevel, m_quietConflictWarnings, dtm);
                else
                    template = m_stylesheetRoot.getTemplateComposed(xctxt, child, mode, m_quietConflictWarnings, dtm);
            } finally {
                xctxt.popNamespaceContext();
            }
        }
        // See http://www.w3.org/TR/xslt#built-in-rule.
        if (null == template) {
            switch(nodeType) {
                case DTM.DOCUMENT_FRAGMENT_NODE:
                case DTM.ELEMENT_NODE:
                    template = m_stylesheetRoot.getDefaultRule();
                    break;
                case DTM.CDATA_SECTION_NODE:
                case DTM.TEXT_NODE:
                case DTM.ATTRIBUTE_NODE:
                    template = m_stylesheetRoot.getDefaultTextRule();
                    isDefaultTextRule = true;
                    break;
                case DTM.DOCUMENT_NODE:
                    template = m_stylesheetRoot.getDefaultRootRule();
                    break;
                default:
                    // No default rules for processing instructions and the like.
                    return false;
            }
        }
    }
    // the value directly to the result tree.
    try {
        pushElemTemplateElement(template);
        m_xcontext.pushCurrentNode(child);
        pushPairCurrentMatched(template, child);
        // Fix copy copy29 test.
        if (!isApplyImports) {
            DTMIterator cnl = new org.apache.xpath.NodeSetDTM(child, m_xcontext.getDTMManager());
            m_xcontext.pushContextNodeList(cnl);
        }
        if (isDefaultTextRule) {
            switch(nodeType) {
                case DTM.CDATA_SECTION_NODE:
                case DTM.TEXT_NODE:
                    ClonerToResultTree.cloneToResultTree(child, nodeType, dtm, getResultTreeHandler(), false);
                    break;
                case DTM.ATTRIBUTE_NODE:
                    dtm.dispatchCharactersEvents(child, getResultTreeHandler(), false);
                    break;
            }
        } else {
            // And execute the child templates.
            // 9/11/00: If template has been compiled, hand off to it
            // since much (most? all?) of the processing has been inlined.
            // (It would be nice if there was a single entry point that
            // worked for both... but the interpretive system works by
            // having the Tranformer execute the children, while the
            // compiled obviously has to run its own code. It's
            // also unclear that "execute" is really the right name for
            // that entry point.)
            m_xcontext.setSAXLocator(template);
            // m_xcontext.getVarStack().link();
            m_xcontext.getVarStack().link(template.m_frameSize);
            executeChildTemplates(template, true);
        }
    } catch (org.xml.sax.SAXException se) {
        throw new TransformerException(se);
    } finally {
        if (!isDefaultTextRule)
            m_xcontext.getVarStack().unlink();
        m_xcontext.popCurrentNode();
        if (!isApplyImports) {
            m_xcontext.popContextNodeList();
        }
        popCurrentMatched();
        popElemTemplateElement();
    }
    return true;
}
Also used : QName(org.apache.xml.utils.QName) DTMIterator(org.apache.xml.dtm.DTMIterator) SAXException(org.xml.sax.SAXException) XPathContext(org.apache.xpath.XPathContext) DTM(org.apache.xml.dtm.DTM) TransformerException(javax.xml.transform.TransformerException)

Example 29 with QName

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

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)

Example 30 with QName

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

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