001: /**
002: * $Id: TasksProcessorServlet.java,v 1.7 2007/01/26 03:48:55 portalbld Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.portlet.service.tasksprocessor;
014:
015: import java.io.StringWriter;
016: import java.io.ByteArrayOutputStream;
017: import java.io.IOException;
018:
019: import java.util.List;
020: import java.util.Iterator;
021:
022: import javax.servlet.ServletContext;
023: import javax.servlet.ServletConfig;
024: import javax.servlet.ServletException;
025:
026: import javax.servlet.http.HttpServlet;
027: import javax.servlet.http.HttpServletRequest;
028: import javax.servlet.http.HttpServletResponse;
029:
030: import com.sun.portal.portlet.service.taskshared.TaskCommonConstant;
031: import com.sun.portal.portletappengine.LifecycleManager;
032:
033: import javax.portlet.PortletContext;
034:
035: import java.util.logging.Logger;
036: import java.util.logging.Level;
037: import com.sun.portal.log.common.PortalLogger;
038:
039: /**
040: * The portlet provision engine servlet is the entry point of the portlet
041: * provision engine.
042: * <P>
043: * The portlet provision engine receives requests from
044: * the provision dispatcher through the Request Dispatcher, and then
045: * deligates the work to the following components:
046: * <UL>
047: * <LI> Lsisteners/Events factory: generates Listeners/Events instances
048: * </UL>
049: */
050:
051: public class TasksProcessorServlet extends HttpServlet {
052:
053: // Global variables
054: private LifecycleManager _lifecycleManager;
055:
056: private static java.util.logging.Logger _logger = PortalLogger
057: .getLogger(TasksProcessorServlet.class);
058: private ServletContext _context;
059: private PortletContext _portletContext;
060:
061: private TaskProvision _taskProvision;
062: private TaskMembership _taskMembership;
063:
064: /*
065: * Initializes global variables.
066: * <P>
067: * @param config The <code>ServletConfig</code> object
068: */
069: public void init(ServletConfig config) throws ServletException {
070:
071: super .init(config);
072: _lifecycleManager = (LifecycleManager) config
073: .getServletContext().getAttribute(
074: LifecycleManager.LIFECYCLE_MANAGER_PREFIX);
075: if (_lifecycleManager == null) {
076: throw new ServletException(
077: "Bootstrapping of this portlet Webapp "
078: + " seems to have failed before this servlet."
079: + " Please check other exceptions in the log.");
080: }
081:
082: _portletContext = _lifecycleManager.getPortletContext();
083: _context = config.getServletContext();
084: _taskProvision = new TaskProvision(config);
085: _taskMembership = new TaskMembership(config);
086: if (_logger.isLoggable(Level.INFO)) {
087: _logger
088: .log(Level.INFO,
089: "TasksProcessorServlet:init:TasksProcessorServlet Initialized successfully");
090: }
091:
092: }
093:
094: /**
095: * This mehtod is the meat of the servlet, which basically handles
096: * the request for executing a portlet.
097: *
098: * This method will do the following tasks:
099: * <UL>
100: * <LI>Obtains provision request/response objects from
101: * request/response factory
102: *
103: * <LI>Obtains the target Lis object from the lifecycle
104: * manager
105: * <LI>Obtains the action list that is passed from the request
106: * <LI>Calls cooresponding portlet methods
107: * <LI>Sets cooresponding results in the response
108: * <LI>Handles exceptions
109: * <P>
110: * @param req The <code>HttpServletRequest</code>
111: * @param res The <code>HttpServletResponse</code>
112: */
113: public void service(HttpServletRequest request,
114: HttpServletResponse response) throws IOException,
115: ServletException {
116:
117: String action = (String) request
118: .getAttribute(TaskCommonConstant.TASK);
119: if (_logger.isLoggable(Level.FINEST)) {
120: _logger.log(Level.FINEST,
121: "TasksProcessorServlet:service:TasksProcessorServlet action:"
122: + action);
123: }
124: try {
125: if (action.equals(TaskCommonConstant.COMMUNITY_EVENT)) {
126: _taskProvision.process(request, response);
127: } else if (action.equals(TaskCommonConstant.MEMBER_ADDED)) {
128: _taskMembership.process(request, response);
129: } else if (action.equals(TaskCommonConstant.MEMBER_REMOVED)) {
130: _taskMembership.process(request, response);
131: }
132: } catch (RuntimeException ex) {
133: ex.printStackTrace();
134: throw new ServletException(
135: "ERROR:Runtime Exception processing listener code:",
136: ex);
137: }
138:
139: }
140:
141: }
|