Search in sources :

Example 1 with ElemLiteralResult

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

Example 2 with ElemLiteralResult

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

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

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

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)

Example 5 with ElemLiteralResult

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

the class ProcessorLRE 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 {
    try {
        ElemTemplateElement p = handler.getElemTemplateElement();
        boolean excludeXSLDecl = false;
        boolean isLREAsStyleSheet = false;
        if (null == p) {
            // Literal Result Template as stylesheet.
            XSLTElementProcessor lreProcessor = handler.popProcessor();
            XSLTElementProcessor stylesheetProcessor = handler.getProcessorFor(Constants.S_XSLNAMESPACEURL, "stylesheet", "xsl:stylesheet");
            handler.pushProcessor(lreProcessor);
            Stylesheet stylesheet;
            try {
                stylesheet = getStylesheetRoot(handler);
            } catch (TransformerConfigurationException tfe) {
                throw new TransformerException(tfe);
            }
            // stylesheet.setDOMBackPointer(handler.getOriginatingNode());
            // ***** Note that we're assigning an empty locator. Is this necessary?
            SAXSourceLocator slocator = new SAXSourceLocator();
            Locator locator = handler.getLocator();
            if (null != locator) {
                slocator.setLineNumber(locator.getLineNumber());
                slocator.setColumnNumber(locator.getColumnNumber());
                slocator.setPublicId(locator.getPublicId());
                slocator.setSystemId(locator.getSystemId());
            }
            stylesheet.setLocaterInfo(slocator);
            stylesheet.setPrefixes(handler.getNamespaceSupport());
            handler.pushStylesheet(stylesheet);
            isLREAsStyleSheet = true;
            AttributesImpl stylesheetAttrs = new AttributesImpl();
            AttributesImpl lreAttrs = new AttributesImpl();
            int n = attributes.getLength();
            for (int i = 0; i < n; i++) {
                String attrLocalName = attributes.getLocalName(i);
                String attrUri = attributes.getURI(i);
                String value = attributes.getValue(i);
                if ((null != attrUri) && attrUri.equals(Constants.S_XSLNAMESPACEURL)) {
                    stylesheetAttrs.addAttribute(null, attrLocalName, attrLocalName, attributes.getType(i), attributes.getValue(i));
                } else if ((attrLocalName.startsWith("xmlns:") || attrLocalName.equals("xmlns")) && value.equals(Constants.S_XSLNAMESPACEURL)) {
                // ignore
                } else {
                    lreAttrs.addAttribute(attrUri, attrLocalName, attributes.getQName(i), attributes.getType(i), attributes.getValue(i));
                }
            }
            attributes = lreAttrs;
            // allowed on a stylesheet.
            try {
                stylesheetProcessor.setPropertiesFromAttributes(handler, "stylesheet", stylesheetAttrs, stylesheet);
            } catch (Exception e) {
                if (stylesheet.getDeclaredPrefixes() == null || !declaredXSLNS(stylesheet)) {
                    throw new org.xml.sax.SAXException(XSLMessages.createWarning(XSLTErrorResources.WG_OLD_XSLT_NS, null));
                } else {
                    throw new org.xml.sax.SAXException(e);
                }
            }
            handler.pushElemTemplateElement(stylesheet);
            ElemTemplate template = new ElemTemplate();
            if (slocator != null)
                template.setLocaterInfo(slocator);
            appendAndPush(handler, template);
            XPath rootMatch = new XPath("/", stylesheet, stylesheet, XPath.MATCH, handler.getStylesheetProcessor().getErrorListener());
            template.setMatch(rootMatch);
            // template.setDOMBackPointer(handler.getOriginatingNode());
            stylesheet.setTemplate(template);
            p = handler.getElemTemplateElement();
            excludeXSLDecl = true;
        }
        XSLTElementDef def = getElemDef();
        Class classObject = def.getClassObject();
        boolean isExtension = false;
        boolean isComponentDecl = false;
        boolean isUnknownTopLevel = false;
        while (null != p) {
            // System.out.println("Checking: "+p);
            if (p instanceof ElemLiteralResult) {
                ElemLiteralResult parentElem = (ElemLiteralResult) p;
                isExtension = parentElem.containsExtensionElementURI(uri);
            } else if (p instanceof Stylesheet) {
                Stylesheet parentElem = (Stylesheet) p;
                isExtension = parentElem.containsExtensionElementURI(uri);
                if ((false == isExtension) && (null != uri) && (uri.equals(Constants.S_BUILTIN_EXTENSIONS_URL) || uri.equals(Constants.S_BUILTIN_OLD_EXTENSIONS_URL))) {
                    isComponentDecl = true;
                } else {
                    isUnknownTopLevel = true;
                }
            }
            if (isExtension)
                break;
            p = p.getParentElem();
        }
        ElemTemplateElement elem = null;
        try {
            if (isExtension) {
                // System.out.println("Creating extension(1): "+uri);
                elem = new ElemExtensionCall();
            } else if (isComponentDecl) {
                elem = (ElemTemplateElement) classObject.newInstance();
            } else if (isUnknownTopLevel) {
                // TBD: Investigate, not sure about this.  -sb
                elem = (ElemTemplateElement) classObject.newInstance();
            } else {
                elem = (ElemTemplateElement) classObject.newInstance();
            }
            elem.setDOMBackPointer(handler.getOriginatingNode());
            elem.setLocaterInfo(handler.getLocator());
            elem.setPrefixes(handler.getNamespaceSupport(), excludeXSLDecl);
            if (elem instanceof ElemLiteralResult) {
                ((ElemLiteralResult) elem).setNamespace(uri);
                ((ElemLiteralResult) elem).setLocalName(localName);
                ((ElemLiteralResult) elem).setRawName(rawName);
                ((ElemLiteralResult) elem).setIsLiteralResultAsStylesheet(isLREAsStyleSheet);
            }
        } catch (InstantiationException ie) {
            //"Failed creating ElemLiteralResult instance!", ie);
            handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMLITRSLT, null, ie);
        } catch (IllegalAccessException iae) {
            //"Failed creating ElemLiteralResult instance!", iae);
            handler.error(XSLTErrorResources.ER_FAILED_CREATING_ELEMLITRSLT, null, iae);
        }
        setPropertiesFromAttributes(handler, rawName, attributes, elem);
        // bit of a hack here...
        if (!isExtension && (elem instanceof ElemLiteralResult)) {
            isExtension = ((ElemLiteralResult) elem).containsExtensionElementURI(uri);
            if (isExtension) {
                // System.out.println("Creating extension(2): "+uri);
                elem = new ElemExtensionCall();
                elem.setLocaterInfo(handler.getLocator());
                elem.setPrefixes(handler.getNamespaceSupport());
                ((ElemLiteralResult) elem).setNamespace(uri);
                ((ElemLiteralResult) elem).setLocalName(localName);
                ((ElemLiteralResult) elem).setRawName(rawName);
                setPropertiesFromAttributes(handler, rawName, attributes, elem);
            }
        }
        appendAndPush(handler, elem);
    } catch (TransformerException te) {
        throw new org.xml.sax.SAXException(te);
    }
}
Also used : XPath(org.apache.xpath.XPath) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ElemTemplate(org.apache.xalan.templates.ElemTemplate) ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement) Stylesheet(org.apache.xalan.templates.Stylesheet) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) Locator(org.xml.sax.Locator) SAXSourceLocator(org.apache.xml.utils.SAXSourceLocator) AttributesImpl(org.xml.sax.helpers.AttributesImpl) ElemLiteralResult(org.apache.xalan.templates.ElemLiteralResult) ElemExtensionCall(org.apache.xalan.templates.ElemExtensionCall) SAXSourceLocator(org.apache.xml.utils.SAXSourceLocator) TransformerException(javax.xml.transform.TransformerException)

Aggregations

ElemLiteralResult (org.apache.xalan.templates.ElemLiteralResult)6 ElemTemplateElement (org.apache.xalan.templates.ElemTemplateElement)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 TransformerException (javax.xml.transform.TransformerException)2 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 ElemExsltFuncResult (org.apache.xalan.templates.ElemExsltFuncResult)2 ElemExsltFunction (org.apache.xalan.templates.ElemExsltFunction)2 ElemExtensionCall (org.apache.xalan.templates.ElemExtensionCall)2 ElemFallback (org.apache.xalan.templates.ElemFallback)2 ElemNumber (org.apache.xalan.templates.ElemNumber)2 ElemPI (org.apache.xalan.templates.ElemPI)2 ElemTemplate (org.apache.xalan.templates.ElemTemplate)2 ElemText (org.apache.xalan.templates.ElemText)2