Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: roblem with XSLT Trasformations - was problem generating PDF using FOP



May be my problem is in the data source (Openbase database) ??
Regards
Amedeo

Begin forwarded message:

From: Amedeo Mantica <email@hidden>
Date: 11 ottobre 2006 21:50:31 GMT+02:00
To: Travis Cripps <email@hidden>
Cc: WebObjects Dev Apple <email@hidden>
Subject: Re: roblem with XSLT Trasformations - was problem generating PDF using FOP

Hello,

Yes, I need to go into pdf (I'm "trying" to use apache fop 0.92 at the moment)

"trying" because of accent proiblems

my generatePDF method works well, but because to wrong XML source encoding PDF is also bad

Also tried FOP command line, … that return bad results.

see:


(all file steps inside...)

Regards
Amedeo

On 11/ott/06, at 19:52, Travis Cripps wrote:

Amadeo,

Hi.  What version of pico are you using?  OS X uses GNU nano (1.2.4 on OS X 10.4) in place of pico.  The FAQ for nano says:

"In version 1.3.12 or later, Unicode should be usable...."

Your file might actually be in UTF-8 format.  There's nothing in an XML file to tell an editor that the file is UTF-8 encoded except the encoding statement.


TextPad (like Notepad) I think looks at the first bytes in the file and if it sees something like FF FE decides that the encoding is unicode. But your file being XML, it relies on the encoding="UTF-8" part to set the encoding to UTF-8 and doesn't use the bytes, which TextPad doesn't pick up. So in other words, I think you're fine.

The main idea in this story is that there is no "standard" mechanism to decide if a set of bytes are text in UTF-8 encoding or in ASCII encoding or a JPEG image (that's why XML needed an "encoding" attribute by the way). So as long as you have rules and mechanisms to ensure that the same encoding is used throughout your system, you are ok .


What are you trying to acheive in the end?  Are you trying to serialize an EO to XML and use XSL to convert to pdf?  I might be able to help with that.

Travis



On Oct 11, 2006, at 9:52 AM, Amedeo Mantica wrote:

Hello all who are helping me in this trouble.

Thank you for all support

We are in right direction but there is still encoding problems, I'm trying everything.

Now I'm trying STEP STEP bug finding, starting with outputting fo a file the serialized EORecord

public pdfScheda xmlpdf() throws Exception
{
pdfScheda nextPage = (pdfScheda)pageWithName("pdfScheda");
String myXml = XMLSerializer.serializeProduct(theProduct);
System.out.println("JUST SERIALIZED: "+myXml);


FileOutputStream out = new FileOutputStream("/tmp/mainXml.xml");
out.write(myXml.getBytes("UTF-8"));
out.flush();
out.close();


return nextPage;
}

file is written to hd, but is NOT utf-8
If you open it with BBedit it renders ok because of UTF-8 xml declaration, but is bad opeding with pico

public static String serializeProduct(product aProduct) throws UnsupportedEncodingException, Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
// Create a stream to the output file.

BufferedOutputStream byte_output_stream = new BufferedOutputStream(out);
NSXMLOutputStream stream = new NSXMLOutputStream(byte_output_stream);

// Set the format of the output document (XML).
NSXMLOutputFormat format = new NSXMLOutputFormat(true);

format.setEncoding("UTF-8");
// turn indentation on
stream.setOutputFormat(format); // app


// Serialize data to object output stream.
stream.writeObject(aProduct);

stream.flush();
stream.close();
byte_output_stream.close();

} catch (IOException e) {
e.printStackTrace();
}
return out.toString("UTF-8");


XMLSerializer.serialize methid here:

public static String serializeProduct(product aProduct) throws UnsupportedEncodingException, Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
// Create a stream to the output file.

BufferedOutputStream byte_output_stream = new BufferedOutputStream(out);
NSXMLOutputStream stream = new NSXMLOutputStream(byte_output_stream);

// Set the format of the output document (XML).
NSXMLOutputFormat format = new NSXMLOutputFormat(true);

format.setEncoding("UTF-8");
// turn indentation on
stream.setOutputFormat(format); // app


// Serialize data to object output stream.
stream.writeObject(aProduct);

stream.flush();
stream.close();
byte_output_stream.close();

} catch (IOException e) {
e.printStackTrace();
}


FileOutputStream justSerializedXml = new FileOutputStream("/tmp/justSerializedXml.xml");
justSerializedXml.write(out.toByteArray());
justSerializedXml.close();


return out.toString("UTF-8");
}

also file /tmp/justSerializedXml.xml is lookong bad.

Regards
Amedeo



On 11/ott/06, at 00:42, Travis Cripps wrote:

