开发者

SEO in WebSphere Portal (Page Title)

Page Title

Is there a way to dinamically change the pages title at runtime?

I know that you can change the page title at the portal level, but this solution doesn't offer any SEO value since it doesn't change the TITLE tag in the page.

For what I've seen the way to changing the portal titles are very static (these are global settings):

  • Changing the bannerTitleText in the theme policy
  • If that's not present adjust the bannerTitleTextResourceBundle and bannerTitleTextResourceKey to the desired value.
  • Otherwise, set the titles globally at the theme configuration

Our goal is to be able to set the title at the page level so that it can change from page to page and include the relevant page's keyword.

Actually it would be most ideal if this could be done from WCM.

Update

I noticed that the default theme in WebSphere Portal 6.1.5 was appending the page title, so examined the theme and surely enough the jspInit.jspf had some the following new methods:



private static com.ibm.portal.state.service.PortalStateManagerServiceHome portalStateManagerServiceHome;

// (This goes in the jspInit constructor)
portalStateManagerServiceHome = (com.ibm.portal.state.service.PortalStateManagerServiceHome) ctx.lookup("portal:service/state/PortalStateManager");

protected com.ibm.portal.state.service.PortalStateManagerService getStateManagerService( javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws Exception {
    final com.ibm.portal.state.service.PortalStateManagerService psms = portalStateManagerServiceHome.getPortalStateManagerService( (javax.servlet.http.HttpServletRequest) request, (javax.servlet.http.HttpServletResponse) response );
    return psms;
}
protected boolean isStaticPage( javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
    final com.ibm.portal.model.NavigationSelectionModelProvider nsmProvider = navigationSelectionModelHome.getNavigationSelectionModelProvider();
    final com.ibm.portal.navigation.NavigationSelectionModel nsm = nsmProvider.getNavigationSelectionModel(request, response);
    final com.ibm.portal.navigation.NavigationNode currentNavNode = (com.ibm.portal.navigation.NavigationNode) nsm.getSelectedNode();
    final com.ibm.portal.content.ContentNode currentContentNode = currentNavNode.getContentNode();

    return currentContentNode.getContentNodeType().equals( com.ibm.portal.content.ContentNodeType.STATICPAGE );
}

protected com.ibm.portal.navigation.NavigationNode getSelectedNode( final javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
    com.ibm.portal.model.NavigationSelectionModelProvider nsmProvider = navigationSelectionModelHome.getNavigationSelectionModelProvider();
    com.ibm.portal.navigation.NavigationSelectionModel nsm = nsmProvider.getNavigationSelectionModel(request, response);
    return (com.ibm.portal.navigation.NavigationNode) nsm.getSelectedNode();
}

protected String getSelectedNodeTitle( final javax.servlet.ServletRequest request, javax.servlet.ServletResponse response ) throws com.ibm.portal.ModelException {
    final String title;
    if ( localizedContextHome != null ) {
        com.ibm.portal.model.LocalizedContext context = localizedContextHome.getLocalizedContext( (javax.servlet.http.HttpServletRequest) request );
        title = context.getTitle( getSelectedNode( request, response ) );
    } else {
        title = "";
    }

    return title;
}

After adding this I was able to copy the head_title.jspf from the 6.1.5 theme; which includes the following new lines:


<c:set var="selectedNodeTitle" value="<%=getSelectedNodeTitle(request, response)%>" />
<title><c:out value="${siteTitle} - ${selectedNodeTitle}"/></title>

Now all that's left is figuring out a way of fet开发者_运维百科ching this from WCM.


I will cover the missing WCM part, since I have implemented that. I will be able to give you required information but not ready code. It is just reading from a stream and writing into an other anyways so you should be able to grasp the idea. The most reasonable way using Portal 6.1 is to develop a Servlet Filter for this requirement. What you want to do is:

  1. Make WCM components that print out the correct information you want to inject to the html headers. This most typically means for instance navigator component to print the current path / title.
  2. Add those components to your presentation templates. What you want it probably to use html comment tags <!-- --> and some scheme you can parse later on from the generated html.
  3. Build a servlet filter that reads the whole page from the ServletResponse if it is html/xhtml (use the mime type). Parse the comments away while you do that. Now, rewrite a new page with correct tags in the html header section.
  4. Re-inject the new response page which this time has correct html headers for SEO.

Unfortunately this is the way you have to take. There aren't even hidden/private APIs that would allow you to take what you want from the WCM rendering portlets' application context and put it into the html headers. Also, you have to add the servlet filter to the wps application. A common gotcha here is that you have to re-deploy it after you edit the web.xml.

The performance impact of the servlet filter is negligible (only couple percentages in total), and the approach simply works. In my experience it works very well for SEO purposes, and you can get practically any information from WCM this way.


I just wanted to update this question to mention that there's a new feature that enables a better way to achieve this same goal.

The new Web Content Viewer (286) takes advantage of a new feature in the JSR 286 called two phase rendering in which a new event is created called doHeaders. Under the doHeaders event the response can be modified in order to add elements in the head such as title.

Now the Web Content Viewer provides a Page Display Title setting which enables you to do a Select from content.

Now all that's left really is to enable us developers set other elements from Web Content such as: Canonical elements/links, meta tags, etc. But I think that the new Web Content Folders feature can enable us to build something at the theme level.

Good luck to every SEO conscious Lotus Web Content Management developers out there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