use of javax.xml.transform.TransformerConfigurationException in project nhin-d by DirectProject.
the class XslConversion method run.
/**
* Perform the XSL conversion using the provided map file and message.
*
* @param mapFile
* The map file.
* @param message
* The message.
* @return an XSL conversion.
* @throws Exception
*/
public String run(String mapFile, String message) throws Exception {
long start = System.currentTimeMillis();
String retXml = "";
Transformer transformer = null;
try {
if (conversions.containsKey(mapFile)) {
Templates temp = conversions.get(mapFile);
transformer = temp.newTransformer();
LOGGER.info("From xsl cache");
} else {
synchronized (conversions) {
if (!conversions.containsKey(mapFile)) {
/*
* Use the static TransformerFactory.newInstance()
* method to instantiate a TransformerFactory. The
* javax.xml.transform.TransformerFactory system
* property setting determines the actual class to
* instantiate --
* org.apache.xalan.transformer.TransformerImpl.
*/
TransformerFactory tFactory = TransformerFactory.newInstance();
/*
* Use the TransformerFactory to instantiate a Template
* that is thread safe for use in generating Transfomers
*/
InputStream is = this.getClass().getClassLoader().getResourceAsStream(mapFile);
if (is == null) {
LOGGER.info("Mapfile did not read " + mapFile);
}
Templates temp = tFactory.newTemplates(new StreamSource(is));
transformer = temp.newTransformer();
conversions.put(mapFile, temp);
}
}
}
CharArrayWriter to = new CharArrayWriter();
transformer.transform(new StreamSource(new CharArrayReader(message.toCharArray())), new StreamResult(to));
retXml = to.toString();
} catch (TransformerConfigurationException e) {
LOGGER.error("Exception occured during XSL conversion", e);
throw e;
} catch (TransformerException e) {
LOGGER.error("Exception occured during XSL conversion", e);
throw e;
}
if (LOGGER.isInfoEnabled()) {
long elapse = System.currentTimeMillis() - start;
LOGGER.info("Started at " + new Timestamp(start).toString());
LOGGER.info("Elapsed conversion time was " + elapse + "ms");
}
return retXml;
}
use of javax.xml.transform.TransformerConfigurationException in project uPortal by Jasig.
the class FragmentDefinitionImporter method unmarshal.
/* (non-Javadoc)
* @see org.springframework.oxm.Unmarshaller#unmarshal(javax.xml.transform.Source)
*/
@Override
public Object unmarshal(Source source) throws IOException, XmlMappingException {
if (source instanceof StAXSource) {
source = fixStAXSource((StAXSource) source);
}
final Transformer identityTransformer;
try {
identityTransformer = this.xmlUtilities.getIdentityTransformer();
} catch (TransformerConfigurationException e) {
throw new RuntimeException("Failed to create identity Transformer", e);
}
final DOMResult domResult = new DOMResult();
try {
identityTransformer.transform(source, domResult);
} catch (TransformerException e) {
throw new RuntimeException("Failed to transform " + source + " into Document", e);
}
final Document resultDoc = (Document) domResult.getNode();
return new Tuple<String, Document>(source.getSystemId(), resultDoc);
}
use of javax.xml.transform.TransformerConfigurationException in project uPortal by Jasig.
the class JaxbPortalDataHandlerServiceTest method setup.
@Before
public void setup() throws Exception {
xmlUtilities = new XmlUtilitiesImpl() {
@Override
public Templates getTemplates(Resource stylesheet) throws TransformerConfigurationException, IOException {
final TransformerFactory transformerFactory = TransformerFactory.newInstance();
return transformerFactory.newTemplates(new StreamSource(stylesheet.getInputStream()));
}
};
dataImportExportService.setXmlUtilities(xmlUtilities);
final ThreadPoolExecutorFactoryBean threadPoolExecutorFactoryBean = new ThreadPoolExecutorFactoryBean();
threadPoolExecutorFactoryBean.setCorePoolSize(0);
threadPoolExecutorFactoryBean.setMaxPoolSize(20);
threadPoolExecutorFactoryBean.setQueueCapacity(20);
threadPoolExecutorFactoryBean.setThreadGroupName("uPortal-ImportExportThreadGroup");
threadPoolExecutorFactoryBean.setThreadNamePrefix("uPortal-ImportExport-");
threadPoolExecutorFactoryBean.setThreadPriority(5);
threadPoolExecutorFactoryBean.setKeepAliveSeconds(30);
threadPoolExecutorFactoryBean.setDaemon(true);
threadPoolExecutorFactoryBean.setAllowCoreThreadTimeOut(true);
threadPoolExecutorFactoryBean.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
threadPoolExecutorFactoryBean.afterPropertiesSet();
threadPoolExecutor = threadPoolExecutorFactoryBean.getObject();
this.dataImportExportService.setImportExportThreadPool(threadPoolExecutor);
dataImportExportService.setDataFileIncludes(ImmutableSet.of("**/*.xml", "**/*.entity-type", "**/*.template-user", "**/*.user", "**/*.group", "**/*.group_membership", "**/*.membership", "**/*.portlet-type", "**/*.channel-type", "**/*.portlet", "**/*.channel", "**/*.permission", "**/*.permission_set", "**/*.permission_owner", "**/*.profile", "**/*.fragment-layout", "**/*.layout", "**/*.fragment-definition"));
dataImportExportService.setDataTypeImportOrder(getPortalDataTypes());
}
use of javax.xml.transform.TransformerConfigurationException in project Asqatasun by Asqatasun.
the class AsqatasunCrawlJob method initializeCrawlContext.
/**
*
* @param url
* @param crawlParameterSet
* @param heritrixFileName
* @return
*/
private File initializeCrawlContext(Collection<String> urlList, Set<Parameter> crawlParameterSet, String heritrixFileName) {
buildOutputDirectory();
BufferedReader in = null;
FileWriter fw = null;
try {
LOGGER.debug("crawlConfigFilePath: " + crawlConfigFilePath + " for copy");
String filepath = crawlConfigFilePath + "/" + heritrixFileName;
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(filepath);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("filepath : " + filepath);
for (Parameter param : crawlParameterSet) {
LOGGER.debug(param.getParameterElement().getParameterElementCode() + " " + param.getValue());
}
}
doc = setOptionToDocument(urlList, crawlParameterSet, doc);
//write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
String resultFileName = currentJobOutputDir.getPath() + "/" + heritrixFileName;
StreamResult result = new StreamResult(new File(resultFileName));
transformer.transform(source, result);
} catch (IOException | ParserConfigurationException | SAXException ex) {
LOGGER.error(ex);
throw new CrawlerException(ex);
} catch (TransformerConfigurationException ex) {
LOGGER.error(ex);
throw new CrawlerException(ex);
} catch (TransformerException ex) {
LOGGER.error(ex);
throw new CrawlerException(ex);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ex) {
LOGGER.error(ex);
throw new CrawlerException(ex);
}
}
if (fw != null) {
try {
fw.close();
} catch (IOException ex) {
LOGGER.error(ex);
throw new CrawlerException(ex);
}
}
}
return new File(currentJobOutputDir.getPath() + "/" + heritrixFileName);
}
use of javax.xml.transform.TransformerConfigurationException in project camel by apache.
the class XsltBuilder method setTransformerSource.
/**
* Sets the XSLT transformer from a Source
*
* @param source the source
* @throws TransformerConfigurationException is thrown if creating a XSLT transformer failed.
*/
public void setTransformerSource(Source source) throws TransformerConfigurationException {
TransformerFactory factory = converter.getTransformerFactory();
if (errorListener != null) {
factory.setErrorListener(errorListener);
} else {
// use a logger error listener so users can see from the logs what the error may be
factory.setErrorListener(new XsltErrorListener());
}
if (getUriResolver() != null) {
factory.setURIResolver(getUriResolver());
}
// Check that the call to newTemplates() returns a valid template instance.
// In case of an xslt parse error, it will return null and we should stop the
// deployment and raise an exception as the route will not be setup properly.
Templates templates = factory.newTemplates(source);
if (templates != null) {
setTemplate(templates);
} else {
throw new TransformerConfigurationException("Error creating XSLT template. " + "This is most likely be caused by a XML parse error. " + "Please verify your XSLT file configured.");
}
}
Aggregations