[opencms-dev] Flex Session variable

Anil K Patel toanilpatel at hotmail.com
Tue Aug 13 07:26:18 CEST 2002


NachrichtAlex,
I know that current version of JSP in OpenCMS does not have all this, I am trying to do this thing, So that I can write all my templates for generating HTML code in JSP instead of CDATA section in Good old OpenCMS style.

Code of Master template I am using for JSP.

<?xml version="1.0"?>
<XMLTEMPLATE>
<ELEMENTDEF name="elementjsp">
<TEMPLATE>/content/elements/jspelement</TEMPLATE>
<CLASS>com.aditisoft.opencms.templates.JSPTemplate</CLASS>
<PARAMETER name="TEMPLATEFILE">
/flexdemo/index.html
</PARAMETER>
</ELEMENTDEF>
<TEMPLATE> 
<ELEMENT name="elementjsp"/> 
</TEMPLATE>
</XMLTEMPLATE>


code in element template pointed by following URL of ELEMENTDEF in above template
<TEMPLATE>/content/elements/jspelement</TEMPLATE> 
file is 

<?xml version="1.0"?>
<XMLTEMPLATE>
<VELOCITYELEMENT>
<PROCESS>jsp_code</PROCESS>
</VELOCITYELEMENT>
<TEMPLATE>
<PROCESS>VELOCITYELEMENT</PROCESS>
</TEMPLATE>
<ELEMENTDEF name="screenJsp">
<!-- The two lines below does not have any use -->
<TEMPLATE>/content/elements/JSPElementA</TEMPLATE>
<CLASS>com.aditisoft.opencms.templates.JSPTemplate</CLASS>
<PARAMETER name="TEMPLATEFILE">
/flexdemo/howto.html
</PARAMETER>
</ELEMENTDEF>
</XMLTEMPLATE>


MAIN JSP Pointed by following parameter of  "elementjsp" ElementDef in Master template 
<PARAMETER name="TEMPLATEFILE">
/flexdemo/index.html
</PARAMETER>

Simplefied code of JSP,  

This line "<% String screenJsp = (String)request.getAttribute("screenJsp"); %>  " can be 
<% String screenJsp = (String)session.getAttribute("screenJsp"); %> 
depending on where the value "screenJsp" is set, I will prefer to use request object.

------ MAIN JSP CODE pointed by--/flexdemo/index.html-----------------------------------------------------------------------------

<% String screenJsp = (String)request.getAttribute("screenJsp"); %>
<html>
<head>
</head>
<body bgcolor="#ffffff">
<table cellspacing="0" width="100%" cellpadding="0" border="0">
  <tr>
    <td valign="top" bgcolor="#ffffff">
      <jsp:include page="<%= screenJsp %>" flush="true" /> 
    </td>
  </tr>
</table>
</body>
</html>

---------------------------------------------JSP CODE END-----------------------------------

Now using the MASTER Template defined in first part of mail, We can create a PAGE in OpenCMS Old Style. When I click in this page, Request is processed and finally 
to process following line in MASTER TEMPLATE

<TEMPLATE> 
<ELEMENT name="elementjsp"/> 
</TEMPLATE>

request comes to JSPTemplate class given in my previous mail. This JSPTemplate class , reads the parameter declared in ELEMENTDEF of and get the URI of JSP that will act as Main TEMPLATE file for the page. This JSP can have multiple include statements, for filling different sections in the page, Like the Sample JSP. 
After JSPTemplate class knows the URI of main JSP, We also read the Template file of the Element, Cotents of this file can have one or more ELEMENTDEF. Information from these ELEMENTDEFs can be used for filling the include JSP URI places. For convention we can have ELEMENTDEF name same as the name of the variable used in Main JSP. The template file part of elementdef in this section is not used. we also provide a PARAMETER with name TEMPLATEFILE, this PARAMETER's value is the URI of JSP that will be used as include in the main JSP.
 
Code that does this work in JspTemplate class 
while (eD.hasMoreElements())

{

String eName = (String) eD.nextElement();

String s = templateDocument.getParameter(eName, PARAMETER_FILE_NAME);

HttpServletRequest req = (HttpServletRequest) cms.getRequestContext().getRequest().getOriginalRequest();


CmsFile tempFile = oCms.getCmsFile(cms, s);


int launcherId = tempFile.getLauncherType();

String startTemplateClass = file.getLauncherClassname();

I_CmsLauncher launcher = cms.getLauncherManager().getLauncher(launcherId);

CmsJspLoader j = (CmsJspLoader)launcher ;

String jspName = j.getJspUri(s, false);

req.setAttribute(eName, jspName);

}


If I am able to set  the names of names of include files in JSP dynamically, this will Give us power to Write Application wide Main template in JSP and define individual sections like HEAD section, NAV section and other sections, using JSP.  

This will mean Independence from CDATA. I was very excited initially but some silly mistake of mine has suppressed all that.

