Search in sources :

Example 11 with ElemTemplateElement

use of org.apache.xalan.templates.ElemTemplateElement in project robovm by robovm.

the class ProcessorExsltFuncResult method startElement.

/**
   * Verify that the func:result element does not appear within a variable,
   * parameter, or another func:result, and that it belongs to a func:function 
   * element.
   */
public void startElement(StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) throws SAXException {
    String msg = "";
    super.startElement(handler, uri, localName, rawName, attributes);
    ElemTemplateElement ancestor = handler.getElemTemplateElement().getParentElem();
    while (ancestor != null && !(ancestor instanceof ElemExsltFunction)) {
        if (ancestor instanceof ElemVariable || ancestor instanceof ElemParam || ancestor instanceof ElemExsltFuncResult) {
            msg = "func:result cannot appear within a variable, parameter, or another func:result.";
            handler.error(msg, new SAXException(msg));
        }
        ancestor = ancestor.getParentElem();
    }
    if (ancestor == null) {
        msg = "func:result must appear in a func:function element";
        handler.error(msg, new SAXException(msg));
    }
}
Also used : ElemVariable(org.apache.xalan.templates.ElemVariable) ElemExsltFuncResult(org.apache.xalan.templates.ElemExsltFuncResult) ElemParam(org.apache.xalan.templates.ElemParam) ElemExsltFunction(org.apache.xalan.templates.ElemExsltFunction) ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement) SAXException(org.xml.sax.SAXException)

Example 12 with ElemTemplateElement

use of org.apache.xalan.templates.ElemTemplateElement in project robovm by robovm.

the class ProcessorExsltFunction method validate.

/**
   * Non-recursive traversal of FunctionElement tree based on TreeWalker to verify that
   * there are no literal result elements except within a func:result element and that
   * the func:result element does not contain any following siblings except xsl:fallback.
   */
public void validate(ElemTemplateElement elem, StylesheetHandler handler) throws SAXException {
    String msg = "";
    while (elem != null) {
        //System.out.println("elem " + elem);
        if (elem instanceof ElemExsltFuncResult && elem.getNextSiblingElem() != null && !(elem.getNextSiblingElem() instanceof ElemFallback)) {
            msg = "func:result has an illegal following sibling (only xsl:fallback allowed)";
            handler.error(msg, new SAXException(msg));
        }
        if ((elem instanceof ElemApplyImport || elem instanceof ElemApplyTemplates || elem instanceof ElemAttribute || elem instanceof ElemCallTemplate || elem instanceof ElemComment || elem instanceof ElemCopy || elem instanceof ElemCopyOf || elem instanceof ElemElement || elem instanceof ElemLiteralResult || elem instanceof ElemNumber || elem instanceof ElemPI || elem instanceof ElemText || elem instanceof ElemTextLiteral || elem instanceof ElemValueOf) && !(ancestorIsOk(elem))) {
            msg = "misplaced literal result in a func:function container.";
            handler.error(msg, new SAXException(msg));
        }
        ElemTemplateElement nextElem = elem.getFirstChildElem();
        while (nextElem == null) {
            nextElem = elem.getNextSiblingElem();
            if (nextElem == null)
                elem = elem.getParentElem();
            if (elem == null || elem instanceof ElemExsltFunction)
                // ok
                return;
        }
        elem = nextElem;
    }
}
Also used : ElemApplyImport(org.apache.xalan.templates.ElemApplyImport) ElemFallback(org.apache.xalan.templates.ElemFallback) ElemExsltFuncResult(org.apache.xalan.templates.ElemExsltFuncResult) ElemCallTemplate(org.apache.xalan.templates.ElemCallTemplate) ElemApplyTemplates(org.apache.xalan.templates.ElemApplyTemplates) ElemComment(org.apache.xalan.templates.ElemComment) ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement) SAXException(org.xml.sax.SAXException) ElemCopy(org.apache.xalan.templates.ElemCopy) ElemText(org.apache.xalan.templates.ElemText) ElemTextLiteral(org.apache.xalan.templates.ElemTextLiteral) ElemLiteralResult(org.apache.xalan.templates.ElemLiteralResult) ElemAttribute(org.apache.xalan.templates.ElemAttribute) ElemCopyOf(org.apache.xalan.templates.ElemCopyOf) ElemElement(org.apache.xalan.templates.ElemElement) ElemPI(org.apache.xalan.templates.ElemPI) ElemExsltFunction(org.apache.xalan.templates.ElemExsltFunction) ElemNumber(org.apache.xalan.templates.ElemNumber) ElemValueOf(org.apache.xalan.templates.ElemValueOf)

Example 13 with ElemTemplateElement

use of org.apache.xalan.templates.ElemTemplateElement in project robovm by robovm.

the class ProcessorTemplateElem method startElement.

/**
   * Receive notification of the start of an element.
   *
   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
   * @param uri The Namespace URI, or an empty string.
   * @param localName The local name (without prefix), or empty string if not namespace processing.
   * @param rawName The qualified name (with prefix).
   * @param attributes The specified or defaulted attributes.
   */
public void startElement(StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) throws org.xml.sax.SAXException {
    super.startElement(handler, uri, localName, rawName, attributes);
    try {
        // ElemTemplateElement parent = handler.getElemTemplateElement();
        XSLTElementDef def = getElemDef();
        Class classObject = def.getClassObject();
        ElemTemplateElement elem = null;
        try {
            elem = (ElemTemplateElement) classObject.newInstance();
            elem.setDOMBackPointer(handler.getOriginatingNode());
            elem.setLocaterInfo(handler.getLocator());
            elem.setPrefixes(handler.getNamespaceSupport());
        } catch (InstantiationException ie) {
            //"Failed creating ElemTemplateElement instance!", ie);
            handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMTMPL, null, ie);
        } catch (IllegalAccessException iae) {
            //"Failed creating ElemTemplateElement instance!", iae);
            handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMTMPL, null, iae);
        }
        setPropertiesFromAttributes(handler, rawName, attributes, elem);
        appendAndPush(handler, elem);
    } catch (TransformerException te) {
        throw new org.xml.sax.SAXException(te);
    }
}
Also used : ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement) TransformerException(javax.xml.transform.TransformerException)

Example 14 with ElemTemplateElement

use of org.apache.xalan.templates.ElemTemplateElement in project robovm by robovm.

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 15 with ElemTemplateElement

use of org.apache.xalan.templates.ElemTemplateElement in project robovm by robovm.

the class ProcessorLRE method endElement.

/**
   * Receive notification of the end of an element.
   *
   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
   * @param uri The Namespace URI, or an empty string.
   * @param localName The local name (without prefix), or empty string if not namespace processing.
   * @param rawName The qualified name (with prefix).
   */
public void endElement(StylesheetHandler handler, String uri, String localName, String rawName) throws org.xml.sax.SAXException {
    ElemTemplateElement elem = handler.getElemTemplateElement();
    if (elem instanceof ElemLiteralResult) {
        if (((ElemLiteralResult) elem).getIsLiteralResultAsStylesheet()) {
            handler.popStylesheet();
        }
    }
    super.endElement(handler, uri, localName, rawName);
}
Also used : ElemLiteralResult(org.apache.xalan.templates.ElemLiteralResult) ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement)

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