Search in sources :

Example 21 with ElemTemplateElement

use of org.apache.xalan.templates.ElemTemplateElement in project j2objc by google.

the class ProcessorExsltFunction method ancestorIsOk.

/**
   * Verify that a literal result belongs to a result element, a variable, 
   * or a parameter.
   */
boolean ancestorIsOk(ElemTemplateElement child) {
    while (child.getParentElem() != null && !(child.getParentElem() instanceof ElemExsltFunction)) {
        ElemTemplateElement parent = child.getParentElem();
        if (parent instanceof ElemExsltFuncResult || parent instanceof ElemVariable || parent instanceof ElemParam || parent instanceof ElemMessage)
            return true;
        child = parent;
    }
    return false;
}
Also used : ElemVariable(org.apache.xalan.templates.ElemVariable) ElemExsltFuncResult(org.apache.xalan.templates.ElemExsltFuncResult) ElemParam(org.apache.xalan.templates.ElemParam) ElemMessage(org.apache.xalan.templates.ElemMessage) ElemExsltFunction(org.apache.xalan.templates.ElemExsltFunction) ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement)

Example 22 with ElemTemplateElement

use of org.apache.xalan.templates.ElemTemplateElement in project j2objc by google.

the class ProcessorText method appendAndPush.

/**
   * Append the current template element to the current
   * template element, and then push it onto the current template
   * element stack.
   *
   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
   * @param elem non-null reference to a {@link org.apache.xalan.templates.ElemText}.
   *
   * @throws org.xml.sax.SAXException Any SAX exception, possibly
   *            wrapping another exception.
   */
protected void appendAndPush(StylesheetHandler handler, ElemTemplateElement elem) throws org.xml.sax.SAXException {
    // Don't push this element onto the element stack.
    ProcessorCharacters charProcessor = (ProcessorCharacters) handler.getProcessorFor(null, "text()", "text");
    charProcessor.setXslTextElement((ElemText) elem);
    ElemTemplateElement parent = handler.getElemTemplateElement();
    parent.appendChild(elem);
    elem.setDOMBackPointer(handler.getOriginatingNode());
}
Also used : ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement)

Example 23 with ElemTemplateElement

use of org.apache.xalan.templates.ElemTemplateElement in project j2objc by google.

the class StylesheetHandler method getElemVersion.

private double getElemVersion() {
    ElemTemplateElement elem = getElemTemplateElement();
    double version = -1;
    while ((version == -1 || version == Constants.XSLTVERSUPPORTED) && elem != null) {
        try {
            version = Double.valueOf(elem.getXmlVersion()).doubleValue();
        } catch (Exception ex) {
            version = -1;
        }
        elem = elem.getParentElem();
    }
    return (version == -1) ? Constants.XSLTVERSUPPORTED : version;
}
Also used : ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException)

Example 24 with ElemTemplateElement

use of org.apache.xalan.templates.ElemTemplateElement in project j2objc by google.

the class TransformerImpl method executeChildTemplates.

/**
   * Execute each of the children of a template element.
   *
   * @param elem The ElemTemplateElement that contains the children
   * that should execute.
   * @param shouldAddAttrs true if xsl:attributes should be executed.
   *
   * @throws TransformerException
   * @xsl.usage advanced
   */
public void executeChildTemplates(ElemTemplateElement elem, boolean shouldAddAttrs) throws TransformerException {
    // Does this element have any children?
    ElemTemplateElement t = elem.getFirstChildElem();
    if (null == t)
        return;
    if (elem.hasTextLitOnly() && m_optimizer) {
        char[] chars = ((ElemTextLiteral) t).getChars();
        try {
            // Have to push stuff on for tooling...
            this.pushElemTemplateElement(t);
            m_serializationHandler.characters(chars, 0, chars.length);
        } catch (SAXException se) {
            throw new TransformerException(se);
        } finally {
            this.popElemTemplateElement();
        }
        return;
    }
    //    // Check for infinite loops if we have to.
    //    boolean check = (m_stackGuard.m_recursionLimit > -1);
    //
    //    if (check)
    //      getStackGuard().push(elem, xctxt.getCurrentNode());
    XPathContext xctxt = m_xcontext;
    xctxt.pushSAXLocatorNull();
    int currentTemplateElementsTop = m_currentTemplateElements.size();
    m_currentTemplateElements.push(null);
    try {
        // each of them.
        for (; t != null; t = t.getNextSiblingElem()) {
            if (!shouldAddAttrs && t.getXSLToken() == Constants.ELEMNAME_ATTRIBUTE)
                continue;
            xctxt.setSAXLocator(t);
            m_currentTemplateElements.setElementAt(t, currentTemplateElementsTop);
            t.execute(this);
        }
    } catch (RuntimeException re) {
        TransformerException te = new TransformerException(re);
        te.setLocator(t);
        throw te;
    } finally {
        m_currentTemplateElements.pop();
        xctxt.popSAXLocator();
    }
// Check for infinite loops if we have to
//    if (check)
//      getStackGuard().pop();
}
Also used : ElemTextLiteral(org.apache.xalan.templates.ElemTextLiteral) XPathContext(org.apache.xpath.XPathContext) ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 25 with ElemTemplateElement

use of org.apache.xalan.templates.ElemTemplateElement in project j2objc by google.

the class TransformerImpl method transformNode.

