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);
}
}
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());
}
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;
}
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("<p>", "<p>").replace("</p>", "</p>");
}
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);
}
}
Aggregations