Re: !newbie generating pdf from xml-source as stream

2004-09-09 Thread J.Pietschmann
Braumüller wrote:
and get the a fatal error by rendering: [Fatal Error] :1:1: Premature end of file.
I suspect you either passed an empty string to the StringReader
for the XML input source, or there is an encoding problem.
J.Pietschmann
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: !newbie generating pdf from xml-source as stream

2004-09-08 Thread Braumüller, Hans
Hi Pietschmann,

thanks for your patience, i know it is not easy alwasy answering always the 
same questions. But i have not been luckily with my research, fag, search 
engines, etc.

Does your browser open a PDF viewer? 
No!
Do you get error messages? Which messages? Yes, please see below.

Can you download the expected content using a command line tool?
Yes i can perform the operation with saving the xml-source as file and then 
transform over fop.bat by command line.


I have log all the steps in Tomcat 4.2.9, i am using java 1.4.

Here it goes:
2004-09-08 10:36:10 START of PDF
2004-09-08 10:36:10 actionId == 10
2004-09-08 10:36:10 try
2004-09-08 10:36:10 if (logPDF == null)
2004-09-08 10:36:10 sXSL: 
http://localhost:8080/ho/cfcreports/xsl/cfcreportpdf.xsl
2004-09-08 10:36:10 sReturnString: ?xml version=1.0 encoding=ISO-8859-1?
?xml-stylesheet 
href=http://localhost:8080/ho/cfcreports/xsl/cfcreportpdf.xsl; 
type=text/xsl?
root lang=en
user
nameAdministrator/name
nr1/nr
/user
interaction
api
uricfcreports/uri
name/name
/api
maskStatus/maskStatus
maskStatusInteger0/maskStatusInteger
selectdocumenttrue/selectdocument
/interactionhead
titleAccount Posting/title
  /head
bodytabelle name=R_KONTOBUCHUNG title=account posting rows=180
... etc
/row
/tabelle/body/root
2004-09-08 10:36:10 xslSource: [EMAIL PROTECTED]
2004-09-08 10:36:10 xmlSource: [EMAIL PROTECTED]
2004-09-08 10:36:10 catch (Exception e)org.apache.fop.apps.FOPException: 
javax.xml.transform.TransformerConfigurationException: 
javax.xml.transform.TransformerException: java.net.MalformedURLException
2004-09-08 10:36:10 END of PDF
2004-09-08 10:36:10 END ofdoGetPost(HttpServletRequest request, 
HttpServletResponse response)

the sReturnString comes from a java instance as string,
the stylesheet is for testing hardcoded:
String sHost = hoToolSet.getHttpProtocol( c_request ) + :// + 
c_request.getHeader(host);
String sXSL = sHost + /ho/cfcreports/xsl/cfcreportpdf.xsl;
Because of an exception the call
XSLTInputHandler input = new XSLTInputHandler(xslSource, xmlSource); is not 
performed.

The CODE:

snip
log(START of PDF);
log(actionId == 10);

// Source xslSource =  new SAXSource(new InputSource(new 
URL(sXSL).openStream()));
// Source xmlSource = new SAXSource(new InputSource(new 
StringReader(sReturnString)));
// ByteArrayInputStream xmlin = new 
ByteArrayInputStream(xml.getBytes()); 
//ByteArrayInputStream xslin = new 
ByteArrayInputStream(xsl.getBytes()); 
 try {
log(try);
if (logPDF == null)
{
log(if (logPDF == null));
logPDF = new 
ConsoleLogger(ConsoleLogger.LEVEL_INFO);
MessageHandler.setScreenLogger(logPDF);
}
String sHost = hoToolSet.getHttpProtocol( 
c_request ) + :// + c_request.getHeader(host);
String sXSL = sHost + 
/ho/cfcreports/xsl/cfcreportpdf.xsl;
log(sXSL:  +  sXSL);
log(sReturnString:  +  sReturnString);
InputSource xslSource = new 
InputSource(new URL(sXSL).openStream());
InputSource xmlSource = new InputSource (new 
StringReader(sReturnString));
log(xslSource:  +  xslSource);
log(xmlSource:  +  xmlSource);
XSLTInputHandler input = new 
XSLTInputHandler(xslSource, xmlSource); 
//StreamSource xmlSource = new StreamSource(new 
StringReader(sReturnString));
log(actionId == 10 go to renderXML );
renderXML(input, c_response);
}
catch (Exception e)
{
log(catch (Exception e) + e);
}
log(END of PDF);
/snip

Thanks,

Hans Braumüller

Braumüller wrote:
 i am trying to generate pdf on fly from dynamic xml-source
...
 What is wrong ?

I have no idea. Would you care to describe what you expect,
and what you got instead?
Does your browser open a PDF viewer? Do you get error
messages? Which messages? Can you download the expected
content using a command line tool?

BTW
  InputSource xmlSource =
new InputSource(new StringReader(sReturnString));
In 99% of all cases I've seen this kind of code
indicates either a major design flaw or that you are
using the wrong tool to solve your problem.

J.Pietschmann



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL 

RE: !newbie generating pdf from xml-source as stream

