You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Kevin <kb...@yahoo.com> on 2007/09/27 21:34:17 UTC

nullpointer exception - FO to Area tree transform

Hi,
I'm getting the following exception while transforming FO -> AREA TREE
java.lang.NullPointerException
	at org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java:264)

	at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:171)
	at
org.apache.xalan.transformer.TransformerIdentityImpl.endDocument
(TransformerIdentityImpl.java:910)
	at org.dom4j.io.aelfred.SAXDriver.parse(SAXDriver.java:328)
	at
org.apache.xalan.transformer.TransformerIdentityImpl.transform
(TransformerIdentityImpl.java:432)

PDF gets created just fine in command line. I'm at FOP 0.94/Windows 2003 server.

Pl help.

Thanks
Kevin


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: nullpointer exception - FO to Area tree transform(another exception)

Posted by Kevin <kb...@yahoo.com>.
(3rd try...could'nt get to post this message)

Hi Andreas,

Below is the code:


// STEP 1: Transform templates to FO
StringWriter writer = new StringWriter();
StreamResult foResult = new StreamResult(writer);
HashMap foParameters = new HashMap(parameters);
foParameters.put("templateInstanceGroups", templateInstanceGroups);
transform(TRANSFORM_FO, templateInstanceGroups, editable, null,
 foParameters, 
foResult);
writer.flush();

if (SystemUtil.isDevelopmentMode() || logger.isDebugEnabled())
{

	System.out.println("------------------------------------------------------");

	System.out.println("------------------------------------------------------");
	System.out.println("--------------------  FO
 -----------------------------");

	System.out.println("------------------------------------------------------");
	System.out.println(writer.toString());

	System.out.println("------------------------------------------------------");

	System.out.println("------------------------------------------------------");

	System.out.println("------------------------------------------------------");

	System.out.println("------------------------------------------------------");
}

// STEP 2: Transform FO  to Area Tree

FopFactory fopFactory = FopFactory.newInstance();

// Used to find images
fopFactory.setURIResolver(TIPResourceResolver.DEFAULT_URI_RESOLVER);

// configure foUserAgent 
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();

//Create an instance of the target renderer so the XMLRenderer can use
 its 
font setup
Renderer targetRenderer =
 foUserAgent.getRendererFactory().createRenderer
(foUserAgent, MimeConstants.MIME_PDF);

//Create the XMLRenderer to create the intermediate format (area tree
 XML)
XMLRenderer xmlRenderer = new XMLRenderer();
xmlRenderer.setUserAgent(foUserAgent);

//Tell the XMLRenderer to mimic the target renderer
xmlRenderer.mimicRenderer(targetRenderer);

//Make sure the prepared XMLRenderer is used
foUserAgent.setRendererOverride(xmlRenderer);

File areaTreeFile = new File(atFile); // area tree file
OutputStream out = new java.io.FileOutputStream(areaTreeFile);
out = new java.io.BufferedOutputStream(out);
if (out == null)
{
	throw new IllegalArgumentException("PDF production requires an 
	OutputStream for binary data, not a Writer, which is for 
	character data.");
}

Fop fop = (Fop)fopFactory.newFop(null, foUserAgent, out);

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();

StreamSource foSource = new StreamSource(new
 StringReader(writer.toString()));
Result areaTreeResult = new SAXResult(fop.getDefaultHandler());

System.out.println("--- Start Area tree transform");
long start = System.currentTimeMillis();
transformer.transform(foSource, areaTreeResult);
long end = System.currentTimeMillis();
System.out.println("--- End Area tree transform: " + (end - start) /
 1000.0);
out.close();

// STEP 3: Transform Area Tree to Area tree with last-odd-page omr
// Get the appropriate transformer name given the transform type
String transformerName = getTransformerName(TRANSFORM_AREA_TREE);

// Read area tree

InputStream is = new FileInputStream(areaTreeFile);
Source source = new StreamSource(is);

StringWriter atWriter = new StringWriter();
StreamResult areaTreeResult1 = new StreamResult(atWriter);

// Perform the transform
TransformUtil.transform(TransformUtil.TRANSFORM_STREAM,
 transformerName, 
parameters, source, areaTreeResult1);


// STEP 4: create PDF
OutputStream out2 = ((StreamResult)result).getOutputStream();
if (out2 == null)
{
	throw new IllegalArgumentException("PDF production requires an 
	OutputStream for binary data, not a Writer, which is for character
 data.");
}
//Setup fonts and user agent
FontInfo fontInfo = new FontInfo();
FOUserAgent userAgent = fopFactory.newFOUserAgent();

AreaTreeModel treeModel = new RenderPagesModel(userAgent, 
MimeConstants.MIME_PDF, fontInfo, out2);

AreaTreeParser parser = new AreaTreeParser();

StreamSource atSource = 
new StreamSource(new StringReader(atWriter.toString()));

parser.parse(atSource, treeModel, userAgent);

treeModel.endDocument();

}
catch (FOPException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (SAXException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}




Thanks
Kevin


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: nullpointer exception - FO to Area tree transform(another exception)

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Sep 28, 2007, at 01:51, Kevin wrote:

Hi Kevin

> The intermediate area tree xml gets produced fine and produces the  
> PDF also from
> command line. But on server(Websphere 6.0) I get this exception in  
> the code
> which does the  AREA TREE -> PDF transfor.
<snip />

Can you show us a bit more of the Java code used to call FOP? I'm  
suspecting the below error message to mean that a part/component of  
FOP is being re-used, while it really should be a new instance for  
every run.

This could explain why the error never occurs from the command-line,  
since you do not run FOP twice inside the same JVM-session there...?

Thanks in advance


Andreas
> java.lang.IllegalStateException: Current RegionViewport must be null
> 	at ...
> org.apache.fop.area.AreaTreeParser$Handler 
> $RegionViewportMaker.startElement
> (AreaTreeParser.java(Compiled
> Code))
> 	at
> org.apache.fop.area.AreaTreeParser$Handler.startElement 
> (AreaTreeParser.java
> (Compiled
> Code))
> 	at



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: nullpointer exception - FO to Area tree transform(another exception)

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
That's exactly why Chris wrote what he wrote. You need to make sure
JAXP's default XML parser is no longer the outdated Aelfred parser but
Xerces. FOP always uses the default JAXP XML parser. WebSphere doesn't
use Aelfred by default so that means you already replaced the default
XML parser somehow. The WebSphere console should help you find out what
exactly is on the classpath.

Jeremias Maerki



On 04.10.2007 02:24:13 Kevin wrote:
> Chris,
> 
> Thanks for your help. I am not explicitly using that parser. Its getting called
> within the FOP code  when I do that area tree -> PDF transform.
> 
> Any suggestions.
> 
> Thanks
> Kevin


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: nullpointer exception - FO to Area tree transform(another exception)

Posted by Kevin <kb...@yahoo.com>.
Chris,

Thanks for your help. I am not explicitly using that parser. Its getting called
within the FOP code  when I do that area tree -> PDF transform.

Any suggestions.

Thanks
Kevin

Chris Bowditch <bowditch_chris <at> hotmail.com> writes:






---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: nullpointer exception - FO to Area tree transform(another exception)

Posted by Chris Bowditch <bo...@hotmail.com>.
Kevin wrote:

Hi Kevin,

<snip/>

> org.apache.xalan.transformer.TransformerIdentityImpl.startElement
> (TransformerIdentityImpl.java(Compiled
> Code))
> 	at org.dom4j.io.aelfred.SAXDriver.startElement(SAXDriver.java(Compiled Code))

This stack trace indicates that you are using the aelfred XML parser, 
which is a very old implementation and doesn't work properly. Please 
check your websphere classpath and ensure that the xerces parser shipped 
with FOP (in the lib sub dir) has higher priority on the classpath.

<snip/>

Chris



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: nullpointer exception - FO to Area tree transform(another exception)

Posted by Kevin <kb...@yahoo.com>.
Another exception I'm getting..

The intermediate area tree xml gets produced fine and produces the PDF also from
command line. But on server(Websphere 6.0) I get this exception in the code
which does the  AREA TREE -> PDF transfor.

Thanks and any help will be great.

Thanks
Kevin

[9/27/07 18:44:21:710 CDT] 0000008c SystemErr     R
java.lang.IllegalStateException: Current RegionViewport must be null
	at
org.apache.fop.area.AreaTreeParser$Handler$RegionViewportMaker.startElement
(AreaTreeParser.java(Compiled
Code))
	at
org.apache.fop.area.AreaTreeParser$Handler.startElement(AreaTreeParser.java
(Compiled
Code))
	at
org.apache.xalan.transformer.TransformerIdentityImpl.startElement
(TransformerIdentityImpl.java(Compiled
Code))
	at org.dom4j.io.aelfred.SAXDriver.startElement(SAXDriver.java(Compiled Code))
	at org.dom4j.io.aelfred.XmlParser.parseElement(XmlParser.java(Compiled Code))
	at org.dom4j.io.aelfred.XmlParser.parseContent(XmlParser.java(Compiled Code))
	at org.dom4j.io.aelfred.XmlParser.parseElement(XmlParser.java(Compiled Code))
	at org.dom4j.io.aelfred.XmlParser.parseContent(XmlParser.java(Compiled Code))
	at org.dom4j.io.aelfred.XmlParser.parseElement(XmlParser.java(Compiled Code))
	at org.dom4j.io.aelfred.XmlParser.parseContent(XmlParser.java(Compiled Code))
	at org.dom4j.io.aelfred.XmlParser.parseElement(XmlParser.java(Compiled Code))
	at org.dom4j.io.aelfred.XmlParser.parseContent(XmlParser.java(Compiled Code))
	at org.dom4j.io.aelfred.XmlParser.parseElement(XmlParser.java(Compiled Code))
	at org.dom4j.io.aelfred.XmlParser.parseDocument
(XmlParser.java:499)
	at org.dom4j.io.aelfred.XmlParser.doParse(XmlParser.java:151)
	at org.dom4j.io.aelfred.SAXDriver.parse(SAXDriver.java:314)
	at
org.apache.xalan.transformer.TransformerIdentityImpl.transform
(TransformerIdentityImpl.java:432)
	at org.apache.fop.area.AreaTreeParser.parse(AreaTreeParser.java:105)






---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org