Java 8 TransformerFactory - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 TransformerFactory class.

This code example shows how to use the following methods:getErrorListener, newTemplates, setErrorListener, setURIResolver
	throws TransformerConfigurationException { 
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory(); 
        } 
	if (_errorlistener != null) {
	    _xsltcFactory.setErrorListener(_errorlistener);	    
	} 
	if (_uriresolver != null) {
	    _xsltcFactory.setURIResolver(_uriresolver);
	} 
	Templates templates = _xsltcFactory.newTemplates(src);
	if (templates == null ) return null;
	return newXMLFilter(templates); 
    } 
 
    /* 
     * Create an XMLFilter that uses the given source as the 
     * transformation instructions. Uses 
     * org.apache.xalan.xsltc.trax.TransformerFactory. 
     */ 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setErrorListener, setURIResolver
	 * Initialize this XsltView's TransformerFactory. 
	 */ 
	@Override 
	protected void initApplicationContext() throws BeansException { 
		this.transformerFactory = newTransformerFactory(this.transformerFactoryClass); 
		this.transformerFactory.setErrorListener(this.errorListener); 
		if (this.uriResolver != null) { 
			this.transformerFactory.setURIResolver(this.uriResolver); 
		} 
		if (this.cacheTemplates) { 
			this.cachedTemplates = loadTemplates(); 
		} 
	} 
 
	/** 
	 * Instantiate a new TransformerFactory for this view. 
	 * <p>The default implementation simply calls 
	 * {@link javax.xml.transform.TransformerFactory#newInstance()}. 
	 * If a {@link #setTransformerFactoryClass "transformerFactoryClass"} 
	 * has been specified explicitly, the default constructor of the 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newTransformer
	 * @param source the source to transform from 
	 * @param result the result to transform to 
	 * @throws TransformerException in case of transformation errors 
	 */ 
	protected void transform(Source source, Result result) throws TransformerException {
		this.transformerFactory.newTransformer().transform(source, result);
	} 
 
 
	/** 
	 * Abstract template method called from {@link #read(Class, HttpInputMessage)}. 
	 * @param clazz the type of object to return 
	 * @param headers the HTTP input headers 
	 * @param source the HTTP input body 
	 * @return the converted object 
	 * @throws IOException in case of I/O errors 
	 * @throws org.springframework.http.converter.HttpMessageConversionException in case of conversion errors 
	 */ 
	protected abstract T readFromSource(Class<? extends T> clazz, HttpHeaders headers, Source source)
			throws IOException;
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getFeature, setAttribute, setErrorListener, setURIResolver
    if (uriResolver == null) {
      throw new RuntimeException("uriResolver property must be set");
    } 
    TransformerFactory tFactory = TransformerFactory.newInstance();
    setFactoryResolver(tFactory);
    tFactory.setAttribute("http://xml.apache.org/xalan/features/incremental", java.lang.Boolean.TRUE);
 
    if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE)) {
      // Cast the TransformerFactory to SAXTransformerFactory. 
      saxTFactory = ( (SAXTransformerFactory) tFactory);
    } 
    if (outputProperties == null) {
      outputProperties = OutputPropertiesFactory.getDefaultMethodProperties("html");
    } 
    templateCache = new ConcurrentHashMap<String, Templates>();
 
  } 
 
  protected void setFactoryResolver(TransformerFactory tFactory) {
    if (uriResolver == null) {

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newTemplates, setErrorListener, setURIResolver
    @Before 
    public void setup() throws Exception {
        final ResourceLoaderURIResolver resolver = new ResourceLoaderURIResolver(new ClassRelativeResourceLoader(getClass()));
         
        this.tFactory = TransformerFactory.newInstance();
        this.tFactory.setURIResolver(resolver);
        this.tFactory.setErrorListener(new SimpleTransformErrorListener(LogFactory.getLog(getClass())));
         
        //Load the XML document so it reads the same way the rendering pipeline reads XML 
        final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
        final XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(this.getClass().getResourceAsStream("test.xml"));
        final XMLStreamReader streamReader = new FixedXMLEventStreamReader(eventReader);
        xmlSource = new StAXSource(streamReader);
         
        xslTemplate = tFactory.newTemplates(new StreamSource(this.getClass().getResourceAsStream("test.xsl")));
         
        expected = IOUtils.toString(this.getClass().getResourceAsStream("result.xml"));
    } 
     
    @Test
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newTransformer
	private void transformAndMarshal(Object graph, Result result) throws IOException {
		try { 
			ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
			marshalOutputStream(graph, os);
			ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
			Transformer transformer = this.transformerFactory.newTransformer();
			transformer.transform(new StreamSource(is), result);
		} 
		catch (TransformerException ex) {
			throw new MarshallingFailureException( 
					"Could not transform to [" + ClassUtils.getShortName(result.getClass()) + "]", ex);
		} 
 
	} 
 
 
	// Unmarshalling 
 
	@Override 
	protected Object unmarshalXmlEventReader(XMLEventReader eventReader) {
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newTransformer, setAttribute
     * @return a transformer that indents entries by 4 characters (never null) 
     */ 
    public static Transformer createIndentingTransformer() {
        Transformer transformer;
        try { 
            TRANSFORMER_FACTORY.setAttribute("indent-number", 4);
            transformer = TRANSFORMER_FACTORY.newTransformer();
        } 
        catch (final Exception e) {
            throw new IllegalStateException(e);
        } 
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(
                "{http://xml.apache.org/xslt}indent-amount", "4"); 
        return transformer;
    } 
 
    /** 
     * Creates an {@link Element} containing the given text 
     *  
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newTransformer, setErrorListener, setURIResolver
    } 
 
    protected void createTransformer() 
        throws Exceptionthis.factory.setErrorListener( this.errors );
        this.factory.setURIResolver( new UriResolverImpl() );
        this.transformer = this.factory.newTransformer( this.xsltSource );
        this.transformer.setErrorListener( this.errors );
        this.transformer.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "yes" );
    } 
 
    private void setParameters() 
        throws Exception
    { 
        final ContextDocBuilder contextDocBuilder = new ContextDocBuilder();
        this.transformer.setParameter( "_", contextDocBuilder.createContextDoc() );
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:newTransformer
			_scriptSource = scriptSource;
		} 
 
		@Override 
		public Transformer run() throws Exception {
			return _transformerFactory.newTransformer(_scriptSource);
		} 
 
		private final StreamSource _scriptSource;
		private TransformerFactory _transformerFactory;
 
	} 
 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setErrorListener, setURIResolver
    @Before 
    public void setup() throws Exception {
        final ResourceLoaderURIResolver resolver = new ResourceLoaderURIResolver(new ClassRelativeResourceLoader(getClass()));
         
        this.tFactory = TransformerFactory.newInstance();
        this.tFactory.setURIResolver(resolver);
        this.tFactory.setErrorListener(new SimpleTransformErrorListener(LogFactory.getLog(getClass())));
         
        this.xmlSource = new StreamSource(this.getClass().getResourceAsStream("test.xml"));
    } 
 
    @Test
    public void testIsUserDeepMemberOf() throws Exception {
        final IXalanMessageHelper helperBean = createMock(IXalanMessageHelper.class);
         
        expect(helperBean.getMessage("im.done", "en_us")).andReturn("I'm Done!");
         
        replay(helperBean);
         
        XalanMessageHelper helper = new XalanMessageHelper();
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 TransformerFactory Questions & Answers:

See Code Examples for Java 8 TransformerFactory Methods: