Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Date
August 19, 2008
Target Audience
Editor
Application Manager
Developer
SU MMARY
In combination with the license component ‘User Access & Profiles’ this module makes it
possible to show a logged-in website visitor a personalized presentation based on his profile.
The visitor can modify his own profile and so adjust his main interests. The website manager
defines which fields are available to the web user. Based on these fields personalization rules
can be defined. Personalization rules are centrally maintained and applied o n several levels in
the content, for instance on page level and in forms.
This document describes how personalization works and where it can be applied. This
document is written for developers. To really understand personalization, knowledge of XML
and XSL is an absolute necessity.
To become familiar with XSL and before working with XSL, please read the tutorials at
http://www.zvon.org. Start with the XPATH tutorial and then study the XSL examples.
PREREQUISITES
Content Management
RELATED TOPICS
Connectivity Management
Advanced Forms
VERSION CONTROL
6 Preconditions ....................................................................................... 31
Maintaining data in the profile and recording the visitor‟s behavior allows offering information
important to that visitor. Once someone's areas of interest are known, the website can be
modified in such a way that the visitor sees content of interest to him. It also gives a better
overview for the visitor, if there is only information available that fits his interests.
Making page parts conditional. For instance, showing an image or a paragraph only if the
visitor is logged in.
Showing information from the session on a „random‟ place on the website (e.g.,
Welcome <christianname>).
Generating forums and community functions based on the same account used for
personalization.
GX WebManager offers accessible personalization. This way, the visitors do not have to select
certain profiles again and again, and are able to set preferences regarding themes and
information items.
The personalization function does not mean that visitors have to log in, but if a visitor is not
logged in, he may not access as much as if he were logged in. On an airline website, for instance,
anybody can request flight information but the user has to be logged in to actually book a flig ht.
2 PERSONALIZIN G CONTE N T
The content should have an indication for which type of visitor it is intended.
The type of information the visitor would like to see should be saved.
How content should be personalized is illustrated in this chapter with an example. Perform the
following steps:
Select the [XSLT Expressions] tab from the Format > Personalize menu to define
conditions that allow certain visitors to see or not see specific elements. Create a new expression
and complete the fields:
Field Description
Name Name of the expression.
Tag name Only in the Type=‟xsl‟ and Type=‟select‟ cases can a tag name be entered.
For other types, a name of the form wm-user-personalization-number is
generated.
‘Condition’:
/root/system/user/sex = '1'
‘Choose’:
count(/root/system/user/username) > 0
and (/root/system/user/username) = 'administrator'
Meaning: First, verify that the „username‟ tag exists and then that the
user is the administrator.
‘Select’:
/root/system/user/firstname
‘XSL’:
<xsl:value-of select="/root/system/user/firstname"/>
<xsl:text > </xsl:text>
<xsl:value-of select="/root/system/user/lastname"/>
Test XSLT Tests whether the XSLT code is correct or not. This is only a syntax check.
Field Description
Name Name of the model.
Show links „Yes‟ results in a protected page on the menu, but there is no effect if
a visitor with insufficient rights clicks the page. The visitor is
redirected to the login page and will be able to access the desired
page if he logs in.
Assigned expressions The expressions of this model.
Test XSLT Tests whether the XSLT code is correct or not. This is only a syntax
check.
The grey personalization icon of the content elements allows indicating which expression or
which personalization model has an element associated with it. Once an expression or a
personalization model is assigned to an element, the icon turns red:
2 .4 Pe rso na liz in g pa ge s
It is also possible to personalize an entire page. On the relevant page, open the File >
Properties > Read access menu:
Check „Overrule inherited settings for this page‟, click [Apply], and select an expression or
personalization model under „Select a personalization‟. If desired, pass on the current settings to
the parallel or underlying pages:
To test if the personalization works correctly at the website environment, on the edit
environment go to the relevant page and open the Preview page using the File menu:
This screen lists the expressions and personalization models used on this page. Check the
personalization(s) to be tested and click [OK]. GX WebManager now shows what happens if a
visitor with the specific properties accesses this page.
Note: It is also possible to view a page on a certain date and time. This, for instance, could be
the case if an action page should show different information at certain times. Additional detail
falls beyond the scope of this document.
Which expressions and which personalization models are assigned to which pages can be viewed
on the [Usage] tab from the Format > Personalize menu:
3 VISITOR PROFILES
Profiles are used for personalization. They contain default data (such as login name, address,
city, and subscriptions to various newsletters):
Data from external applications can also be used to set personalization for certain persons. The
forms module allows filling session variables with the use of special handlers, such as the
QueryToSessionHandler. In the personalization, the data can then be read again from the session
variables. This implies customization software and modifications to the database to read data
from the session variables and save them in the database. If the visitor returns, his information
can be retrieved from the database and his visit can be monitored immediately.
4 .1 Tec hn ic a l in fo r ma tio n
The session is used in GX WebManager to store profiles (the use of the visitor‟s information to
personalize pages for that visitor). Using handlings, a visitor is logged in and his/her information
is retrieved from the database and added to the session in XML form, under session keys. The
handler performing this action is called „QueryToSessionHandler‟.
Session keys starting with „GX_‟ are special in GX WebManager and are used to personalize pages.
Session keys are divided in groups. The group can be found in the name. The name always consists
of three parts separated by hyphens: GX-<class_name>-<template_name>. Session keys with
visitor‟s information start, for instance, with GX-user. When creating keys, maintain these
groups, or it will not be possible to locate the session keys in the session.
For every requested page, an XML document is constructed from the XML saved in t he session
under these keys, the page HTML, and the information from the request.
Example: If a visitor is logged in, the XML being constructed will roughly look like this:
<root>
<system>
<cookies>
... all cookies ...
</cookies>
<headers>
... all headers ...
</header>
<requestparameters>
... all request parameters ...
</requestparameters>
<date>2005-12-09</date>
<time>11:17:06</time>
<usergroup>
<id>3</id>
<webid>26098</webid>
<groupname>Women</groupname>
<useindocuments>1</useindocuments>
<originalid/>
</usergroup>
... all other user groups where this user belongs to ...
<user>
<id>1</id>
<webid>26098</webid>
<username>noel</username>
<email>noel@gx.nl</email>
<password>fugo45rd</password>
<firstname>Noël</firstname>
<lastname>Hilton</lastname>
... other user data ...
</user>
</system>
<showhtml>
<![CDATA[ HTML block ]]>
</showhtml>
<wm-user-personalization-45676 forpage="true" orgurl="http...">
<showhtml>
<![CDATA[ HTML block ]]>
</showhtml>
<wm-hostname default="127.0.0.1" />
<showhtml>
<![CDATA[ HTML block ]]>
</showhtml>
<wm-user-personalization-46482>
<showhtml>
<![CDATA[
<h2 class="header">Example of inline personalization:</h2>
<p class="normal">Welcome back!
]]>
</showhtml>
<wm-user-christianname />
<showhtml>
<![CDATA[
!<br /><br /><br /><br /></p>
]]>
</showhtml>
... all other content in HTML and XML (when needed) ...
</wm-user-personalization-45676>
<showhtml>
<![CDATA[ HTML block ]]>
</showhtml>
</root>
The XML above has been shortened in a few places to make it easier on the eye.
Note: If information is written to the session, the tags are GX-xxx-yyy. If information is
retrieved from the session, those same tags are WM-xxx-yyy.
root
o system
cookies (these are passed on from the browser in the request)
headers (idem)
requestparameters (idem)
date
time
flow
usergroup
user
o showhtml
o wm-classname-templatename
The <system> tag contains all the information from the session needed to construct this
request.
The <flow> tag appears only during a form flow that consists of several steps and
contains the entered values and possible validator warnings, errors, etc. The form design
uses this information, with the described personalization mechanism, to show errors and
prefill previously completed form parts (e.g., if a step back is taken on a form).
The <usergroup> and <user> tags contain the web user information from the session.
This XML can also be requested in a handler by requesting the GX-usergroup or the
GX-user from the session object. If needed, XML can also be added to handlers by
saving XML fragments under their own session key. This session key should also start with
GX- (e.g., GX-myproject).
The <system> tag is followed by one or more <showhtml> tags with the page HTML in a
CDATA block. This is used to ensure that the XML parser does not try to parse the HTML.
The HTML is interrupted with special <wm-XML> tags. The personalization module in GX
WebManager generates these <wm-XML> tags. It is the intention to replace these tags
during the personalization. In the XML above, for instance, there is a
<wm-user-christianname > tag between the <showhtml> blocks. The personalization
ensures that this tag is replaced with the <firstname> value. The <firstname> is
located in the same document under the root/system/user/firstname tag. The
technique replacing these tags is XSL.
Personalized content and dynamic functionality use more resources than static pages. To
minimize this in the case of personalized pages, XSL transformations are used to combine the
content of a session with the cached content of the generator. This way, maximum use is made of
the cache when dynamic pages are constructed.
HTML
XSL translation
XML +
Session information
Session
GX user
Header
s
Cookies
Cache
XML
XSLT
Style sheet
GX WebManager
Generator
As shown in the last part of the previous paragraph, personalization in GX WebManager is nothing
more than transforming an XML document with an XSL style sheet. XSL is a programming language
used to transform XML documents into another format (XML, HTML, PDF, …). In GX WebManager,
the XML is constructed as described above; in other words, the page HTML, supplemented with
personal and other data. An XSL style sheet is used to transform this XML in a perso nalized HTML
document to eventually be presented to the visitor.
A <wm-user-christianname /> tag from the example in the previous paragraph is replaced
during the XSL transformation with the <firstname> value. The XSL needed to do this:
<xsl:template match="//wm-user-christianname">
<xsl:value-of disable-output-escaping="yes"
select="/root/system/user/firstname" />
</xsl:template>
This XSL template matches the <wm-user-christianname /> tags and replaces them with a
value selected from the XML document with the /root/system/user/firstname XPATH
expression.
This XSL template is part of a large XSL style sheet containing several templates that have been
created, for example, with the GX WebManager personalization module or that are part of
GX WebManager‟s standard functionality for, e.g., visitors, forms, searches, etc.
The personalization module allows adding new XSL templates. A personalization XSL template
name is always constructed as follows:
wm-<class_name>-<template_name>
The fact that the tag starts with wm (Attention: THIS IS MANDATORY!) is used by GX WebManager
to divide pages in parts that show up as CDATA in a „showhtml‟ block and in the WM tags (see the
example in the previous paragraph). This makes it possible to insert the
„Welcome <wm-user-christianname/>!‟ text line in the title of a paragraph. The page HTML
is then split in two pieces (before and after the WM tag) that end up in the „showhtml‟ blocks.
During the personalization, they are put together again.
In a nutshell:
By default, there is an XSL template that transforms the „showhtml‟ blocks to regular
HTML in the CDATA.
The WM tag matches the XSL template above and is in this template replaced with the
<firstname> value.
The WM tag used as an example (<wm-user-christianname />) is closed with a />. There are,
however, also WM tags that have a beginning and an ending tag. In between these tags, there can
be „showhtml‟ and other WM tags. These types of tags can be used to, for instance, authorize a
visitor. See also wm-user-personalization in the previous paragraph‟s example. The XSL
template for these types of tags does not consist of an „xsl:value-of‟ but an „xsl:choose‟
(a conditional XSL expression). Parts of a page can be made conditional using such an expression
(e.g., showing a paragraph only if the visitor is logged in).
The personalization mechanism can be expanded. Customization handlers can often add their own
pieces of XML to the session under GX keys. In combination with project-specific XSL templates,
these keys can be used to personalize pages based on information from an external system
(retrieved by a customization handler) and placed in the session in XML form.
XSL is a very powerful language and allows very complicated actions (it is a professional
programming language). In GX WebManager – using XSL, forms, and personalizations - complicated
web applications are built for various projects (e.g., web shops). This information and knowledge
of XSL and Java allows programmers to do the same.
To debug personalization, it can be handy to have the XML and XSL available that are generated
below the surface. Take the next step to retrieve the XML and XSL that WebManager uses:
Check the reference to the XML file that contains the users (by default this is the file
tomcat-users.xml):
Check if the role “wmadmin” is present and that there is at least one user that uses that
role. A minimal population of the users XML file looks like this:
If the status page is displayed successfully, then open the homepage of your website in
the same browser window. Use the backend hostname when visiting the homepage:
http://<backend-hostname>:<port>/web/show
Log in as a webuser on the website and go to personalized page that you want to debug
the XML and XSL of. The XML can be retrieved by adding “/xmldebug=true” to the URL.
The XSL can be retrieved by adding “/xsldebug=true” to the URL. An example:
Normal URL: http://localhost/web/show/id=76284/langid=43
XML source: http://localhost/web/show/id=76284/langid=43/xmldebug=true
XSL source: http://localhost/web/show/id=76284/langid=43/xsldebug=true
Note: The XML is „smartly‟ constructed. This means that the XML from session keys beginning with
wm- (e.g., wm-user-lastname) is only added to the XML if the XSL used to do the
transformation also contains templates (in this case wm-user) that match this XML. Performance
is the reason for this: Long documents are harder to transform than short ones. However, during
the debugging, it can make it look like there is XML missing.
5 PERSONALIZED MESSAGE S
Personalization can also be used to create a handler. To produce the login name of the visitor,
the example in this chapter uses an XSL template as a parameter value. The handler should then
transform the XML in the session to this XSL to obtain the username. The code fragment below
shows a handler that prints the result of this transformation in the log.
package nl.gx.product.form;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import nl.gx.webmanager.handler.forms.FormComponentConfig;
import nl.gx.webmanager.handler.forms.FormDefinition;
import nl.gx.webmanager.handler.forms.HandleException;
import nl.gx.webmanager.handler.forms.Handler;
import nl.gx.webmanager.handler.forms.InitializationException;
import nl.gx.webmanager.handler.forms.State;
import nl.gx.webmanager.handler.forms.foundation.FormHandlerBase;
String userXsl;
FormComponentConfig config;
In this fragment, the init method places the configuration object in a class field so it can be
used in the doHandle. The XSL template that has to produce the userName is read from the
userXSL parameter (this has to be entered as the parameter value in the forms module).
Note: The tags for the template‟s definition can be omitted (<xsl:template...).
This method retrieves the parameter and then tries to transform the session with its value. The
getText method already performs an XSL transformation of the parameter value. If this does not
work, the value of the parameter is generated.
This way, it can be decided in the forms module if the login name should be generated w ith XSL
or if it should simply be included as parameter without having to modify the Java code. A similar
getTexts method exists for parameters with multiple values. For a more detailed description on
how to create, deploy & configure handlers, please read the document “Integration APIs”
(http://www.gxdeveloperweb.com/Software/Documentation.htm#GXD0052 ).
6 PRECONDITIONS
Example:
To make it easier to understand the expression in the screen shot, the next page shows an
example of a piece of XML flow on a form that is part of the web user‟s registration process.
The image above shows a rule definition with a precondition based on the RequestRouter. The
precondition consists of an XSL expression that generates „true‟ if there are mistakes in the XML
flow.
<root>
<system>
...
<flow id="43772">
<formpath>43772</formpath>
<formnavigation>
http://127.0.0.1:7081/web/show?id=43680&langid=43&
cfe=43772&ff=43772
</formnavigation>
<formelement id="43772" pageid="43682" formid="43775">
<formpart id="f44108" XSLtag="username">
<userentry>noel</userentry>
</formpart>
<formpart id="f44109">
<userentry>XXXXX</userentry>
</formpart>
<formpart id="f44110">
<userentry>YYYYY</userentry>
</formpart>
<formpart id="f44111" XSLtag="email">
<userentry>noel@gx.nl</userentry>
</formpart>
<error code="not_found">
This login name 'noel' has already been used
</error>
<error code="not_found">
This e-mail address 'noel@gx.nl' has already been used
</error>
</formelement>
<values></values>
</flow>
...
</system>
...
</root>
This fragment states that in a form flow, on a form element with a number of form parts, two
errors have occurred. The exact format of the XML flow is usually not important because the
SessionFormFlow class makes it easy to manipulate the flow from Java. The only exception is
the use of preconditions, in which case XSLT or XPath expressions should be written to match this
XML.
The precondition in the RequestRouter screen shot above eventually shows up in an XSL style
sheet generated by GX WebManager:
<?XML version="1.0"?>
<xsl:stylesheet XMLns:XSL="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:if test=
"count(/handler/flow/formelement[@id=43772]/error) > 0 ">true
</xsl:if>
</xsl:template>
</xsl:stylesheet>
It is easy to see that in this fragment the predefined @formelement@ variable has been replaced
by GX WebManager with a specific ID of a form element that also appears in the XML flow on the
previous page.
The XML transformation to this template generates „t rue‟, because there are error tags in the
form element with id=“43772”. The associated RequestRouter is executed.
More complicated expressions also allow checking the values of certain fields.