List of usage examples for javax.xml.transform Transformer setParameter
public abstract void setParameter(String name, Object value);
From source file:com.spoledge.audao.generator.GeneratorFlow.java
private void setDbType(Transformer transformer) { transformer.setParameter("db_type", generator.getTarget().getIdentifier()); }
From source file:org.kuali.mobility.knowledgebase.service.KnowledgeBaseServiceImpl.java
public String getConvertedKnowledgeBaseDocument(String documentId, String templatesCode, Map<String, Object> transformerParameters) { String xml = this.getKnowledgeBaseDocument(documentId); String output = ""; try {/* w w w . ja va2 s . com*/ Templates templates = this.getXslTemplates(templatesCode); // Templates templates = this.cacheService.findCachedXSLTemplates(templatesCode); Transformer transformer = templates.newTransformer(); for (String key : transformerParameters.keySet()) { transformer.setParameter(key, transformerParameters.get(key)); } ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); transformer.transform(new StreamSource(new ByteArrayInputStream(xml.getBytes())), new StreamResult(byteArrayOutputStream)); output = byteArrayOutputStream.toString(); } catch (Exception e) { LOG.error(e.getMessage(), e); } return output; }
From source file:be.fedict.eid.dss.document.xml.XMLDSSDocumentService.java
public DocumentVisualization visualizeDocument(byte[] document, String language, List<MimeType> mimeTypes, String documentViewerServlet) throws Exception { // per default we do nothing byte[] browserData = document; String browserContentType = "text/xml"; ByteArrayInputStream documentInputStream = new ByteArrayInputStream(document); Document dom = this.documentBuilder.parse(documentInputStream); String namespace = dom.getDocumentElement().getNamespaceURI(); if (null != namespace) { LOG.debug("document namespace: " + namespace); byte[] xsl = this.context.getXmlStyleSheet(namespace); if (null != xsl) { LOG.debug("XML style sheet present"); browserContentType = "text/html"; Transformer transformer = this.transformerFactory .newTransformer(new StreamSource(new ByteArrayInputStream(xsl))); if (null != language) { transformer.setParameter("language", language); }/*from ww w .j a v a 2 s .c o m*/ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); transformer.transform(new DOMSource(dom), new StreamResult(outputStream)); browserData = outputStream.toByteArray(); } } return new DocumentVisualization(browserContentType, browserData); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.XSLTProcessor.java
/** * @return {@link Node} or {@link String} *//*from ww w .j ava2s .c o m*/ private Object transform(final Node source) { try { Source xmlSource = new DOMSource(source.getDomNodeOrDie()); final Source xsltSource = new DOMSource(style_.getDomNodeOrDie()); final org.w3c.dom.Document containerDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder() .newDocument(); final org.w3c.dom.Element containerElement = containerDocument.createElement("container"); containerDocument.appendChild(containerElement); final DOMResult result = new DOMResult(containerElement); final Transformer transformer = TransformerFactory.newInstance().newTransformer(xsltSource); for (final Map.Entry<String, Object> entry : parameters_.entrySet()) { transformer.setParameter(entry.getKey(), entry.getValue()); } transformer.transform(xmlSource, result); final org.w3c.dom.Node transformedNode = result.getNode(); if (transformedNode.getFirstChild().getNodeType() == Node.ELEMENT_NODE) { return transformedNode; } //output is not DOM (text) xmlSource = new DOMSource(source.getDomNodeOrDie()); final StringWriter writer = new StringWriter(); final Result streamResult = new StreamResult(writer); transformer.transform(xmlSource, streamResult); return writer.toString(); } catch (final Exception e) { throw Context.reportRuntimeError("Exception: " + e); } }
From source file:de.awtools.xml.XSLTransformer.java
/** * Initialisiert den Transformer mit den Parametern. * //from w ww . j a v a 2 s . com * @param _transe Der zu initialisierende Transformer. */ private void addParams(final Transformer _transe) { for (String key : getParams().keySet()) { _transe.setParameter(key, getParams().get(key)); } }
From source file:com.recomdata.datasetexplorer.proxy.XmlHttpProxy.java
/** * Do the XSLT transformation/* w w w .ja v a 2 s . co m*/ */ public void transform(InputStream xmlIS, InputStream xslIS, Map params, OutputStream result, String encoding) { try { TransformerFactory trFac = TransformerFactory.newInstance(); Transformer transformer = trFac.newTransformer(new StreamSource(xslIS)); Iterator it = params.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); transformer.setParameter(key, (String) params.get(key)); } transformer.setOutputProperty("encoding", encoding); transformer.transform(new StreamSource(xmlIS), new StreamResult(result)); } catch (Exception e) { getLogger().severe("XmlHttpProxy: Exception with xslt " + e); } }
From source file:eionet.gdem.conversion.converters.ConvertStrategy.java
/** * Sets the map of xsl global parameters to xsl transformer. * @param transformer XSL transformer object. *///from w w w . j av a 2 s . c o m private void setTransformerParameters(Transformer transformer) { if (xslParams == null) { return; } Iterator<String> keys = xslParams.keySet().iterator(); while (keys.hasNext()) { String key = keys.next(); String value = xslParams.get(key); if (value != null) { transformer.setParameter(key, value); } } // sets base URI for xmlfiles uploaded into xmlconv String xmlFilePathURI = Utils.getURIfromPath(eionet.gdem.Properties.xmlfileFolder, true); if (xmlFilePathURI != null) { transformer.setParameter(XML_FOLDER_URI_PARAM, xmlFilePathURI); } }
From source file:com.consol.citrus.admin.service.spring.SpringBeanService.java
/** * Method adds a new Spring bean definition to the XML application context file. * @param project// w w w .j a v a2 s . c om * @param jaxbElement */ public void addBeanDefinition(File configFile, Project project, Object jaxbElement) { Source xsltSource; Source xmlSource; try { xsltSource = new StreamSource(new ClassPathResource("transform/add-bean.xsl").getInputStream()); xsltSource.setSystemId("add-bean"); xmlSource = new StringSource(FileUtils.readToString(new FileInputStream(configFile))); //create transformer Transformer transformer = transformerFactory.newTransformer(xsltSource); transformer.setParameter("bean_content", getXmlContent(jaxbElement).replaceAll("(?m)^(.)", getTabs(1, project.getSettings().getTabSize()) + "$1")); //transform StringResult result = new StringResult(); transformer.transform(xmlSource, result); FileUtils.writeToFile(format(result.toString(), project.getSettings().getTabSize()), configFile); return; } catch (IOException e) { throw new ApplicationRuntimeException(UNABLE_TO_READ_TRANSFORMATION_SOURCE, e); } catch (TransformerException e) { throw new ApplicationRuntimeException(FAILED_TO_UPDATE_BEAN_DEFINITION, e); } }
From source file:com.consol.citrus.admin.service.spring.SpringBeanService.java
/** * Method removes a Spring bean definition from the XML application context file. Bean definition is * identified by its id or bean name.//from w ww. java 2 s . c o m * @param project * @param id */ public void removeBeanDefinition(File configFile, Project project, String id) { Source xsltSource; Source xmlSource; try { xsltSource = new StreamSource(new ClassPathResource("transform/delete-bean.xsl").getInputStream()); xsltSource.setSystemId("delete-bean"); List<File> configFiles = new ArrayList<>(); configFiles.add(configFile); configFiles.addAll(getConfigImports(configFile, project)); for (File file : configFiles) { xmlSource = new StringSource(FileUtils.readToString(new FileInputStream(configFile))); //create transformer Transformer transformer = transformerFactory.newTransformer(xsltSource); transformer.setParameter("bean_id", id); //transform StringResult result = new StringResult(); transformer.transform(xmlSource, result); FileUtils.writeToFile(format(result.toString(), project.getSettings().getTabSize()), file); return; } } catch (IOException e) { throw new ApplicationRuntimeException(UNABLE_TO_READ_TRANSFORMATION_SOURCE, e); } catch (TransformerException e) { throw new ApplicationRuntimeException(FAILED_TO_UPDATE_BEAN_DEFINITION, e); } }