Amadeo,

Hi.  I created a sample project from your files, and was initially getting the same result, with the characters in the file resulting from your transform being messed up.

I changed all instances of String -> byte[] and byte[] -> String conversions to specify the character encoding and the resulting xml was perfect.

The basic changes were to read the xml and xsl into Strings like this:

String sourceXML = null;
byte[] bytes = WOApplication.application().resourceManager().bytesForResourceNamed("sourceXML.xml", null, null);
try {
sourceXML = new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException uee) {
uee.printStackTrace();
}

and to get the result of the transformation like this:

try {
result = ((ByteArrayOutputStream)((StreamResult) output).getOutputStream()).toString("UTF-8");
} catch (UnsupportedEncodingException uee) {
uee.printStackTrace();
}

I've posted the simple project to http://apparentmotion.com/downloadables/XSLTest.zip. (47 KB)

Have a great day.

Travis

On Oct 10, 2006, at 3:36 AM, Amedeo Mantica wrote:

Thank you for reply and collaboration

here the link for dile downloads


the sourceXML is the XML data grabbed from database (using WebObjects's NSXMLOutputStream)
the file is perfect.  (some /u000d for CR/LF, but I think is ok)

the SimpleTrasformation.xls is an Apple provided XLST file for removing unuseful data and simplyfing the XML file.

the destinationXML file is the result of sourceXML trasformed using SimpleTrasformation.xml
myTrasformer.java is the routine that do the XSLT trasformation.

see the accented letters in destinationXML file...



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
Begin forwarded message:

From: Amedeo Mantica <email@hidden>
Date: 10 ottobre 2006 12:36:19 GMT+02:00
To: Travis Cripps <email@hidden>
Cc: WebObjects Dev Apple <email@hidden>
Subject: Re: roblem with XSLT Trasformations - was problem generating PDF using FOP

Thank you for reply and collaboration

here the link for dile downloads


the sourceXML is the XML data grabbed from database (using WebObjects's NSXMLOutputStream)
the file is perfect.  (some /u000d for CR/LF, but I think is ok)

the SimpleTrasformation.xls is an Apple provided XLST file for removing unuseful data and simplyfing the XML file.

the destinationXML file is the result of sourceXML trasformed using SimpleTrasformation.xml
myTrasformer.java is the routine that do the XSLT trasformation.

see the accented letters in destinationXML file...

Regards
Amedeo

On 09/ott/06, at 21:23, Travis Cripps wrote:

Hi, Amadeo.

Would you mind sending me your xslt file, your xml file, and a sample of the data output by your xml serializer (object->xml tag mapping) file?

Travis

On Oct 9, 2006, at 6:08 AM, Amadeo Mantica wrote:

Date: Mon, 9 Oct 2006 11:58:54 +0200
From: Amedeo Mantica <email@hidden>
Subject: Need Help - problem with XSLT Trasformations - was problem
generating PDF using FOP
To: WebObjects Dev Apple <email@hidden>
Message-ID: <email@hidden">email@hidden>
Content-Type: text/plain; charset="us-ascii"

Hi all,

I have my data storage on a OpenBase SQL server and data is stored un
UTF-8 format.

The web applications works fine ( I overrided the appendToResponse,
takeValuesFromRequest and dispatchRequest methods in Application.java
for setting the encoding to UTF-8).

You can see my work at:


These are seven websites, but is an unique WebObject applicatiion
that select correct products, graphics, text and css based on
selected site and language.

Now I need to export PDF tacnical sheet of products.

I followed the great Sasha an Chuck's book "Practical WebObjects" for
serializing my data in XML format, then trasforming to PDF using
Apache FOP.

Exporting data from EO to XML works fine. First XML become UTF-8
encoded.

When I do  the "SimpleTrasformation" with XSLT provided by Apple
(where the Output Format is set UTF-8), I got bad data encoding, and
all accented letters are bad.

Then trasforming again using apache FOP produce really bad results.

I tried to do the "SimpleTraformation" using a software (TestXSLT,
app that get in input the original XML and the XLST, and outputs the
trasformed XML. It works fine, no encoding trouble.

So I think the trouble is inside the Java trasformation engine, but I
don't know how to fix.

Can you help me?
Thanks
Regards
Amedeo

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
Begin forwarded message:

From: Amedeo Mantica <email@hidden>
Date: 10 ottobre 2006 16:59:38 GMT+02:00
To: Steve Quirk <email@hidden>
Cc: WebObjects Dev Apple <email@hidden>, Travis Cripps <email@hidden>
Subject: Re: roblem with XSLT Trasformations - was problem generating PDF using FOP

Thaks for collaboration Steve
I tried, but got same identical result
regards
Amedeo

On 10/ott/06, at 16:36, Steve Quirk wrote:



I think your problem may be caused bby converting your XML and XSL into Strings instead of leaving them as bytes.

Instead of these lines:
   String xsl = new String(resource_manager.bytesForResourceNamed(xslfile, null, null));
   ...
   .... new StreamSource(new StringReader(xsl)...

Could you try something like:
   InputStream aStream = resource_manager.inputStreamForResourceNamed(xslfile, null, null)
   StreamSource xsl = new StreamSource(aStream);

And instead of passing your XML in as a String ("String xml"), use the XML Node class.  Then you can set up the transform on the DOM directly:

   transformer.transform(new DOMSource(xml), output);

This should remove your character problems.

Steve

On Tue, 10 Oct 2006, Amedeo Mantica wrote:

Thank you for reply and collaboration

here the link for dile downloads


the sourceXML is the XML data grabbed from database (using WebObjects's NSXMLOutputStream)
the file is perfect.  (some /u000d for CR/LF, but I think is ok)

the SimpleTrasformation.xls is an Apple provided XLST file for removing unuseful data and simplyfing the XML file.

the destinationXML file is the result of sourceXML trasformed using SimpleTrasformation.xml
myTrasformer.java is the routine that do the XSLT trasformation.

see the accented letters in destinationXML file...

Regards
Amedeo

On 09/ott/06, at 21:23, Travis Cripps wrote:

Hi, Amadeo.
Would you mind sending me your xslt file, your xml file, and a sample of the data output by your xml serializer (object->xml tag mapping) file?
Travis
On Oct 9, 2006, at 6:08 AM, Amadeo Mantica wrote:
Date: Mon, 9 Oct 2006 11:58:54 +0200
From: Amedeo Mantica <email@hidden>
Subject: Need Help - problem with XSLT Trasformations - was problem
generating PDF using FOP
To: WebObjects Dev Apple <weboemail@hidden>
Message-ID: <email@hidden">email@hidden>
Content-Type: text/plain; charset="us-ascii"
Hi all,
I have my data storage on a OpenBase SQL server and data is stored un
UTF-8 format.
The web applications works fine ( I overrided the appendToResponse,
takeValuesFromRequest and dispatchRequest methods in Application.java
for setting the encoding to UTF-8).
You can see my work at:
These are seven websites, but is an unique WebObject applicatiion
that select correct products, graphics, text and css based on
selected site and language.
Now I need to export PDF tacnical sheet of products.
I followed the great Sasha an Chuck's book "Practical WebObjects" for
serializing my data in XML format, then trasforming to PDF using
Apache FOP.
Exporting data from EO to XML works fine. First XML become UTF-8
encoded.
When I do  the "SimpleTrasformation" with XSLT provided by Apple
(where the Output Format is set UTF-8), I got bad data encoding, and
all accented letters are bad.
Then trasforming again using apache FOP produce really bad results.
I tried to do the "SimpleTraformation" using a software (TestXSLT,
app that get in input the original XML and the XLST, and outputs the
trasformed XML. It works fine, no encoding trouble.
So I think the trouble is inside the Java trasformation engine, but I
don't know how to fix.
Can you help me?
Thanks
Regards
Amedeo

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
Begin forwarded message:

From: Jean-François Veillette <email@hidden>
Date: 10 ottobre 2006 17:16:18 GMT+02:00
To: Amedeo Mantica <email@hidden>
Cc: WebObjects Dev Apple <email@hidden>
Subject: Re: roblem with XSLT Trasformations - was problem generating PDF using FOP

Make sure that everytime you convert from binary to string you specify the encoding.
Same thing when you convert from string to binary, explicitely set the encoding.

If you do not specify the encoding, java will use the platform default (MacRoman on OSX) to do the conversion.

I haven't looked yet at the source you provided, but it has to be a problem like that.  It does sounds like you have a string, get the binary, get back to string all that without specifying the encoding.

- jfv

Le 06-10-10 à 10:59, Amedeo Mantica a écrit :

Thaks for collaboration Steve
I tried, but got same identical result
regards
Amedeo

On 10/ott/06, at 16:36, Steve Quirk wrote:



I think your problem may be caused bby converting your XML and XSL into Strings instead of leaving them as bytes.

Instead of these lines:
   String xsl = new String(resource_manager.bytesForResourceNamed(xslfile, null, null));
   ...
   .... new StreamSource(new StringReader(xsl)...

Could you try something like:
   InputStream aStream = resource_manager.inputStreamForResourceNamed(xslfile, null, null)
   StreamSource xsl = new StreamSource(aStream);

And instead of passing your XML in as a String ("String xml"), use the XML Node class.  Then you can set up the transform on the DOM directly:

   transformer.transform(new DOMSource(xml), output);

This should remove your character problems.

Steve

On Tue, 10 Oct 2006, Amedeo Mantica wrote:

Thank you for reply and collaboration

here the link for dile downloads


the sourceXML is the XML data grabbed from database (using WebObjects's NSXMLOutputStream)
the file is perfect.  (some /u000d for CR/LF, but I think is ok)

the SimpleTrasformation.xls is an Apple provided XLST file for removing unuseful data and simplyfing the XML file.

the destinationXML file is the result of sourceXML trasformed using SimpleTrasformation.xml
myTrasformer.java is the routine that do the XSLT trasformation.

see the accented letters in destinationXML file...

Regards
Amedeo

On 09/ott/06, at 21:23, Travis Cripps wrote:

Hi, Amadeo.
Would you mind sending me your xslt file, your xml file, and a sample of the data output by your xml serializer (object->xml tag mapping) file?
Travis
On Oct 9, 2006, at 6:08 AM, Amadeo Mantica wrote:
Date: Mon, 9 Oct 2006 11:58:54 +0200
From: Amedeo Mantica <email@hidden>
Subject: Need Help - problem with XSLT Trasformations - was problem
generating PDF using FOP
To: WebObjects Dev Apple <email@hidden>
Message-ID: <email@hidden">email@hidden>
Content-Type: text/plain; charset="us-ascii"
Hi all,
I have my data storage on a OpenBase SQL server and data is stored un
UTF-8 format.
The web applications works fine ( I overrided the appendToResponse,
takeValuesFromRequest and dispatchRequest methods in Application.java
for setting the encoding to UTF-8).
You can see my work at:
These are seven websites, but is an unique WebObject applicatiion
that select correct products, graphics, text and css based on
selected site and language.
Now I need to export PDF tacnical sheet of products.
I followed the great Sasha an Chuck's book "Practical WebObjects" for
serializing my data in XML format, then trasforming to PDF using
Apache FOP.
Exporting data from EO to XML works fine. First XML become UTF-8
encoded.
When I do  the "SimpleTrasformation" with XSLT provided by Apple
(where the Output Format is set UTF-8), I got bad data encoding, and
all accented letters are bad.
Then trasforming again using apache FOP produce really bad results.
I tried to do the "SimpleTraformation" using a software (TestXSLT,
app that get in input the original XML and the XLST, and outputs the
trasformed XML. It works fine, no encoding trouble.
So I think the trouble is inside the Java trasformation engine, but I
don't know how to fix.
Can you help me?
Thanks
Regards
Amedeo

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
Begin forwarded message:

From: Travis Cripps <email@hidden>
Date: 11 ottobre 2006 0:42:06 GMT+02:00
To: Amedeo Mantica <email@hidden>
Cc: WebObjects Dev Apple <email@hidden>
Subject: Re: roblem with XSLT Trasformations - was problem generating PDF using FOP

Amadeo,

Hi.  I created a sample project from your files, and was initially getting the same result, with the characters in the file resulting from your transform being messed up.

I changed all instances of String -> byte[] and byte[] -> String conversions to specify the character encoding and the resulting xml was perfect.

The basic changes were to read the xml and xsl into Strings like this:

String sourceXML = null;
byte[] bytes = WOApplication.application().resourceManager().bytesForResourceNamed("sourceXML.xml", null, null);
try {
sourceXML = new String(bytes, "UTF-8");
} catch (UnsupportedEncodingException uee) {
uee.printStackTrace();
}

and to get the result of the transformation like this:

try {
result = ((ByteArrayOutputStream)((StreamResult) output).getOutputStream()).toString("UTF-8");
} catch (UnsupportedEncodingException uee) {
uee.printStackTrace();
}

I've posted the simple project to http://apparentmotion.com/downloadables/XSLTest.zip. (47 KB)

Have a great day.

Travis

On Oct 10, 2006, at 3:36 AM, Amedeo Mantica wrote:

Thank you for reply and collaboration

here the link for dile downloads


the sourceXML is the XML data grabbed from database (using WebObjects's NSXMLOutputStream)
the file is perfect.  (some /u000d for CR/LF, but I think is ok)

the SimpleTrasformation.xls is an Apple provided XLST file for removing unuseful data and simplyfing the XML file.

the destinationXML file is the result of sourceXML trasformed using SimpleTrasformation.xml
myTrasformer.java is the routine that do the XSLT trasformation.

see the accented letters in destinationXML file...

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.