Search in sources :

Example 1 with ElemExsltFunction

use of org.apache.xalan.templates.ElemExsltFunction 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 2 with ElemExsltFunction

use of org.apache.xalan.templates.ElemExsltFunction 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 3 with ElemExsltFunction

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

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 4 with ElemExsltFunction

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

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 5 with ElemExsltFunction

use of org.apache.xalan.templates.ElemExsltFunction 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)

Aggregations

ElemExsltFuncResult (org.apache.xalan.templates.ElemExsltFuncResult)6 ElemExsltFunction (org.apache.xalan.templates.ElemExsltFunction)6 ElemTemplateElement (org.apache.xalan.templates.ElemTemplateElement)6 ElemParam (org.apache.xalan.templates.ElemParam)4 ElemVariable (org.apache.xalan.templates.ElemVariable)4 SAXException (org.xml.sax.SAXException)4 ElemApplyImport (org.apache.xalan.templates.ElemApplyImport)2 ElemApplyTemplates (org.apache.xalan.templates.ElemApplyTemplates)2 ElemAttribute (org.apache.xalan.templates.ElemAttribute)2 ElemCallTemplate (org.apache.xalan.templates.ElemCallTemplate)2 ElemComment (org.apache.xalan.templates.ElemComment)2 ElemCopy (org.apache.xalan.templates.ElemCopy)2 ElemCopyOf (org.apache.xalan.templates.ElemCopyOf)2 ElemElement (org.apache.xalan.templates.ElemElement)2 ElemFallback (org.apache.xalan.templates.ElemFallback)2 ElemLiteralResult (org.apache.xalan.templates.ElemLiteralResult)2 ElemMessage (org.apache.xalan.templates.ElemMessage)2 ElemNumber (org.apache.xalan.templates.ElemNumber)2 ElemPI (org.apache.xalan.templates.ElemPI)2 ElemText (org.apache.xalan.templates.ElemText)2