001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */
013: package com.sun.portal.providers.containers.jsp.tab;
014:
015: import java.util.List;
016: import java.util.ArrayList;
017:
018: import java.util.Map;
019: import java.util.HashMap;
020: import java.util.ResourceBundle;
021: import java.util.logging.Level;
022: import java.util.logging.Logger;
023:
024: import java.net.URL;
025: import java.net.MalformedURLException;
026: import java.io.*;
027:
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
030:
031: import com.sun.portal.providers.containers.JSPContainerProviderAdapter;
032: import com.sun.portal.providers.containers.ProviderWindowStates;
033: import com.sun.portal.providers.containers.UnsupportedWindowStateException;
034: import com.sun.portal.providers.ProviderException;
035: import com.sun.portal.providers.context.ProviderContextException;
036: import com.sun.portal.providers.InvalidEditFormDataException;
037: import com.sun.portal.providers.containers.jsp.tab.util.TabException;
038: import com.sun.portal.providers.containers.jsp.tab.util.TabData;
039: import com.sun.portal.log.common.PortalLogger;
040:
041: /**
042: * This class provides the implementation for JSPTabContainerProvider
043: * and extends <code>JSPContainerProviderAdapter</code> and
044: * implements <code>TabContainer</code>
045: *
046: *
047: * A TabContainer provider is a container provider that generates its views primarily
048: * by being a client of table container objects.The Tab Container displays one of its
049: * contained channels at a time. The tab container allows table containers to be arranged
050: * onto virtual pages. The container can then switch between these pages allowing them to
051: * be physically viewed one at a time.
052: * It allows the user to switch logically separate row-column displays.
053: * Viewing this with container glasses on, each page is a table container.
054: * The tab container then contains multiple table containers, one for each page.
055: * Each tab in tab container corresponds to a table container.
056: *
057: * Here, a Tab container provider is defined as a container
058: * provider that has a selected and available channels list,
059: * and allows getting and setting of these lists.
060: *
061: * Tab container uses the selected channels list to hold the names of the tabs
062: * that the user has configured on their desktop.
063: * The available channels list is used to hold the list of tab topics,
064: * or the tabs that the user can add to their desktop.
065: * This does not adhere to the semantics of the getSelectedChannels
066: * defined in ContainerProvider.
067: *
068: * Selected Tabs are the container channels that are considered "active" on the
069: * portal page. Available Tabs are those that are available to
070: * be added to the portal page from the edit page.
071: *
072: *
073: * @see com.sun.portal.providers.containers.jsp.tab.TabContainer
074: * @see com.sun.portal.providers.containers.JSPContainerProviderAdapter
075: */
076: public class JSPTabContainerProvider extends
077: JSPContainerProviderAdapter implements TabContainer {
078:
079: private TabData tabdata = null;
080: private ResourceBundle bundle = null;
081: private Map tabPropsMap = null;
082: private String channel = null;
083: private static Logger logger = PortalLogger
084: .getLogger(JSPTabContainerProvider.class);
085:
086: private static int[] supportedStates = new int[2];
087:
088: static {
089: supportedStates[0] = ProviderWindowStates.NORMAL;
090: }
091:
092: /**
093: * Initializes the TabContainerProvider.
094: * This method must be called by clients of the TabContainerProvider object
095: * when the provider object is created (after it is constructed, or
096: * before the object is used). This method should not be called more
097: * than once per object.
098: *
099: * @param n Unique name identifying this TabContainerprovider. This value
100: * should always be returned from <code>getName()</code>.
101: *
102: * @param req The HTTP request object corresponding to the HTTP request
103: * that caused this provider object ot be created. This request may be
104: * used to extract session or user information that could be used to
105: * gain access to external resources.
106: *
107: * @exception ProviderException If there was an error initializing the
108: * TabContainerProvider. How this exception is handled is up to the client of the
109: * TabContainerProvider object.
110: *
111: * @see com.sun.portal.providers.Provider#getName
112: */
113: public void init(String n, HttpServletRequest req)
114: throws ProviderException {
115: super .init(n, req);
116: //
117: // init TabData
118: //
119: channel = getName();
120: bundle = getResourceBundle();
121: tabdata = new TabData(getContainerProviderContext(), channel,
122: bundle);
123:
124: tabPropsMap = getMapProperty("TabProperties");
125: }
126:
127: /**
128: * Gets the list of tab names that are available on the portal page.
129: *
130: * The semantics of this method are different than <code>getSelectedChannels()</code>
131: * in ContainerProvider. This method returns the names of the tabs that
132: * the user has configured on their desktop.
133: *
134: * @return The list of selected channel names, a list of string names.
135: *
136: * @exception ProviderException If the list of channel names cannot be
137: * returned.
138: */
139: public List getSelectedChannels() throws ProviderException {
140: return super .getSelectedChannels();
141: }
142:
143: /**
144: * Gets the list of tab topics that are available to be added to the portal page.
145: *
146: * @return The list of available channel names, a list of string names.
147: *
148: * @exception ProviderException If the list of channel names cannot be
149: * returned.
150: */
151: public List getAvailableChannels() throws ProviderException {
152: return super .getAvailableChannels();
153: }
154:
155: /**
156: * Sets the list of selected channel names.
157: *
158: * This method sets the available tabs on the portal page.
159: *
160: * @param sel The new list of channel names.
161: *
162: * @exception ProviderException If the list of channel names cannot be
163: * set.
164: */
165: public void setSelectedChannels(List sel) throws ProviderException {
166: super .setSelectedChannels(sel);
167: }
168:
169: /**
170: * Sets the list of available channel names.
171: *
172: * This method sets the available tab topics ussed by the user
173: * to configure the portal desktop.
174: *
175: * @param avail The new list of channel names.
176: *
177: * @exception ProviderException If the list of channel names cannot be
178: * set.
179: */
180: public void setAvailableChannels(List avail)
181: throws ProviderException {
182: super .setAvailableChannels(avail);
183: }
184:
185: /**
186: * Gets the maximum number of tabs allowed on the user's desktop.
187: *
188: * @return The maximum number of tabs.
189: *
190: * @exception ProviderException If the maximum number of tabs cannot be
191: * returned.
192: */
193: public int getMaxTabs() throws ProviderException {
194: try {
195: return tabdata.getMaxTabs();
196: } catch (TabException te) {
197: throw new ProviderException(
198: "TabContainerProvider.getMaxTabs():couldn't get maxTabs",
199: te);
200: }
201: }
202:
203: /**
204: * Gets the List of selected tabs.
205: *
206: * @return The list of selected tabs, a list of UnmodifiableTabs.
207: *
208: * @exception ProviderException If the list of selected tabs cannot be
209: * returned.
210: *
211: * @see com.sun.portal.providers.containers.jsp.tab.UnmodifiableTab
212: */
213: public List getSelectedTabs() throws ProviderException {
214: List tabs = new ArrayList();
215: try {
216: tabs = tabdata.getSelectedTabs();
217: } catch (TabException te) {
218: throw new ProviderException(
219: "TabContainerProvider.getSelectedTabs():couldn't get selectedtabs",
220: te);
221: }
222: return tabs;
223: }
224:
225: /**
226: * Gets the List of available tab topics.
227: *
228: * @return The list of available tabs, a list of UnmodifiableTabs.
229: *
230: * @exception ProviderException If the list of available tabs cannot be
231: * returned.
232: *
233: * @see com.sun.portal.providers.containers.jsp.tab.UnmodifiableTab
234: */
235: public List getAvailableTabs() throws ProviderException {
236: List tabs = new ArrayList();
237: try {
238: tabs = tabdata.getAvailableTabs();
239: } catch (TabException te) {
240: throw new ProviderException(
241: "TabContainerProvider.getAvailableTabs():couldn't get available tabs",
242: te);
243: }
244: return tabs;
245: }
246:
247: /**
248: * Gets the start tab, the tab to be displayed when the user logs in.
249: *
250: * @return The start tab, <code>UnmodifiableTab</code>.
251: *
252: * @exception ProviderException If the start tab cannot be
253: * returned.
254: *
255: * @see com.sun.portal.providers.containers.jsp.tab.UnmodifiableTab
256: */
257: public UnmodifiableTab getStartTab() throws ProviderException {
258: UnmodifiableTab t = null;
259: try {
260: t = tabdata.getStartTab();
261: } catch (TabException te) {
262: throw new ProviderException(
263: "TabContainerProvider.getStartTab():couldn't get start tab",
264: te);
265: }
266: return t;
267: }
268:
269: /**
270: * Gets the start tab Name, the name of the tab to be displayed when the user logs in.
271: *
272: * @return The start tab name as a <code>String</code>.
273: *
274: * @exception ProviderException If the start tab name cannot be
275: * returned.
276: */
277: public String getStartTabName() throws ProviderException {
278: try {
279: return tabdata.getStartTabName();
280: } catch (TabException te) {
281: throw new ProviderException(
282: "TabContainerProvider.getStartTabName():couldn't get start tab name ",
283: te);
284: }
285: }
286:
287: /**
288: * Gets the make tab, the tab spec to be used for 'Make My Own tab' creation by the user .
289: *
290: * @return The make tab, <code>UnmodifiableTab</code> .
291: *
292: * @exception ProviderException If the make tab cannot be
293: * returned.
294: *
295: * @see com.sun.portal.providers.containers.jsp.tab.UnmodifiableTab
296: */
297: public UnmodifiableTab getMakeTab() throws ProviderException {
298: UnmodifiableTab t = null;
299: try {
300: t = tabdata.getMakeTab();
301: } catch (TabException te) {
302: throw new ProviderException(
303: "TabContainerProvider.getMakeTab():couldn't get make tab",
304: te);
305: }
306: return t;
307: }
308:
309: /**
310: * Gets the make tab channel Name, the tab spec to be used for 'Make My Own tab' creation by the user .
311: *
312: * @return The make tab channel name as a <code>String</code>.
313: *
314: * @exception ProviderException If the make tab name cannot be
315: * returned.
316: */
317: public String getMakeTabName() throws ProviderException {
318: try {
319: return tabdata.getMakeTabName();
320: } catch (TabException te) {
321: throw new ProviderException(
322: "TabContainerProvider.getMakeTabName():couldn't get make tab name ",
323: te);
324: }
325: }
326:
327: /**
328: * Gets the make tab provider Name, the tab spec to be used for 'Make My Own tab' creation by the user .
329: *
330: * @return The make tab provider name as a <code>String</code>.
331: *
332: * @exception ProviderException If the make tab provider name cannot be
333: * returned.
334: */
335: public String getMakeTabProviderName() throws ProviderException {
336: try {
337: return tabdata.getMakeTabProviderName();
338: } catch (TabException te) {
339: throw new ProviderException(
340: "TabContainerProvider.getMakeTabProvider Name():couldn't get make tab provider name ",
341: te);
342: }
343: }
344:
345: /**
346: * Gets the selected tab Name, the current selected tab in the user's session .
347: *
348: * @return The selected tab name as a <code>String</code>.
349: *
350: * @exception ProviderException If the selected tab name cannot be
351: * returned.
352: *
353: */
354: public String getSelectedTabName() throws ProviderException {
355: String name = null;
356: try {
357: name = tabdata.getSelectedTabName();
358: } catch (TabException te) {
359: throw new ProviderException(
360: "TabContainerProvider.getSelectedTabName():couldn't get the selected tab name",
361: te);
362: }
363: return name;
364: }
365:
366: /**
367: * Gets the selected tab, the current selected tab in the user's session .
368: *
369: * This method implements the semantics of <code>getSelectedChannels()</code>
370: * in ContainerProvider and gets the active tab on the portal page.
371: *
372: * @return The selected tab, <code>UnmodifiableTab</code>.
373: *
374: * @exception ProviderException If the selected tab cannot be
375: * returned.
376: *
377: * @see com.sun.portal.providers.containers.jsp.tab.UnmodifiableTab
378: * @see com.sun.portal.providers.containers.ContainerProvider
379: */
380: public UnmodifiableTab getSelectedTab() throws ProviderException {
381: UnmodifiableTab t = null;
382: try {
383: t = tabdata.getSelectedTab();
384: } catch (TabException te) {
385: throw new ProviderException(
386: "TabContainerProvider.getSelectedTab():couldn't get selected tab",
387: te);
388: }
389: return t;
390: }
391:
392: /**
393: * Gets a tab.
394: * This method returns an instance of the <code>UnmodifiableTab</code> for the named channel.
395: *
396: * @param name. The name of the channel for which the tab Object is requested.
397: *
398: * @return The tab, <code>UnmodifiableTab</code>.
399: *
400: * @exception ProviderException If the tab cannot be
401: * returned.
402: *
403: * @see com.sun.portal.providers.containers.jsp.tab.UnmodifiableTab
404: */
405: public UnmodifiableTab getTab(String name) throws ProviderException {
406: UnmodifiableTab t = null;
407: try {
408: t = tabdata.getTab(name);
409: } catch (TabException te) {
410: throw new ProviderException(
411: "TabContainerProvider.getTab():couldn't get the tab:name="
412: + name, te);
413: }
414: return t;
415: }
416:
417: /**
418: * Sets a tab.
419: *
420: * @param ModifiableTab. Tab that needs to be set.
421: *
422: * This method adds the ModifiableTab to the selected tabs list.
423: *
424: * @exception ProviderException If the tab cannot be set
425: *
426: * @see com.sun.portal.providers.containers.jsp.tab.UnmodifiableTab
427: * @see com.sun.portal.providers.containers.jsp.tab.ModifiableTab
428: */
429: public void setTab(ModifiableTab t) throws ProviderException {
430: setTab(t, false);
431: }
432:
433: /**
434: * Sets a tab.
435: *
436: * @param ModifiableTab. Tab that needs to be set.
437: * @param selected. if true Sets the tab to the current
438: * selected tab on the user's desktop.
439: *
440: * This method adds the ModifiableTab to the selected tabs list
441: *
442: * @exception ProviderException If the tab cannot be set
443: *
444: * @see com.sun.portal.providers.containers.jsp.tab.UnmodifiableTab
445: * @see com.sun.portal.providers.containers.jsp.tab.ModifiableTab
446: */
447: public void setTab(ModifiableTab t, boolean selected)
448: throws ProviderException {
449: try {
450: tabdata.setTab(t, selected);
451: } catch (TabException te) {
452: throw new ProviderException(
453: "TabContainerProvider.setTab():couldn't set the tab",
454: te);
455: }
456: }
457:
458: /**
459: * Sets the start tab Name, the name of the tab to be displayed when the user logs in.
460: *
461: * This method sets the current selected tab name in the user's session to the start tab.
462: *
463: * @exception ProviderException If the start tab name cannot be
464: * returned.
465: *
466: */
467: public void setStartTabName() throws ProviderException {
468: setStartTabName(getSelectedTabName());
469: }
470:
471: /**
472: * Sets the start tab Name, the name of the tab to be displayed when the user logs in.
473: *
474: * @param UnmodifiableTab.Whose tab name needs to be set as the start tab name.
475: *
476: * This method sets the start tab name to the name of UnmodifiableTab that was passed in.
477: *
478: * @exception ProviderException If the start tab name cannot be set
479: *
480: * @see com.sun.portal.providers.containers.jsp.tab.UnmodifiableTab
481: */
482: public void setStartTabName(UnmodifiableTab t)
483: throws ProviderException {
484: setStartTabName(t.getName());
485: }
486:
487: /**
488: * Sets the start tab Name, the name of the tab to be displayed when the user logs in.
489: *
490: * @param name. The name of the channel which needs to be set as the start tab.
491: * This method sets the start tab to the name passed in..
492: *
493: * @exception ProviderException If the start tab name cannot be set.
494: *
495: */
496: public void setStartTabName(String name) throws ProviderException {
497: try {
498: tabdata.setStartTabName(name);
499: } catch (TabException te) {
500: throw new ProviderException(
501: "TabContainerProvider.setStartTabName():attempt to set start to non-existent tab",
502: te);
503: }
504: }
505:
506: /**
507: * Sets the selected tab Name in the session.
508: *
509: * @param ModifiableTab.Whose tab name needs to be set as the selected tab name.
510: *
511: * This method sets the active tab name on the user's desktop to the name of
512: * ModifiableTab that was passed in.
513: *
514: * @exception ProviderException If the start tab name cannot be set
515: *
516: * @see com.sun.portal.providers.containers.jsp.tab.ModifiableTab
517: */
518: public void setSelectedTab(ModifiableTab t)
519: throws ProviderException {
520: setSelectedTabName(t.getName());
521: }
522:
523: /**
524: * Sets the selected tab Name in the session
525: *
526: * @param tabName. The name of the channel which needs to be set as the selected tab.
527: *
528: * This method sets the active tab on the user's desktop
529: * to the name passed in..
530: *
531: * @exception ProviderException If the selected tab name cannot be set.
532: *
533: */
534: public void setSelectedTabName(String tabName)
535: throws ProviderException {
536: try {
537: tabdata.setSelectedTabName(tabName);
538: } catch (TabException te) {
539: throw new ProviderException(
540: "TabContainerProvider.setSelectedTabName():attempt to set selected to non-existent tab",
541: te);
542: }
543: }
544:
545: public StringBuffer getContent(HttpServletRequest req,
546: HttpServletResponse res) throws ProviderException {
547: //
548: // request to change the selected?
549: //
550: String selected = req.getParameter(getName() + ".setSelected");
551: if ((selected != null) && (selected.length() > 0)) {
552: setSelectedTabName(selected);
553: }
554:
555: return super .getContent(req, res);
556: }
557:
558: /**
559: * Process a form for this provider.
560: * This method is called to process form data associated with the
561: * tab container provider. Typically, this method is called to process the edit page
562: * generated from the getEdit() method. Usually, the client calling
563: * this method on a provider object is the desktop servlet.
564: * <p>
565: * Form data, passed into this method in the request, has been decoded into
566: * Unicode.
567: * <p>
568: * When the desktop servlet receives a request where the action is
569: * "process", it looks at the
570: * parameters to identify which provider will handle the action, through
571: * this method. The request passed in contains the parameters.
572: * <p>
573: * After calling this method, the desktop servlet will re-direct to the URL
574: * returned from this method. Therefore, the result of a provider post
575: * can be any desktop serlvet action, or the content of an arbitrary URL.
576: * For more information on constructing desktop serlvet URLs, see
577: * <code>DesktopSerlvet</code>.
578: *
579: *
580: * @param request An HttpServletRequest that contains
581: * information related to this
582: * request for content.
583: *
584: * @param response An HttpServletResponse that allows the
585: * provider to influence the
586: * overall response for the desktop page (besides generating the content).
587: *
588: * @exception ProviderException If there was an error processing
589: * the edit form. How this exception is handled is up to the client of the
590: * provider object.
591: *
592: * @return The URL that the iPS desktop will re-direct to. A value
593: * of null should indicate to the client that it should return to its
594: * default view.
595: *
596: * @see com.sun.portal.providers.Provider#getEdit
597: * @see com.sun.portal.providers.Provider#isEditable
598: * @see com.sun.portal.providers.InvalidEditFormDataException
599: * @see com.sun.portal.desktop.DesktopServlet
600: */
601: public URL processEdit(HttpServletRequest req,
602: HttpServletResponse res) throws ProviderException {
603:
604: if (isSetTabRequest(req)) {
605: setSelectedTab(req);
606: return getDesktopURL(req);
607: }
608:
609: URL url = null;
610: //Check whether request is for make a new tab
611: String makeparam = req.getParameter(getName() + ".make");
612: if ((makeparam != null) && (makeparam.equals("make"))) {
613: //
614: //
615: // try to "make new tab ..."
616: //
617: Map results = new HashMap();
618: try {
619: tabdata.makeNewTab(req, results);
620: if ((Boolean) results.get("make") != null) {
621: boolean make = ((Boolean) results.get("make"))
622: .booleanValue();
623: if (make) {
624: ModifiableTab tab = (ModifiableTab) results
625: .get("tab");
626: url = getContentURL(tab, req);
627: }
628: }
629: } catch (InvalidEditFormDataException e) {
630: if (logger.isLoggable(Level.SEVERE))
631: logger.log(Level.SEVERE, "PSDT_CSPPCJTB0001", e);
632: String error = getProviderContext().encodeURLParameter(
633: e.getMessage());
634: StringBuffer args = new StringBuffer(64);
635: args.append("?action=edit&provider=").append(getName())
636: .append("&error=").append(error).append(
637: "&page=make");
638:
639: String inputName = (String) results.get("inputTabName");
640: if (inputName != null) {
641: args.append("&inputTabName=").append(
642: getProviderContext().encodeURLParameter(
643: inputName));
644: }
645:
646: inputName = (String) results.get("inputDescName");
647: if (inputName != null) {
648: args.append("&inputDescName=").append(
649: getProviderContext().encodeURLParameter(
650: inputName));
651: }
652:
653: try {
654: url = new URL(getProviderContext().getDesktopURL(
655: req)
656: + args.toString());
657: } catch (MalformedURLException me) {
658: if (logger.isLoggable(Level.SEVERE))
659: logger.log(Level.SEVERE, "PSDT_CSPPCJTB0002",
660: url);
661: return null;
662: }
663:
664: }
665:
666: } else {
667: //
668: // process remove/rename
669: //
670: try {
671: url = tabdata.removeRenameTab(req);
672: } catch (TabException te) {
673: throw new ProviderException(
674: "TabContainerProvider.processEdit():couldn't remove/rename tab",
675: te);
676: } catch (InvalidEditFormDataException e) {
677: if (logger.isLoggable(Level.SEVERE))
678: logger.log(Level.SEVERE, "PSDT_CSPPCJTB0001", e);
679: String error = getProviderContext().encodeURLParameter(
680: e.getMessage());
681: StringBuffer args = new StringBuffer(64);
682: args.append("?action=edit&provider=").append(getName())
683: .append("&error=").append(error);
684:
685: try {
686: url = new URL(getProviderContext().getDesktopURL(
687: req)
688: + args.toString());
689: } catch (MalformedURLException me) {
690: if (logger.isLoggable(Level.SEVERE))
691: logger.log(Level.SEVERE, "PSDT_CSPPCJTB0002",
692: url);
693: return null;
694: }
695:
696: }
697:
698: }
699:
700: return url;
701: }
702:
703: /**
704: * Gets the Tab URL.
705: * This method gets the tab url used to switch the selected tab on the user's desktop.
706: *
707: * @param <code>UnmodifiableTab</code> tab. The tab used in generating the <code>URL</code>
708: * to be used to switch the selected tab to the passed in tab on the user's desktop.
709: *
710: * @param req An HttpServletRequest that contains
711: * information related to this
712: * request for content.
713: *
714: * @return The URL that is used for tab switching on the desktop.
715: *
716: * @exception ProviderException If the Tab URL cannot be generated.
717: */
718: public URL getTabURL(UnmodifiableTab tab, HttpServletRequest req)
719: throws ProviderException {
720: URL url = null;
721: try {
722: url = tabdata.getTabURL(tab, req);
723: } catch (TabException te) {
724: throw new ProviderException(
725: "TabContainerProvider.processEdit():couldn't get the desktop URL",
726: te);
727: }
728: return url;
729: }
730:
731: /**
732: * Removes the tab.
733: * @param name. Name of the tab to be removed.
734: *
735: * This method removes the tab from the selected channels list if predefined
736: * and removes the tab from the selected and available lists and deletes the
737: * corresponding table container if user created.
738: *
739: * @exception ProviderException If the tab cannot be removed.
740: */
741:
742: public void removeTab(String name) throws ProviderException {
743: try {
744: tabdata.removeTab(name);
745: } catch (TabException te) {
746: throw new ProviderException(
747: "TabContainerProvider.removeTab():couldn't remove tab from the selected tab",
748: te);
749: }
750: }
751:
752: /**
753: * Adds the tab back to the desktop that has been removed before
754: *
755: * @param name. Name of the tab.
756: *
757: * @param title. displayname of the tab.
758: *
759: * @exception ProviderException If the tab cannot be added.
760: *
761: */
762: public void addTab(String name, String title)
763: throws ProviderException {
764: try {
765: tabdata.addTab(name, title);
766: } catch (TabException te) {
767: throw new ProviderException(
768: "TabContainerProvider.addTab():couldn't add tab to the selected tab",
769: te);
770: }
771: }
772:
773: /**
774: * Gets the ContentPage URL.
775: *
776: * @param <code>ModifiableTab</code> tab. The tab used in generating the <code>URL</code>
777: * to be used to redirect to when the
778: * user is making a tab from scratch in the Make New Tab Page..
779: *
780: * @param req An HttpServletRequest that contains
781: * information related to this
782: * request for content.
783: *
784: * @return The URL that the desktop will redirect to when the
785: * user is making a tab from scratch in the Make New Tab Page.
786: *
787: * @exception ProviderException If the ContentPage URL cannot be generated.
788: */
789:
790: public URL getContentURL(ModifiableTab tab, HttpServletRequest req)
791: throws ProviderException {
792: URL url = null;
793: String charset = getProviderContext().getCharset();
794:
795: //---------This part of the code is only to make the (tab read only) change backward compatible----
796: int version;
797: boolean newInstallation;
798: boolean isDisplayNew;
799: try {
800: String makeTabChannel = this
801: .getStringProperty("makeTabChannel");
802: version = getProviderContext().getProviderVersion(
803: makeTabChannel);
804: File file = getProviderContext().getTemplatePath(
805: makeTabChannel, "contentLayoutBarCombined.jsp");
806: if (file == null) {
807: newInstallation = false;
808: } else {
809: newInstallation = true;
810: }
811: } catch (ProviderContextException pce) {
812: throw new ProviderException(pce.getMessage());
813: }
814: if (newInstallation && (version > 2)) {
815: isDisplayNew = true;
816: } else {
817: isDisplayNew = false;
818: }
819: //---------------------------------------------------------------------------------------------
820:
821: //old url
822: if (!isDisplayNew) {
823: String contentChannel = getStringProperty("contentChannel");
824: try {
825: StringBuffer urlbuffer = new StringBuffer(
826: getContainerProviderContext()
827: .getDesktopURL(req));
828: urlbuffer.append("?action=edit&provider=");
829: urlbuffer.append(contentChannel);
830: urlbuffer.append("&container=");
831: urlbuffer.append(tab.getName());
832: urlbuffer.append("&selected=");
833: urlbuffer.append(getProviderContext()
834: .encodeURLParameter(tab.getDisplayname()));
835: url = new URL(urlbuffer.toString());
836: } catch (MalformedURLException me) {
837: throw new ProviderException(
838: "TabContainerProvider.getContentURL():couldn't create the url",
839: me);
840: }
841: //new url
842: } else if (isDisplayNew) {
843: String editContainerName = getStringProperty("editContainerName");
844: String containerName = tab.getName();
845: try {
846: StringBuffer urlbuffer = new StringBuffer(
847: getContainerProviderContext()
848: .getDesktopURL(req));
849: urlbuffer.append("?action=edit&provider=");
850: urlbuffer.append(editContainerName);
851: urlbuffer.append("&targetprovider=");
852: urlbuffer.append(containerName);
853: urlbuffer.append("&containerName=");
854: urlbuffer.append(containerName);
855: urlbuffer.append("&selected=");
856: urlbuffer.append(getProviderContext()
857: .encodeURLParameter(tab.getDisplayname()));
858: urlbuffer.append("&editMode=content");
859: url = new URL(urlbuffer.toString());
860: } catch (MalformedURLException me) {
861: throw new ProviderException(
862: "TabContainerProvider.getContentURL():couldn't create the url",
863: me);
864: }
865: }
866: return url;
867: }
868:
869: /**
870: * Gets the window state of the channel.
871: *
872: * This method just returns ProviderWindowStates.NORMAL.
873: *
874: * @param channelName channel for which the window state is requested.
875: *
876: * @return window state
877: * @exception ProviderException
878: * @see com.sun.portal.providers.containers.ProviderWindowStates#NORMAL
879: */
880: public int getWindowState(String channelName)
881: throws ProviderException {
882: return ProviderWindowStates.NORMAL;
883: }
884:
885: /**
886: * Sets the window state of a channel.
887: *
888: * This method currently has no effect and throws
889: * UnsupportedWindowStateException if windowState passed is not
890: * ProviderWindowStates#NORMAL.
891: *
892: * Subclasses that wish to allow setting a WindowState should
893: * override this method.
894: * @param channelName channel for which the window state needs to be set
895: * @param windowState The new window state
896: *
897: * @exception UnsupportedWindowStateException.
898: */
899: public void setWindowState(String channelName, int windowState)
900: throws UnsupportedWindowStateException {
901: if (windowState != ProviderWindowStates.NORMAL) {
902: throw new UnsupportedWindowStateException(
903: "JSPTabContainerProvider.setWindowState(): windowState passed in is not supported");
904: }
905: }
906:
907: /**
908: * Gets the supported window states.
909: *
910: * @return Supported Window States as an integer array containing
911: * <code>ProviderWindowStates.NORMAL</code>
912: *
913: * @exception ProviderException If the window states cannot be returned.
914: *
915: * @see com.sun.portal.providers.containers.ProviderWindowStates#NORMAL
916: * @see com.sun.portal.providers.containers.jsp.tab.JSPTabContainerProvider#getWindowState()
917: * @see com.sun.portal.providers.containers.jsp.tab.JSPTabContainerProvider#setWindowState()
918: */
919: public int[] getSupportedWindowStates() throws ProviderException {
920: return supportedStates;
921: }
922:
923: protected URL getDesktopURL(HttpServletRequest req) {
924:
925: URL url = null;
926: String sUrl = null;
927:
928: try {
929: sUrl = getProviderContext().getDesktopURL(req);
930: url = new URL(sUrl);
931: } catch (MalformedURLException me) {
932: logger.log(Level.SEVERE, "PSDT_CSPPCJTB0002", sUrl);
933: }
934:
935: return url;
936: }
937:
938: public boolean isSetTabRequest(HttpServletRequest req) {
939: String tabName = req.getParameter(channel + ".setSelected");
940: return (tabName != null) && (tabName.length() > 0);
941: }
942:
943: protected void setSelectedTab(HttpServletRequest req)
944: throws ProviderException {
945: String tabName = req.getParameter(channel + ".setSelected");
946:
947: if ((tabName != null) && (tabName.length() > 0)) {
948: setSelectedTabName(tabName);
949: getProviderContext().contentChanged(getName());
950: }
951: }
952: }
|