01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.desktop.taglib.container.table;
06:
07: import javax.servlet.jsp.JspException;
08: import java.util.Map;
09: import java.util.List;
10: import java.util.Iterator;
11: import com.sun.portal.desktop.taglib.DesktopTaglibException;
12: import com.sun.portal.providers.util.ProviderProperties;
13: import com.sun.portal.providers.ProviderException;
14: import com.sun.portal.providers.containers.jsp.table.JSPTableContainerProvider;
15:
16: public class GetDetachedTag extends BaseTableContainerTagSupport {
17: public int doStartTag() throws JspException {
18: Boolean result = null;
19: JSPTableContainerProvider tcp = (JSPTableContainerProvider) getCurrentObj();
20:
21: Map channelsIsDetached = getMapProperty(_ChannelsIsDetached,
22: ProviderProperties.CHANNELS_IS_DETACHED);
23: boolean dIsDetached = getBooleanProperty(_dChannelsIsDetached,
24: ProviderProperties.DEFAULT_CHANNEL_IS_DETACHED);
25:
26: List allChannels = null;
27: List allAvailableChannels = null;
28: try {
29: allChannels = tcp.getSelectedChannels();
30: allAvailableChannels = tcp.getAvailableChannels();
31: } catch (ProviderException pe) {
32: throw new DesktopTaglibException(pe);
33: }
34:
35: for (int i = 0; i < allChannels.size(); i++) {
36: String selectedChannel = (String) allChannels.get(i);
37: if (!allAvailableChannels.contains(selectedChannel)) {
38: channelsIsDetached.remove(selectedChannel);
39: }
40: }
41:
42: // return all the channels if channelsIsDetached is empty
43: // and if the default is to detach all the channels
44: if (channelsIsDetached.isEmpty() && dIsDetached) {
45: for (int i = 0; i < allChannels.size(); i++) {
46: String channel = (String) allChannels.get(i);
47: if (allAvailableChannels.contains(channel)) {
48: channelsIsDetached.put(channel, Boolean.TRUE);
49: }
50: }
51: } else {
52: //remove the channel entries not present in selected channels
53: boolean unreferencedChannel = false;
54: Iterator i = channelsIsDetached.keySet().iterator();
55: while (i.hasNext()) {
56: String channel = (String) i.next();
57: if (!allChannels.contains(channel)) {
58: channelsIsDetached.remove(channel);
59: unreferencedChannel = true;
60: }
61: }
62:
63: if (unreferencedChannel) {
64: try {
65: tcp.setMapProperty(
66: ProviderProperties.CHANNELS_IS_DETACHED,
67: channelsIsDetached);
68: } catch (ProviderException pe) {
69: throw new DesktopTaglibException(pe);
70: }
71: }
72: }
73:
74: processResult(channelsIsDetached.keySet());
75: return SKIP_BODY;
76: }
77: }
|