Search in sources :

Example 31 with QName

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

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

use of org.apache.xml.utils.QName in project webtools.sourceediting by eclipse.

the class XalanStyleFrame method getName.

public String getName() {
    String name = event.m_styleNode.getNodeName();
    if (event.m_styleNode instanceof ElemTemplate) {
        ElemTemplate et = (ElemTemplate) event.m_styleNode;
        QName q = et.getName();
        if (q != null) {
            name += " name=\"" + q.getLocalName() + "\"";
        }
        XPath xp = et.getMatch();
        if (xp != null) {
            name += " match=\"" + xp.getPatternString() + "\"";
        }
    } else if (event.m_styleNode instanceof ElemCallTemplate) {
        ElemCallTemplate et = (ElemCallTemplate) event.m_styleNode;
        QName q = et.getName();
        if (q != null) {
            name += " name=\"" + q.getLocalName() + "\"";
        }
    }
    return name;
}
Also used : XPath(org.apache.xpath.XPath) ElemTemplate(org.apache.xalan.templates.ElemTemplate) QName(org.apache.xml.utils.QName) ElemCallTemplate(org.apache.xalan.templates.ElemCallTemplate)

Example 33 with QName

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

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

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

the class XSLTAttributeDef method processQNAMESRNU.

/**
 * Process an attribute string of type T_QNAMES_RESOLVE_NULL into a vector
 * of QNames where the specification requires non-prefixed elements to be
 * placed in the default namespace.  (See section 16 of XSLT 1.0; the
 * <em>only</em> time that this will get called is for the
 * <code>cdata-section-elements</code> attribute on <code>xsl:output</code>.
 *
 * @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.
 */
final Vector processQNAMESRNU(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);
    String defaultURI = handler.getNamespaceForPrefix("");
    for (int i = 0; i < nQNames; i++) {
        String tok = tokenizer.nextToken();
        if (tok.indexOf(':') == -1) {
            qnames.addElement(new QName(defaultURI, tok));
        } else {
            qnames.addElement(new QName(tok, 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 35 with QName

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

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)

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