Hi Thorsten,

I did do some work on a TextSerializer and a JsonSerializer. I got it all working now.

I looked at the EncodingXHTMLSerializer as a starting point. I should note that I basically know nothing about the internal organization of cocoon 3, and this makes it really hard for an outsider to contribute, as it is rather unclear where to start. Sorry to say but the documentation in the various AIPs is really terrible. The organization of the classes explained below may be incorrect.

I made a EncodingTextSerializer->TextSerializer->XMLSerializer (the arrow means 'extend'). Both TextSerializer and XMLSerializer are in the package org.apache.cocoon.components.serializers.util. (Note: The XMLSerializer was already available, it is not mine). The EncodingTextSerializer is part of org.apache.cocoon.optional.servlet.components.sax.serializers The TextSerializer is based upon one I found in the cocoon 2 base code, but had to be augmented to implement the ContentHandler and other interfaces.

Similarly, I made EncodingJsonSerializer->JsonSerializer->TextSerializer.

The JsonSerializer checks whether the JSON text is actually valid JSON (using org.json.JSONObject, see http://www.json.org/), and throws a SAXException if this is not the case.

The EncodingJsonSerializer is in org.apache.cocoon.optional.servlet.components.sax.serializers, while the JsonSerializer is in org.apache.cocoon.components.serializers.util.

Both encoding classes implement SAXPipelineComponent, Finisher, SAXConsumer, CachingPipelineComponent so that both encoding serializers can be used in a pipeline.

(NOTE: there appears to be 2-3 different XMLSerializers in use for cocoon 3? E.g. The FopSerializer derives from another XMLSerializer. It should be quite possible to use the same XMLSerializer for all serializers.)

Using an encoding serializer requires an alternative encoder for the TextSerializer, so I made a TextEncoder->XMLEncoder for use by the TextSerializer. Both TextEncoder and XMLEncoder are in org.apache.cocoon.components.serializers.encoding (the XMLEncoder already exists, it is not mine). The TextEncoder does not encode anything. It just returns the original character. There is no separate JsonEncoder.

Basically, this all works with the simple test files I made. It is easy to test this outside of cocoon, by creating an XMLReader and setting the ContentHandler as being any of the above serializers and parse some XML representing text or JSON (both must be enclosed by a single element).

I also incorporated this into cocoon 3 and made some simple pipelines to see if the two encoding serializers work as they should. For this, I created two beans defined as serializer:text and serializer:json. Basically everything seems to work just fine.

(I use a Java-based RESTClient at http://code.google.com/p/rest-client/ to see the response by cocoon 3. Very nice tool.)

I have attached the various classes to this email. Any comment by you and others are certainly welcome. If you think that attached code is actually useful for cocoon 3, I would be pleased if somebody would commit the code.

One final comment, IMHO the packages org.apache.cocoon.components.serializers.util and org.apache.cocoon.components.serializers.encoding should be transferred to cocoon 3 and probably should become part of cocoon-optional. The spring configuration in these packages are still based on Spring 2, while cocoon 3 uses Spring 3.

Thanks,
André



On 09/02/2011 02:31 PM, Andre Juffer wrote:
On 02/09/11 13:45, Thorsten Scherler wrote:
On Fri, 2011-09-02 at 09:58 +0300, Andre Juffer wrote:
On 09/02/2011 02:46 AM, Thorsten Scherler wrote:
Hi Andre,

sorry for top posting but I am responding from my mobile device.

Regarding 1) the org.apache.cocoon.serialization.TextSerializer
migration into c3 is ASAIK not yet done. However that should be
pretty straight forward to implement.
Yes, I was already thinking that I could do this.
Contributions are always welcome. ;)

If you or somebody else will do the migration please open an issue in
https://issues.apache.org/jira/browse/COCOON3 and attach the diff. We
will apply it ASAP.

OK, I do my best to get it done.



