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)

Base Action

The DisplayURL portlet's BaseAction class is a superclass which is extended by the DisplayAction, EditorAction, OkAction, and CancelAction classes. The source code is shown below.


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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sas.portal.Logger;
import com.sas.portal.container.deployment.PortletActionInfoInterface;
import com.sas.portal.portlet.NavigationUtil;
import com.sas.portal.portlet.PortletActionInterface;
import com.sas.portal.portlet.PortletContext;
import com.sas.portal.portlets.displayurl.Initializer;

public abstract class BaseAction implements PortletActionInterface
{
    private final String _loggingContext = this.getClass().getName();

    private PortletActionInfoInterface _actionInfo = null;

    /**
     * This method must be overridden in subclasses. 
	 * They must call super and supply a return value.
     * In this class, the method returns null.
     * 
     * @see com.sas.portal.portlet.PortletActionInterface#service(
     * HttpServletRequest, HttpServletResponse, PortletContext)
     */
    public String service(HttpServletRequest request,
                          HttpServletResponse response,
                          PortletContext context) throws Exception
    {
    	Logger.debug("started..", _loggingContext);
        response.setContentType("text/html;charset=UTF-8");
		
        // prepare the localized resources for use by the jsp.
        try {
            NavigationUtil.prepareLocalizedResources(
                 "com.sas.portal.portlets.displayurl.Resources", 
				 request, context);
        }
        catch (java.io.IOException ioe) {
            Logger.error(ioe.getMessage(), _loggingContext, ioe);
        }
    
        return null;
    }

    /**
     * @see com.sas.portal.portlet.PortletActionInterface#setInfo(
     * PortletActionInfoInterface)
     */
    public final void setInfo(PortletActionInfoInterface info)
    {
        _actionInfo = info;
    }

    /**
     * @see com.sas.portal.portlet.PortletActionInterface#getInfo()
     */
    public final PortletActionInfoInterface getInfo()
    {
        return _actionInfo;
    }
    

    /**
     * Check the PortletContext for an exception object. If present,
	 * throw it so that the error handler will kick in.
     * @param context the PortletContext
     */
    protected static final void errorCheck(PortletContext context)
	    throws Exception
    {
        Exception e = (Exception)context.getAttribute(
          Initializer.PORTLET_EXCEPTION_KEY); 
        if (e != null)
            throw e;
    }
}