use of javax.xml.transform.Source 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.Source in project ACS by ACS-Community.
the class DumpXML method main.
/**
* @param args
*/
public static void main(String[] args) throws Throwable {
if (args.length != 1) {
System.err.println("Usage: java " + DumpXML.class.getName() + " <xml file>");
System.exit(1);
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
// XercesJ 2.9.1 rejects this, it supports it by default
//factory.setXIncludeAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document xmldoc = builder.parse(new InputSource(new FileReader(args[0])));
Source src = new DOMSource(xmldoc);
Result dest = new StreamResult(System.out);
TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer transformer = tranFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(src, dest);
}
use of javax.xml.transform.Source in project claw-compiler by C2SM-RCM.
the class Configuration method validate.
/**
* Validate the configuration file with the XSD schema.
*
* @param xsdPath Path to the XSD schema.
* @throws Exception If configuration file is not valid.
*/
private void validate(String xsdPath) throws Exception {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Source schemaFile = new StreamSource(new File(xsdPath));
Schema schema = factory.newSchema(schemaFile);
Validator validator = schema.newValidator();
validator.validate(new DOMSource(_document));
}
use of javax.xml.transform.Source 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.Source in project adempiere by adempiere.
the class TopicExportProcessor method process.
/**
*
*/
public void process(Properties ctx, MEXPProcessor expProcessor, Document document, Trx trx) throws Exception {
String host = expProcessor.getHost();
int port = expProcessor.getPort();
String account = expProcessor.getAccount();
String password = expProcessor.getPasswordInfo();
String protocol = null;
String topicName = "";
String clientID = null;
String timeToLiveStr = null;
int timeToLive = 10000;
boolean isDeliveryModePersistent = true;
// Read all processor parameters and set them!
X_EXP_ProcessorParameter[] processorParameters = expProcessor.getEXP_ProcessorParameters(trx.getTrxName());
if (processorParameters != null && processorParameters.length > 0) {
for (int i = 0; i < processorParameters.length; i++) {
log.info("ProcesParameter Value = " + processorParameters[i].getValue());
log.info("ProcesParameter ParameterValue = " + processorParameters[i].getParameterValue());
if (processorParameters[i].getValue().equals("topicName")) {
topicName = processorParameters[i].getParameterValue();
} else if (processorParameters[i].getValue().equals("protocol")) {
protocol = processorParameters[i].getParameterValue();
} else if (processorParameters[i].getValue().equals("clientID")) {
clientID = processorParameters[i].getParameterValue();
} else if (processorParameters[i].getValue().equals("timeToLive")) {
timeToLiveStr = processorParameters[i].getParameterValue();
timeToLive = Integer.parseInt(timeToLiveStr);
} else if (processorParameters[i].getValue().equals("isDeliveryModePersistent")) {
isDeliveryModePersistent = Boolean.parseBoolean(processorParameters[i].getParameterValue());
} else {
// Some other mandatory parameter here
}
}
}
if (topicName == null || topicName.length() == 0) {
throw new Exception("Missing " + X_EXP_ProcessorParameter.Table_Name + " with key 'topicName'!");
}
if (protocol == null || protocol.length() == 0) {
throw new Exception("Missing " + X_EXP_ProcessorParameter.Table_Name + " with key 'protocol'!");
}
if (clientID == null || clientID.length() == 0) {
throw new Exception("Missing " + X_EXP_ProcessorParameter.Table_Name + " with key 'clientID'!");
}
if (timeToLiveStr == null || timeToLiveStr.length() == 0) {
throw new Exception("Missing " + X_EXP_ProcessorParameter.Table_Name + " with key 'timeToLive'!");
}
// Construct Transformer Factory and Transformer
TransformerFactory tranFactory = TransformerFactory.newInstance();
String jVersion = System.getProperty("java.version");
if (jVersion.startsWith("1.5.0"))
tranFactory.setAttribute("indent-number", Integer.valueOf(1));
Transformer aTransformer = tranFactory.newTransformer();
aTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
Source src = new DOMSource(document);
// =================================== Write to String
Writer writer = new StringWriter();
Result dest2 = new StreamResult(writer);
aTransformer.transform(src, dest2);
sendJMSMessage(host, port, writer.toString(), protocol, topicName, clientID, account, password, timeToLive, isDeliveryModePersistent);
}
Aggregations