Search in sources :

Example 66 with TransformerException

use of javax.xml.transform.TransformerException 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 67 with TransformerException

use of javax.xml.transform.TransformerException in project robovm by robovm.

the class ElemTemplateElement method unexecuteNSDecls.

/**
   * Send endPrefixMapping events to the result tree handler
   * for all declared prefix mappings in the stylesheet.
   *
   * @param transformer non-null reference to the the current transform-time state.
   * @param ignorePrefix string prefix to not endPrefixMapping
   * 
   * @throws TransformerException
   */
void unexecuteNSDecls(TransformerImpl transformer, String ignorePrefix) throws TransformerException {
    try {
        if (null != m_prefixTable) {
            SerializationHandler rhandler = transformer.getResultTreeHandler();
            int n = m_prefixTable.size();
            for (int i = 0; i < n; i++) {
                XMLNSDecl decl = (XMLNSDecl) m_prefixTable.get(i);
                if (!decl.getIsExcluded() && !(null != ignorePrefix && decl.getPrefix().equals(ignorePrefix))) {
                    rhandler.endPrefixMapping(decl.getPrefix());
                }
            }
        }
    } catch (org.xml.sax.SAXException se) {
        throw new TransformerException(se);
    }
}
Also used : SerializationHandler(org.apache.xml.serializer.SerializationHandler) TransformerException(javax.xml.transform.TransformerException)

Example 68 with TransformerException

use of javax.xml.transform.TransformerException in project robovm by robovm.

the class ElemTextLiteral method execute.

/**
   * Copy the text literal to the result tree.
   *
   * @param transformer non-null reference to the the current transform-time state.
   *
   * @throws TransformerException
   */
public void execute(TransformerImpl transformer) throws TransformerException {
    try {
        SerializationHandler rth = transformer.getResultTreeHandler();
        if (m_disableOutputEscaping) {
            rth.processingInstruction(javax.xml.transform.Result.PI_DISABLE_OUTPUT_ESCAPING, "");
        }
        rth.characters(m_ch, 0, m_ch.length);
        if (m_disableOutputEscaping) {
            rth.processingInstruction(javax.xml.transform.Result.PI_ENABLE_OUTPUT_ESCAPING, "");
        }
    } catch (SAXException se) {
        throw new TransformerException(se);
    }
}
Also used : SerializationHandler(org.apache.xml.serializer.SerializationHandler) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 69 with TransformerException

use of javax.xml.transform.TransformerException in project robovm by robovm.

the class FuncDocument method error.

/**
   * Tell the user of an error, and probably throw an
   * exception.
   *
   * @param xctxt The XPath runtime state.
   * @param msg The error message key
   * @param args Arguments to be used in the error message
   * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
   * the error condition is severe enough to halt processing.
   *
   * @throws javax.xml.transform.TransformerException
   */
public void error(XPathContext xctxt, String msg, Object[] args) throws javax.xml.transform.TransformerException {
    String formattedMsg = XSLMessages.createMessage(msg, args);
    ErrorListener errHandler = xctxt.getErrorListener();
    TransformerException spe = new TransformerException(formattedMsg, (SourceLocator) xctxt.getSAXLocator());
    if (null != errHandler)
        errHandler.error(spe);
    else
        System.out.println(formattedMsg);
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) XMLString(org.apache.xml.utils.XMLString) TransformerException(javax.xml.transform.TransformerException)

Example 70 with TransformerException

use of javax.xml.transform.TransformerException in project robovm by robovm.

the class ProcessorInclude method parse.

/**
   * Set off a new parse for an included or imported stylesheet.  This will 
   * set the {@link StylesheetHandler} to a new state, and recurse in with 
   * a new set of parse events.  Once this function returns, the state of 
   * the StylesheetHandler should be restored.
   *
   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
   * @param uri The Namespace URI, which should be the XSLT namespace.
   * @param localName The local name (without prefix), which should be "include" or "import".
   * @param rawName The qualified name (with prefix).
   * @param attributes The list of attributes on the xsl:include or xsl:import element.
   *
   * @throws org.xml.sax.SAXException Any SAX exception, possibly
   *            wrapping another exception.
   */
