You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by rushabh <ru...@igate.com> on 2014/05/16 13:04:51 UTC

Failed to transform report due to Handler Problem

I am getting error while running a test case regarding Handler issue.
Can you help me ?

Here is a code :-

*A Method which returns a ContentHandler :-*

 protected ContentHandler getRendererAsHandler(
	         final OutputStream anOutputStream)
	        throws ReportException
	    {
	    	
	    	FOUserAgent foUserAgent = fopFactory.newFOUserAgent();	               	                          
                          ContentHandler ch = null;
	    	
	        try {
				
	        	Fop fop =
fopFactory.newFop(MimeConstants.MIME_PDF,foUserAgent,anOutputStream);
			      ().createDocumentHandler(foUserAgent, "application/pdf");
	        	ch = fop.getDefaultHandler();		       
			    
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
	       
	     	        return ch;	       
	    }


*A class that calls above method and transform into PDF or printable format
:-*

ContentHandler handler = (ContentHandler)
            getRendererAsHandler(anOutputStream);

SAXTransformerFactory tFactory =
(SAXTransformerFactory)SAXTransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();

            final SAXSource inputSource =
                new SAXSource(this.xmlReader, new
InputSource(reportStream));
            
            
         *   transformer.transform(inputSource, new SAXResult(handler));*


On this line i am getting error like unable to transform : - 

ReportException:Failed to transform report
Caused by:
javax.xml.transform.TransformerException:
org.apache.fop.fo.ValidationException: First element must be the fo:root
formatting object. Found (Namespace URI:
"http://www.xx.com/xx/ReportTemplate", Local Name: "reportTemplate")
instead. Please make sure you're producing a valid XSL-FO document.

On debug i got FOTreeBuilder object instead ContentHandler object , Thats
why i think it caused error, I also tried to type cast it but not working
properly.

I konw it is some silly mistake but i am new to FOP , So can't able to
resolve it.



--
View this message in context: http://apache-fop.1065347.n5.nabble.com/Failed-to-transform-report-due-to-Handler-Problem-tp40609.html
Sent from the FOP - Dev mailing list archive at Nabble.com.