Search in sources :

Example 16 with TransformerException

use of javax.xml.transform.TransformerException in project pcgen by PCGen.

the class FopTask method run.

/**
	 * Run the FO to PDF/AWT conversion. This automatically closes any provided OutputStream for
	 * this FopTask.
	 */
@Override
public void run() {
    try (OutputStream out = outputStream) {
        userAgent.setProducer("PC Gen Character Generator");
        userAgent.setAuthor(System.getProperty("user.name"));
        userAgent.setCreationDate(new Date());
        userAgent.getEventBroadcaster().addEventListener(new FOPEventListener());
        String mimeType;
        if (renderer != null) {
            userAgent.setKeywords("PCGEN FOP PREVIEW");
            mimeType = MimeConstants.MIME_FOP_AWT_PREVIEW;
        } else {
            userAgent.setKeywords("PCGEN FOP PDF");
            mimeType = MimeConstants.MIME_PDF;
        }
        Fop fop;
        if (out != null) {
            fop = FOP_FACTORY.newFop(mimeType, userAgent, out);
        } else {
            fop = FOP_FACTORY.newFop(mimeType, userAgent);
        }
        Transformer transformer;
        if (xsltSource != null) {
            transformer = TRANS_FACTORY.newTransformer(xsltSource);
        } else {
            // identity transformer		
            transformer = TRANS_FACTORY.newTransformer();
        }
        transformer.setErrorListener(new FOPErrorListener());
        transformer.transform(inputSource, new SAXResult(fop.getDefaultHandler()));
    } catch (TransformerException | FOPException | IOException e) {
        errorBuilder.append(e.getMessage()).append(Constants.LINE_SEPARATOR);
        Logging.errorPrint("Exception in FopTask:run", e);
    } catch (RuntimeException ex) {
        errorBuilder.append(ex.getMessage()).append(Constants.LINE_SEPARATOR);
        Logging.errorPrint("Unexpected exception in FopTask:run: ", ex);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) Fop(org.apache.fop.apps.Fop) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Date(java.util.Date) FOPException(org.apache.fop.apps.FOPException) SAXResult(javax.xml.transform.sax.SAXResult) TransformerException(javax.xml.transform.TransformerException)

Example 17 with TransformerException

use of javax.xml.transform.TransformerException in project rhino by PLOS.

the class AbstractXpathReader method recoverXml.

private static String recoverXml(Node node) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.transform(new DOMSource(node), new StreamResult(outputStream));
    } catch (TransformerException e) {
        throw new RuntimeException(e);
    }
    // TODO: Encoding?
    return new String(outputStream.toByteArray());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TransformerException(javax.xml.transform.TransformerException)

Example 18 with TransformerException

use of javax.xml.transform.TransformerException in project rhino by PLOS.

the class AuthorsXmlExtractor method getOtherFootnotesMap.

/**
   * Grab all footnotes and put them into their own map
   *
   * @param doc   the article XML document
   * @param xpath XpathReader to use to process xpath expressions
   * @return a Map of footnote IDs and values
   */
private static Map<String, String> getOtherFootnotesMap(Document doc, XpathReader xpath) throws XPathException {
    Map<String, String> otherFootnotesMap = new HashMap<>();
    //Grab all 'other' footnotes and put them into their own map
    NodeList footnoteNodeList = xpath.selectNodes(doc, "//fn[@fn-type='other']");
    for (int a = 0; a < footnoteNodeList.getLength(); a++) {
        Node node = footnoteNodeList.item(a);
        // Not all <aff>'s have the 'id' attribute.
        String id = (node.getAttributes().getNamedItem("id") == null) ? "" : node.getAttributes().getNamedItem("id").getTextContent();
        log.debug("Found footnote node: {}", id);
        DocumentFragment df = doc.createDocumentFragment();
        df.appendChild(node);
        String footnote;
        try {
            footnote = getAsXMLString(xpath.selectNode(df, "//p"));
        } catch (TransformerException e) {
            throw new RuntimeException(e);
        }
        otherFootnotesMap.put(id, footnote);
    }
    return otherFootnotesMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) DocumentFragment(org.w3c.dom.DocumentFragment) TransformerException(javax.xml.transform.TransformerException)

Example 19 with TransformerException

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

the class ReportGenerator method stringToHtml.

public static String stringToHtml(String inxml, String infilexsl) {
    Document doc = null;
    // factory.setNamespaceAware(true);
    // factory.setValidating(true);
    File stylesheet = null;
    StringReader inReader = new StringReader(inxml);
    StringWriter writer = new StringWriter();
    try {
        stylesheet = new File(infilexsl);
        DocumentBuilder builder = XmlUtils.newXxeDisabledDocumentBuilderFactory().newDocumentBuilder();
        doc = builder.parse(new InputSource(inReader));
        // Use a Transformer for output
        TransformerFactory tFactory = TransformerFactory.newInstance();
        StreamSource stylesource = new StreamSource(stylesheet);
        Transformer transformer = tFactory.newTransformer(stylesource);
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(writer);
        transformer.transform(source, result);
    } catch (TransformerException | SAXException | ParserConfigurationException | IOException e) {
        showDialogForGUI();
        logger.error(e.getMessage(), e);
    } finally {
    }
    // we should really adopt something other than XSLT ;)
    return writer.toString().replace("&lt;p&gt;", "<p>").replace("&lt;/p&gt;", "</p>");
}
Also used : InputSource(org.xml.sax.InputSource) 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) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) StringWriter(java.io.StringWriter) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 20 with TransformerException

use of javax.xml.transform.TransformerException in project intellij-community by JetBrains.

the class XalanStyleFrame method addVariable.

private void addVariable(ElemVariable variable, boolean global, Collection<Debugger.Variable> variables) {
    final Debugger.Variable.Kind kind = variable instanceof ElemParam ? Debugger.Variable.Kind.PARAMETER : Debugger.Variable.Kind.VARIABLE;
    assert global == variable.getIsTopLevel() : global + " vs. " + variable.getIsTopLevel() + " (" + variable.getName() + ")";
    final String name = variable.getName().getLocalName();
    try {
        final Value value = kind == Debugger.Variable.Kind.PARAMETER ? // http://youtrack.jetbrains.net/issue/IDEA-78638
        eval("$" + variable.getName().toString()) : new XObjectValue(variable.getValue(myTransformer, myCurrentNode));
        variables.add(new VariableImpl(name, value, global, kind, variable.getSystemId(), variable.getLineNumber()));
    } catch (TransformerException e) {
        debug(e);
    } catch (Debugger.EvaluationException e) {
        debug(e);
    }
}
Also used : Debugger(org.intellij.plugins.xsltDebugger.rt.engine.Debugger) VariableImpl(org.intellij.plugins.xsltDebugger.rt.engine.local.VariableImpl) ElemVariable(org.apache.xalan.templates.ElemVariable) ElemParam(org.apache.xalan.templates.ElemParam) Value(org.intellij.plugins.xsltDebugger.rt.engine.Value) 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