Pages

Friday, September 18, 2009

Changing the Landing page after Login in Lotus Connections 2.5

As I described in an earlier post, how to modify the Homepage link of the navigation bar in order to display the "My page" instead of the update page, I describe in this post how to modify the Homepage redirection after logging in to Connections. We make use of the WASReqURL cookie that is set to remember the URL to a protected resource when there is no User session active. WAS redirects to the Login page and remembers the previously called URL in the WASReqURL. Via a small JavaScript on the login page, we modify this cookie to point to the My Page url. The login page is defined in dboard.war/auth/login.jsp. Add the following snippet to the head scripts of the file.


function setRedirectCookie(){
var cookieName = "WASReqURL";
var requestURL = getCookie(cookieName);
if(requestURL.substr(requestURL.length - 9) == "homepage/") {
  requestURL += "web/widgets";
}
setCookie(cookieName, requestURL, null, "/");
}


The getCookie() and setCookie() methods are copied from the example on w3schools. Note, that the setCookie() method uses a fourth parameter, which is the path that is simply appended after the expires parameter. The setRedirectCookie() method retrieves the WASReqURL and checks if it ends with "homepage/" - which is the Updates page. If thats the case, the "web/widgets" is appended, pointing to the My Page.

Thursday, September 17, 2009

Adding a multi-lingual link to Header or Footer in Lotus Connections 2.5

According to the InfoCenter, it is quite simple to add additional content such as links to the header of the footer. What the InfoCenter doesn't mention, how you could have the labels of these links multilangual. But fortunately, that's not very complicated.


For editing the header or footer itself, follow the instructions in the InfoCenter. But instead of writing the label of a link directly to the file, use a placeholder similar to the existing ones, like {{ label.header.mylink }}.


To add the label: for each component, locate the lc.util.web-2.5.jar file - should be in the WEB-INF/lib of the the web modules. This jar file contains the resource files. Open the file for edit (use a proper archive tool*) and search for the package/path com.ibm.lconn.core.web.ui.resources. That path contains the resource files. Edit the resource files for your language and add the label (i.e. label.header.mylink) and a value in the proper language. Important: add the label you are using at least to the resources.properties file, that is used as fallback if a label is not defined in the localized properties file.


*: If you have no tool to edit the files directly in the jar file, you could also rename the .jar file to a .zip file, extract it, edit the files, compress it again as .zip and rename it back to .jar

Changing the landing tab for a Lotus Connections 2.5 feature


We had a customer, that wanted that the Homepage feature's default tab should be the "My Page" tab not the Update tab as it is per default. The InfoCenter mentions, that you could add additional links to the navigation bar by editing the header.html. Another entry mentions, if you want to edit the application links themselves, you have to set the href attributes in the LotusConnections-config.xml. However, the latter SHOULD NOT be used, to modify the landing page because the href attribute refers to the application ROOT entry. For instance, if you change this for the homepage feature, the static widget resources which are searched relative to this root are not found. So use this setting only for pointing to a different server or a different context root.


So the first link was of more use, to edit the header.html directly. But, it only mentions to add additional links not to modify existing one. However, by using a simple JavaScript snippet, it is possible to alter the generated links after display. Simpy insert the following snippet into the header.html right after {{application links: li }}.


<script type="text/javascript">
function changeHomepageLink() {

var homePageLink = null;
var homePageLink = document.getElementById('lotusBannerHomepage');


if(homePageLink != null) {
var link = homePageLink.firstChild;
var hrefAttr = link .getAttribute('href');
var newHrefAttr = hrefAttr + '/web/widgets';
link .setAttribute('href', newHrefAttr);
}
}
changeHomepageLink();
</script>

Actually, we don't know if that is the official or correct way to do so, but it works. The "welcome" page is defined in the web.xml of the web application. Another way to change this would be to change the web.xml of the war file and redeploy it, though, this seemed a little too risky to us.


Tuesday, September 15, 2009

CSS stylesheets in Lotus Connections 2.5

