NOTE:  I'm re-posting this to struts-dev, because it's a better forum for
this discussion 

What about using a combination of XML/XSLT to do the localization/device
detection part?  For instance, you have one main jsp page, responsible
for
outputting XML data.  Say the content would already be localized if you
were
to use some Struts i18n tags (currently known as the bean:message tag).
That way you have your content to display in XML, and then it's the
responsibility of a taglib to take that XML data and find the correct
stylesheet to apply to it, depending on some sort of automatic device
detection done on the part of Struts.  Of course, alot of this stuff
doesn't
exist, but I'd like to put in this addition for 1.1

For instance, this would be your JSP:

<!--
   The purpose of this tag would be to detect the type of device,
   and find the correct stylesheet for that device.  For instance,
   in some sort of mapping file you would map web browsers to the
   suffix "br", so this tag, if the device was a web browser,
   would look for "myStylesheet_br.xsl", or something similar
   to that mechanism
-->
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-xml.tld" prefix="xml" %>
<%@ taglib uri="/WEB-INF/struts-i18n.tld" prefix="i18n" %>
<xml:transform stylesheet="myStylesheet.xsl">
 <document>
  
  <title>
    <!--
        This is just a different prefix for the message tag...
        This message tag would probably tie into an i18n Service
        to retrieve localized content
    -->
    <i18n:message key="my.title" />
  </title>
  
  <body>
    <i18n:message key="my.content" />
  </body>
 </document>
</xml:transform>

Your basic stylesheet would then apply whatever style you want to that
XML
data:

[myStylesheet_br.xsl] (stylesheet to apply to browsers)
<xsl:stylesheet 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:template match="document">
   <html>
    <head>
     <title><xsl:value-of select="title" /></title>
    </head>
     
    <body>
      <xsl:value-of select="header" />

      <xsl:value-of select="body" />
    </body>
   </html>
  </xsl:template>    
</xsl:stylesheet>

That way, all your localization is done through one JSP, and all your
device
presentation is separated in different XSL templates.


-----Original Message-----
From: Vincent Massol
To: [EMAIL PROTECTED]
Sent: 1/30/01 2:39 AM
Subject: [Proposal] Portal Framework

Hi,
 
Here is an idea for extending Struts in future versions. However, I
think we must not mix it with Struts code. It should be seen as an
extension (what I like in Struts is it's simplicity and cluttering it
with tons of features in the core will make it harder to use/install).
 
This is a proposal for bringing the following additional services to
Struts. Note that this is more than a proposal, it comes from a real
project that I have built and that I am using in production :
- Possibility to choose a JSP page based on several criteria : Language,
Device type, User group, ... : thus support for building multi-language,
mutli-device applications
- Template mechanism
- API (through custom JSP tags) to build Navigation menus
- Integration with Portlets from WebLogic Personalization Server 3.1/3.2
- Custom JSP tags
 
Principle :
- extension of ActionServlet and ActionForward to support includes in
addition to forwards
- 3 Struts actions :
  - GetPageAction : responsible for retrieving a JSP page based on
several criteria (it's id, Language, Device, user group, ...). The
mapping between the physical JSP page and it's attributes is defined in
an xml file (let's call it pages.xml).
  - GetTemplateAction : responsible for building a template page. A
template is a JSP page with <pf:insertArea id="area1"/> tags whenever
there is a need to insert a an area (equivalent to the BEA Portlet). A
View is an instanciation of a template. A view is defined in an xml file
(let's call it templates.xml). A view has an id. For each view, the
following information is specified : the page id of the template JSP to
use for that view, the list of page id to use for each of the area
defined in the template.
  - GetPortletAction : integrates with WLPS by getting the Portlet(Area
in our terminology) definition from the WL Database using the Portlet
Manager API.
- An XML file (navigation.xml and navigation.properties) to define a
hierarchy of links (supports multi-language and multi-device). These
data are then accessed by using a provided custom JSP tag library (for
doing operations such as getParent, getRoot, getSiblings, getAncestors,
getChildren, .... and a getProperty for getting information on a link :
label, url, level, ...)
 
How it works :
- the user calls http://.../mywebapp/getTemplate.do?view=viewid
<http://.../mywebapp/getTemplate.do?view=viewid> 
- the GetTemplateAction action is called. It fins the entry
corresponding to id viewid in it's XML configuration file (see below for
a sample) and does a forward to the template file
(/getPage.do?forward=templateid)
- the template files executes and each of the <pf:insertArea
id="area1"/> tags do a jsp:include on their content, thus calling the
GetPageAction (/getPage.do?include=pageid or
/getPortlet.do?include=portlet name)
- the GetPortletAction calls a provided portlet.jsp file which is
responsible for rendering a portlet. this portlet.jsp makes calls to the
WL API to extract portlet definition values : content URL, ... The
content URL is specified in the WL admin as :
/getPage.do?include=pageid.
 
The XML file formats :
 
templates.xml
 
<?xml version="1.0"?>
 
<Views>
  <View id="technology/index" template="/getPage.do?forward=layout1">
    <Areas>
      <Area id="area1"
content="/getPage.do?include=technology/areas/someText" />
      <Area id="area2" content="/getPortlet.do?include=Technology_News"
/>
      <Area id="area3"
content="/getPage.do?include=technology/areas/userMgt" />
    </Areas>
  </View>
 
pages.xml
 
<?xml version="1.0"?>
 
<pages>
 
  <page id="layout1">
    <device type="WEB" default_uri="/web/templates/layout1.jsp"/>
    <device type="WAP" default_uri="/wap/templates/layout1.jsp"/>
  </page>
 
  <page id="technology/areas/someText">
    <device type="WEB" default_uri="/web/en/technology/someText.jsp">
      <language type="en" uri="/web/en/technology/someText.jsp"/>
      <language type="fr" uri="/web/fr/technology/someText.jsp"/>
    </device>
    <device type="WAP" default_uri="/wap/en/technology/someText.jsp">
      <language type="en" uri="/wap/en/technology/someText.jsp"/>
      <language type="fr" uri="/wap/fr/technology/someText.jsp"/>
    </device>
  </page>
 
  <!-- The "technews" area in the layout1 template. The definition for
this  -->
  <!-- page id is found in the "Technology_News" Portlet definition in
the   -->
  <!-- WLCS admin.
-->
  <page id="technology/areas/technews">
    <device type="WEB" default_uri="/web/en/technology/technews.jsp">
      <language type="en" uri="/web/en/technology/technews.jsp"/>
      <language type="fr" uri="/web/fr/technology/technews.jsp"/>
    </device>
    <device type="WAP" default_uri="/wap/en/technology/technews.jsp">
      <language type="en" uri="/wap/en/technology/technews.jsp"/>
      <language type="fr" uri="/wap/fr/technology/technews.jsp"/>
    </device>
  </page>
 
[...]
 
The question : What do you think of this design ? Would you like to see
this as an extension to Struts ? If you want more details, email me at
[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> 
 
thanks.
Vincent.

Reply via email to