public Properties generate(File[] allTestFiles, String uploadDestPath) { FileOutputStream transformedHtml = null; File mergedResults = new File(folderToUpload.getAbsolutePath() + FileUtil.fileseparator() + TEST_RESULTS_FILE); File mergedResource = null; FileInputStream mergedFileStream = null; try { mergedResource = mergeAllTestResultToSingleFile(allTestFiles); transformedHtml = new FileOutputStream(mergedResults); try { mergedFileStream = new FileInputStream(mergedResource); Source xmlSource = new StreamSource(mergedFileStream); StreamResult result = new StreamResult(transformedHtml); templates.newTransformer().transform(xmlSource, result); } catch (Exception e) { publisher.reportErrorMessage("Unable to publish test properties. Error was " + e.getMessage(), e); } extractProperties(mergedResults); publisher.upload(mergedResults, uploadDestPath); return null; } catch (Exception e) { publisher.reportErrorMessage("Unable to publish test properties. Error was " + e.getMessage(), e); } finally { IOUtils.closeQuietly(mergedFileStream); IOUtils.closeQuietly(transformedHtml); if (mergedResource != null) { mergedResource.delete(); } } return new Properties(); }
argv[++i], ObjectFactory.findClassLoader(), true); tfactory.setURIResolver(uriResolver); stylesheet = tfactory.newTemplates(new StreamSource(xslFileName)); strResult = new StreamResult(new FileOutputStream(outFileName)); strResult.setSystemId(outFileName); strResult = new StreamResult(System.out); throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEET_IN_MEDIA, new Object[]{inFileName, media})); //"No stylesheet found in: " throw new TransformerException(XSLMessages.createMessage(XSLTErrorResources.ER_NO_STYLESHEET_PI, new Object[]{inFileName})); //"No xml-stylesheet PI found in: " Transformer transformer = flavor.equals("th") ? null : stylesheet.newTransformer(); transformer.setErrorListener(new DefaultErrorHandler(false)); transformer.setOutputProperty(OutputKeys.METHOD, outputType); stylesheet.getOutputProperties(); serializer.setOutputProperties(serializationProps); transformer.transform(new StreamSource(inFileName), result);
@Override public void write(OutputStream output) throws IOException { try { Transformer transformer = templates.newTransformer(); transformer.transform(source, new StreamResult(output)); } catch (TransformerException tre) { throw new IOException(tre.getMessage(), tre); } } }
private String transformLocally(Message m, UriInfo ui, Source source) throws Exception { InputStream is = ResourceUtils.getResourceStream(stylesheetReference, m.getExchange().getBus()); TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true); Transformer t = transformerFactory.newTemplates(new StreamSource(is)).newTransformer(); t.setParameter("base.path", m.get("http.base.path")); StringWriter stringWriter = new StringWriter(); t.transform(source, new StreamResult(stringWriter)); return stringWriter.toString(); }
TransformerFactory factory = TransformerFactory.newInstance(); try { Templates template = factory.newTemplates( new StreamSource( xslInputStream ) ); Transformer xformer = template.newTransformer(); xformer.setOutputProperties( outputProperties ); xformer.setParameter( nameOfParams[i], valueOfParams[i] ); Source source = new StreamSource( xmlInputStream ); os = KettleVFS.getOutputStream( outputfile, false ); StreamResult resultat = new StreamResult( os ); xformer.transform( source, resultat );
if (location != null) { templates = getTemplates(location); transformer = templates.newTransformer(); } else transformer = TransformerFactory.newInstance().newTransformer(); transformer.setURIResolver(getURIResolver()); mimeType = "text/xml"; // no stylesheet, raw xml else mimeType = templates.getOutputProperties().getProperty(OutputKeys.MEDIA_TYPE); if (mimeType == null) { transformer.transform(xmlSource, new StreamResult(out));
"</xsl:stylesheet>"; TransformerFactory transFactory = new TransformerFactoryImpl(); Templates templates = transFactory.newTemplates( new SAXSource(new InputSource(new StringReader(stylesheet)))); StreamResult result = new StreamResult(new StringWriter()); final StringWriter messageOut = new StringWriter(); Transformer transformer = templates.newTransformer(); ((net.sf.saxon.jaxp.TransformerImpl)transformer).getUnderlyingController().setMessageEmitter( new MessageEmitter() { transformer.transform(new StreamSource(new StringReader("<in/>")), result); assertEquals("Hi!", messageOut.toString().trim()); } catch (TransformerException e) { e.printStackTrace(); fail();
public MaryData process(MaryData d) throws Exception { DOMSource domSource = new DOMSource(d.getDocument()); Transformer transformer = stylesheet.newTransformer(); // Log transformation errors to client: if (doWarnClient) { // Use custom error handler: transformer.setErrorListener(new LoggingErrorHandler(Thread.currentThread().getName() + " client.Sable transformer")); } // Transform DOMSource into a DOMResult Document maryxmlDocument = docBuilder.newDocument(); DOMResult domResult = new DOMResult(maryxmlDocument); transformer.transform(domSource, domResult); MaryData result = new MaryData(outputType(), d.getLocale()); result.setDocument(maryxmlDocument); return result; } }
public static Document transform(Templates xsltTemplate, Document in) { try { DOMSource beforeSource = new DOMSource(in); Document out = DOMUtils.createDocument(); Transformer trans = xsltTemplate.newTransformer(); trans.transform(beforeSource, new DOMResult(out)); return out; } catch (TransformerException e) { throw new Fault("XML_TRANSFORM", LOG, e, e.getMessage()); } } }
Transformer transformer = stylesheet.newTransformer(); transformer.setErrorListener(new LoggingErrorHandler(Thread.currentThread().getName() + " client.EmotionML transformer")); transformer.setParameter("voice", d.getDefaultVoice().getName()); transformer.transform(domSource, domResult);
Transformer transformer = templates.newTransformer(); String mimeType = templates.getOutputProperties().getProperty(OutputKeys.MEDIA_TYPE); if (mimeType == null) { transformer.transform(xmlSource, new StreamResult(out));
final String document1 = ... final String document2 = ... final Templates template = ... final Transformer transformer = template.newTransformer(); transformer.setURIResolver(new StringURIResolver().put("document2", document2)); final StringWriter out = new StringWriter(); transformer.transform(new StreamSource(new StringReader(document1)), new StreamResult(out));
Templates stylesheet = tfactory.newTemplates(new DOMSource(xslDOM)); Transformer transformer = stylesheet.newTransformer(); if (namevalueParameters != null) { for (int i = 0; i < namevalueParameters.length; i++) { String value = namevalueParameters[i][1]; transformer.setParameter(name, value); transformer.transform(new DOMSource(inDoc, null), domResult);
/** * Transforms the given input nodes to a list of output nodes. * * @param inputNodes input nodes * @return transformed output nodes * @throws XSLTransformException if there's a problem in the transformation */ public List<Content> transform(List<Content> inputNodes) throws XSLTransformException { JDOMSource source = new JDOMSource(inputNodes); JDOMResult result = new JDOMResult(); result.setFactory(factory); // null ok try { templates.newTransformer().transform(source, result); return result.getResult(); } catch (TransformerException e) { throw new XSLTransformException("Could not perform transformation", e); } }
transformer = templates.newTransformer(); transformer.setErrorListener(this); if (uriResolver != null) { transformer.setURIResolver(uriResolver); transformer.setOutputProperty(pair[0], pair[1]);
public void setStylesheet(File stylesheet) throws Exception { xslStream = new FileInputStream(stylesheet); StreamSource src = new StreamSource(xslStream); src.setSystemId(getSystemId(stylesheet)); templates = tfactory.newTemplates(src); transformer = templates.newTransformer(); }
path.getParent().mkdirs(); Properties output = stylesheet.getOutputProperties(); transformer = stylesheet.newTransformer(); transformer.setParameter(param, req.getParameter(param)); transformer.setParameter("xtp:context_path", contextPath); transformer.setParameter("xtp:servlet_path", servletPath);
/** * Create the {@link Transformer} instance used to prefer the XSLT transformation. * <p>The default implementation simply calls {@link Templates#newTransformer()}, and * configures the {@link Transformer} with the custom {@link URIResolver} if specified. * @param templates the XSLT Templates instance to create a Transformer for * @return the Transformer object * @throws TransformerConfigurationException in case of creation failure */ protected Transformer createTransformer(Templates templates) throws TransformerConfigurationException { Transformer transformer = templates.newTransformer(); if (this.uriResolver != null) { transformer.setURIResolver(this.uriResolver); } return transformer; }
/** * Construct an empty XML filter, with no parent. * * <p>This filter will have no parent: you must assign a parent * before you start a parse or do any configuration with * setFeature or setProperty.</p> * * @see org.xml.sax.XMLReader#setFeature * @see org.xml.sax.XMLReader#setProperty */ public TrAXFilter (Templates templates) throws TransformerConfigurationException { m_templates = templates; m_transformer = (TransformerImpl)templates.newTransformer(); }
public static Transformer newRawResultsTransformer() throws TransformerException { //In case of start method is not called by Jenkins plugin life cycle management if (templates == null) { try { initTemplate(); } catch (Exception e) { throw new TransformerException("Can't initialize template", e); } } return templates.newTransformer(); }