protected void parse(StylesheetHandler handler, String uri, String localName, String rawName, Attributes attributes) throws org.xml.sax.SAXException {
    TransformerFactoryImpl processor = handler.getStylesheetProcessor();
    URIResolver uriresolver = processor.getURIResolver();
    try {
        Source source = null;
        if (null != uriresolver) {
            // There is a user provided URI resolver.
            // At the startElement() call we would
            // have tried to obtain a Source from it
            // which we now retrieve
            source = handler.peekSourceFromURIResolver();
            if (null != source && source instanceof DOMSource) {
                Node node = ((DOMSource) source).getNode();
                // There is a user provided URI resolver.
                // At the startElement() call we would
                // have already pushed the system ID, obtained
                // from either the source.getSystemId(), if non-null
                // or from SystemIDResolver.getAbsoluteURI() as a backup
                // which we now retrieve.
                String systemId = handler.peekImportURL();
                // stylesheet module onto the stack.
                if (systemId != null)
                    handler.pushBaseIndentifier(systemId);
                TreeWalker walker = new TreeWalker(handler, new org.apache.xml.utils.DOM2Helper(), systemId);
                try {
                    walker.traverse(node);
                } catch (org.xml.sax.SAXException se) {
                    throw new TransformerException(se);
                }
                if (systemId != null)
                    handler.popBaseIndentifier();
                return;
            }
        }
        if (null == source) {
            String absURL = SystemIDResolver.getAbsoluteURI(getHref(), handler.getBaseIdentifier());
            source = new StreamSource(absURL);
        }
        // possible callback to a class that over-rides this method.
        source = processSource(handler, source);
        XMLReader reader = null;
        if (source instanceof SAXSource) {
            SAXSource saxSource = (SAXSource) source;
            // may be null
            reader = saxSource.getXMLReader();
        }
        InputSource inputSource = SAXSource.sourceToInputSource(source);
        if (null == reader) {
            // Use JAXP1.1 ( if possible )
            try {
                javax.xml.parsers.SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance();
                factory.setNamespaceAware(true);
                if (handler.getStylesheetProcessor().isSecureProcessing()) {
                    try {
                        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
                    } catch (org.xml.sax.SAXException se) {
                    }
                }
                javax.xml.parsers.SAXParser jaxpParser = factory.newSAXParser();
                reader = jaxpParser.getXMLReader();
            } catch (javax.xml.parsers.ParserConfigurationException ex) {
                throw new org.xml.sax.SAXException(ex);
            } catch (javax.xml.parsers.FactoryConfigurationError ex1) {
                throw new org.xml.sax.SAXException(ex1.toString());
            } catch (NoSuchMethodError ex2) {
            } catch (AbstractMethodError ame) {
            }
        }
        if (null == reader)
            reader = XMLReaderFactory.createXMLReader();
        if (null != reader) {
            reader.setContentHandler(handler);
            // Push the absolute URI of the included/imported
            // stylesheet module onto the stack.
            handler.pushBaseIndentifier(inputSource.getSystemId());
            try {
                reader.parse(inputSource);
            } finally {
                handler.popBaseIndentifier();
            }
        }
    } catch (IOException ioe) {
        handler.error(XSLTErrorResources.ER_IOEXCEPTION, new Object[] { getHref() }, ioe);
    } catch (TransformerException te) {
        handler.error(te.getMessage(), te);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) Node(org.w3c.dom.Node) URIResolver(javax.xml.transform.URIResolver) DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SAXSource(javax.xml.transform.sax.SAXSource) TransformerException(javax.xml.transform.TransformerException) XMLReader(org.xml.sax.XMLReader) StreamSource(javax.xml.transform.stream.StreamSource) TreeWalker(org.apache.xml.utils.TreeWalker) IOException(java.io.IOException) SAXSource(javax.xml.transform.sax.SAXSource)

Aggregations

TransformerException (javax.xml.transform.TransformerException)808 Transformer (javax.xml.transform.Transformer)364 StreamResult (javax.xml.transform.stream.StreamResult)362 DOMSource (javax.xml.transform.dom.DOMSource)311 IOException (java.io.IOException)277 TransformerFactory (javax.xml.transform.TransformerFactory)184 Document (org.w3c.dom.Document)161 StringWriter (java.io.StringWriter)159 SAXException (org.xml.sax.SAXException)157 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)156 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)131 Source (javax.xml.transform.Source)100 StreamSource (javax.xml.transform.stream.StreamSource)94 Element (org.w3c.dom.Element)91 DocumentBuilder (javax.xml.parsers.DocumentBuilder)83 File (java.io.File)74 Node (org.w3c.dom.Node)65 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)64 ByteArrayOutputStream (java.io.ByteArrayOutputStream)62 StringReader (java.io.StringReader)59