use of javax.xml.transform.TransformerConfigurationException in project buck by facebook.
the class WorkspaceGenerator method writeWorkspace.
public Path writeWorkspace() throws IOException {
DocumentBuilder docBuilder;
Transformer transformer;
try {
docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
transformer = TransformerFactory.newInstance().newTransformer();
} catch (ParserConfigurationException | TransformerConfigurationException e) {
throw new RuntimeException(e);
}
DOMImplementation domImplementation = docBuilder.getDOMImplementation();
final Document doc = domImplementation.createDocument(/* namespaceURI */
null, "Workspace", /* docType */
null);
doc.setXmlVersion("1.0");
Element rootElem = doc.getDocumentElement();
rootElem.setAttribute("version", "1.0");
final Stack<Element> groups = new Stack<>();
groups.push(rootElem);
FileVisitor<Map.Entry<String, WorkspaceNode>> visitor = new FileVisitor<Map.Entry<String, WorkspaceNode>>() {
@Override
public FileVisitResult preVisitDirectory(Map.Entry<String, WorkspaceNode> dir, BasicFileAttributes attrs) throws IOException {
Preconditions.checkArgument(dir.getValue() instanceof WorkspaceGroup);
Element element = doc.createElement("Group");
element.setAttribute("location", "container:");
element.setAttribute("name", dir.getKey());
groups.peek().appendChild(element);
groups.push(element);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Map.Entry<String, WorkspaceNode> file, BasicFileAttributes attrs) throws IOException {
Preconditions.checkArgument(file.getValue() instanceof WorkspaceFileRef);
WorkspaceFileRef fileRef = (WorkspaceFileRef) file.getValue();
Element element = doc.createElement("FileRef");
element.setAttribute("location", "container:" + MorePaths.relativize(MorePaths.normalize(outputDirectory), fileRef.getPath()).toString());
groups.peek().appendChild(element);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Map.Entry<String, WorkspaceNode> file, IOException exc) throws IOException {
return FileVisitResult.TERMINATE;
}
@Override
public FileVisitResult postVisitDirectory(Map.Entry<String, WorkspaceNode> dir, IOException exc) throws IOException {
groups.pop();
return FileVisitResult.CONTINUE;
}
};
walkNodeTree(visitor);
Path projectWorkspaceDir = getWorkspaceDir();
projectFilesystem.mkdirs(projectWorkspaceDir);
Path serializedWorkspace = projectWorkspaceDir.resolve("contents.xcworkspacedata");
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(outputStream);
transformer.transform(source, result);
String contentsToWrite = outputStream.toString();
if (MoreProjectFilesystems.fileContentsDiffer(new ByteArrayInputStream(contentsToWrite.getBytes(Charsets.UTF_8)), serializedWorkspace, projectFilesystem)) {
projectFilesystem.writeContentsToPath(contentsToWrite, serializedWorkspace);
}
} catch (TransformerException e) {
throw new RuntimeException(e);
}
Path xcshareddata = projectWorkspaceDir.resolve("xcshareddata");
projectFilesystem.mkdirs(xcshareddata);
Path workspaceSettingsPath = xcshareddata.resolve("WorkspaceSettings.xcsettings");
String workspaceSettings = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\"" + " \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + "<plist version=\"1.0\">\n" + "<dict>\n" + "\t<key>IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded</key>\n" + "\t<false/>\n" + "</dict>\n" + "</plist>";
projectFilesystem.writeContentsToPath(workspaceSettings, workspaceSettingsPath);
return projectWorkspaceDir;
}
use of javax.xml.transform.TransformerConfigurationException in project series-rest-api by 52North.
the class PDFReportGenerator method encodeAndWriteTo.
@Override
public void encodeAndWriteTo(DataCollection<QuantityData> data, OutputStream stream) throws IoParseException {
try {
generateOutput(data);
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.build(document.newInputStream());
FopFactory fopFactory = new FopFactoryBuilder(baseURI).setConfiguration(cfg).build();
final String mimeType = MimeType.APPLICATION_PDF.getMimeType();
Fop fop = fopFactory.newFop(mimeType, stream);
//FopFactory fopFactory = FopFactory.newInstance(cfg);
//Fop fop = fopFactory.newFop(APPLICATION_PDF.getMimeType(), stream);
//FopFactory fopFactory = fopFactoryBuilder.build();
//Fop fop = fopFactory.newFop(APPLICATION_PDF.getMimeType(), stream);
// Create PDF via XSLT transformation
TransformerFactory transFact = TransformerFactory.newInstance();
StreamSource transformationRule = getTransforamtionRule();
Transformer transformer = transFact.newTransformer(transformationRule);
Source source = new StreamSource(document.newInputStream());
Result result = new SAXResult(fop.getDefaultHandler());
if (LOGGER.isDebugEnabled()) {
try {
File tempFile = File.createTempFile(TEMP_FILE_PREFIX, ".xml");
StreamResult debugResult = new StreamResult(tempFile);
transformer.transform(source, debugResult);
String xslResult = XmlObject.Factory.parse(tempFile).xmlText();
LOGGER.debug("xsl-fo input (locale '{}'): {}", i18n.getTwoDigitsLanguageCode(), xslResult);
} catch (IOException | TransformerException | XmlException e) {
LOGGER.error("Could not debug XSL result output!", e);
}
}
// XXX debug, diagram is not embedded
transformer.transform(source, result);
} catch (FOPException e) {
throw new IoParseException("Failed to create Formatting Object Processor (FOP)", e);
} catch (SAXException | ConfigurationException | IOException e) {
throw new IoParseException("Failed to read config for Formatting Object Processor (FOP)", e);
} catch (TransformerConfigurationException e) {
throw new IoParseException("Invalid transform configuration. Inspect xslt!", e);
} catch (TransformerException e) {
throw new IoParseException("Could not generate PDF report!", e);
}
}
use of javax.xml.transform.TransformerConfigurationException in project midpoint by Evolveum.
the class DOMUtil method printDom.
public static StringBuffer printDom(Node node, boolean indent, boolean omitXmlDeclaration) {
StringWriter writer = new StringWriter();
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans;
try {
trans = transfac.newTransformer();
} catch (TransformerConfigurationException e) {
throw new SystemException("Error in XML configuration: " + e.getMessage(), e);
}
trans.setOutputProperty(OutputKeys.INDENT, (indent ? "yes" : "no"));
// XALAN-specific
trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
trans.setParameter(OutputKeys.ENCODING, "utf-8");
// Note: serialized XML does not contain xml declaration
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, (omitXmlDeclaration ? "yes" : "no"));
DOMSource source = new DOMSource(node);
try {
trans.transform(source, new StreamResult(writer));
} catch (TransformerException e) {
throw new SystemException("Error in XML transformation: " + e.getMessage(), e);
}
return writer.getBuffer();
}
use of javax.xml.transform.TransformerConfigurationException in project uPortal by Jasig.
the class SitemapTest method testStylesheetCompilation.
@Test
public void testStylesheetCompilation() throws IOException {
final MockHttpServletRequest request = new MockHttpServletRequest();
Resource resource = new ClassPathResource(STYLESHEET_LOCATION);
Source source = new StreamSource(resource.getInputStream(), resource.getURI().toASCIIString());
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer(source);
transformer.setParameter(SitemapPortletController.USE_TAB_GROUPS, useTabGroups);
transformer.setParameter(SitemapPortletController.USER_LANG, "en_US");
transformer.setParameter(XsltPortalUrlProvider.CURRENT_REQUEST, request);
transformer.setParameter(XsltPortalUrlProvider.XSLT_PORTAL_URL_PROVIDER, this.xsltPortalUrlProvider);
Source xmlSource = new StreamSource(new ClassPathResource(XML_LOCATION).getFile());
CharArrayWriter buffer = new CharArrayWriter();
TransformerUtils.enableIndenting(transformer);
transformer.transform(xmlSource, new StreamResult(buffer));
if (logger.isTraceEnabled()) {
logger.trace("XML: " + new String(buffer.toCharArray()));
}
} catch (TransformerConfigurationException e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
} catch (TransformerException e) {
logger.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
use of javax.xml.transform.TransformerConfigurationException in project adempiere by adempiere.
the class PackInHandler method init.
private void init() throws SAXException {
if (packIn == null)
packIn = new PackIn();
packageDirectory = PackIn.m_Package_Dir;
m_UpdateMode = PackIn.m_UpdateMode;
m_DatabaseType = PackIn.m_Database;
SimpleDateFormat formatter_file = new SimpleDateFormat("yyMMddHHmmssZ");
SimpleDateFormat formatter_log = new SimpleDateFormat("MM/dd/yy HH:mm:ss");
Date today = new Date();
String fileDate = formatter_file.format(today);
logDate = formatter_log.format(today);
String file_document = packageDirectory + File.separator + "doc" + File.separator + "Importlog_" + fileDate + ".xml";
log.info("file_document=" + file_document);
try {
fw_document = new FileOutputStream(file_document, false);
} catch (FileNotFoundException e1) {
log.warning("Failed to create log file:" + e1);
}
streamResult_document = new StreamResult(fw_document);
tf_document = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
try {
logDocument = tf_document.newTransformerHandler();
} catch (TransformerConfigurationException e2) {
log.info("startElement:" + e2);
}
serializer_document = logDocument.getTransformer();
serializer_document.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
serializer_document.setOutputProperty(OutputKeys.INDENT, "yes");
logDocument.setResult(streamResult_document);
logDocument.startDocument();
logDocument.processingInstruction("xml-stylesheet", "type=\"text/css\" href=\"adempiereDocument.css\"");
Properties tmp = new Properties();
if (m_ctx != null)
tmp.putAll(m_ctx);
else
tmp.putAll(Env.getCtx());
m_ctx = tmp;
if (m_trxName == null)
m_trxName = Trx.createTrxName("PackIn");
m_AD_Client_ID = Env.getContextAsInt(m_ctx, "AD_Client_ID");
Start_Doc = 1;
}
Aggregations