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     */
017    package org.apache.geronimo.console;
018    
019    import java.io.IOException;
020    import java.util.HashMap;
021    import java.util.Map;
022    import java.util.Properties;
023    
024    import javax.portlet.ActionRequest;
025    import javax.portlet.ActionResponse;
026    import javax.portlet.PortletConfig;
027    import javax.portlet.PortletException;
028    import javax.portlet.PortletRequestDispatcher;
029    import javax.portlet.RenderRequest;
030    import javax.portlet.RenderResponse;
031    
032    import org.apache.commons.fileupload.FileItem;
033    
034    /**
035     * Base class for handlers for the multi page portlet.  Each one is expected
036     * to handle a single page -- the action request before the page is rendered,
037     * the render request, and the action request after the page is rendered.
038     *
039     * @version $Rev: 706640 $ $Date: 2008-10-21 14:44:05 +0000 (Tue, 21 Oct 2008) $
040     */
041    public abstract class MultiPageAbstractHandler {
042        protected final static String BEFORE_ACTION="-before";
043        protected final static String AFTER_ACTION="-after";
044        protected PortletRequestDispatcher view;
045        private final String mode;
046        private final String viewName;
047        private Map<String, FileItem> uploadFiles = new HashMap<String, FileItem>();
048        private Properties uploadFields = new Properties();
049    
050        protected MultiPageAbstractHandler(String mode, String viewName) {
051            this.mode = mode;
052            this.viewName = viewName;
053        }
054    
055        public String getMode() {
056            return mode;
057        }
058    
059        public void init(PortletConfig portletConfig) throws PortletException {
060            if(viewName != null) {
061                view = portletConfig.getPortletContext().getRequestDispatcher(viewName);
062            }
063        }
064    
065        public void destroy() {
066            view = null;
067        }
068    
069        public PortletRequestDispatcher getView() {
070            return view;
071        }
072    
073        protected static boolean isEmpty(String s) {
074            return s == null || s.trim().equals("");
075        }
076    
077        /**
078         * Returns the mode for the next screen to render (usually this one)
079         */
080        public abstract String actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException;
081    
082        public abstract void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException;
083    
084        /**
085         * Returns the mode for the next screen to render (usually the one after this in the sequence)
086         */
087        public abstract String actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException;
088    
089        public Map<String, FileItem> getUploadFiles() {
090            return uploadFiles;
091        }
092    
093        public Properties getUploadFields() {
094            return uploadFields;
095        }
096    
097    }