shuber      2005/04/26 16:52:18 CEST

  Modified files:
    core/src/java/org/jahia/engines EngineRenderer.java 
    core/src/java/org/jahia/engines/core Core_Engine.java 
    core/src/java/org/jahia/params ParamBean.java 
    core/src/webapp/WEB-INF web.xml 
  Log:
  New mechanism for template parameter to be able to specify the mime type to 
use by using an extension. For example :
  /template/simple.xml will actually dispatch to
  simple.jsp
  but the content type will be resolved according to what is set in the MIME 
type of the web.xml file.
  
  Revision  Changes    Path
  1.4       +7 -2      jahia/core/src/java/org/jahia/engines/EngineRenderer.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/engines/EngineRenderer.java.diff?r1=1.3&r2=1.4&f=h
  1.6       +29 -1     
jahia/core/src/java/org/jahia/engines/core/Core_Engine.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/engines/core/Core_Engine.java.diff?r1=1.5&r2=1.6&f=h
  1.18      +8 -0      jahia/core/src/java/org/jahia/params/ParamBean.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/params/ParamBean.java.diff?r1=1.17&r2=1.18&f=h
  1.10      +8 -0      jahia/core/src/webapp/WEB-INF/web.xml
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/webapp/WEB-INF/web.xml.diff?r1=1.9&r2=1.10&f=h
  
  
  
  Index: EngineRenderer.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/engines/EngineRenderer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- EngineRenderer.java       6 Aug 2004 19:36:59 -0000       1.3
  +++ EngineRenderer.java       26 Apr 2005 14:52:17 -0000      1.4
  @@ -103,11 +103,16 @@
               if (engineHashMap.get (JahiaEngine.ENGINE_URL_PARAM) == null)
                   engineHashMap.put (JahiaEngine.ENGINE_URL_PARAM, 
JahiaEngine.EMPTY_STRING);
   
  +            String mimeType = "text/html";
  +            // did we override the mime type ?
  +            if (jParams.getResponseMimeType() != null) {
  +                mimeType = jParams.getResponseMimeType();
  +            }
               // set response attributes...
               if (jParams.settings ().isUtf8Encoding ()) {
  -                jParams.getResponse ().setContentType 
("text/html;charset=UTF-8");
  +                jParams.getResponse ().setContentType (mimeType + 
";charset=UTF-8");
               } else {
  -                jParams.getResponse ().setContentType ("text/html");
  +                jParams.getResponse ().setContentType (mimeType);
               }
   
               // add "no cache" to request header only if methode is not a get
  
  
  
  Index: Core_Engine.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/engines/core/Core_Engine.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Core_Engine.java  26 Apr 2005 12:04:20 -0000      1.5
  +++ Core_Engine.java  26 Apr 2005 14:52:18 -0000      1.6
  @@ -195,9 +195,37 @@
               if (pathToAlternateTemplate.indexOf("..") == -1) {
                   logger.debug ("template source path :" + jspFullFileName);
   
  +                // the code below is quite powerful, it allows us to set an
  +                // extension on the name of the template that will specify
  +                // the mime type we want to use. For example simple.xml will
  +                // use the mime type (text/xml) (if mapped properly in the
  +                // web.xml configuration file or in the server config), and
  +                // then the actual dispatching will be done to simple.jsp
  +                String justFileName = pathToAlternateTemplate;
  +                String justPath = "";
  +                int altLastSlashPos = 
pathToAlternateTemplate.lastIndexOf("/");
  +                if (altLastSlashPos != -1) {
  +                    justFileName = 
pathToAlternateTemplate.substring(altLastSlashPos + 1);
  +                    justPath = pathToAlternateTemplate.substring(0, 
altLastSlashPos + 1);
  +                }
  +                String mimeType = 
jData.params().getContext().getMimeType(justFileName);
  +                if (mimeType != null) {
  +                    // we found a mime type, let's use it.
  +                    logger.debug("Using mime type " + mimeType);
  +                    jData.params().setResponseMimeType(mimeType);
  +                }
  +                int extensionPos = justFileName.lastIndexOf(".");
  +                if (extensionPos != -1) {
  +                    String extension = justFileName.substring(extensionPos);
  +                    if (!extension.equalsIgnoreCase(".jsp")) {
  +                        justFileName = justFileName.substring(0, 
extensionPos) + ".jsp";
  +                    }
  +                }
  +                pathToAlternateTemplate = justPath + justFileName;
  +
                   int lastSlashPos = jspFullFileName.lastIndexOf ("/");
                   if (lastSlashPos != -1) {
  -                    jspFullFileName = jspFullFileName.substring(0, 
lastSlashPos + 1) + jData.params ().getParameter (ParamBean.TEMPLATE_PARAMETER);
  +                    jspFullFileName = jspFullFileName.substring(0, 
lastSlashPos + 1) + pathToAlternateTemplate;
                   }
                   logger.debug ("resolvedJSPFullFileName :" + jspFullFileName);
   
  
  
  
  Index: ParamBean.java
  ===================================================================
  RCS file: 
/home/cvs/repository/jahia/core/src/java/org/jahia/params/ParamBean.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- ParamBean.java    22 Mar 2005 15:49:54 -0000      1.17
  +++ ParamBean.java    26 Apr 2005 14:52:18 -0000      1.18
  @@ -303,6 +303,7 @@
       private int diffVersionID = 0;
   
       private ArrayList pageURLKeys = new ArrayList();
  +    private String responseMimeType = "text/html";
   
       static {
           /** @todo we might want to put this in a configuration file so the
  @@ -2922,6 +2923,10 @@
           return cacheExpirationDate;
       }
   
  +    public String getResponseMimeType () {
  +        return responseMimeType;
  +    }
  +
       /**
        * Sets the current page's cache expiration date.
        * @param cacheExpirationDate a date which is the expiration date at 
which
  @@ -3522,4 +3527,7 @@
           this.theUser = theUser;
       }
   
  +    public void setResponseMimeType (String responseMimeType) {
  +        this.responseMimeType = responseMimeType;
  +    }
   } // end ParamBean
  
  
  
  Index: web.xml
  ===================================================================
  RCS file: /home/cvs/repository/jahia/core/src/webapp/WEB-INF/web.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- web.xml   28 Feb 2005 16:10:22 -0000      1.9
  +++ web.xml   26 Apr 2005 14:52:18 -0000      1.10
  @@ -931,6 +931,10 @@
       <mime-type>application/x-troff</mime-type>
     </mime-mapping>
     <mime-mapping>
  +    <extension>rss</extension>
  +    <mime-type>text/xml</mime-type>
  +  </mime-mapping>
  +  <mime-mapping>
       <extension>rtf</extension>
       <mime-type>application/rtf</mime-type>
     </mime-mapping>
  @@ -1047,6 +1051,10 @@
       <mime-type>application/vnd.ms-excel</mime-type>
     </mime-mapping>
     <mime-mapping>
  +    <extension>xml</extension>
  +    <mime-type>text/xml</mime-type>
  +  </mime-mapping>
  +  <mime-mapping>
       <extension>xpm</extension>
       <mime-type>image/x-xpixmap</mime-type>
     </mime-mapping>
  

Reply via email to