[opencms-dev] problems with own class after publishing

Reichmann, Clemens reichmann at itiv.uni-karlsruhe.de
Mon Sep 2 17:58:30 CEST 2002


Hi,

thanks Petr for the hint. 
I disabled the cache by 
   public CmsCacheDirectives getCacheDirectives(CmsObject cms,
                                                 String templateFile, String
elementName,
                                                 Hashtable parameters,
String templateSelector) {
       return new CmsCacheDirectives(false);
}
and now it works fine. Thanks a lot. But I didn't understand why I can't use
the caching mechanism inherited by 
com.opencms.template.CmsXmlTemplate cause there it works fine without my
extensions.

Regards
Clemens


> -----Ursprüngliche Nachricht-----
> Von: Petr Hollay [mailto:ph at ethikom.de]
> Gesendet: Montag, 2. September 2002 18:13
> An: opencms-dev at www.opencms.org
> Betreff: RE: [opencms-dev] problems with own class after publishing
> 
> 
> Hi,
> 
> you have to configure element caching by overriding 
> getCacheDirectives()
> method for dynamic pages. Are you doing this?
> 
> Regards
> Petr
> 
> 
> -----Original Message-----
> From: owner-opencms-dev at www.opencms.org
> [mailto:owner-opencms-dev at www.opencms.org]On Behalf Of Reichmann,
> Clemens
> Sent: Monday, September 02, 2002 4:07 PM
> To: 'opencms-dev at www.opencms.org'
> Subject: [opencms-dev] problems with own class after publishing
> 
> 
> Hi,
> 
> we have extended the 'com.opencms.template.CmsXmlTemplate' 
> class. The result
> is an own class called 'ITIVCmsXmlTemplate' (which contains 
> among others a
> possiblity to request the last modification date) and a redirect for
> download resources.
> In the preview of OpenCMS all works fine, but after 
> publishing the output
> (i.ex. of the file date) isn't correct. It seems that the 
> system is not
> useing our class.
> 
> Can anybody help?
> 
> Regards
> Clemens
> 
> 
> ------------------------------------------
> here is the mastertemplate:
> 
> <?xml version="1.0"?>
> <XMLTEMPLATE>
> <ELEMENTDEF name="contenttemplate">
> 	<CLASS>ITIVCmsXmlTemplate</CLASS>
> 	<TEMPLATE>/content/contenttemplates/contenttemplate</TEMPLATE>
> </ELEMENTDEF>
> <ELEMENTDEF name="frametemplate">
> 	<CLASS>ITIVCmsXmlTemplate</CLASS>
> 	<TEMPLATE>/content/frametemplates/frametemplate</TEMPLATE>
> </ELEMENTDEF>
> <TEMPLATE><ELEMENT name="frametemplate"/></TEMPLATE>
> </XMLTEMPLATE>
> 
> --------------------------------------------
> here is the control code of a page which uses the own class:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <PAGE>
>     <class>com.opencms.template.CmsXmlTemplate</class>
> 
> <masterTemplate>/content/templates/mastertemplate_news_level1<
> /masterTemplat
> e>
>     <ELEMENTDEF name="body">
>         <CLASS>ITIVCmsXmlTemplate</CLASS>
>         <TEMPLATE>/content/bodys/de/index.html</TEMPLATE>
>     </ELEMENTDEF>
>     <ELEMENTDEF name="news">
>         <CLASS>com.opencms.modules.homepage.news.NewsTemplate</CLASS>
>         <TEMPLATE>/content/elements/news</TEMPLATE>
>         <PARAMETER name="channelid">1</PARAMETER>
>     </ELEMENTDEF>
> </PAGE>
> 
> 
> --------------------------------------------
> here is the java code:
> 
> /*
>  * ITIVCmsXmlTemplate.java
>  *
>  * Created on 24. August 2002, 15:38
>  */
> 
> import com.opencms.core.CmsException;
> import com.opencms.file.CmsFile;
> import com.opencms.file.CmsObject;
> import com.opencms.template.CmsXmlTemplate;
> import com.opencms.template.CmsXmlTemplateFile;
> 
> import java.text.DateFormat;
> import java.text.Format;
> import java.util.Date;
> import java.util.Hashtable;
> import java.util.Locale;
> 
> /**
>  * EXTENDS THE DEFULT TEMPLATE
>  * @author Clemens Reichmann
>  * @version 1.0
>  */
> public class ITIVCmsXmlTemplate extends CmsXmlTemplate {
>   private final String _STRINGCHANGE = "<a
> href=\"/opencms/opencms/download/";
>   private final String _REPLACE = "<a href=\"/download/";
> 
>   /**
>    * Extends the default template rendering:
>    * 1.) if there is a link to download so opencms/opencms is deleted.
>    * 2.) time and date is set u in the properties
>    * @param cms siehe OpenCMS Doku
>    * @param templateFile siehe OpenCMS Doku
>    * @param elementName siehe OpenCMS Doku
>    * @param parameters siehe OpenCMS Doku
>    * @param templateSelector siehe OpenCMS Doku
>    * @throws CmsException siehe OpenCMS Doku
>    * @return siehe OpenCMS Doku
>    */
>   public byte[] getContent(CmsObject cms, String templateFile, String
> elementName, Hashtable parameters, String templateSelector) throws
> CmsException {
>     CmsXmlTemplateFile templateDocument = 
> setLastModifiedProperties(cms,
> templateFile, elementName, parameters, templateSelector);
>     byte[] array = startProcessing(cms, templateDocument, elementName,
> parameters, templateFile);
>     String tmp = replaceOpenCmsOpenCms4DownloadArea(array);
>     return tmp.getBytes();
>   }
> 
>   /**
>    * replace /download/opencms/opencms/ with /download/
>    * @param theArray
>    * @return
>    */
>   private String replaceOpenCmsOpenCms4DownloadArea(byte[] theArray) {
>     String tmp = new String(theArray);
>     while (tmp.indexOf(_STRINGCHANGE) != -1) {
>       int index = tmp.indexOf(_STRINGCHANGE);
>       tmp = tmp.substring(0, index) + _REPLACE + tmp.substring(index +
> _STRINGCHANGE.length());
>     }
>     return tmp;
>   }
> 
>   /**
>    * Set last modified properties
>    * @param cms
>    * @param templateFile
>    * @param elementName
>    * @param parameters
>    * @param templateSelector
>    * @return
>    * @throws CmsException
>    */
>   private CmsXmlTemplateFile 
> setLastModifiedProperties(CmsObject cms, String
> templateFile, String elementName, Hashtable parameters, String
> templateSelector) throws CmsException {
>     // get time + date format
>     Locale german = new Locale("DE", "de");
>     Format fmt_de = 
> DateFormat.getTimeInstance(DateFormat.SHORT, german);
>     Format fmd_de = 
> DateFormat.getDateInstance(DateFormat.LONG, german);
>     Locale eng = new Locale("EN", "en");
>     Format fmt_en = DateFormat.getTimeInstance(DateFormat.SHORT, eng);
>     Format fmd_en = DateFormat.getDateInstance(DateFormat.LONG, eng);
> 
>     // read last modified date from file
>     String tUri = cms.getRequestContext().getUri();
>     CmsFile tFile = cms.readFile(tUri);
>     Date lastmod = new Date(tFile.getDateLastModified());
> 
>     // write formatted output to data elements
>     String tTime_de = fmt_de.format(lastmod);
>     String tDate_de = fmd_de.format(lastmod);
>     String tTime_en = fmt_en.format(lastmod);
>     String tDate_en = fmd_en.format(lastmod);
> 
>     CmsXmlTemplateFile templateDocument = getOwnTemplateFile(cms,
> templateFile, elementName, parameters, templateSelector);
>     templateDocument.setData("zeit", tTime_de);
>     templateDocument.setData("datum", tDate_de);
>     templateDocument.setData("time", tTime_en);
>     templateDocument.setData("date", tDate_en);
>     return templateDocument;
>   }
> 
>   /**
>    * TEST
>    * @param args
>    */
>   public static void main(String[] args) {
>     String STRINGCHANGE = "<a href=\"/opencms/opencms/download/";
>     String REPLACE = "<a href=\"/download/";
>     String original = ("hällo#und&<>" + STRINGCHANGE + " bal ö blub" +
> STRINGCHANGE + "hi <a href=\"/opencms/opencms/sel");
>     byte[] b = original.getBytes();
>     String tmp = new String(b);
>     System.out.println("[ITIVCmsXmlTemplate.main] 0=" + original);
>     System.out.println("[ITIVCmsXmlTemplate.main] s=" + tmp);
>     while (tmp.indexOf(STRINGCHANGE) != -1) {
>       int index = tmp.indexOf(STRINGCHANGE);
>       tmp = tmp.substring(0, index) + REPLACE + tmp.substring(index +
> STRINGCHANGE.length());
>     }
>     System.out.println("[ITIVCmsXmlTemplate.main] r=" + tmp);
>   }
> } // end of class
> 
> Dipl.-Ing. Clemens Reichmann
> Universität Karlsruhe (ITIV Gebäude 30.10)
> Engesserstr. 5
> 76131 Karlsruhe
> Tel:  +49 721 608-7659
> Fax: +49 721 60 74 38
> mailto:reichmann at itiv.uni-karlsruhe.de
> http://www.itiv.uni-karlsruhe.de
> 
> 



More information about the opencms-dev mailing list