KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > console > MultiPageAbstractHandler


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.console;
18
19 import org.apache.commons.fileupload.portlet.PortletFileUpload;
20
21 import javax.portlet.PortletRequestDispatcher;
22 import javax.portlet.PortletConfig;
23 import javax.portlet.PortletException;
24 import javax.portlet.ActionRequest;
25 import javax.portlet.ActionResponse;
26 import javax.portlet.RenderRequest;
27 import javax.portlet.RenderResponse;
28 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Properties JavaDoc;
33
34 /**
35  * Base class for handlers for the multi page portlet. Each one is expected
36  * to handle a single page -- the action request before the page is rendered,
37  * the render request, and the action request after the page is rendered.
38  *
39  * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
40  */

41 public abstract class MultiPageAbstractHandler {
42     protected final static String JavaDoc BEFORE_ACTION="-before";
43     protected final static String JavaDoc AFTER_ACTION="-after";
44     protected PortletRequestDispatcher view;
45     private final String JavaDoc mode;
46     private final String JavaDoc viewName;
47     private Map JavaDoc uploadFiles = new HashMap JavaDoc();
48     private Properties JavaDoc uploadFields = new Properties JavaDoc();
49
50     protected MultiPageAbstractHandler(String JavaDoc mode, String JavaDoc viewName) {
51         this.mode = mode;
52         this.viewName = viewName;
53     }
54
55     public String JavaDoc getMode() {
56         return mode;
57     }
58
59     public void init(PortletConfig portletConfig) throws PortletException {
60         if(viewName != null) {
61             view = portletConfig.getPortletContext().getRequestDispatcher(viewName);
62         }
63     }
64
65     public void destroy() {
66         view = null;
67     }
68
69     public PortletRequestDispatcher getView() {
70         return view;
71     }
72
73     protected static boolean isEmpty(String JavaDoc s) {
74         return s == null || s.trim().equals("");
75     }
76
77     /**
78      * Returns the mode for the next screen to render (usually this one)
79      */

80     public abstract String JavaDoc actionBeforeView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc;
81
82     public abstract void renderView(RenderRequest request, RenderResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc;
83
84     /**
85      * Returns the mode for the next screen to render (usually the one after this in the sequence)
86      */

87     public abstract String JavaDoc actionAfterView(ActionRequest request, ActionResponse response, MultiPageModel model) throws PortletException, IOException JavaDoc;
88
89     public Map JavaDoc getUploadFiles() {
90         return uploadFiles;
91     }
92
93     public Properties JavaDoc getUploadFields() {
94         return uploadFields;
95     }
96
97     protected static void waitForProgress(ProgressObject JavaDoc po) {
98         while(po.getDeploymentStatus().isRunning()) {
99             try {
100                 Thread.sleep(100);
101             } catch (InterruptedException JavaDoc e) {
102                 e.printStackTrace();
103             }
104         }
105     }
106
107 }
108
Popular Tags