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

Anil Patel toanilpatel at hotmail.com
Wed Nov 27 09:45:43 CET 2002


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().getOriginalRequest();
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




_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*. 
http://join.msn.com/?page=features/featuredemail




More information about the opencms-dev mailing list