/**
   * Process the source node to the output result, if the
   * processor supports the "http://xml.org/trax/features/dom/input"
   * feature.
   * %REVIEW% Do we need a Node version of this?
   * @param node  The input source node, which can be any valid DTM node.
   *
   * @throws TransformerException
   */
public void transformNode(int node) throws TransformerException {
    //dml
    setExtensionsTable(getStylesheet());
    // Make sure we're not writing to the same output content handler.
    synchronized (m_serializationHandler) {
        m_hasBeenReset = false;
        XPathContext xctxt = getXPathContext();
        DTM dtm = xctxt.getDTM(node);
        try {
            pushGlobalVars(node);
            // ==========
            // Give the top-level templates a chance to pass information into 
            // the context (this is mainly for setting up tables for extensions).
            StylesheetRoot stylesheet = this.getStylesheet();
            int n = stylesheet.getGlobalImportCount();
            for (int i = 0; i < n; i++) {
                StylesheetComposed imported = stylesheet.getGlobalImport(i);
                int includedCount = imported.getIncludeCountComposed();
                for (int j = -1; j < includedCount; j++) {
                    Stylesheet included = imported.getIncludeComposed(j);
                    included.runtimeInit(this);
                    for (ElemTemplateElement child = included.getFirstChildElem(); child != null; child = child.getNextSiblingElem()) {
                        child.runtimeInit(this);
                    }
                }
            }
            // ===========        
            // System.out.println("Calling applyTemplateToNode - "+Thread.currentThread().getName());
            DTMIterator dtmIter = new org.apache.xpath.axes.SelfIteratorNoPredicate();
            dtmIter.setRoot(node, xctxt);
            xctxt.pushContextNodeList(dtmIter);
            try {
                this.applyTemplateToNode(null, null, node);
            } finally {
                xctxt.popContextNodeList();
            }
            // System.out.println("Done with applyTemplateToNode - "+Thread.currentThread().getName());
            if (null != m_serializationHandler) {
                m_serializationHandler.endDocument();
            }
        } catch (Exception se) {
            // SAXSourceLocator
            while (se instanceof org.apache.xml.utils.WrappedRuntimeException) {
                Exception e = ((org.apache.xml.utils.WrappedRuntimeException) se).getException();
                if (null != e)
                    se = e;
            }
            if (null != m_serializationHandler) {
                try {
                    if (se instanceof org.xml.sax.SAXParseException)
                        m_serializationHandler.fatalError((org.xml.sax.SAXParseException) se);
                    else if (se instanceof TransformerException) {
                        TransformerException te = ((TransformerException) se);
                        SAXSourceLocator sl = new SAXSourceLocator(te.getLocator());
                        m_serializationHandler.fatalError(new org.xml.sax.SAXParseException(te.getMessage(), sl, te));
                    } else {
                        m_serializationHandler.fatalError(new org.xml.sax.SAXParseException(se.getMessage(), new SAXSourceLocator(), se));
                    }
                } catch (Exception e) {
                }
            }
            if (se instanceof TransformerException) {
                m_errorHandler.fatalError((TransformerException) se);
            } else if (se instanceof org.xml.sax.SAXParseException) {
                m_errorHandler.fatalError(new TransformerException(se.getMessage(), new SAXSourceLocator((org.xml.sax.SAXParseException) se), se));
            } else {
                m_errorHandler.fatalError(new TransformerException(se));
            }
        } finally {
            this.reset();
        }
    }
}
Also used : StylesheetComposed(org.apache.xalan.templates.StylesheetComposed) Stylesheet(org.apache.xalan.templates.Stylesheet) ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXException(org.xml.sax.SAXException) TransformerException(javax.xml.transform.TransformerException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) DTMIterator(org.apache.xml.dtm.DTMIterator) StylesheetRoot(org.apache.xalan.templates.StylesheetRoot) XPathContext(org.apache.xpath.XPathContext) DTM(org.apache.xml.dtm.DTM) SAXSourceLocator(org.apache.xml.utils.SAXSourceLocator) TransformerException(javax.xml.transform.TransformerException)

Aggregations

ElemTemplateElement (org.apache.xalan.templates.ElemTemplateElement)35 TransformerException (javax.xml.transform.TransformerException)18 SAXException (org.xml.sax.SAXException)10 ElemTextLiteral (org.apache.xalan.templates.ElemTextLiteral)8 ElemExsltFuncResult (org.apache.xalan.templates.ElemExsltFuncResult)6 ElemExsltFunction (org.apache.xalan.templates.ElemExsltFunction)6 ElemLiteralResult (org.apache.xalan.templates.ElemLiteralResult)6 ElemVariable (org.apache.xalan.templates.ElemVariable)5 IOException (java.io.IOException)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)4 ElemParam (org.apache.xalan.templates.ElemParam)4 Stylesheet (org.apache.xalan.templates.Stylesheet)4 SAXSourceLocator (org.apache.xml.utils.SAXSourceLocator)4 XPathContext (org.apache.xpath.XPathContext)4 SAXNotRecognizedException (org.xml.sax.SAXNotRecognizedException)4 SAXNotSupportedException (org.xml.sax.SAXNotSupportedException)4 StringWriter (java.io.StringWriter)2 Vector (java.util.Vector)2 ElemApplyImport (org.apache.xalan.templates.ElemApplyImport)2