Actually I did lately work with the RESTController of c3 since the
JAX-RS integration was not needed for my use cases. If you choose
the c3 REST way you can use the TextResponse [1] to return your json
objects to the client. In the same package you will as well find a
BinaryResponse [2] which you can use to return binary data like
images from your rest services.
The TextResponse is a good alternative, and I will certainly look into
it. It is apparently not yet part of the current alpha Cocoon
3.0.0-alpha-3 that I downloaded from the cocoon website.
No you would need the HEAD or the latest beta snapshot.

I just commited an example [3] of an asyncron processing with REST
you may want to look into. It is based on jquery on the client side
but you will get the idea. If you look at [4] you will see the basic
background. The block provides a workig example when starting with
"mvn install jetty:run" and browse to localhost:8888/,
Great!
Actually I am still thinking on implementing comet
http://en.wikipedia.org/wiki/Comet_(programming) Actually long polling
should not to be too complicate to be implemented with our REST
framework (hopefully I will find some play time for implementing
that). ;)

However html5 will open some new approaches to the comet technique where
Server-sent events and websockets come into play, but I think there we
need to make some changes to our controller.

Somebody had worked with streaming message in cocoon yet?

Regarding the bean lookup, why not using autowiring in your
components (more when you use the REST part)? See [5].
Yes, that would do it.

Thanks for your valuable response.
you are welcome. I am glad if it helps you.

salu2

André

HTH

[1]
http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/TextResponse.java

[2]
http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest/src/main/java/org/apache/cocoon/rest/controller/response/BinaryResponse.java

[3]
http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-rest-optional/
[4] https://issues.apache.org/jira/browse/COCOON3-75
[5]
http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sample/src/main/java/org/apache/cocoon/sample/controller/DemoRESTController.java?view=markup


Thorsten Scherler<thorsten.at.apache.org>
codeBusters S.L. - web based systems<consulting, training and
solutions>
http://www.codebusters.es

Andre Juffer<ajuf...@cc.oulu.fi> wrote:

Hi All,

I have two questions:

(1)
I want to be to be able to return JSON to the client, typically a
browser. The client is responsible to properly present the response to
the user, typically with the Dojotoolkit. As I would like to move to
cocoon3, I was looking for a JsonSerializer or a simple
TextSerializer.

With cocoon 2.2, one can simply use the TextSerializer to return JSON,
by defining

<map:serializer name="json" mime-type="application/json;
charset=UTF-8"
src="org.apache.cocoon.serialization.TextSerializer">
<encoding>UTF-8</encoding>
</map:serializer>

Cocoon 3 apparently is restricted to only return XML/HTML [1], as
far as
I can see. I did not find in the API any mentioning of other types of
serializers, besides XMLSerializer and FopSerializer.

If so, this would be a limitation. Especially for designing RIAs [2]
(like Twitter), it would be very useful to be able to return JSON.

So, is there a particular way to return JSON or Text.


(2)
With flowscript in cocoon 2.2, it was very easy to instantiate a Java
bean defined in some appropriate Spring bean configuration file, like

var someFacade = cocoon.getComponent("someFacade");
someFacade.doSomething(...);

Is there a recommended way in Cocoon 3 to instantiate beans. One
could do

