SAS 9.1.3 Integration Technologies » SAS Web Infrastructure Kit: Developer's Guide


Developing Custom Portlets
Development Steps
Creating a Deployment Descriptor
Creating Display Resources Files
Developing the Presentation JSP Page
Creating Action Classes
Implementing Portlet Help
Creating a PAR File
Use Cases
Simple Display Portlet
Localized Portlet
Portlet Template (Editable Portlet)
Remote Portlet
Tips and Best Practices
Using the Portlet API
Sample Portlets
Localized Display Portlet (Welcome)
Interactive Form Portlet (FormExample)
Portlet Template, or Editable Portlet (DisplayURL)
Web Application (HelloUserWikExample)
Remote Portlet (HelloUserRemote
Portlet
Sample: Portlet Template, or Editable Portlet (DisplayURL)

Initializer Action

The DisplayURL portlet's Initializer action class initializes properties that are used by the other action classes and puts the properties into a PortletContext object. The source code follows.


/**Copyright (c) 2003 by SAS Institute Inc., Cary, NC 27513.
 * All Rights Reserved.
 */
package com.sas.portal.portlets.displayurl;

import java.rmi.RemoteException;
import java.util.Properties;

import com.sas.portal.Logger;
import com.sas.portal.portlet.PortletContext;
import com.sas.portal.portlet.PortletInitializerInterface;
import com.sas.portal.portlet.configuration.Attribute;
import com.sas.portal.portlet.configuration.Configuration;
import com.sas.portal.portlet.configuration.ConfigurationFactory;


/**
 * This initializes common properties by putting them into a
 * PortletContext object.
 */
public class Initializer implements PortletInitializerInterface
{
    private final String _loggingContext = this.getClass().getName();

    /* Key for the URL String in the PortletContext.*/
    public static final String DISPLAY_URL_KEY =
        "sas_DisplayURL_DisplayURL";

    /* PortletContext key for the edit screen Ok button URL */
    public static final String EDIT_OK_URL_KEY =
        "sas_DisplayURL_EditOkURL";

    /* PortletContext key for the edit screen Cancel button URL */
    public static final String EDIT_CANCEL_URL_KEY =
        "sas_DisplayURL_EditCancelURL";

    /** Key for the PortletException object in the PortletContext.*/
    public static final String PORTLET_EXCEPTION_KEY =
        "sasPortletException";

    /**
     * Puts initial properties into the PortletContext object. These 
     * come from the portlet.xml.
     * @param initProperties a Properties object
     * @param context the PortletContext for this portlet
     */
    public void initialize(Properties initProperties, 
        PortletContext context)
    {
        try {
          // get the initial url from the portlet configuration object
          Configuration config = ConfigurationFactory.getConfiguration(
              context);
          Attribute attr = config.getAttribute(
              Initializer.DISPLAY_URL_KEY);
          String url = (attr == null) ? "" : attr.getValue();

          context.setAttribute("error-page",
              initProperties.getProperty("error-page"));
          context.setAttribute("display-page",
              initProperties.getProperty("display-page"));
          context.setAttribute("edit-page",
              initProperties.getProperty("edit-page"));
          context.setAttribute(Initializer.DISPLAY_URL_KEY, url);

          if (Logger.isDebugEnabled(_loggingContext)){
          	Logger.debug("Display portlet URL: " +
          	    url, _loggingContext);
          }
		} catch ( RemoteException e) {
          context.setAttribute(Initializer.PORTLET_EXCEPTION_KEY, e);
		}
    }
}