You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "PLISSON Sébastien (DSIT-XS/I)" <se...@sncf.fr> on 2002/08/01 08:11:22 UTC

HSSFSerializer / Null Pointer exception

Hi,

When i try to use the HSSFSerializer from java, using an XMLReader,
i get a NullPointer Exception when i use the parse function.

I use POI, Xerces and xalan from cocoon 2.0.3 distribution.
All is deployed on Websphere 3.5.6.

Any idea how to solve this problem ?

Thanks.
Seb

Here is my code :

/ Output XML to XLS
		//
		// Instantiate a TransformerFactory.
		javax.xml.transform.TransformerFactory tFactory = 
	
javax.xml.transform.TransformerFactory.newInstance();
		// Verify that the TransformerFactory implementation you are
using
		// supports SAX input and output (Xalan-Java does!).
		if
(tFactory.getFeature(javax.xml.transform.sax.SAXSource.FEATURE) &&
	
tFactory.getFeature(javax.xml.transform.sax.SAXResult.FEATURE))
		{
  		  //System.out.println("sauveXMLToXLS - Debut
transformation");
		  // Cast the TransformerFactory to SAXTransformerFactory.
		  javax.xml.transform.sax.SAXTransformerFactory saxTFactory
=
	
((javax.xml.transform.sax.SAXTransformerFactory) tFactory);
		  // Create a Templates ContentHandler to handle parsing of
the
		  // stylesheet.
		  javax.xml.transform.sax.TemplatesHandler templatesHandler
=
	
saxTFactory.newTemplatesHandler();
		
		  // Create an XMLReader and set its ContentHandler.
		  org.xml.sax.XMLReader reader =
	
org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
		  reader.setContentHandler(templatesHandler);
		
		  // Parse the stylesheet.
		  reader.parse(xslFilename);
		
		  // Get the Templates object (generated during the parsing
of the stylesheet)
		  // from the TemplatesHandler.
		  javax.xml.transform.Templates templates =
	
templatesHandler.getTemplates();
		  // Create a Transformer ContentHandler to handle parsing
of
		  // the XML Source.
		  javax.xml.transform.sax.TransformerHandler
transformerHandler
								 =
saxTFactory.newTransformerHandler(templates);
		  // Reset the XMLReader's ContentHandler to the
TransformerHandler.
		  reader.setContentHandler(transformerHandler);
		
		  // Set the ContentHandler to also function as a
LexicalHandler, which
		  // can process "lexical" events (such as comments and
CDATA).
	
reader.setProperty("http://xml.org/sax/properties/lexical-handler",
	
transformerHandler);
		
		  // Set up a Serializer to serialize the Result to a file.
		  HSSFSerializer ser = new HSSFSerializer();
		  ser.setOutputStream(xlsFile);

		  //org.apache.cocoon.serialization.XMLSerializer ser = new
org.apache.cocoon.serialization.XMLSerializer();
		  //ser.setOutputStream(System.out);
		
		  // The Serializer functions as a SAX ContentHandler.
		  javax.xml.transform.Result result =
			new
javax.xml.transform.sax.SAXResult((org.xml.sax.ContentHandler)ser);
		  transformerHandler.setResult(result);
		   	
		  // Parse the XML input document.
		  reader.parse(xmlFilename); // Here i get NullPointer
Exception


Sébastien PLISSON
DSIT XS / Infocentre
Tél. : 30.13.90


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>