KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > api > OmniaWebAction


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.api;
7
8 import java.util.*;
9
10 import javax.servlet.http.*;
11
12 import org.apache.struts.Globals;
13 import org.apache.struts.action.ActionForm;
14
15 import com.raptus.owxv3.*;
16
17 /**
18  *
19  * <hr>
20  * <table width="100%" border="0">
21  * <tr>
22  * <td width="24%"><b>Filename</b></td><td width="76%">OmniaWebAction.java</td>
23  * </tr>
24  * <tr>
25  * <td width="24%"><b>Author</b></td><td width="76%">Guy Z�rcher (gzuercher@raptus.com)</td>
26  * </tr>
27  * <tr>
28  * <td width="24%"><b>Date</b></td><td width="76%">19th of April 2001</td>
29  * </tr>
30  * </table>
31  * <hr>
32  * <table width="100%" border="0">
33  * <tr
34  * <td width="24%"><b>Date / Author</b></td><td width="76%"><b>Changes</b></td>
35  * </tr>
36  * </table>
37  * <hr>
38  */

39 public class OmniaWebAction extends org.apache.struts.action.Action
40 {
41     /**
42      *
43      *
44      */

45     protected String JavaDoc getSelectedElement(ActionForm form, HttpServletRequest request)
46     {
47         String JavaDoc element = request.getParameter(Constants.HTTPGET_PARAM_ELEMENT);
48         if(element == null || element.length() == 0)
49             element = ((OmniaWebBean) form).getElement();
50         else
51             ((OmniaWebBean) form).setElement(element);
52
53         return element;
54     }
55
56     /**
57      * return the selected section
58      */

59     protected String JavaDoc getSelectedSection(ActionForm form, HttpServletRequest request)
60     {
61         String JavaDoc section = request.getParameter(Constants.HTTPGET_PARAM_SECTION);
62         if(section == null || section.length() == 0)
63             section = ((OmniaWebBean) form).getSection();
64         else
65             ((OmniaWebBean) form).setSection(section);
66
67         return section;
68     }
69     
70     /**
71      *
72      *
73      */

74     protected String JavaDoc getSelectedVModule(ActionForm form, HttpServletRequest request)
75     {
76         String JavaDoc vmid = request.getParameter(Constants.HTTPGET_PARAM_VMODULE);
77         if(vmid == null || vmid.length() == 0)
78             vmid = ((OmniaWebBean) form).getVModule();
79         else
80             ((OmniaWebBean) form).setVModule(vmid);
81
82         return vmid;
83     }
84
85     /**
86      *
87      *
88      */

89     protected Locale getSelectedLocale(ActionForm form, HttpServletRequest request)
90     {
91         String JavaDoc l = request.getParameter(Constants.HTTPGET_PARAM_LOCALE);
92         if(l == null || l.length() == 0)
93         {
94             // 20020306gz: removed necessity of having a locale param. If NOT specified, the
95
// default from session is selected, if any.
96
HttpSession session = request.getSession();
97             return (Locale) session.getAttribute(Globals.LOCALE_KEY);
98         }
99
100         PairOfObjects po = LocaleManager.stripLocaleString(l);
101         return new Locale((String JavaDoc) po.getObjectOne(), (String JavaDoc) po.getObjectTwo());
102     }
103
104     /**
105      *
106      */

107     protected com.raptus.owxv3.api.usermgr.User checkForUserInSession(HttpSession session)
108     {
109         return (com.raptus.owxv3.api.usermgr.User) session.getAttribute(Constants.SESSIONKEY_USER);
110     }
111
112
113     /**
114      * Locale INSENSITIVE cache of used virtual modules. In other words:
115      * Every virtual module instance is used for all locales that user may
116      * request.
117      *
118      */

119     protected VModule cachedVModuleAccess(HttpSession session, String JavaDoc vmid)
120     {
121         Hashtable vmcache = (Hashtable) session.getAttribute(Constants.SESSIONKEY_VMCACHE);
122         if(vmcache == null)
123         {
124             // seems to be the very first time ...
125
vmcache = new Hashtable();
126             session.setAttribute(Constants.SESSIONKEY_VMCACHE, vmcache);
127             LoggingManager.log("Created virtual module cache for session " +
128                                session.getId(), this);
129         }
130
131         VModule vm = (VModule) vmcache.get(vmid);
132         if(vm == null)
133         {
134             // seems to be the first time. Create one
135
VModuleManager vmm = VModuleManager.getInstance();
136             vm = vmm.getVModule(vmid);
137             if(vm != null)
138             {
139                 vmcache.put(vmid, vm);
140                 LoggingManager.log("Created virtual module (" + vmid +
141                                    "), and stored in the vmodule cache.", this);
142             }
143         }
144
145         return vm;
146     }
147
148     /**
149      *
150      */

151     public static int convertToInteger(int defVal, String JavaDoc strValue)
152     {
153         int value = defVal;
154         if(strValue != null && strValue.length() > 0)
155         {
156             try
157             {
158                 value = Integer.parseInt(strValue);
159             }
160             catch(NumberFormatException JavaDoc e) {
161             }
162         }
163
164         return value;
165     }
166
167 }
168
169 // eof
170
Popular Tags