Home » Struts-1.3.10 » org.apache.struts » chain » [javadoc | source]

    1   /*
    2    * Copyright 2003,2004 The Apache Software Foundation.
    3    * 
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    * 
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    * 
   10    * Unless required by applicable law or agreed to in writing, software
   11    * distributed under the License is distributed on an "AS IS" BASIS,
   12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    * See the License for the specific language governing permissions and
   14    * limitations under the License.
   15    */
   16   
   17   package org.apache.struts.chain;
   18   
   19   
   20   import org.apache.commons.chain.Command;
   21   import org.apache.commons.chain.Context;
   22   import org.apache.commons.chain.web.WebContext;
   23   import org.apache.struts.config.ModuleConfig;
   24   
   25   
   26   /**
   27    * <p>Check to see if the content type is set, and if so, set it for this
   28    * response.</p>
   29    *
   30    * @author Don Brown
   31    * @version $Rev: 54933 $ $Date: 2004-10-16 18:04:52 +0100 (Sat, 16 Oct 2004) $
   32    */
   33   
   34   public abstract class AbstractSetContentType implements Command {
   35   
   36   
   37       // ------------------------------------------------------ Instance Variables
   38   
   39   
   40       private String moduleConfigKey = Constants.MODULE_CONFIG_KEY;
   41   
   42   
   43       // -------------------------------------------------------------- Properties
   44   
   45   
   46       /**
   47        * <p>Return the context attribute key under which the
   48        * <code>ModuleConfig</code> for the currently selected application
   49        * module is stored.</p>
   50        */
   51       public String getModuleConfigKey() {
   52   
   53           return (this.moduleConfigKey);
   54   
   55       }
   56   
   57   
   58       /**
   59        * <p>Set the context attribute key under which the
   60        * <code>ModuleConfig</code> for the currently selected application
   61        * module is stored.</p>
   62        *
   63        * @param moduleConfigKey The new context attribute key
   64        */
   65       public void setModuleConfigKey(String moduleConfigKey) {
   66   
   67           this.moduleConfigKey = moduleConfigKey;
   68   
   69       }
   70   
   71   
   72       // ---------------------------------------------------------- Public Methods
   73   
   74   
   75       /**
   76        * <p>Check to see if the content type is set, and if so, set it for this
   77        * response.</p>
   78        *
   79        * @param context The <code>Context</code> for the current request
   80        *
   81        * @return <code>false</code> so that processing continues
   82        */
   83       public boolean execute(Context context) throws Exception {
   84   
   85           // Retrieve the ModuleConfig instance
   86           WebContext wcontext = (WebContext) context;
   87           ModuleConfig moduleConfig = (ModuleConfig)
   88               wcontext.get(getModuleConfigKey());
   89               
   90           // If the content type is configured, set it for the response
   91           String contentType =
   92               moduleConfig.getControllerConfig().getContentType();
   93           if (contentType != null) {
   94               setContentType(context, contentType);
   95           }
   96           return (false);
   97   
   98       }
   99   
  100   
  101       // ------------------------------------------------------- Protected Methods
  102   
  103   
  104       /**
  105        * <p>Request no cache flags are set.</p>
  106        *
  107        * @param context The <code>Context</code> for this request
  108        * @param contentType The content type for the response
  109        */
  110       protected abstract void setContentType(Context context, String contentType);
  111   
  112   
  113   }

Home » Struts-1.3.10 » org.apache.struts » chain » [javadoc | source]