001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.console;
017:
018: import java.io.IOException;
019: import java.util.HashMap;
020: import java.util.Map;
021: import java.util.Properties;
022:
023: import javax.portlet.ActionRequest;
024: import javax.portlet.ActionResponse;
025: import javax.portlet.PortletConfig;
026: import javax.portlet.PortletException;
027: import javax.portlet.PortletRequestDispatcher;
028: import javax.portlet.RenderRequest;
029: import javax.portlet.RenderResponse;
030:
031: import org.apache.commons.fileupload.FileItem;
032:
033: /**
034: * Base class for handlers for the multi page portlet. Each one is expected
035: * to handle a single page -- the action request before the page is rendered,
036: * the render request, and the action request after the page is rendered.
037: *
038: * @version $Rev: 612052 $ $Date: 2008-01-15 01:10:00 -0800 (Tue, 15 Jan 2008) $
039: */
040: public abstract class MultiPageAbstractHandler {
041: protected final static String BEFORE_ACTION = "-before";
042: protected final static String AFTER_ACTION = "-after";
043: protected PortletRequestDispatcher view;
044: private final String mode;
045: private final String viewName;
046: private Map<String, FileItem> uploadFiles = new HashMap<String, FileItem>();
047: private Properties uploadFields = new Properties();
048:
049: protected MultiPageAbstractHandler(String mode, String viewName) {
050: this .mode = mode;
051: this .viewName = viewName;
052: }
053:
054: public String getMode() {
055: return mode;
056: }
057:
058: public void init(PortletConfig portletConfig)
059: throws PortletException {
060: if (viewName != null) {
061: view = portletConfig.getPortletContext()
062: .getRequestDispatcher(viewName);
063: }
064: }
065:
066: public void destroy() {
067: view = null;
068: }
069:
070: public PortletRequestDispatcher getView() {
071: return view;
072: }
073:
074: protected static boolean isEmpty(String s) {
075: return s == null || s.trim().equals("");
076: }
077:
078: /**
079: * Returns the mode for the next screen to render (usually this one)
080: */
081: public abstract String actionBeforeView(ActionRequest request,
082: ActionResponse response, MultiPageModel model)
083: throws PortletException, IOException;
084:
085: public abstract void renderView(RenderRequest request,
086: RenderResponse response, MultiPageModel model)
087: throws PortletException, IOException;
088:
089: /**
090: * Returns the mode for the next screen to render (usually the one after this in the sequence)
091: */
092: public abstract String actionAfterView(ActionRequest request,
093: ActionResponse response, MultiPageModel model)
094: throws PortletException, IOException;
095:
096: public Map<String, FileItem> getUploadFiles() {
097: return uploadFiles;
098: }
099:
100: public Properties getUploadFields() {
101: return uploadFields;
102: }
103:
104: }
|