001: /**
002: * $Id: DesktopDispatcherProvider.java,v 1.18 2006/08/05 13:42:44 ss150821 Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wireless.providers.containers;
014:
015: import com.sun.portal.providers.Provider;
016: import com.sun.portal.providers.containers.ContainerProviderAdapter;
017: import com.sun.portal.providers.ProviderException;
018: import com.sun.portal.providers.UnknownEditTypeException;
019: import com.sun.portal.providers.context.ContainerProviderContext;
020: import com.sun.portal.providers.context.ProviderContextException;
021: import com.sun.mobile.util.MAPConfigProperties;
022: import com.sun.portal.log.common.PortalLogger;
023:
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026: import java.util.Map;
027: import java.util.List;
028: import java.util.Set;
029: import java.util.logging.Level;
030: import java.util.logging.Logger;
031: import java.net.URL;
032:
033: public class DesktopDispatcherProvider extends ContainerProviderAdapter {
034:
035: private static final String MA_MAIL_JSP = "MAMailJSP";
036:
037: private static final String DESKTOP_DISPATCHER = "WirelessDesktopDispatcher";
038:
039: private static final String DESKTOPCONTAINER = "desktopContainer";
040:
041: private static final String SELECTEDCLIENTS = "selectedClients";
042:
043: private static final String GENERICHTML = "genericHTML";
044:
045: private static final String PARENTCLIENTS = "parentId";
046:
047: private static final String STOREPROFILEINCLIENT = "storeProfileInClient";
048:
049: private static Logger logger = PortalLogger
050: .getLogger(DesktopDispatcherProvider.class);
051:
052: private Provider desktop = null;
053:
054: public void init(String n, HttpServletRequest req)
055: throws ProviderException {
056: super .init(n, req);
057:
058: desktop = getDesktopProvider(req);
059: }
060:
061: private Provider getDesktopProvider(HttpServletRequest request)
062: throws ProviderException {
063:
064: if (desktop == null
065: || getContainerProviderContext().isAuthless(request)) {
066: desktop = initDesktopProvider(request);
067: }
068:
069: return desktop;
070:
071: }
072:
073: private Provider initDesktopProvider(HttpServletRequest request)
074: throws ProviderException {
075:
076: ContainerProviderContext context = getContainerProviderContext();
077: List filters = null;
078: try {
079: filters = context.getClientPropertiesFilters();
080: } catch (ProviderContextException e) {
081: throw new ProviderException(
082: "WirelessDesktopDispatcher.initDesktopProvider(): ",
083: e);
084: }
085:
086: String desktopName = getStringProperty(DESKTOPCONTAINER,
087: filters);
088:
089: if (logger.isLoggable(Level.FINEST)) {
090: Object[] param = { "clientFilters", filters };
091: logger.log(Level.FINEST, "PSMA_CSPWPC0001", param);
092: param[0] = "desktopName";
093: param[1] = desktopName;
094: logger.log(Level.FINEST, "PSMA_CSPWPC0001", param);
095: }
096:
097: // add client if it is not on selected list
098: if (!context.isAuthless(request)) {
099: Map selectedClients = getMapProperty(SELECTEDCLIENTS);
100: String clientType = context.getClientType();
101:
102: boolean genericHTML;
103: try {
104: genericHTML = Boolean.valueOf(
105: context.getClientTypeProperty(GENERICHTML))
106: .booleanValue();
107: } catch (Exception e) {
108: genericHTML = false;
109: }
110:
111: // if client is UAProf, then use it's first ancestor client
112: boolean isUAProf = (context.getClientTypeProperties(
113: clientType, MAPConfigProperties.get(
114: STOREPROFILEINCLIENT, null)) != null);
115:
116: if (isUAProf) {
117: try {
118: Set parents = context.getClientTypeProperties(
119: clientType, PARENTCLIENTS);
120: clientType = (String) parents.iterator().next();
121:
122: if (logger.isLoggable(Level.FINEST))
123: logger.log(Level.FINEST, "PSMA_CSPWPC0002",
124: clientType);
125:
126: } catch (Exception e) {
127: if (logger.isLoggable(Level.INFO))
128: logger.log(Level.INFO, "PSMA_CSPWPC0003", e);
129: }
130: }
131:
132: if (!genericHTML)
133: addClientTypeToMaMailJSP(context, clientType);
134:
135: if (!genericHTML
136: && !selectedClients.containsKey(clientType)) {
137: selectedClients.put(clientType, "");
138: setMapProperty(SELECTEDCLIENTS, selectedClients);
139:
140: if (logger.isLoggable(Level.FINEST))
141: logger.log(Level.FINEST, "PSMA_CSPWPC0004",
142: clientType);
143: }
144: }
145:
146: return context.getProvider(request, getName(), desktopName);
147:
148: }
149:
150: private void addClientTypeToMaMailJSP(
151: ContainerProviderContext context, String clientType) {
152: // Add this client type to the MAMailJSP channel if not present there
153: // already. - 6330973
154: try {
155: Map maMailClients = context.getCollectionProperty(
156: MA_MAIL_JSP, SELECTEDCLIENTS);
157: if (!maMailClients.containsKey(clientType)) {
158: maMailClients.put(clientType, "");
159: context.setCollectionProperty(MA_MAIL_JSP,
160: SELECTEDCLIENTS, maMailClients);
161: }
162: } catch (ProviderContextException e) {
163: if (logger.isLoggable(Level.WARNING))
164: logger
165: .log(Level.WARNING, "PSMA_CSPWPC0005",
166: clientType);
167: }
168: }
169:
170: public boolean isPresentable(HttpServletRequest request) {
171:
172: try {
173: return getDesktopProvider(request).isPresentable(request);
174: } catch (ProviderException prEx) {
175: if (logger.isLoggable(Level.INFO))
176: logger.log(Level.INFO, "", prEx);
177: }
178: return false;
179: }
180:
181: public StringBuffer getContent(HttpServletRequest request,
182: HttpServletResponse response) throws ProviderException {
183:
184: return getDesktopProvider(request)
185: .getContent(request, response);
186: }
187:
188: public int getEditType() throws UnknownEditTypeException {
189: return desktop.getEditType();
190: }
191:
192: public boolean isEditable() throws ProviderException {
193: return desktop.isEditable();
194: }
195:
196: public StringBuffer getEdit(HttpServletRequest request,
197: HttpServletResponse response) throws ProviderException {
198:
199: return getDesktopProvider(request).getEdit(request, response);
200:
201: }
202:
203: public URL processEdit(HttpServletRequest request,
204: HttpServletResponse response) throws ProviderException {
205:
206: return getDesktopProvider(request).processEdit(request,
207: response);
208: }
209:
210: // Not customer public.
211: public static Map getSelectedClients(
212: ContainerProviderContext context)
213: throws ProviderContextException {
214:
215: return context.getCollectionProperty(DESKTOP_DISPATCHER,
216: SELECTEDCLIENTS);
217: }
218:
219: // Not customer public.
220: public static String getClientContainerName(
221: ContainerProviderContext context, String clientType)
222: throws ProviderContextException {
223:
224: List filters = context.getClientPropertiesFilters(clientType);
225: return context.getStringProperty(DESKTOP_DISPATCHER,
226: DESKTOPCONTAINER, filters);
227: }
228:
229: // Not customer public.
230: public static void removeClient(HttpServletRequest request,
231: ContainerProviderContext context, String clientType)
232: throws ProviderContextException {
233:
234: if (!context.isAuthless(request)) {
235: Map selectedClients = getSelectedClients(context);
236: selectedClients.remove(clientType);
237: context.setCollectionProperty(DESKTOP_DISPATCHER,
238: SELECTEDCLIENTS, selectedClients);
239: }
240: }
241:
242: }
|