472,794 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

FOP, XSLT: problems with SAX2DTM Parsing trying to convert to XSL-FO in Java

Hi there,

this is a Java-XML Question, so I am not sure whether this is the
right place, haven't found anything better ....

I try to convert a Java object to XML via SAX and let the FOP
Transformer convert that via XSLT to valid XSL-FO. So I define a
SAXReader which fires the SAX Events for the Java Object. This works
fine and the Transformation to PDF is ok.
However, I have one object which contains an XHTML String and the tags
inside that string shall be passed to the XSLT without changing them.
I have a XSL which would handle them properly and convert them to
valid XSL-FO, I just don't know how to get them thru SAX ...
My understanding is that I have to just make them fire the correct SAX
events as well. My Idea was to use a SAX Parser for that part, let it
handle the XHTML text and then continue with my other object's
attributes:

code sample (will not compile, ok ;-):

class MyObjectReader{
public void parse(MyObject obj) throws SAXException {

// this works fine
handler.startDocument();
handler.startElement("address");
handler.element("city", obj.getCity());
handler.element("street", obj.getStreet());
handler.endElement("address");
// now try to let a vanilla SAX parser do the xhtml
XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerce s.parsers.SAXParser");
reader.setContentHandler(handler);
handler.startElement("xhml");
reader.parse(new InputSource(new StringReader(obj.getXHTMLString())));
handler.endElement("xhml");
handler.endDocument();

}
}

The whole thing gets used inside the FOP Transformation:

class PDFHelper{
public void convertObj2PDF(){

Driver driver = new Driver();
//Setup Renderer (output format)
driver.setRenderer(Driver.RENDER_PDF);
TransformerFactory factory = TransformerFactory.newInstance();
// create transformer with the appropriate xsl
Transformer transformer = factory.newTransformer(new StreamSource(new
File(indir, xslFileName)));

// Setup input for XSLT transformation
// this returns a source which uses the above Reader
Source src = obj.getSource();
// Resulting SAX events (the generated FO) must be piped through to
FOP
Result res = new SAXResult(driver.getContentHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
}
}

now what happens is that I get a NullPointerException when, inside the
XSL Transformation, after the "embedded" Parser has finished, the
reader tries to end the "xhtml" element (line:
handler.endElement("xhml");).
The exception looks like this:

[12.04.05 17:07:21:531 CEST] 5dd35dd3 SystemOut O [12.04.05
17:07:21,406 CEST] util.pdf.PDFHelper - convertObj2PDF:
obj=vo.AusgangspostVO@754d754d : Error in Transformer: null
java.lang.NullPointerException
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.NullPointerException.<init>(NullPointerE xception.java:60)
at org.apache.xml.dtm.ref.sax2dtm.SAX2DTM.endElement( SAX2DTM.java:1886)
at util.pdf.EasyGenerationContentHandlerProxy.endElem ent(EasyGenerationContentHandlerProxy.java:208)
at util.pdf.EasyGenerationContentHandlerProxy.endElem ent(EasyGenerationContentHandlerProxy.java:123)
at util.pdf.AusgangspostXMLReader.generateFor(Ausgang spostXMLReader.java:159)
at util.pdf.AusgangspostXMLReader.parse(AusgangspostX MLReader.java:57)
at util.pdf.AusgangspostXMLReader.parse(AusgangspostX MLReader.java:33)
at org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DT MManagerDefault.java:493)
at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:658)
at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1129)
at org.apache.xalan.transformer.TransformerImpl.trans form(TransformerImpl.java:1107)
at util.pdf.PDFHelper.convertObj2PDF(PDFHelper.java:1 11)

I guess this might be bcause the SAX2DTM class used by the XSLT is not
compatible with my org.apache.xerces.parsers.SAXParser. Is this the
right direction? Can I fix the problem by using another parser?
Am I getting something terribly wrong?

I am using FOP 0.20.5 with xalan 2.4.1 and xerces 2.2.1
The app is running with jdk 1.4 and I cannot switch to newer versions
of xerces or xalan due to problems with the appserver.

Any hints are highly appreciated (even to a better suited newsgroup
....)

Regards

Jens
Jul 20 '05 #1
1 3026
Hi

did u find any solution for this problem

even m facing same situation

Please advice what to do

Thanks in advance
Apr 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Doug Farrell | last post by:
Hi all, I'm trying to use the 4Suite xml/xsl tools to transform some XML data into HTML. I'm using some examples from the O'Reilly book "Python and XML" and things are blowing up. Here is the...
2
by: Geathaa | last post by:
Hi everyone, I want to transform a xml document containing the description of a menu tree to HTML. The MenuTree XML contains the target URL for each tree node. Some URL's contain parameters...
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
3
by: Justine Hlista | last post by:
I'm using xalan-j_2_6_0 and trying to get an example from Michael Kay's book to work: <xsl:template match="/"> <xsl:variable name="rainbow"> <color>red</color> <color>blue</color>...
6
by: Mark | last post by:
Hello, I'm having problems with an XSLT template I'm developing. I have a date in an odd format which I'm trying to convert into something more readable. The original date is in the format...
5
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case...
12
by: gipsy boy | last post by:
Hello, I have sort of a big problem. I would really appreciate any help you could give me. I made a web service in C++ that throws XML to the client (browser). But, the XSLT transormation...
2
by: chris | last post by:
Hi there, I create an XML file from a dataset like this: System.IO.StreamWriter xmlSW = new System.IO.StreamWriter(FILENAME); dsUserData1.WriteXml(xmlSW, XmlWriteMode.WriteSchema);...
10
by: Bilal | last post by:
Hello, I'm trying to perform some string manipulations in my stylesheet and have gotten stuck on the issue below so hopefully can elicit some useful hints. Namely, the problem is that I need to...
4
by: th1421 | last post by:
Hi, I'm new to FireFox. I am currently trying to convert my website to be compatible with it. Doing so Iím trying to process some XML/XSLT pages (preferably without using JavaScript). When I...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.