You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Lionel Crine <cr...@4dconcept.fr> on 2003/03/10 14:34:56 UTC

Change default encoding in the transformer

I'd like to change the default encoding in my custom transformer, how can I 
do that ?


Lionel


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


Re: Change default encoding in the transformer

Posted by Lionel Crine <cr...@4dconcept.fr>.
You're right.

But my transformer take a part of SAX events sent by the generator and 
parse it :

Here some lines of my transformer :

.....
public void endElement(String uri, String loc, String raw)
     throws SAXException {
         if (extractLevel == 0) {
             super.endElement(uri,loc,raw);
         } else {
             this.currentBuilder.endElement(uri,loc,raw);
             if (this.extractURI.equals(uri) && 
this.extractElement.equals(loc)) {
                 extractLevel--;
                 getLogger().debug("extractLevel now " + extractLevel + ".");
                 if (extractLevel == 0) {
                     // finish building the DOM. remove existing prefix 
mappings.
                     Iterator itt = prefixMap.entrySet().iterator();
                     while (itt.hasNext()) {
                         Map.Entry entry = (Map.Entry) itt.next();
                         this.currentBuilder.endPrefixMapping((String)entry.getKey());
                     }
                     this.currentBuilder.endDocument();
                     /**
                      * request in textml
                      */
                     Document doc  = this.currentBuilder.getDocument(); -> 
create the DOM document
                     String id   = null;
                     String stringQuery = null;
                     ByteArrayInputStream my_string_as_stream = null;
                     InputSource input_source = null;

                     this.request = new StringBuffer();
                     try {
                         this.format.put(OutputKeys.ENCODING, "UTF-16");
                         id = 
org.apache.cocoon.xml.XMLUtils.serializeNode(doc, this.format); -> 
serialized the DOM to a String
                         this.request.append(id);

....

That doesn't work...the is still have the header ISO-8859-1 encoding.





At 14:45 10/03/2003 +0100, you wrote:
>Lionel Crine <cr...@4dconcept.fr> writes:
>
> > I'd like to change the default encoding in my custom transformer, how
> > can I do that ?
>
>How is a transformer related to encoding? It's a internal
>component and is working on java strings only (unless it is
>reading additional data  from a external source).
>Set the encoding in your serializer.
>
>Martin
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: cocoon-users-help@xml.apache.org


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


Re: Change default encoding in the transformer

Posted by Lionel Crine <cr...@4dconcept.fr>.
i found something which work.

...
  try {
         this.format2 = 
org.apache.cocoon.xml.XMLUtils.defaultSerializeToXMLFormat(true);
         id = org.apache.cocoon.xml.XMLUtils.serializeNode(doc, this.format2);
         this.request.append(id);
...

Hope that helps other people.

At 14:53 10/03/2003 +0100, you wrote:
>You're right.
>
>But my transformer take a part of SAX events sent by the generator and 
>parse it :
>
>Here some lines of my transformer :
>
>.....
>public void endElement(String uri, String loc, String raw)
>     throws SAXException {
>         if (extractLevel == 0) {
>             super.endElement(uri,loc,raw);
>         } else {
>             this.currentBuilder.endElement(uri,loc,raw);
>             if (this.extractURI.equals(uri) && 
> this.extractElement.equals(loc)) {
>                 extractLevel--;
>                 getLogger().debug("extractLevel now " + extractLevel + ".");
>                 if (extractLevel == 0) {
>                     // finish building the DOM. remove existing prefix 
> mappings.
>                     Iterator itt = prefixMap.entrySet().iterator();
>                     while (itt.hasNext()) {
>                         Map.Entry entry = (Map.Entry) itt.next();
> 
>this.currentBuilder.endPrefixMapping((String)entry.getKey());
>                     }
>                     this.currentBuilder.endDocument();
>                     /**
>                      * request in textml
>                      */
>                     Document doc  = this.currentBuilder.getDocument(); -> 
> create the DOM document
>                     String id   = null;
>                     String stringQuery = null;
>                     ByteArrayInputStream my_string_as_stream = null;
>                     InputSource input_source = null;
>
>                     this.request = new StringBuffer();
>                     try {
>                         this.format.put(OutputKeys.ENCODING, "UTF-16");
>                         id = 
> org.apache.cocoon.xml.XMLUtils.serializeNode(doc, this.format); -> 
> serialized the DOM to a String
>                         this.request.append(id);
>
>....
>
>That doesn't work...the is still have the header ISO-8859-1 encoding.
>
>
>
>
>
>At 14:45 10/03/2003 +0100, you wrote:
>>Lionel Crine <cr...@4dconcept.fr> writes:
>>
>> > I'd like to change the default encoding in my custom transformer, how
>> > can I do that ?
>>
>>How is a transformer related to encoding? It's a internal
>>component and is working on java strings only (unless it is
>>reading additional data  from a external source).
>>Set the encoding in your serializer.
>>
>>Martin
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
>>For additional commands, e-mail: cocoon-users-help@xml.apache.org


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


Re: Change default encoding in the transformer

Posted by Martin Holz <ho...@fiz-chemie.de>.
Lionel Crine <cr...@4dconcept.fr> writes:

> I'd like to change the default encoding in my custom transformer, how
> can I do that ?

How is a transformer related to encoding? It's a internal
component and is working on java strings only (unless it is
reading additional data  from a external source).
Set the encoding in your serializer.

Martin


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