[opencms-dev] 5 Beta 2: CmsJspTemplate::getContent method

Alexander Kandzior alex at opencms.org
Tue Dec 3 10:36:44 CET 2002


Anil,

I see what you are doing and you are right that the current way of doing
things limits one to using the default XMLTemplate class, which might
not be acceptable in all scenarios. Your solution provides a valid fix
for this. I will address the matter for the final 5.0 version and will
use your code as a base.


Best Regards,
Alex.

Alexander Kandzior
OpenCms Group / Alkacon Software

> -----Original Message-----
> From: owner-opencms-dev at www.opencms.org 
> [mailto:owner-opencms-dev at www.opencms.org] On Behalf Of Anil K Patel
> Sent: Tuesday, December 03, 2002 9:50 AM
> To: opencms-dev at www.opencms.org
> Subject: [opencms-dev] 5 Beta 2: CmsJspTemplate::getContent method
> 
> 
> Alex,
> Did you with some purpose left two parameters unused in 
> CmsJspTemplate::getContent method ?
>      * @param elementName <em>not used</em>
>      * @param parameters <em>not used</em>
> I have a scenario.
> Master template is XML Template, the default template that 
> comes with Beta2. Freme Template is JSP Template, the default 
> template that comes with Beta2. I create a resource of type 
> Page, that used Good Old OpenCMS XML templating. In order to 
> override the control code in getContent method of 
> CmsXmlTemplate, I define a class extending CmsXmlTemplate and 
> Edit control file of the page to point to my Derived class. 
> While running, The code in CmsXmlLouncher, does following thing
> *****************
> if (replaceDef == null){
> replaceDef = new CmsElementDefinition(replace.substring(0,index),
> "com.opencms.template.CmsXmlTemplate",
> replace.substring(index+1), null, new Hashtable());
> }
> *******************
> These lines have Hardcoded name of the Template control 
> class. Because of this My Change in Control code is 
> nullified. CmsElementDefinitionCollection build in parsing 
> Master template and page control file is lost when control is 
> transferrend to CmsJspTemplate::getContent  system.
> 
> The work around I did.
> 
> In CmsJspTemplate::getContent method I added follwing lines. 
> HttpServletRequest req = 
> (HttpServletRequest)cms.getRequestContext().getRequest().getOr
> iginalRequest(
> );
> req.setAttribute("CmsParameters", parameters);
> 
> And In CmsXmlLouncher I modified as following.
> 
> // check if printversion is requested
> String replace = req.getParameter(C_ELEMENT_REPLACE);
> boolean elementreplace = false;
> CmsElementDefinition replaceDef = null;
> if(replace != null){
> int index = replace.indexOf(":");
> if(index != -1){
>   elementreplace = true;
>   cmsUri = null;
>   HttpServletRequest oriReq = 
> (HttpServletRequest)req.getOriginalRequest ();
>   Hashtable cmsParameters = (Hashtable)oriReq.getAttribute
> ("CmsParameters");
>   CmsElementDefinitionCollection elDefs =  
> (CmsElementDefinitionCollection)
> cmsParameters.get("_ELDEFS_");
>   String partName = replace.substring(0,index);
>   replaceDef = elDefs.get(partName);
>   if (replaceDef == null){
>     replaceDef = new CmsElementDefinition(replace.substring(0,index),
>         "com.opencms.template.CmsXmlTemplate",
>     replace.substring(index+1), null, new Hashtable());
>   }
> }
> }
> 
> By doing above thing I can maintain modified control file, 
> and so page works correct.
> 
> REAL REQUEST IS.
> 
> IS This OK To do?
> Will you accept it in the main code?
> Or Do you have any other solution for this?
> I Hope you will spend some time to reply to this mail.
> 
> Anil Patel
> 





More information about the opencms-dev mailing list