2004-09-08 Thread Braumüller, Hans
Hello,

after testing again i noticed, that i do the call to
XSLTInputHandler with the parameters wrong, now 
i do the same code with
XSLTInputHandler input = new XSLTInputHandler(xmlSource, xslSource); 
and get the a fatal error by rendering: [Fatal Error] :1:1: Premature end of 
file.

2004-09-08 11:46:00 xslSource: [EMAIL PROTECTED]
2004-09-08 11:46:00 xmlSource: [EMAIL PROTECTED]
2004-09-08 11:46:00 actionId == 10 go to renderXML
2004-09-08 11:46:00 renderXML
2004-09-08 11:46:02 catch (Exception e)javax.servlet.ServletException: 
javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: 
Premature end of file.
2004-09-08 11:46:02 END of PDF
2004-09-08 11:46:02 END ofdoGetPost(HttpServletRequest request, 
HttpServletResponse response)
2004-09-08 11:46:03 doGetPost() Request: test.pdf:;
HEADER: accept:*/*;accept-encoding:gzip, deflate;user-agent:Mozilla/4.0 
(compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 
1.1.4322);host:localhost:8080;connection:Keep-Alive;cookie:JSESSIONID=D6B77EAFB03D2225EDE631A163F88B92;

the code:

snip
public void renderXML(XSLTInputHandler input,
  HttpServletResponse response) throws ServletException 
{
try {
log(renderXML);
ByteArrayOutputStream out = new ByteArrayOutputStream();

response.setContentType(application/pdf);
//response.setHeader(   Content-disposition,inline; 
filename=test.pdf );

Driver driver = new Driver();
driver.setLogger(logPDF);
driver.setRenderer(Driver.RENDER_PDF);
driver.setOutputStream(out);
driver.render(input.getParser(), input.getInputSource());

byte[] content = out.toByteArray();
response.setContentLength(content.length);
response.getOutputStream().write(content);
response.getOutputStream().flush();
} catch (Exception ex) {
throw new ServletException(ex);
}
}
/snip





Does your browser open a PDF viewer? 
No!
Do you get error messages? Which messages? Yes, please see below.

Can you download the expected content using a command line tool?
Yes i can perform the operation with saving the xml-source as file and then 
transform over fop.bat by command line.


I have log all the steps in Tomcat 4.2.9, i am using java 1.4.

Here it goes:
2004-09-08 10:36:10 START of PDF
2004-09-08 10:36:10 actionId == 10
2004-09-08 10:36:10 try
2004-09-08 10:36:10 if (logPDF == null)
2004-09-08 10:36:10 sXSL: 
http://localhost:8080/ho/cfcreports/xsl/cfcreportpdf.xsl
2004-09-08 10:36:10 sReturnString: ?xml version=1.0 encoding=ISO-8859-1?
?xml-stylesheet 
href=http://localhost:8080/ho/cfcreports/xsl/cfcreportpdf.xsl; 
type=text/xsl?
root lang=en
user
nameAdministrator/name
nr1/nr
/user
interaction
api
uricfcreports/uri
name/name
/api
maskStatus/maskStatus
maskStatusInteger0/maskStatusInteger
selectdocumenttrue/selectdocument
/interactionhead
titleAccount Posting/title
  /head
bodytabelle name=R_KONTOBUCHUNG title=account posting rows=180
... etc
/row
/tabelle/body/root
2004-09-08 10:36:10 xslSource: [EMAIL PROTECTED]
2004-09-08 10:36:10 xmlSource: [EMAIL PROTECTED]
2004-09-08 10:36:10 catch (Exception e)org.apache.fop.apps.FOPException: 
javax.xml.transform.TransformerConfigurationException: 
javax.xml.transform.TransformerException: java.net.MalformedURLException
2004-09-08 10:36:10 END of PDF
2004-09-08 10:36:10 END ofdoGetPost(HttpServletRequest request, 
HttpServletResponse response)

the sReturnString comes from a java instance as string,
the stylesheet is for testing hardcoded:
String sHost = hoToolSet.getHttpProtocol( c_request ) + :// + 
c_request.getHeader(host);
String sXSL = sHost + /ho/cfcreports/xsl/cfcreportpdf.xsl;
Because of an exception the call
XSLTInputHandler input = new XSLTInputHandler(xslSource, xmlSource); is not 
performed.

The CODE:

snip
log(START of PDF);
log(actionId == 10);

// Source xslSource =  new SAXSource(new InputSource(new 
URL(sXSL).openStream()));
// Source xmlSource = new SAXSource(new InputSource(new 
StringReader(sReturnString)));
// ByteArrayInputStream xmlin = new 
ByteArrayInputStream(xml.getBytes()); 
//ByteArrayInputStream xslin = new 
ByteArrayInputStream(xsl.getBytes()); 
 try {
log(try);
if (logPDF == null)
{
log(if (logPDF == null));
logPDF = new 
ConsoleLogger(ConsoleLogger.LEVEL_INFO);
MessageHandler.setScreenLogger(logPDF);
}
String sHost = hoToolSet.getHttpProtocol( 
c_request ) + :// + c_request.getHeader(host);
String sXSL = sHost +