Search in sources :

Example 6 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 7 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 8 with ElemTemplateElement

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

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

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

the class ProcessorTemplateElem 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 the current template element.
   *
   * @throws org.xml.sax.SAXException Any SAX exception, possibly
   *            wrapping another exception.
   */
protected void appendAndPush(StylesheetHandler handler, ElemTemplateElement elem) throws org.xml.sax.SAXException {
    ElemTemplateElement parent = handler.getElemTemplateElement();
    if (// defensive, for better multiple error reporting. -sb
    null != parent) {
        parent.appendChild(elem);
        handler.pushElemTemplateElement(elem);
    }
}
Also used : ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement)

Example 10 with ElemTemplateElement

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

the class ProcessorAttributeSet method startElement.

/**
   * Receive notification of the start of an xsl:attribute-set element.
   *
   * @param handler The calling StylesheetHandler/TemplatesBuilder.
   * @param uri The Namespace URI, or the empty string if the
   *        element has no Namespace URI or if Namespace
   *        processing is not being performed.
   * @param localName The local name (without prefix), or the
   *        empty string if Namespace processing is not being
   *        performed.
   * @param rawName The raw XML 1.0 name (with prefix), or the
   *        empty string if raw names are not available.
   * @param attributes The attributes attached to the element.  If
   *        there are no attributes, it shall be an empty
   *        Attributes object.
   * 
   * @see org.apache.xalan.processor.StylesheetHandler#startElement
   * @see org.xml.sax.ContentHandler#startElement
   * @see org.xml.sax.ContentHandler#endElement
   * @see org.xml.sax.Attributes
   */
public void startElement(StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) throws org.xml.sax.SAXException {
    ElemAttributeSet eat = new ElemAttributeSet();
    eat.setLocaterInfo(handler.getLocator());
    try {
        eat.setPrefixes(handler.getNamespaceSupport());
    } catch (TransformerException te) {
        throw new org.xml.sax.SAXException(te);
    }
    eat.setDOMBackPointer(handler.getOriginatingNode());
    setPropertiesFromAttributes(handler, rawName, attributes, eat);
    handler.getStylesheet().setAttributeSet(eat);
    // handler.pushElemTemplateElement(eat);
    ElemTemplateElement parent = handler.getElemTemplateElement();
    parent.appendChild(eat);
    handler.pushElemTemplateElement(eat);
}
Also used : ElemAttributeSet(org.apache.xalan.templates.ElemAttributeSet) TransformerException(javax.xml.transform.TransformerException) 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