001: /**
002: * $Id: TemplateLayoutProvider.java,v 1.24 2006/09/05 19:56:20 dpolla Exp $
003: * Copyright 2003 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.template;
014:
015: import com.sun.portal.providers.ProviderException;
016: import com.sun.portal.providers.context.ProviderContextException;
017: import com.sun.portal.wireless.providers.containers.DesktopDispatcherProvider;
018: import com.sun.portal.wireless.providers.containers.WirelessContainerProvider;
019: import com.sun.portal.log.common.PortalLogger;
020:
021: import javax.servlet.http.HttpServletRequest;
022: import javax.servlet.http.HttpServletResponse;
023: import java.net.URL;
024: import java.net.MalformedURLException;
025: import java.util.ResourceBundle;
026: import java.util.List;
027: import java.util.Map;
028: import java.util.Hashtable;
029: import java.util.Iterator;
030: import java.util.logging.Level;
031: import java.util.logging.Logger;
032:
033: public class TemplateLayoutProvider extends
034: WirelessContainerProviderAdapter {
035:
036: private static Logger logger = PortalLogger
037: .getLogger(TemplateLayoutProvider.class);
038:
039: public StringBuffer getEdit(HttpServletRequest request,
040: HttpServletResponse response) throws ProviderException {
041:
042: // read client type passed in
043: String client = request.getParameter(CLIENT);
044: if (client == null) {
045: throw new ProviderException(
046: "WirelessTemplateLayout.getEdit():"
047: + "client parameter missing");
048: }
049: String containerName = null;
050: WirelessContainerProvider clientContainer = null;
051: List userChannels = null;
052: try {
053:
054: containerName = DesktopDispatcherProvider
055: .getClientContainerName(
056: getContainerProviderContext(), client);
057: clientContainer = (WirelessContainerProvider) getContainerProviderContext()
058: .getProvider(request, null, containerName);
059:
060: userChannels = clientContainer.getOrderedSelectedChannels(
061: request, true);
062: } catch (ProviderContextException e) {
063: throw new ProviderException(
064: "WirelessTemplateContent.getEdit():", e);
065: }
066:
067: // edit content buffer
068: StringBuffer content = new StringBuffer();
069:
070: // tag tables
071: Hashtable channelTags = new Hashtable();
072: Hashtable mainTags = new Hashtable();
073:
074: String name = null;
075: String title = null;
076: int channelCount = 0;
077:
078: if (getTemplatePath(BANNER_TEMPLATE) != null) {
079: mainTags.put(BANNER_TAG, getTemplate(BANNER_TEMPLATE));
080: }
081: if (getTemplatePath(BULLETCOLOR_TEMPLATE) != null) {
082: mainTags.put(BULLETCOLOR_TAG,
083: getTemplate(BULLETCOLOR_TEMPLATE));
084: }
085: if (getTemplatePath(DEVICEMENUBAR_TEMPLATE) != null) {
086: mainTags.put(DEVICEMENUBAR_TAG,
087: getTemplate(DEVICEMENUBAR_TEMPLATE));
088: }
089:
090: if (client != null) {
091: ResourceBundle bundle = null;
092: try {
093: bundle = getResourceBundle(PROPERTIES_DEV);
094: mainTags.put(CLIENTNAME_TAG, bundle.getString(client));
095: } catch (Exception e) {
096: mainTags.put(CLIENTNAME_TAG, client);
097: }
098: }
099:
100: StringBuffer clientconfigQuerystring = new StringBuffer();
101: Map editPages = getMapProperty(EDITPAGES);
102: clientconfigQuerystring = clientconfigQuerystring
103: .append(ACTION).append('=').append(EDIT).append('&')
104: .append(PROVIDER).append('=').append(
105: editPages.get(CLIENTCONFIG));
106: mainTags.put(CLIENTCONFIGLINK_TAG, getProviderContext()
107: .getDesktopURL(request,
108: clientconfigQuerystring.toString(), true));
109: mainTags.put(LOGOUTLINK_TAG, getProviderContext()
110: .getLogoutURL());
111: mainTags.put(PRODUCTNAME, getStringProperty(PRODUCTNAME));
112: mainTags.put(LAYOUTPROVIDER_TAG, editPages.get(LAYOUT));
113: mainTags.put(CLIENTCONTAINER_TAG, containerName);
114: URL helpURL = null;
115: try {
116: helpURL = getHelp(request);
117: } catch (ProviderException e) {
118: if (logger.isLoggable(Level.INFO))
119: logger.log(Level.INFO, "PSMA_CSPWPCT0003", e);
120: }
121: if (helpURL != null) {
122: mainTags.put(HELPLINK_TAG, helpURL.toString());
123: }
124:
125: // Iterate thru the available providers
126: for (Iterator i = userChannels.iterator(); i.hasNext();) {
127: name = (String) i.next();
128:
129: try {
130: title = getProviderContext().getStringProperty(name,
131: TITLE);
132: } catch (ProviderContextException e) {
133: throw new ProviderException(
134: "WirelessTemplateLayout.getEdit(): ", e);
135: }
136:
137: channelTags.put(PROVIDER_TAG, name);
138: channelTags.put(TITLE_TAG, title);
139:
140: channelCount++;
141:
142: content.append(getTemplate(ANCHORWRAPPER_TEMPLATE,
143: channelTags));
144:
145: }
146:
147: if (channelCount == 0) {
148: ResourceBundle bundle = getResourceBundle(PROPERTIES_BASE);
149: channelTags.put(TITLE_TAG, bundle.getString(NOCHANNELS));
150: channelTags.put(PROVIDER_TAG, "");
151: content.append(getTemplate(ANCHORWRAPPER_TEMPLATE,
152: channelTags));
153: }
154: mainTags.put(CONTENT_TAG, content.toString());
155: // Put the number of providers into the main tagtable.
156: mainTags.put(PROVIDERCOUNT_TAG, Integer.toString(channelCount));
157:
158: boolean minimizable = false;
159: boolean maximizable = false;
160: try {
161: minimizable = getContainerProviderContext()
162: .getBooleanProperty(containerName,
163: DEFAULTISMINIMIZABLE, false);
164: maximizable = getContainerProviderContext()
165: .getBooleanProperty(containerName,
166: DEFAULTISMAXIMIZABLE, false);
167:
168: if (minimizable && maximizable
169: && getTemplatePath(MINIMIZEOPTION_TEMPLATE) != null) {
170:
171: Hashtable minimizeTags = new Hashtable();
172: boolean isMinimized = getContainerProviderContext()
173: .getBooleanProperty(containerName,
174: DEFAULTISMINIMIZED);
175: if (!isMinimized) {
176: minimizeTags.put(CHECKED_TAG,
177: getTemplate(CHECKED_TEMPLATE));
178: }
179:
180: mainTags.put(MINIMIZEOPTION_TAG, getTemplate(
181: MINIMIZEOPTION_TEMPLATE, minimizeTags));
182: }
183: } catch (ProviderContextException pce) {
184: throw new ProviderException(
185: "WirelessTemplateLayout.getEdit(): ", pce);
186: }
187:
188: // Return the main template, swapping in the tagtable.
189: return getTemplate(LAYOUT_TEMPLATE, mainTags);
190: }
191:
192: public URL processEdit(HttpServletRequest request,
193: HttpServletResponse response) throws ProviderException {
194:
195: // read container name passed from client config provider
196: String containerName = request.getParameter(CONTAINER);
197: if (containerName == null) {
198: throw new ProviderException(
199: "WirelessTemplateLayout.processEdit():"
200: + "container parameter missing.");
201: }
202: List userChannels = null;
203: Map channelsRow = null;
204: WirelessContainerProvider clientContainer = null;
205:
206: clientContainer = (WirelessContainerProvider) getContainerProviderContext()
207: .getProvider(request, null, containerName);
208:
209: userChannels = clientContainer.getOrderedSelectedChannels(
210: request, true);
211:
212: try {
213: channelsRow = getContainerProviderContext()
214: .getCollectionProperty(containerName, CHANNELSROW);
215: } catch (ProviderContextException e) {
216: throw new ProviderException(
217: "WirelessTemplateLayout.processEdit(): ", e);
218: }
219:
220: // If moveUp is true, the channel must be moved up.
221: String moveUp = request.getParameter(MOVEUP);
222: // If moveDown is true, the channel must be moved down.
223: String moveDown = request.getParameter(MOVEDOWN);
224: // If order is non-null, the providers are in a list
225: String[] order = request.getParameterValues(ORDER);
226:
227: if (moveUp != null) {
228: // channel that we are moving up
229: String moveChannel = request.getParameter(MOVECHANNEL);
230: if (moveChannel != null) {
231: int rowIndex = userChannels.indexOf(moveChannel);
232:
233: if (rowIndex == -1 && logger.isLoggable(Level.FINEST)) {
234: logger.log(Level.FINEST, "PSMA_CSPWPCT0010",
235: moveChannel);
236: } else if (rowIndex > 0) {
237: userChannels.remove(rowIndex);
238: userChannels.add(rowIndex - 1, moveChannel);
239:
240: String currentChannel = null;
241: for (int i = 0; i < userChannels.size(); i++) {
242: currentChannel = (String) userChannels.get(i);
243: if (channelsRow.containsKey(currentChannel)) {
244: channelsRow.remove(currentChannel);
245: }
246: channelsRow.put(currentChannel,
247: (new Integer(i)).toString());
248: }
249:
250: if (logger.isLoggable(Level.FINEST)) {
251: String[] param = { moveChannel, "" + rowIndex,
252: "" + (rowIndex - 1) };
253: logger.log(Level.FINEST, "PSMA_CSPWPCT0011",
254: param);
255: }
256: }
257: } else if (logger.isLoggable(Level.INFO)) {
258: logger.log(Level.INFO, "PSMA_CSPWPCT0012");
259: }
260:
261: } else if (moveDown != null) {
262: // channel that we are moving down
263: String moveChannel = request.getParameter(MOVECHANNEL);
264: if (moveChannel != null) {
265: int rowIndex = userChannels.indexOf(moveChannel);
266: if (rowIndex == -1 && logger.isLoggable(Level.FINEST)) {
267: logger.log(Level.FINEST, "PSMA_CSPWPCT0013",
268: moveChannel);
269: } else if (rowIndex < userChannels.size() - 1) {
270: userChannels.remove(rowIndex);
271: userChannels.add(rowIndex + 1, moveChannel);
272:
273: String currentChannel = null;
274: for (int i = 0; i < userChannels.size(); i++) {
275: currentChannel = (String) userChannels.get(i);
276: if (channelsRow.containsKey(currentChannel)) {
277: channelsRow.remove(currentChannel);
278: }
279: channelsRow.put(currentChannel,
280: (new Integer(i)).toString());
281: }
282:
283: if (logger.isLoggable(Level.FINEST)) {
284: String[] param = { moveChannel, "" + rowIndex,
285: "" + (moveChannel + 1) };
286: logger.log(Level.FINEST, "PSMA_CSPWPCT0014",
287: param);
288: }
289: }
290: } else if (logger.isLoggable(Level.FINEST)) {
291: logger.log(Level.FINEST, "PSMA_CSPWPCT0015");
292: }
293:
294: } else if (order != null) {
295: // this is for html client only
296: for (int i = 0; i < order.length; i++) {
297: channelsRow.put(order[i], String.valueOf(i + 1));
298: }
299:
300: if (logger.isLoggable(Level.FINEST)) {
301: Object[] param = { "channelsRow", channelsRow };
302: logger.log(Level.FINEST, "PSMA_CSPWPCT0001", param);
303: }
304:
305: }
306:
307: try {
308: getContainerProviderContext().setCollectionProperty(
309: containerName, CHANNELSROW, channelsRow);
310: } catch (ProviderContextException e) {
311: throw new ProviderException(
312: "WirelessTemplateLayout.processedit(): ", e);
313: }
314:
315: // check for loadChannels flag
316: boolean genericHTML = false;
317: try {
318: genericHTML = Boolean.valueOf(
319: getProviderContext().getClientTypeProperty(
320: GENERICHTML)).booleanValue();
321: } catch (Exception e) {
322: genericHTML = false;
323: }
324:
325: try {
326: if (genericHTML
327: && getContainerProviderContext()
328: .existsBooleanProperty(containerName,
329: DEFAULTISMINIMIZED)) {
330:
331: String loadChannels = request
332: .getParameter(LOADCHANNELS);
333: if (loadChannels != null) {
334: getContainerProviderContext().setBooleanProperty(
335: containerName, DEFAULTISMINIMIZED, false);
336: } else {
337: getContainerProviderContext().setBooleanProperty(
338: containerName, DEFAULTISMINIMIZED, true);
339: }
340: }
341: } catch (ProviderContextException pce) {
342: throw new ProviderException(
343: "WirelessTemplateLayout.processEdit(): ", pce);
344: }
345:
346: URL nextUrl = null;
347: StringBuffer nextQuerystring = new StringBuffer();
348:
349: if (genericHTML) {
350: Map editPages = getMapProperty(EDITPAGES);
351: nextQuerystring.append(PROVIDER).append('=').append(
352: editPages.get(CLIENTCONFIG)).append('&').append(
353: ACTION).append('=').append(EDIT);
354: } else {
355: nextQuerystring.append(PROVIDER).append('=').append(
356: getName()).append('&').append(ACTION).append('=')
357: .append(EDIT).append('&').append(CLIENT)
358: .append('=').append(
359: getProviderContext().getClientType());
360: }
361: String next = getProviderContext().getDesktopURL(request,
362: nextQuerystring.toString(), false);
363: try {
364: nextUrl = new URL(next);
365: } catch (MalformedURLException e) {
366: throw new ProviderException(
367: "WirelessTemplateLayout.processEdit(): ", e);
368: }
369:
370: return nextUrl;
371: }
372:
373: }
|