Search in sources :

Example 41 with TransformerException

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

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)

Example 42 with TransformerException

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

the class ProcessorCharacters method startNonText.

/**
   * Receive notification of the start of the non-text event.  This
   * is sent to the current processor when any non-text event occurs.
   *
   * @param handler non-null reference to current StylesheetHandler that is constructing the Templates.
   */
public void startNonText(StylesheetHandler handler) throws org.xml.sax.SAXException {
    if (this == handler.getCurrentProcessor()) {
        handler.popProcessor();
    }
    int nChars = m_accumulator.length();
    if ((nChars > 0) && ((null != m_xslTextElement) || !XMLCharacterRecognizer.isWhiteSpace(m_accumulator)) || handler.isSpacePreserve()) {
        ElemTextLiteral elem = new ElemTextLiteral();
        elem.setDOMBackPointer(m_firstBackPointer);
        elem.setLocaterInfo(handler.getLocator());
        try {
            elem.setPrefixes(handler.getNamespaceSupport());
        } catch (TransformerException te) {
            throw new org.xml.sax.SAXException(te);
        }
        boolean doe = (null != m_xslTextElement) ? m_xslTextElement.getDisableOutputEscaping() : false;
        elem.setDisableOutputEscaping(doe);
        elem.setPreserveSpace(true);
        char[] chars = new char[nChars];
        m_accumulator.getChars(0, nChars, chars, 0);
        elem.setChars(chars);
        ElemTemplateElement parent = handler.getElemTemplateElement();
        parent.appendChild(elem);
    }
    m_accumulator.setLength(0);
    m_firstBackPointer = null;
}
Also used : ElemTextLiteral(org.apache.xalan.templates.ElemTextLiteral) TransformerException(javax.xml.transform.TransformerException) ElemTemplateElement(org.apache.xalan.templates.ElemTemplateElement)

Example 43 with TransformerException

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

the class XsltStylesheet method transform.

@JRubyMethod(rest = true, required = 1, optional = 2)
public IRubyObject transform(ThreadContext context, IRubyObject[] args) {
    Ruby runtime = context.getRuntime();
    argumentTypeCheck(runtime, args[0]);
    NokogiriXsltErrorListener elistener = new NokogiriXsltErrorListener();
    DOMSource domSource = new DOMSource(((XmlDocument) args[0]).getDocument());
    DOMResult result = null;
    String stringResult = null;
    try {
        // DOMResult
        result = tryXsltTransformation(context, args, domSource, elistener);
        if (result.getNode().getFirstChild() == null) {
            // StreamResult
            stringResult = retryXsltTransformation(context, args, domSource, elistener);
        }
    } catch (TransformerConfigurationException ex) {
        throw runtime.newRuntimeError(ex.getMessage());
    } catch (TransformerException ex) {
        throw runtime.newRuntimeError(ex.getMessage());
    } catch (IOException ex) {
        throw runtime.newRuntimeError(ex.getMessage());
    }
    switch(elistener.getErrorType()) {
        case ERROR:
        case FATAL:
            throw runtime.newRuntimeError(elistener.getErrorMessage());
        case WARNING:
        default:
    }
    if (stringResult == null) {
        return createDocumentFromDomResult(context, runtime, result);
    } else {
        return createDocumentFromString(context, runtime, stringResult);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DOMResult(javax.xml.transform.dom.DOMResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) RubyString(org.jruby.RubyString) IOException(java.io.IOException) Ruby(org.jruby.Ruby) TransformerException(javax.xml.transform.TransformerException) NokogiriXsltErrorListener(nokogiri.internals.NokogiriXsltErrorListener) JRubyMethod(org.jruby.anno.JRubyMethod)

Example 44 with TransformerException

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

the class ReportGenerator method XMLToHtml.

public static File XMLToHtml(Document xmlDocument, String infilexsl, File outFile) {
    File stylesheet = null;
    outFile = new File(outFile.getAbsolutePath());
    try {
        stylesheet = new File(infilexsl);
        DOMSource source = new DOMSource(xmlDocument);
        // Use a Transformer for output
        TransformerFactory tFactory = TransformerFactory.newInstance();
        StreamSource stylesource = new StreamSource(stylesheet);
        Transformer transformer = tFactory.newTransformer(stylesource);
        // Make the transformation and write to the output file
        StreamResult result = new StreamResult(outFile);
        transformer.transform(source, result);
    } catch (TransformerException e) {
        logger.error(e.getMessage(), e);
    }
    return outFile;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 45 with TransformerException

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

the class FileXML method saveFile.

public void saveFile(String fileName) {
    //		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    //factory.setNamespaceAware(true);
    //factory.setValidating(true);
    File file = null;
    FileOutputStream outFile = null;
    try {
        file = new File(fileName);
        outFile = new FileOutputStream(file);
        // Use a Transformer for output
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(outFile);
        //StreamResult result = new StreamResult(System.out);
        transformer.transform(source, result);
    } catch (TransformerException | IOException e) {
        logger.error(e.getMessage(), e);
    } finally {
        if (outFile != null) {
            try {
                outFile.close();
            } catch (IOException e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

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