From Lotus Connections 2.0 to 2.5 the handling of theme and styles has been changed. While LC20 used static stylesheets, LC25 uses a specialized servlet for that purpose. This servlet called JAWR bundles multiple files and sends them compressed to the client. The HTML that is styled by this JAWR servlet refer to a normal URL, in LC25 this URL points to something like "/bundle/css/gzip_something/coreBundle.css". The context of the URL - /bundle/css - is mapped to the JAWR servlet, and the id of the bundle - /coreBundle.css - may look like file and is resolved by the servlet.. That makes it difficult, to find the proper stylesheet in the filesystem - simply, because it does not exist.

Looking at a sinlge LC25 component (i.e. Communities), the configuration file for the JAWR servlet can be found in /WEB-INF/properties.
In the configuration file, a bundle with the name "core" and the id "/coreBundle.css" is defined. The /coreBundle.css is mapped to the files
  • /stylesheet/update_styles.css,
  • /stylesheet/update_community.css,
  • /nav/common/styles/base/core.css,
  • /nav/common/styles/defaultTheme/defaultTheme.css,
  • /javascript/build/dijit/themes/dijit.css,
  • /nav/common/styles/base/dojo.css,
  • /nav/common/styles/defaultTheme/dojoTheme.css,
  • /javascript/source/lconn/comm/typeahead/themes/lconn.typeahead.css,
  • /javascript/source/lconn/comm/typeahead/themes/lotusBlue/LotusBlue.css,
  • /nav/common/styles/base/connectionsCore.css,
  • /nav/common/styles/base/semanticTagStyles.css,
  • /nav/lconn/styles/sprite-lconn.css
These files are located relative to the root of the web archive comm.web.war.

For faster development, the JAWR servlet offers a debug mode. According to the JAWR documentation the debug mode is enable by setting the jawr.debug.on=true in the jawr.properties file. The setting is applied after restarting the application.
The debug mode has two advantages:
  1. changes to the css stylesheets in the filesystem are effective immediately
  2. stylesheets are not included as a single, one-lined compressed file but as a set of files pointing to every single stylesheet. In the html, each mapped stylesheet is included via a separate link-tag. That way, it is transparent, which css definition is set in which stylesheet. Second, the stylesheets are not reformatted meaning that the line-numbers of tools such as firebug point to the correct line of the included stylesheet.

Friday, September 11, 2009

Creating a singleton using Eclipse Code Templates

In this post I'd like to demonstrate the Eclipse Code Template feature for implementing a singleton pattern.
The Singleton is a creational pattern of the set of Gang-of-Four Java Design patterns. It uses a single static variable (the singleton), a private constructor to prevent public instantiation and a public static getter method to retrieve the instance. For lazy instantiation, the singleton instance is not preinitialized, instead, the static getter method checks if the instance is null and instantiates a new instance on its first call. Lazy instantiation (as used in the following example) is not uncommon, though it may cause race conditions in multithreaded environments.
The Code Template feature is an extension to the code-completion functionality that is accessible by pressing Ctrl+Space. When the user types in code, he may hit Ctrl+Space to auto-complete, what he was typing. Eclipse proposes a set of options for completion, i.e. a Type, method of that type etc.
The Code Template feature might be known from typing in "sysout", pressing Ctrl+Space and Eclipse completes this to "System.out.println("");".
To add a new code template,
  1. open to Window -> Preferences
  2. navigate to Java -> Editor -> Templates.
  3. click on "New..."
  4. set the name of the new template to "singleton" (this is what you type into the editor)
  5. as pattern enter
    /**
     * static Singleton instance
     */
    private static ${enclosing_type} instance;
    /**
     * Private constructor for singleton
     */
    private ${enclosing_type}(){
    }
    /**
     * Static getter method for retrieving the singleton instance
     */
    public static ${enclosing_type} getInstance(){
      if(instance == null) {
        instance = new ${enclosing_type}();
      }
      return instance;
    }

The variable ${enclosing_type} resolves to the Class you are editing. From now on, it is possible to create the entire singleton pattern by just typing "singleton" and hitting Ctrl+Space - saving lots of keystrokes!