List of usage examples for javax.xml.transform.stream StreamSource StreamSource
public StreamSource(File f)
From source file:org.lareferencia.backend.indexer.IntelligoIndexer.java
private Transformer buildTransformer() throws IndexerException { Transformer trf;//from w w w . j a va 2 s.c o m try { StreamSource stylesource = new StreamSource(stylesheet); trf = xformFactory.newTransformer(stylesource); trf = MedatadaDOMHelper.buildXSLTTransformer(stylesheet); trf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); trf.setOutputProperty(OutputKeys.INDENT, "yes"); trf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); } catch (TransformerConfigurationException e) { throw new IndexerException(e.getMessage(), e.getCause()); } return trf; }
From source file:ch.entwine.weblounge.tools.importer.AbstractImporterCallback.java
protected boolean transformXml(File srcFile, File resultFile, Transformer trans) { Source src = new StreamSource(srcFile); Result result = new StreamResult(resultFile); try {//from w w w.j a v a 2s .c om trans.transform(src, result); } catch (TransformerException e) { System.err.println("Error transforming file '" + srcFile.getPath() + "': " + e.getMessage()); return false; } return true; }
From source file:edu.wustl.bulkoperator.templateImport.AbstractImportBulkOperation.java
/** * * @param operationName/*from w w w .ja v a 2s .co m*/ * @param dropdownName * @param csvFile * @param xmlFile * @param mappingXml * @return * @throws BulkOperationException * @throws SQLException * @throws IOException * @throws DAOException */ protected Set<String> validate(String operationName, String dropdownName, String csvFile, String xmlFile, String mappingXml, String xsdLocation) throws BulkOperationException, SQLException, IOException, DAOException { Set<String> errorList = null; CsvReader csvReader = null; try { csvReader = CsvFileReader.createCsvFileReader(csvFile, true); } catch (Exception exp) { ErrorKey errorkey = ErrorKey.getErrorKey("bulk.error.incorrect.csv.file"); throw new BulkOperationException(errorkey, exp, ""); } BulkOperationMetaData bulkOperationMetaData = null; try { SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); File schemaLocation = new File(xsdLocation); Schema schema = factory.newSchema(schemaLocation); DigesterLoader digesterLoader = DigesterLoader.newLoader(new XmlRulesModule(mappingXml)); Digester digester = digesterLoader.newDigester(); digester.setValidating(true); digester.setXMLSchema(schema); Validator validator = schema.newValidator(); Source xmlFileForValidation = new StreamSource(new File(xmlFile)); validator.validate(xmlFileForValidation); InputStream inputStream = new FileInputStream(xmlFile); bulkOperationMetaData = digester.parse(inputStream); } catch (SAXException e) { logger.debug(e.getMessage()); ErrorKey errorkey = ErrorKey.getErrorKey("bulk.error.xml.template"); throw new BulkOperationException(errorkey, e, e.getMessage()); } Collection<BulkOperationClass> classList = bulkOperationMetaData.getBulkOperationClass(); if (classList == null) { ErrorKey errorkey = ErrorKey.getErrorKey("bulk.no.templates.loaded.message"); throw new BulkOperationException(errorkey, null, ""); } else { Iterator<BulkOperationClass> iterator = classList.iterator(); if (iterator.hasNext()) { BulkOperationClass bulkOperationClass = iterator.next(); TemplateValidator templateValidator = new TemplateValidator(); errorList = templateValidator.validateXmlAndCsv(bulkOperationClass, operationName, csvReader); } } return errorList; }
From source file:org.dataone.proto.trove.mn.rest.exceptions.DataOneExceptionMarshaller.java
@Override public void marshal(Object o, Result result) throws IOException, XmlMappingException { BaseException baseException = (BaseException) o; ByteArrayInputStream is = new ByteArrayInputStream( baseException.serialize(BaseException.FMT_XML).getBytes()); try {//from ww w. j a v a 2 s .c o m Transformer transformer = transformerFactory.newTransformer(); transformer.transform(new StreamSource(is), result); } catch (TransformerException ex) { throw new MarshallingFailureException("DataOneExceptionMarshaller: " + ex.getMessage()); } }
From source file:edu.unc.lib.dl.ingest.sip.METSPackageSIPProcessor.java
public METSPackageSIPProcessor() { try {/*from w ww . j av a 2s.c o m*/ _countObjectsXpath = XPath.newInstance(countObjectsXpath); _countObjectsXpath.addNamespace(METS_NS); } catch (JDOMException e) { log.error("Bad Configuration for Mets2FoxmlFilter", e); throw new IllegalArgumentException("Bad Configuration for Mets2FoxmlFilter", e); } Source mets2foxsrc = new StreamSource( METSPackageSIPProcessor.class.getResourceAsStream(stylesheetPackage + "base-model.xsl")); // requires a Saxon 8 transformer factory try { TransformerFactory factory = TransformerFactory.newInstance(); // set a Resolver that can look in the classpath factory.setURIResolver(new URIResolver() { public Source resolve(String href, String base) throws TransformerException { Source result = null; if (href.startsWith("/")) result = new StreamSource(METSPackageSIPProcessor.class.getResourceAsStream(href)); else result = new StreamSource( METSPackageSIPProcessor.class.getResourceAsStream(stylesheetPackage + href)); return result; } }); mets2fox = factory.newTemplates(mets2foxsrc); } catch (TransformerFactoryConfigurationError e) { log.error("Error setting up transformer factory.", e); throw new Error("Error setting up transformer factory", e); } catch (TransformerConfigurationException e) { log.error("Error setting up transformer.", e); throw new Error("Error setting up transformer", e); } }
From source file:com.aurel.track.report.export.bl.XsltTransformer.java
public void transform(File source, File target, File stylesheet) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document dom = null;/*from ww w . jav a2 s .c o m*/ try { DocumentBuilder builder = factory.newDocumentBuilder(); dom = builder.parse(source); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } try { TransformerFactory tFactory = TransformerFactory.newInstance(); StreamSource stylesource = new StreamSource(stylesheet); Transformer transformer = tFactory.newTransformer(stylesource); StreamResult result = new StreamResult(new FileOutputStream(target)); DOMSource domsource = new DOMSource(dom); transformer.transform(domsource, result); } catch (TransformerConfigurationException tce) { LOGGER.error(ExceptionUtils.getStackTrace(tce)); } catch (TransformerException te) { LOGGER.error(ExceptionUtils.getStackTrace(te)); } catch (FileNotFoundException e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } }
From source file:dz.alkhwarizmix.framework.java.utils.impl.XMLUtil.java
protected AbstractAlKhwarizmixDomainObject internal_unmarshalObjectFromXML( // NOPMD final String xmlValue) { return (AbstractAlKhwarizmixDomainObject) jaxb2Marshaller .unmarshal(new StreamSource(IOUtils.toInputStream(xmlValue))); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.xml.InlineXmlWriter.java
@Override public void process(final JCas aJCas) throws AnalysisEngineProcessException { OutputStream docOS = null;/*from w ww .j av a 2 s . c o m*/ try { docOS = getOutputStream(aJCas, ".xml"); final String xmlAnnotations = cas2xml.generateXML(aJCas.getCas()); if (transformer != null) { transformer.transform(new StreamSource(new ByteArrayInputStream(xmlAnnotations.getBytes("UTF-8"))), new StreamResult(docOS)); } else { docOS.write(xmlAnnotations.getBytes("UTF-8")); } } catch (final CASException e) { throw new AnalysisEngineProcessException(e); } catch (final IOException e) { throw new AnalysisEngineProcessException(e); } catch (TransformerException e) { throw new AnalysisEngineProcessException(e); } finally { closeQuietly(docOS); } }
From source file:Main.java
/** * Gets the transformer.//from ww w.j av a 2 s .c om * * @param xsltFile * the xslt file * @return the transformer * @throws TransformerFactoryConfigurationError * the transformer factory configuration error * @throws TransformerConfigurationException * the transformer configuration exception */ public static Transformer getTransformer(final File xsltFile) throws TransformerFactoryConfigurationError, TransformerConfigurationException { return getTransformer(new StreamSource(xsltFile)); }
From source file:com.example.switchyard.sap.Transformers.java
private Element toElement(String xml) { DOMResult dom = new DOMResult(); try {/* w w w. j a v a 2 s .c o m*/ TransformerFactory.newInstance().newTransformer().transform(new StreamSource(new StringReader(xml)), dom); } catch (Exception ex) { ex.printStackTrace(); } return ((Document) dom.getNode()).getDocumentElement(); }