ApplicationContext context =
new ClassPathXmlApplicationContext( new String[]
{"beans-spring.cfg.xml");
SomeFacade facade = (SomeFacade)context.getBean("someFacade");
facade.doSomething(...);

within a JAX-RS resource [3].

So, is this way to do instantiate beans?

Thanks,
Andre


[1] http://cocoon.apache.org/3.0/features.html
[2] http://en.wikipedia.org/wiki/Rich_Internet_application
[3]
http://cocoon.apache.org/3.0/referenc/html/webapps.html#webapps.rest

--
Andre H. Juffer | Phone: +358-8-553 1161
Biocenter Oulu and | Fax: +358-8-553-1141
Department of Biochemistry | Email: andre.juf...@oulu.fi
University of Oulu, Finland | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat | WWW: www.strubiocat.oulu.fi
NordProt | WWW: www.nordprot.org
Triacle Biocomputing | WWW: www.triacle-bc.com

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






--
Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email: andre.juf...@oulu.fi
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat                   | WWW: www.strubiocat.oulu.fi
NordProt                     | WWW: www.nordprot.org
Triacle Biocomputing         | WWW: www.triacle-bc.com
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.cocoon.components.serializers.util;

import org.apache.cocoon.components.serializers.encoding.TextEncoder;
import org.apache.cocoon.components.serializers.encoding.XMLEncoder;

import org.xml.sax.SAXException;
import org.xml.sax.Attributes;

/**
 * Converts XML into plain text.
 * It omits all XML tags and writes only character events to the output.
 * Input document must have at least one element - root element - which 
 * should wrap all the text inside it.
 * 
 * @author Andr&#233; Juffer, Triacle Biocomputing
 */
public class TextSerializer extends XMLSerializer {
    
    private static final XMLEncoder XML_ENCODER = new TextEncoder();
    
    /*
     * Set to true after first XML element
     */
    private boolean hasRootElement;
    
    private final static String CHARSET = "UTF-8";
    
    public TextSerializer()
        throws Exception
    {
        super(XML_ENCODER);
        super.setEncoding(CHARSET);        
        this.hasRootElement = false;
    }    
    
    @Override
    public void head()
    {
        // Do nothing.
    }
    
    @Override
    public void startElement(String uri,
                             String loc,
                             String raw,
                             Attributes a)
            throws SAXException
    {
        this.hasRootElement = true;
    }
    
    /**
     * @throws SAXException if text is encountered before root element.
     */
    @Override
    public void characters(char c[], int start, int len)
            throws SAXException 
    {
	if ( !this.hasRootElement )
            throw new SAXException("Encountered text before root element");
	super.characters(c, start, len);
    }
    
    @Override
    public void recycle()
    {
        this.hasRootElement = false;
        super.recycle();
    }
    
    /**
     * @return text/plain; charset= followed by character set, by default UTF-8
     */
    @Override
    public String getMimeType()
    {
        return("text/plain; charset=" + this.charset.getName());
    }
    
    @Override
    public void startElementImpl(String uri,
                                 String local,
                                 String qual,
                                 String namespaces[][],
                                 String attributes[][])
        throws SAXException
    {
        // Do nothing.
    }
    
    @Override
    public void endElementImpl(String uri,
                               String local,
                               String qual)
        throws SAXException
    {
        // Do nothing.
    }
    
    
    @Override
    public void charactersImpl(char[] chars,
                               int start,
                               int len)
        throws SAXException
    {
        super.encode(chars, start, len);
    }
    
    
    @Override
    public void body(String uri,
                     String local,
                     String qual)
    {
        // Do nothing.
    }

    @Override
    public void skippedEntity(String name)
        throws SAXException
    {
        // Do nothing.
    }
    
    @Override
    public void processingInstruction(String target, String data)
        throws SAXException
    {        
        // Do nothing.
    }
    
    @Override
    public void ignorableWhitespace(char[] ch,
                                    int start,
                                    int length)
        throws SAXException    
    {        
        // Do nothing.
    }
    
    @Override
    public void comment(char[] ch,
                        int start,
                        int length)
        throws SAXException
    {        
        // Do nothing.
    }
    
    @Override
    public void startCDATA()
        throws SAXException
    {
        // Do nothing.
    }
    
    @Override
    public void endCDATA()
        throws SAXException
    {
        // Do nothing.
    }
    
    @Override
    public void startEntity(String name)
        throws SAXException
    {
        // Do nothing.
    }
    
    @Override
    public void endEntity(String name)
        throws SAXException
    {
        // Do nothing.
    }
    
    @Override
    public void startDTD(String name,
                         String publicId,
                         String systemId)
        throws SAXException
    {
        // Do nothing.
    }
    
    @Override
    public void endDTD()
        throws SAXException
    {
        // Do nothing.
    }
    
    @Override
    public String toString()
    {
        String newline = System.getProperty("line.separator");
        
        StringBuilder s = new StringBuilder(this.getClass().getName() + " : [" + newline);
        if ( this.charset != null )
            s.append("charset - ").append(this.charset.toString()).append(newline);
        if ( this.doctype != null )
            s.append("doctype - ").append(this.doctype.toString()).append(newline);
        s.append("hasRootElement - ").append(this.hasRootElement).append(newline);
        s.append("indentPerLevel - ").append(this.indentPerLevel).append(newline);
        if ( this.namespaces != null )
            s.append("namespaces - ").append(this.namespaces.toString()).append(newline);
        if ( this.request != null )
            s.append("request - ").append(this.request.toString()).append(newline);
        s.append("mime-type - ").append(this.getMimeType()).append(newline);
        s.append("]").append(newline);
        
        return s.toString();
    }
}
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.cocoon.components.serializers.util;

import org.json.JSONObject;
import org.json.JSONException;

import org.xml.sax.SAXException;
import org.xml.sax.Attributes;

/**
 * A text serializer for JSON. This serializer expects all JSON text to be enclosed by a 
 * single element. It also checks whether or not the received JSON text is valid.
 * @author Andr&#233; Juffer, Triacle Biocomputing
 * 
 * @see <a href="http://www.json.org/";>JSON.org</a>
 */
public class JsonSerializer extends TextSerializer {
    
    StringBuilder jsonString;
    boolean element;
    
    public JsonSerializer()
        throws Exception        
    {
        super();
        this.jsonString = new StringBuilder();
        this.element = false;
    }
    
    @Override
    public String getMimeType()
    {
        return "application/json; charset=" + this.charset.getName();
    }
    
    @Override
    public void characters(char[] chars,
                           int start,
                           int len)
        throws SAXException
    {
        if ( this.element )
        {
            String s = new String(chars, start, len);
            this.jsonString.append(s);
        }
        super.characters(chars, start, len);
    }
    
    @Override
    public void startElement(String uri,
                             String localName,
                             String qName,
                             Attributes atts)
    throws SAXException
    {
        this.element = true;
        super.startElement(uri, uri, uri, atts);
        
    }
        
    /**
     * Validates JSON.
     * @throws SAXException if JSON is invalid.
     */
    @Override
    public void endElement(String uri,
                           String localName,
                           String qName)
        throws SAXException
    {
        String s = this.jsonString.toString();
        try
        {
            JSONObject jsonObject = new JSONObject(s);
        }
        catch (JSONException exception)
        {
            throw new SAXException(s + ": Invalid JSON.", exception);
        }
        super.endElement(uri, localName, qName);
    }
    
    @Override
    public void recycle()
    {
        this.jsonString = new StringBuilder();
        this.element = false;
        super.recycle();
    }

    
    @Override
    public String toString()
    {
        String newline = System.getProperty("line.separator");
        
        StringBuilder s = new StringBuilder(this.getClass().getName() + " : [" + newline);
        if ( this.charset != null )
            s.append("charset - ").append(this.charset.toString());
        if ( this.doctype != null )
            s.append("").append(this.doctype.toString()).append(newline);
        s.append("mime-type - ").append(this.getMimeType()).append(newline);
        s.append("]").append(newline);
        
        return s.toString();
    }
}
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.cocoon.optional.servlet.components.sax.serializers;

import org.apache.cocoon.components.serializers.util.TextSerializer;

import org.apache.cocoon.optional.servlet.components.sax.serializers.util.ConfigurationUtils;
import org.apache.cocoon.sax.SAXPipelineComponent;
import org.apache.cocoon.pipeline.component.Finisher;
import org.apache.cocoon.sax.SAXConsumer;
import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
import org.apache.cocoon.pipeline.caching.CacheKey;
import org.apache.cocoon.pipeline.caching.ParameterCacheKey;
import org.apache.cocoon.pipeline.SetupException;
import org.apache.cocoon.servlet.util.HttpContextHelper;

import java.util.Map;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * <p>Usage in sitemap:
 * <pre>
 * &lt;map:serialize type='text' /&gt;
 * </pre>
 *
 * @author Andr&#233; Juffer, Triacle Biocomputing
 */
public class EncodingTextSerializer extends TextSerializer 
                                    implements SAXPipelineComponent, Finisher, SAXConsumer, CachingPipelineComponent {
    
    private String encoding;
    private int indent = 0;
    private String omitXmlDeclaration;
    private String docType;
    
    public EncodingTextSerializer()
        throws Exception
    {
        super();
    }
    
    @Override
    public void setup(java.util.Map<java.lang.String, java.lang.Object> parameters)
    {
        this.setup(HttpContextHelper.getRequest(parameters));
    }
    
    @Override
    public void setConfiguration(Map<String,? extends Object> configuration)
    {
        try {
            this.encoding = ConfigurationUtils.getEncoding(configuration);
            this.setEncoding(this.encoding);
        }
        catch (UnsupportedEncodingException exception)
        {
              throw new SetupException(exception);
 	}

        try {
            this.indent = ConfigurationUtils.getIndent(configuration);
            this.setIndentPerLevel(this.indent);
        } 
        catch (NumberFormatException exception)
        {
            throw new SetupException(exception);
        }

        this.omitXmlDeclaration = (String) configuration.get("omit-xml-declaration");
        this.docType = (String) configuration.get("doctype-default");
    }
    
    @Override
    public void finish()
    {
        // Do nothing.
    }
    
    @Override
    public String getContentType()
    {
        return this.getMimeType();
    }
    
    public CacheKey constructCacheKey()
    {
        ParameterCacheKey parameterCacheKey = new ParameterCacheKey();
        parameterCacheKey.addParameter("encoding", this.encoding);
        parameterCacheKey.addParameter("indent", this.indent);
        parameterCacheKey.addParameter("docType", this.docType);
        parameterCacheKey.addParameter("omitXmlDeclaration", this.omitXmlDeclaration);
        return parameterCacheKey;
    }
    
    @Override
    public void setOutputStream(OutputStream outputStream)
    {
        try
        {
            super.setOutputStream(outputStream);
 	} 
        catch (IOException exception)
        {
            throw new SetupException(exception);
 	} 	        
    }
    
    @Override
    public String toString()
    {
        String newline = System.getProperty("line.separator");
        
        StringBuilder s = new StringBuilder(this.getClass().getName() + newline);
        s.append("charset - ").append(this.charset).append(newline);
        s.append("docType - ").append(this.docType).append(newline);
        if ( this.doctype != null )
            s.append("doctype - ").append(this.doctype.toString()).append(newline);
        s.append("encoding - ").append(this.encoding).append(newline);
        s.append("indent - ").append(this.indent).append(newline);
        s.append("indentPerLevel - ").append(this.indentPerLevel).append(newline);
        if ( this.namespaces != null )
            s.append("namespaces - ").append(this.namespaces.toString()).append(newline);
        s.append("omitXmlDeclaration - ").append(this.omitXmlDeclaration).append(newline);
        if ( this.request != null )
            s.append("request - ").append(this.request.toString()).append(newline);
        s.append("mime-type - ").append(this.getMimeType()).append(newline);
        s.append("]").append(newline);
        
        return s.toString();
    }
}
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.cocoon.optional.servlet.components.sax.serializers;

import org.apache.cocoon.components.serializers.util.JsonSerializer;

import org.apache.cocoon.optional.servlet.components.sax.serializers.util.ConfigurationUtils;
import org.apache.cocoon.sax.SAXPipelineComponent;
import org.apache.cocoon.pipeline.component.Finisher;
import org.apache.cocoon.sax.SAXConsumer;
import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
import org.apache.cocoon.pipeline.caching.CacheKey;
import org.apache.cocoon.pipeline.caching.ParameterCacheKey;
import org.apache.cocoon.pipeline.SetupException;
import org.apache.cocoon.servlet.util.HttpContextHelper;

import java.util.Map;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
/**
 * <p>Usage in sitemap:
 * <pre>
 * &lt;map:serialize type='json' /&gt;
 * </pre>
 *

 * @author Andr&#233; Juffer, Triacle Biocomputing
 */
public class EncodingJsonSerializer extends JsonSerializer 
                                    implements SAXPipelineComponent, Finisher, SAXConsumer, CachingPipelineComponent
{
    
    private String encoding;
    private int indent = 0;
    private String omitXmlDeclaration;
    private String docType;
    
    public EncodingJsonSerializer()
        throws Exception
    {
        super();
    }
    
    @Override
    public void setup(java.util.Map<java.lang.String, java.lang.Object> parameters)
    {
        this.setup(HttpContextHelper.getRequest(parameters));
    }
    
    @Override
    public void setConfiguration(Map<String,? extends Object> configuration)
    {
        try {
            this.encoding = ConfigurationUtils.getEncoding(configuration);
            this.setEncoding(this.encoding);
        }
        catch (UnsupportedEncodingException exception)
        {
              throw new SetupException(exception);
 	}

        try {
            this.indent = ConfigurationUtils.getIndent(configuration);
            this.setIndentPerLevel(this.indent);
        } 
        catch (NumberFormatException exception)
        {
            throw new SetupException(exception);
        }

        this.omitXmlDeclaration = (String) configuration.get("omit-xml-declaration");
        this.docType = (String) configuration.get("doctype-default");
    }
    
    @Override
    public void finish()
    {
        // Do nothing.
    }
    
    @Override
    public String getContentType()
    {
        return this.getMimeType();
    }
    
    public CacheKey constructCacheKey()
    {
        ParameterCacheKey parameterCacheKey = new ParameterCacheKey();
        parameterCacheKey.addParameter("encoding", this.encoding);
        parameterCacheKey.addParameter("indent", this.indent);
        parameterCacheKey.addParameter("docType", this.docType);
        parameterCacheKey.addParameter("omitXmlDeclaration", this.omitXmlDeclaration);
        return parameterCacheKey;
    }
    
    @Override
    public void setOutputStream(OutputStream outputStream)
    {
        try
        {
            super.setOutputStream(outputStream);
 	} 
        catch (IOException exception)
        {
            throw new SetupException(exception);
 	} 	        
    }
    
    @Override
    public String toString()
    {
        String newline = System.getProperty("line.separator");
        
        StringBuilder s = new StringBuilder(this.getClass().getName() + newline);
        s.append("charset - ").append(this.charset).append(newline);
        s.append("docType - ").append(this.docType).append(newline);
        if ( this.doctype != null )
            s.append("doctype - ").append(this.doctype.toString()).append(newline);
        s.append("encoding - ").append(this.encoding).append(newline);
        s.append("indent - ").append(this.indent).append(newline);
        s.append("indentPerLevel - ").append(this.indentPerLevel).append(newline);
        if ( this.namespaces != null )
            s.append("namespaces - ").append(this.namespaces.toString()).append(newline);
        s.append("omitXmlDeclaration - ").append(this.omitXmlDeclaration).append(newline);
        if ( this.request != null )
            s.append("request - ").append(this.request.toString()).append(newline);
        s.append("mime-type - ").append(this.getMimeType()).append(newline);
        s.append("]").append(newline);
        
        return s.toString();
    }
}
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.cocoon.components.serializers.encoding;

/**
 *
 * @author Andr&#233; Juffer, Triacle Biocomputing
 */
public class TextEncoder extends XMLEncoder {
    
    private final static String ENCODING_NAME = "X-W3C-TEXT";
    
    public TextEncoder()
    {
        super(ENCODING_NAME);
    }
    
    protected TextEncoder(String encodingName)
    {
        super(encodingName);
    }
    
    @Override
    public boolean compile(char ch)
    {
        return true;
    }
    
    @Override
    public char[] encode(char ch)
    {
        char chs[] = { ch };
        return chs;
    }
    
}

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

Reply via email to