Transformer setParameter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Transformer setParameter method.

This code example shows how to use the following methods:setParameter, transform
        Source xsltSource = new StreamSource(Specdox.class.getResourceAsStream("/specdox.xsl"));
        xsltSource.setSystemId("/specdox.xsl");
         
        TransformerFactory transFact = new TransformerFactoryImpl();
        Transformer trans = transFact.newTransformer(xsltSource);
        trans.setParameter("spec-file-dir", specXmlDir);
        trans.setParameter("xref", xref.getName());
        trans.setParameter("output-dir", outputDir);
        trans.setParameter("frameset-index-filename", filename);
        trans.transform(xmlSource, new StreamResult(System.out));
    } 
} 
7
CodeRank
This code example shows how to use the following methods:setParameter, setURIResolver, transform
            try { 
                final InputStreamUriParameter inputStreamUriParameter = new InputStreamUriParameter(source.getInputStream());
                final StreamResult resultWriter = new StreamResult(target);
                // The XSL requires a parameter to represent the absolute limits. 
                // This harness cheats and provides the input stream directly. 
                pooledObject.setURIResolver(inputStreamUriParameter);
                pooledObject.setParameter("absoluteURL", inputStreamUriParameter.getHref());
                final Limits limitsObject = new Limits();
                limitsObject.setRates(source.getRateLimitList());
                pooledObject.transform(new JAXBSource(jaxbContext, factory.createLimits(limitsObject)), resultWriter);
            } catch (Exception e) {
                objectPool.invalidateObject(pooledObject);
                pooledObject = null;
                throw new XsltTransformationException("Failed while attempting XSLT transformation.", e);
            } finally { 
                if (pooledObject != null) {
                    objectPool.returnObject(pooledObject);
                } 
            } 
        } catch (XsltTransformationException e) {

7
CodeRank
This code example shows how to use the following methods:setParameter, setURIResolver, transform
			Source source = null;
			String uri = pkg.getBaseURI() + path;
			Document doc = pkg.getDom(path);
			source = new DOMSource(doc);
			Transformer transformer = templates.newTransformer();
			transformer.setURIResolver(pkg.getURIResolver());
 
			transformer.setParameter("sourceURL", uri);
			transformer.setParameter("sourceBaseURL", pkg.getBaseURI() + "/");
 
			uri = result.getSystemId();
			if (uri != null) {
				transformer.setParameter("targetURL", uri);
				int i = uri.lastIndexOf('/');
				if (i > 0) {
					uri = uri.substring(0, i + 1);
					transformer.setParameter("targetBaseURL", uri);
				} 
			} 
			DocumentType doctype = doc.getDoctype();

6
CodeRank
This code example shows how to use the following methods:getClass, setParameter, transform
This code example shows how to use the following methods:setParameter, transform
		source.setSystemId(xsl);
		 
		Transformer tr = null;
		try { 
			tr = tFactory.newTransformer(source);			
			tr.setParameter("helper", new XSLHelper());
			tr.setParameter("idElementName", "e_id");
			tr.setParameter("idValuePrefix", "id");
			tr.setParameter("labelElementName", "label");
		} catch (TransformerConfigurationException e1) {
			logger.error("Transformation error:"+e1.getMessage());
		} 
		try { 
			StreamResult result = new StreamResult(out);
			StreamSource docSrc = new StreamSource(xml);
			docSrc.setSystemId(xml);
			tr.transform(docSrc, result);
		} catch (Exception e) {
			logger.error("Transformation error:"+e.getMessage());
		} finally { 

6
CodeRank
This code example shows how to use the following methods:setErrorListener, setParameter, transform
 
        Transformer transformer = stylesheet.newTransformer();
        // Log transformation errors to client: 
        if (doWarnClient) {
            // Use custom error handler: 
            transformer.setErrorListener(new LoggingErrorHandler(Thread.currentThread().getName() + " client.EmotionML transformer"));
        } 
 
        transformer.setParameter("voice", d.getDefaultVoice().getName());
         
        // Transform DOMSource into a DOMResult 
        Document maryxmlDocument = docBuilder.newDocument();
        DOMResult domResult = new DOMResult(maryxmlDocument);
        transformer.transform(domSource, domResult);
        // We add the 'xml:lang' attribute manually: 
        maryxmlDocument.getDocumentElement().setAttribute("xml:lang", MaryUtils.locale2xmllang(d.getLocale()));
         
        MaryData result = new MaryData(outputType(), d.getLocale());
        result.setDocument(maryxmlDocument);
        return result;
6
CodeRank
This code example shows how to use the following methods:setParameter, transform
            Source source = new DOMSource(document);
 
            ByteArrayOutputStream baos = new ByteArrayOutputStream(text.length());
            Result result = new StreamResult(baos);
 
            transformer.setParameter("baseUri", baseUri);
            transformer.setParameter("originBundleSymbolicName", originBundleSymbName);
            transformer.transform(source, result);
 
            String resultedText = baos.toString("UTF-8");
            int startIdx = resultedText.indexOf(openingTag) + openingTag.length();
            int endIdx = resultedText.lastIndexOf(closingTag);
            return new TypedLiteralImpl(resultedText.substring(startIdx, endIdx),
                    XML_LITERAL);
        } catch (SAXException se) {
            logger.warn("SAXException {} while transforming xml literal: {}", 
                    se.getMessage(), text);
        } catch (ParserConfigurationException pce) {
            logger.warn("ParserConfigurationException {} while transforming xml literal: {}", 
                    pce.getMessage(), text);
5
CodeRank
This code example shows how to use the following methods:setParameter, transform
         
        final InputStream xslStream = this.getClass().getResourceAsStream("authorizationTest.xsl");
        final StreamSource xslSource = new StreamSource(xslStream);
        final Transformer transformer = tFactory.newTransformer(xslSource);
         
        transformer.setParameter("USER_ID", "testUser");
         
        transformer.transform(xmlSource, new StreamResult(resultWriter));
         
        final String result = resultWriter.getBuffer().toString();
        logger.debug(result);
         
        final String expected = IOUtils.toString(this.getClass().getResourceAsStream("authorizationResult.xml"));
 
        XMLUnit.setIgnoreWhitespace(true); 
        Diff d = new Diff(expected, result);
        assertTrue("Transformation result differs from what's expected" + d, d.similar());
         
        verify(helperBean);
    } 
5
CodeRank
This code example shows how to use the following methods:setParameter, transform
         
        final InputStream xslStream = this.getClass().getResourceAsStream("groupMembershipTest.xsl");
        final StreamSource xslSource = new StreamSource(xslStream);
        final Transformer transformer = tFactory.newTransformer(xslSource);
         
        transformer.setParameter("USER_ID", "testUser");
         
        transformer.transform(xmlSource, new StreamResult(resultWriter));
         
        final String result = resultWriter.getBuffer().toString();
        logger.debug(result);
         
        final String expected = IOUtils.toString(this.getClass().getResourceAsStream("groupMemebershipResult.xml"));
 
        XMLUnit.setIgnoreWhitespace(true); 
        Diff d = new Diff(expected, result);
        assertTrue("Transformation result differs from what's expected" + d, d.similar());
         
        verify(helperBean);
    } 
5
CodeRank
This code example shows how to use the following methods:setParameter, transform
      transformer = tFactory.newTransformer();
    } catch (TransformerConfigurationException e) {
      throw new SelendroidException(e);
    } 
 
    transformer.setParameter("encoding", "UTF-8");
 
    DOMSource domSource = new DOMSource(document);
    Writer outWriter = new StringWriter();
 
    StreamResult result = new StreamResult(outWriter);
    try { 
      transformer.transform(domSource, result);
    } catch (TransformerException e) {
      throw new SelendroidException(e);
    } 
 
    return outWriter.toString();
  } 
} 
5
CodeRank
setParameter Method Overview
Add a parameter for the transformation.
See Code Examples for other Java 8 Transformer Methods: