001: /*
002: * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package javax.portlet;
030:
031: import java.io.IOException;
032: import java.util.Enumeration;
033: import java.util.ResourceBundle;
034:
035: public abstract class GenericPortlet implements Portlet, PortletConfig {
036: private transient PortletConfig _config;
037:
038: public GenericPortlet() {
039: }
040:
041: public void init(PortletConfig config) throws PortletException {
042: _config = config;
043: init();
044: }
045:
046: public void init() throws PortletException {
047: }
048:
049: public void processAction(ActionRequest request,
050: ActionResponse response) throws PortletException,
051: IOException {
052: throw new PortletException(
053: "processAction method not implemented");
054: }
055:
056: public void render(RenderRequest request, RenderResponse response)
057: throws PortletException, IOException {
058: response.setTitle(getTitle(request));
059: doDispatch(request, response);
060: }
061:
062: protected String getTitle(RenderRequest request) {
063: return _config.getResourceBundle(request.getLocale())
064: .getString("javax.portlet.title");
065: }
066:
067: protected void doDispatch(RenderRequest request,
068: RenderResponse response) throws PortletException,
069: IOException {
070: WindowState state = request.getWindowState();
071:
072: if (!state.equals(WindowState.MINIMIZED)) {
073: PortletMode mode = request.getPortletMode();
074:
075: if (mode.equals(PortletMode.VIEW)) {
076: doView(request, response);
077: } else if (mode.equals(PortletMode.EDIT)) {
078: doEdit(request, response);
079: } else if (mode.equals(PortletMode.HELP)) {
080: doHelp(request, response);
081: } else {
082: throw new PortletException("unknown portlet mode: "
083: + mode);
084: }
085: }
086:
087: }
088:
089: protected void doView(RenderRequest request, RenderResponse response)
090: throws PortletException, IOException {
091: throw new PortletException("doView method not implemented");
092: }
093:
094: protected void doEdit(RenderRequest request, RenderResponse response)
095: throws PortletException, IOException {
096: throw new PortletException("doEdit method not implemented");
097: }
098:
099: protected void doHelp(RenderRequest request, RenderResponse response)
100: throws PortletException, IOException {
101: throw new PortletException("doHelp method not implemented");
102:
103: }
104:
105: public PortletConfig getPortletConfig() {
106: return _config;
107: }
108:
109: public void destroy() {
110: }
111:
112: public String getPortletName() {
113: return _config.getPortletName();
114: }
115:
116: public PortletContext getPortletContext() {
117: return _config.getPortletContext();
118: }
119:
120: public ResourceBundle getResourceBundle(java.util.Locale locale) {
121: return _config.getResourceBundle(locale);
122: }
123:
124: public String getInitParameter(String name) {
125: return _config.getInitParameter(name);
126: }
127:
128: public Enumeration getInitParameterNames() {
129: return _config.getInitParameterNames();
130: }
131: }
|