You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by mp...@apache.org on 2003/11/03 22:23:45 UTC

cvs commit: cocoon-2.1/src/java/org/apache/cocoon/serialization AbstractTextSerializer.java

mpo         2003/11/03 13:23:45

  Modified:    src/java/org/apache/cocoon/servlet CocoonServlet.java
               src/java/org/apache/cocoon Constants.java
               src/java/org/apache/cocoon/serialization
                        AbstractTextSerializer.java
  Log:
  Fixing the inconsistent default 'encoding' between html-serializer and request-parameter-decoding.
  The fix uses the Context/Contextualizable to communicate the used 'form-encoding' init-param down to the AbstractTextSerializer.
  
  Revision  Changes    Path
  1.20      +3 -2      cocoon-2.1/src/java/org/apache/cocoon/servlet/CocoonServlet.java
  
  Index: CocoonServlet.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/servlet/CocoonServlet.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- CocoonServlet.java	20 Oct 2003 13:27:17 -0000	1.19
  +++ CocoonServlet.java	3 Nov 2003 21:23:45 -0000	1.20
  @@ -498,7 +498,8 @@
   
           this.containerEncoding = getInitParameter("container-encoding", "ISO-8859-1");
           this.defaultFormEncoding = getInitParameter("form-encoding","ISO-8859-1");
  -
  +        this.appContext.put(Constants.CONTEXT_DEFAULT_ENCODING, this.defaultFormEncoding);
  +        
   		this.manageExceptions = getInitParameterAsBoolean("manage-exceptions", true);
   
   		this.enableInstrumentation = getInitParameterAsBoolean("enable-instrumentation", false);
  
  
  
  1.10      +5 -1      cocoon-2.1/src/java/org/apache/cocoon/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/Constants.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Constants.java	31 Oct 2003 11:12:56 -0000	1.9
  +++ Constants.java	3 Nov 2003 21:23:45 -0000	1.10
  @@ -301,6 +301,10 @@
        */
       public static final String CONTEXT_CONFIG_URL = "config-url";
   
  +    /** Application <code>Context</code> Key for the default encoding */
  +    public static final String CONTEXT_DEFAULT_ENCODING = "default-encoding";
  +
  +    
       /**
        * Should descriptors be reloaded?
        *
  
  
  
  1.6       +16 -2     cocoon-2.1/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java
  
  Index: AbstractTextSerializer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/serialization/AbstractTextSerializer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractTextSerializer.java	11 Jun 2003 00:11:15 -0000	1.5
  +++ AbstractTextSerializer.java	3 Nov 2003 21:23:45 -0000	1.6
  @@ -53,6 +53,9 @@
   import org.apache.avalon.framework.configuration.Configurable;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.context.Context;
  +import org.apache.avalon.framework.context.ContextException;
  +import org.apache.avalon.framework.context.Contextualizable;
   import org.apache.cocoon.Constants;
   import org.apache.cocoon.caching.CacheableProcessingComponent;
   import org.apache.cocoon.util.ClassUtils;
  @@ -90,7 +93,7 @@
    * @version CVS $Id$
    */
   public abstract class AbstractTextSerializer extends AbstractSerializer
  -        implements Configurable, CacheableProcessingComponent {
  +        implements Configurable, CacheableProcessingComponent, Contextualizable {
   
       /**
        * The trax <code>TransformerFactory</code> used by this serializer.
  @@ -123,6 +126,7 @@
        */
       private NamespaceAsAttributes namespacePipe;
   
  +
       /**
        * Interpose namespace pipe if needed.
        */
  @@ -192,6 +196,16 @@
           //  }
       }
   
  +    /**
  +     * Uses the context to retrieve a default encoding for the serializers. 
  +     */
  +    public void contextualize(Context context) throws ContextException {
  +        String defaultEncoding  = (String)context.get(Constants.CONTEXT_DEFAULT_ENCODING);
  +        if (defaultEncoding != null) {
  +            this.format.setProperty(OutputKeys.ENCODING, defaultEncoding);            
  +        }
  +    }    
  +    
       /**
        * Set the configurations for this serializer.
        */