I appriciate your interest, I hope you will not lose your interest in this problem because of cummunication problem. In case you still have any more queries please write to me. 

Regards
Anil Patel






  ----- Original Message ----- 
  From: Alexander Kandzior 
  To: opencms-dev at www.opencms.org 
  Sent: Monday, August 12, 2002 8:34 PM
  Subject: RE: [opencms-dev] Flex Session variable


  Anil,

  I still do not fully understand what you are trying to do. Can you please also include the code of the XMLTemplates with the ElementDefs? 

  I do not see in what context your JSPTemplate class gets called. Since it extends CmsXmlTemplate is (obviously) seems to be called from a XMLTemplate. So you would have a XMLTemplate that includes a JSP element, a function that is not included in the current Flex alpha 1 release. Is it that what you are trying to do?

  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: Monday, August 12, 2002 9:56 AM
    To: opencms-dev at www.opencms.org
    Subject: Re: [opencms-dev] Flex Session variable


    Alex,

    What I am trying to do is bit of Hack, I am trying to do Templating with JSP that you have provided. 

    public class JSPTemplate extends CmsXmlTemplate

    {

    static final String JSP_TEMPLATE = "/flexdemo/default.jsp";

    static final String PARAMETER_FILE_NAME = "TEMPLATEFILE";



    public byte[] getContent(CmsObject cms,String templateFile,String elementName,Hashtable theParameters,String templateSelector) 

    throws CmsException

    {

    String jspTemplateFileName = (String) theParameters.get(elementName + "." + PARAMETER_FILE_NAME);

    if (jspTemplateFileName == null || "".equals(jspTemplateFileName))

    {

    jspTemplateFileName = JSP_TEMPLATE;

    }

    try

    {

    OpenCms oCms = OpenCms.getInstance();

    CmsFile file = oCms.getCmsFile(cms, jspTemplateFileName);

    if (file != null)

    {

    CmsXmlTemplateFile templateDocument =

    getOwnTemplateFile(cms, templateFile, elementName, theParameters, templateSelector);

    Enumeration eD = templateDocument.getAllSubElementDefinitions().elements();

    while (eD.hasMoreElements())

    {

    String eName = (String) eD.nextElement();

    String s = templateDocument.getParameter(eName, PARAMETER_FILE_NAME);

    HttpServletRequest req = (HttpServletRequest) cms.getRequestContext().getRequest().getOriginalRequest();


    CmsFile tempFile = oCms.getCmsFile(cms, s);


    int launcherId = tempFile.getLauncherType();

    String startTemplateClass = file.getLauncherClassname();

    I_CmsLauncher launcher = cms.getLauncherManager().getLauncher(launcherId);

    CmsJspLoader j = (CmsJspLoader)launcher ;

    String jspName = j.getJspUri(s, false);

    req.setAttribute(eName, jspName);

    HttpSession ssn = req.getSession();

    ssn.setAttribute(eName, jspName); //Also tryied session to see if this works

    }

    oCms.setResponse(cms, file);

    oCms.showResource(cms, file);

    }

    } catch (IOException e)

    {

    } catch (CmsException e)

    {

    }

    String s = "";

    return s.getBytes();

    }

    }

    In JSP I have following line 

    <% String screenJsp = (String)session.getAttribute("screenJsp"); 
    System.out.println(screenJsp);
    %>
    <jsp:include page="<%= screenJsp %>" flush="true" /> 


    What I am trying to do is.
    Define a Master JSP template with include tag like defined above. Create a OpenCMS Element template file. The element template will have ELEMENTDEF defined for each jsp include tag with a Paramenter having the value of Path to JSP file.
    In JSPTemplate class I will read name of Elemendef and Template file paratmeter and save in Attribute collection of request of Session object. I will read values of each include file  in the JSP master template and set the values, Like this I can get a JSP file prepared for rendering.
    This will provide template support to JSP.

    I don't know how good I explained this situation but If you have my Velocity template doc, that will help, because I am trying to do this in samilar way.

    Regards
    Anil Patel

      ----- Original Message ----- 
      From: Alexander Kandzior 
      To: opencms-dev at www.opencms.org 
      Sent: Monday, August 12, 2002 12:09 AM
      Subject: AW: [opencms-dev] Flex Session variable


      Hi Anil,

      I can, but I need more information. Some example code would help.

      Best Regards,
      Alex

      Alexander Kandzior
      OpenCms Group / Alkacon Software
        -----Ursprüngliche Nachricht-----
        Von: owner-opencms-dev at www.opencms.org [mailto:owner-opencms-dev at www.opencms.org] Im Auftrag von Anil K Patel
        Gesendet: Montag, 12. August 2002 07:40
        An: opencms-dev at www.opencms.org
        Betreff: [opencms-dev] Flex Session variable


        I am having problems in reading session variable in JSP. It the return value is null. Can somebody help me in understanding the issue
        Anil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20020812/b7d013ca/attachment.htm>


More information about the opencms-dev mailing list