Java Code Examples for javax.xml.transform.Transformer#clearParameters()
The following examples show how to use
javax.xml.transform.Transformer#clearParameters() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RuleFlowMigrator.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public static void transform(String stylesheet, Source src, Result res, HashMap<String, String> params) throws Exception { Transformer transformer = getTransformer(stylesheet); transformer.clearParameters(); if (params != null && params.size() > 0) { Iterator<String> itKeys = params.keySet().iterator(); while (itKeys.hasNext()) { String key = itKeys.next(); String value = params.get(key); transformer.setParameter(key, value); } } transformer.transform(src, res); }
Example 2
Source File: TfClearParamTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Obtains transformer's parameter whose initiated with a dom source with * the a name that wasn't set before. Null is expected. * @throws Exception If any errors occur. */ @Test public void clear10() throws Exception { TransformerFactory tfactory = TransformerFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse(new File(XSL_FILE)); DOMSource domSource = new DOMSource((Node)document); Transformer transformer = tfactory.newTransformer(domSource); transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); transformer.clearParameters(); assertNull(transformer.getParameter(LONG_PARAM_NAME)); }
Example 3
Source File: XmlUtils.java From iaf with Apache License 2.0 | 6 votes |
/** * sets all the parameters of the transformer using a Map with parameter values. */ public static void setTransformerParameters(Transformer t, Map<String,Object> parameters) { t.clearParameters(); if (parameters == null) { return; } for (String paramName:parameters.keySet()) { Object value = parameters.get(paramName); if (value != null) { t.setParameter(paramName, value); log.debug("setting parameter [" + paramName+ "] on transformer"); } else { log.info("omitting setting of parameter ["+paramName+"] on transformer, as it has a null-value"); } } }
Example 4
Source File: XsltData.java From hop with Apache License 2.0 | 5 votes |
public Transformer getTemplate( String xslFilename, boolean isAfile ) throws Exception { Transformer template = transformers.get( xslFilename ); if ( template != null ) { template.clearParameters(); return template; } return createNewTemplate( xslFilename, isAfile ); }
Example 5
Source File: TfClearParamTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Obtains transformer's parameter with the a name that wasn't set before. * Null is expected. * @throws TransformerConfigurationException If for some reason the * TransformerHandler can not be created. */ @Test public void clear02() throws TransformerConfigurationException { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); transformer.clearParameters(); assertNull(transformer.getParameter(LONG_PARAM_NAME)); }
Example 6
Source File: TfClearParamTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Obtains transformer's parameter whose initiated with a stream source with * the a name that wasn't set before. Null is expected. * @throws TransformerConfigurationException If for some reason the * TransformerHandler can not be created. */ @Test public void clear06() throws TransformerConfigurationException { Transformer transformer = TransformerFactory.newInstance(). newTransformer(new StreamSource(new File(XSL_FILE))); transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); transformer.clearParameters(); assertNull(transformer.getParameter(LONG_PARAM_NAME)); }
Example 7
Source File: TfClearParamTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Obtains transformer's parameter whose initiated with a sax source with * the a name that wasn't set before. Null is expected. * @throws Exception If any errors occur. */ @Test public void clear08() throws Exception { try (FileInputStream fis = new FileInputStream(XSL_FILE)) { SAXSource saxSource = new SAXSource(); saxSource.setInputSource(new InputSource(fis)); Transformer transformer = TransformerFactory.newInstance().newTransformer(saxSource); transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE); transformer.clearParameters(); assertNull(transformer.getParameter(LONG_PARAM_NAME)); } }
Example 8
Source File: XsltData.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public Transformer getTemplate( String xslFilename, boolean isAfile ) throws Exception { Transformer template = transformers.get( xslFilename ); if ( template != null ) { template.clearParameters(); return template; } return createNewTemplate( xslFilename, isAfile ); }
Example 9
Source File: XmlTransformer.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Transform XML documents using XSLT with cache * * @param source * The XML document content * @param stylesheet * The XSL source * @param strStyleSheetId * The StyleSheet Id * @param params * Parameters that can be used by the XSL StyleSheet * @param outputProperties * Properties to use for the XSL transform. Will overload the XSL output definition. * @return The output document * @throws TransformerException * The exception */ public String transform( Source source, Source stylesheet, String strStyleSheetId, Map<String, String> params, Properties outputProperties ) throws TransformerException { Templates templates = this.getTemplates( stylesheet, strStyleSheetId ); Transformer transformer = templates.newTransformer( ); if ( outputProperties != null ) { transformer.setOutputProperties( outputProperties ); } if ( params != null ) { transformer.clearParameters( ); for ( Entry<String, String> entry : params.entrySet( ) ) { transformer.setParameter( entry.getKey( ), entry.getValue( ) ); } } StringWriter sw = new StringWriter( ); Result result = new StreamResult( sw ); try { transformer.transform( source, result ); } catch( TransformerException e ) { String strMessage = "strStyleSheetId = " + strStyleSheetId + " " + e.getMessage( ); if ( e.getLocationAsString( ) != null ) { strMessage += ( " - location : " + e.getLocationAsString( ) ); } throw new TransformerException( ERROR_MESSAGE_XLST + strMessage, e.getCause( ) ); } finally { this.releaseTemplates( templates, strStyleSheetId ); } return sw.toString( ); }