use of javax.xml.transform.TransformerException 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.TransformerException in project GDSC-SMLM by aherbert.
the class BatchPeakFit method setParameters.
/**
* Modify the XML document using the specified values for the given parameter. For each value
* call the method recursively for the next parameter. If there are no more parameters
* then add the XML document to the xmlSettings.
*
* @param parameters
* The list of parameters
* @param i
* Parameter to process
* @param doc
* The XML document containing all the current parameters
* @param xmlSettings
* A list of XML parameter settings
*/
private void setParameters(ArrayList<ParameterSettings> parameters, int i, Document doc, ArrayList<String> xmlSettings) {
if (i < parameters.size()) {
ParameterSettings param = parameters.get(i);
NodeList nodes = doc.getElementsByTagName(param.name);
if (nodes.getLength() == 1) {
// For each value, set the parameter and move to the next
String[] values = param.value.split(",");
for (String value : values) {
Node node = nodes.item(0);
node.setTextContent(value);
setParameters(parameters, i + 1, doc, xmlSettings);
}
} else {
// Just move to the next parameter
setParameters(parameters, i + 1, doc, xmlSettings);
}
} else {
// Add the final XML to the parameters to run
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringWriter writer = new StringWriter();
transformer.transform(new DOMSource(doc), new StreamResult(writer));
xmlSettings.add(writer.getBuffer().toString());
} catch (TransformerConfigurationException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
}
}
}
use of javax.xml.transform.TransformerException in project adempiere by adempiere.
the class ModelExporter method doIt.
/**
* Process
*
* @return info
*/
protected String doIt() throws Exception {
ExportHelper expHelper = new ExportHelper(getCtx(), p_AD_Client_ID);
MEXPFormat exportFormat = new MEXPFormat(getCtx(), p_EXP_Format_ID, get_TrxName());
File file = new File(p_FileName);
Document doc = expHelper.exportRecord(exportFormat, "", MReplicationStrategy.REPLICATION_TABLE, X_AD_ReplicationTable.REPLICATIONTYPE_Merge, ModelValidator.TYPE_AFTER_CHANGE);
// Save the document to the disk file
TransformerFactory tranFactory = TransformerFactory.newInstance();
// tranFactory.setAttribute("indent-number", 4); //Adempiere-65 change
Transformer aTransformer = tranFactory.newTransformer();
aTransformer.setOutputProperty(OutputKeys.METHOD, "xml");
aTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
Source src = new DOMSource(doc);
// =================================== Write to String
Writer writer = new StringWriter();
Result dest2 = new StreamResult(writer);
aTransformer.transform(src, dest2);
// =================================== Write to Disk
try {
Result dest = new StreamResult(file);
aTransformer.transform(src, dest);
writer.flush();
writer.close();
} catch (TransformerException ex) {
ex.printStackTrace();
throw ex;
}
return "Exported";
}
use of javax.xml.transform.TransformerException in project adempiere by adempiere.
the class ADServiceImpl method getStringFromDocument.
/*<r>
<f colname="AD_Client_ID">1000000</f>
</r>
<AD_Client_ID>1000000</AD_Client_ID>
*/
// method to convert Document to String
public String getStringFromDocument(Document doc) {
try {
DOMSource domSource = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
return writer.toString();
} catch (TransformerException ex) {
ex.printStackTrace();
return null;
}
}
use of javax.xml.transform.TransformerException in project poi by apache.
the class RecordGenerator method transform.
/**
* <p>Executes an XSL transformation. This process transforms an XML input
* file into a text output file controlled by an XSLT specification.</p>
*
* @param in the XML input file
* @param out the text output file
* @param xslt the XSLT specification, i.e. an XSL style sheet
* @throws FileNotFoundException
* @throws TransformerException
*/
private static void transform(final File in, final File out, final File xslt) throws FileNotFoundException, TransformerException {
final StreamSource ss = new StreamSource(xslt);
final TransformerFactory tf = TransformerFactory.newInstance();
final Transformer t;
try {
t = tf.newTransformer(ss);
} catch (TransformerException ex) {
System.err.println("Error compiling XSL style sheet " + xslt);
throw ex;
}
final Properties p = new Properties();
p.setProperty(OutputKeys.METHOD, "text");
t.setOutputProperties(p);
final Result result = new StreamResult(out);
t.transform(new StreamSource(in), result);
}
Aggregations