0001: /*
0002: * Copyright 2002 Sun Microsystems, Inc. All
0003: * rights reserved. Use of this product is subject
0004: * to license terms. Federal Acquisitions:
0005: * Commercial Software -- Government Users
0006: * Subject to Standard License Terms and
0007: * Conditions.
0008: *
0009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0010: * are trademarks or registered trademarks of Sun Microsystems,
0011: * Inc. in the United States and other countries.
0012: */
0013: package com.sun.portal.providers.containers.jsp.table;
0014:
0015: import java.util.*;
0016: import java.util.logging.Level;
0017: import java.util.logging.LogRecord;
0018: import java.util.logging.Logger;
0019: import java.net.URL;
0020: import java.net.URLEncoder;
0021:
0022: import javax.servlet.http.HttpServletRequest;
0023: import javax.servlet.http.HttpServletResponse;
0024:
0025: import com.sun.portal.providers.containers.JSPContainerProviderAdapter;
0026: import com.sun.portal.providers.containers.ProviderWindowStates;
0027: import com.sun.portal.providers.containers.UnsupportedWindowStateException;
0028: import com.sun.portal.providers.Provider;
0029: import com.sun.portal.providers.ProviderException;
0030: import com.sun.portal.providers.ProviderWidths;
0031:
0032: import com.sun.portal.providers.util.Layout;
0033: import com.sun.portal.providers.util.UnknownLayoutException;
0034:
0035: import com.sun.portal.providers.util.PropertyUtil;
0036: import com.sun.portal.providers.util.ProviderOrder;
0037: import com.sun.portal.providers.util.ProviderProperties;
0038:
0039: import com.sun.portal.providers.context.ProviderContext;
0040: import com.sun.portal.providers.context.ContainerProviderContext;
0041: import com.sun.portal.providers.context.ProviderContextException;
0042:
0043: import com.sun.portal.desktop.util.Integers;
0044: import com.sun.portal.desktop.ubt.DesktopEvents;
0045: import com.sun.portal.desktop.ubt.ProviderLogRecord;
0046: import com.sun.portal.ubt.UBTEvent;
0047: import com.sun.portal.ubt.UBTLogField;
0048: import com.sun.portal.ubt.UBTLogManager;
0049: import com.sun.portal.log.common.PortalLogger;
0050:
0051: /**
0052: * This class provides the implementation for JSPTableContainerProvider
0053: * and extends <code>JSPContainerProviderAdapter</code>
0054: *
0055: * The table container facilitates the aggregation of multiple channels
0056: * into a single display. JSPTableContainerProvider aggregates channels into HTML
0057: * rows and Columns.
0058: *
0059: * @see com.sun.portal.providers.containers.JSPContainerProviderAdapter
0060: */
0061: public class JSPTableContainerProvider extends
0062: JSPContainerProviderAdapter {
0063:
0064: private static Logger logger = PortalLogger
0065: .getLogger(JSPTableContainerProvider.class);
0066:
0067: /**
0068: * Left column in the TableContainerProvider
0069: */
0070: public final static int LEFT = 1;
0071:
0072: /**
0073: * Right column in the TableContainerProvider
0074: */
0075: public final static int RIGHT = 2;
0076:
0077: /**
0078: * Center column in the TableContainerProvider
0079: */
0080: public final static int CENTER = 3;
0081:
0082: /**
0083: * Top Row in the TableContainerProvider
0084: */
0085: public final static int TOP = 4;
0086:
0087: /**
0088: * Bottom Row in the TableContainerProvider
0089: */
0090: public final static int BOTTOM = 5;
0091:
0092: private static int[] supportedStates = new int[3];
0093: //Category Content
0094: public static final String CATEGORY_CONTENT = "categoryContent";
0095: static {
0096: supportedStates[0] = ProviderWindowStates.MINIMIZE;
0097: supportedStates[1] = ProviderWindowStates.NORMAL;
0098: supportedStates[2] = ProviderWindowStates.MAXIMIZE;
0099: }
0100:
0101: /**
0102: * Initializes the JSPTableContainerProvider.
0103: *
0104: * @param n The unique indentifying name for this channel.
0105: * @param httpreq The servlet request.
0106: * @exception ProviderException if JSPProvider.init throws an exception
0107: * @see com.sun.portal.providers.jsp.JSPProvider#init
0108: **/
0109:
0110: public void init(String n, HttpServletRequest httpreq)
0111: throws ProviderException {
0112: super .init(n, httpreq);
0113:
0114: ContainerProviderContext cpc = getContainerProviderContext();
0115:
0116: boolean parallelChannelsInit = false;
0117:
0118: try {
0119: parallelChannelsInit = cpc.getBooleanProperty(getName(),
0120: ProviderProperties.PARALLEL_CHANNELS_INIT);
0121: } catch (ProviderContextException pce) {
0122:
0123: if (logger.isLoggable(Level.WARNING))
0124: logger.log(Level.WARNING, "PSDT_CSPPCJT0001",
0125: ProviderProperties.PARALLEL_CHANNELS_INIT);
0126: // error not fatal, keep going
0127: }
0128: if (parallelChannelsInit) {
0129: cpc.initProviders(httpreq, n, getSelectedChannels(), 0);
0130: }
0131: }
0132:
0133: /**
0134: * Gets the layout for this container.
0135: * The desktop calls this method when the front page is drawn, and when
0136: * the layout page is drawn.
0137: *
0138: * @return The layout; either <code>LAYOUT_THIN_THICK</code>
0139: * or <code>LAYOUT_THICK_THIN</code> or <code>LAYOUT_THIN_THICK_THIN</code>
0140: * or <code>LAYOUT_UNKNOWN</code>
0141: * @see com.sun.portal.providers.util.Layout#LAYOUT_THIN_THICK
0142: * @see com.sun.portal.providers.util.Layout#LAYOUT_THICK_THIN
0143: * @see com.sun.portal.providers.util.Layout#LAYOUT_THIN_THICK_THIN
0144: * @see com.sun.portal.providers.util.Layout#LAYOUT_UNKNOWN
0145: * @see com.sun.portal.providers.containers.jsp.table.JSPTableContainerProvider#setLayout
0146: */
0147: public int getLayout() throws ProviderException {
0148: int layout = getIntegerProperty(ProviderProperties.LAYOUT);
0149: if ((layout < Layout.LAYOUT_THIN_THICK)
0150: || (layout > Layout.LAYOUT_THIN_THIN_THIN))
0151: throw new UnknownLayoutException(
0152: "TableContainerProvider:getLayout");
0153: return layout;
0154: }
0155:
0156: /**
0157: * Sets the layout for this container.
0158: * The desktop calls this method when the user changes the layout
0159: * in the layout page.
0160: * @param lo; new layout either <code>LAYOUT_THIN_THICK</code>
0161: * or <code>LAYOUT_THICK_THIN</code> or <code>LAYOUT_THIN_THICK_THIN</code>
0162: * or <code>LAYOUT_UNKNOWN</code>
0163: * @see com.sun.portal.providers.util.Layout#LAYOUT_THIN_THICK
0164: * @see com.sun.portal.providers.util.Layout#LAYOUT_THICK_THIN
0165: * @see com.sun.portal.providers.util.Layout#LAYOUT_THIN_THICK_THIN
0166: * @see com.sun.portal.providers.util.Layout#LAYOUT_UNKNOWN
0167: * @see com.sun.portal.providers.containers.jsp.table.JSPTableContainerProvider#setLayout
0168: */
0169: public void setLayout(int lo) throws ProviderException {
0170: setIntegerProperty(ProviderProperties.LAYOUT, lo);
0171: }
0172:
0173: /**
0174: * Gets the timeout for this container, in seconds.
0175: * The number of seconds to wait to fetch the content
0176: * for the selected channels when the front page is drwan.
0177: *
0178: * @return The number of seconds the front page should wait before
0179: * displaying a <code>Content Not available</code> message for a channel
0180: */
0181: public int getTimeout() throws ProviderException {
0182: int timeout = getIntegerProperty(ProviderProperties.TIMEOUT);
0183: return timeout;
0184: }
0185:
0186: /**
0187: * Constructs the channel into three columns, the left column, the
0188: * center column, and the right column. Channel names are put into
0189: * each column list and the list objects are put in a Map.
0190: *
0191: * @param req An HttpServletRequest that contains information related to this
0192: * request for content.
0193: *
0194: * @return Map. Map of left, center, right, fullTop and fullBottom lists
0195: * Each list contains the channel names in that column.
0196: *
0197: * @exception ProviderException If the columns Map cannot be returned
0198: */
0199: public Map setupColumns(HttpServletRequest req)
0200: throws ProviderException {
0201: ContainerProviderContext cpc = getContainerProviderContext();
0202: ProviderContext pc = getProviderContext();
0203: List selectedChannels = getSelectedChannels();
0204: List providerOrder = ProviderOrder.order(selectedChannels,
0205: getName(), cpc, req);
0206: List leftList = new ArrayList();
0207: List centerList = new ArrayList();
0208: List rightList = new ArrayList();
0209: List fullTopList = new ArrayList();
0210: List fullBottomList = new ArrayList();
0211: Map channelsColumn = null;
0212: String defaultChannelColumn = null;
0213:
0214: try {
0215: channelsColumn = pc.getCollectionProperty(getName(),
0216: ProviderProperties.CHANNELS_COLUMN);
0217: defaultChannelColumn = pc.getStringProperty(getName(),
0218: ProviderProperties.DEFAULT_CHANNEL_COLUMN);
0219: } catch (ProviderContextException pce) {
0220: throw new ProviderException(
0221: "JSPTableContainerProvider.setupColumns(): Could not get "
0222: + ProviderProperties.CHANNELS_COLUMN, pce);
0223: }
0224: int layout = getLayout();
0225:
0226: List allProviders = getAvailableChannels();
0227:
0228: for (int i = 0; i < providerOrder.size(); i++) {
0229: String providerName = (String) providerOrder.get(i);
0230:
0231: // Check if the selected channel is also in the available list
0232: if (!allProviders.contains(providerName)) {
0233: continue;
0234: }
0235:
0236: Provider p = null;
0237:
0238: p = cpc.getProvider(req, getName(), providerName);
0239:
0240: if (p == null || !p.isPresentable(req)) {
0241: continue;
0242: }
0243: int column = -1;
0244: int width = -1;
0245: String val = null;
0246: try {
0247: width = p.getWidth();
0248: val = PropertyUtil.getStringValueFromMap(
0249: channelsColumn, providerName,
0250: defaultChannelColumn);
0251: column = Integer.parseInt(val);
0252:
0253: if (logger.isLoggable(Level.FINER))
0254: logger.log(Level.FINER, "PSDT_CSPPCJT0002", ""
0255: + column);
0256: } catch (NumberFormatException e) {
0257: if (logger.isLoggable(Level.WARNING))
0258: logger.log(Level.WARNING, "PSDT_CSPPCJT0003", val);
0259: } catch (Throwable e) {
0260: if (logger.isLoggable(Level.SEVERE)) {
0261: LogRecord rec = new LogRecord(Level.SEVERE,
0262: "PSDT_CSPPCJT0004");
0263: rec.setLoggerName(logger.getName());
0264: String[] param = { p.getName() };
0265: rec.setParameters(param);
0266: rec.setThrown(e);
0267: logger.log(rec);
0268: }
0269: }
0270:
0271: if (width != -1) {
0272: switch (width) {
0273: case ProviderWidths.WIDTH_THIN:
0274: switch (layout) {
0275: case Layout.LAYOUT_THIN_THICK:
0276: leftList.add(providerName);
0277: break;
0278: case Layout.LAYOUT_THICK_THIN:
0279: rightList.add(providerName);
0280: break;
0281: case Layout.LAYOUT_THIN_THICK_THIN:
0282: if (column == 1) {
0283: leftList.add(providerName);
0284: } else {
0285: rightList.add(providerName);
0286: }
0287: break;
0288:
0289: default:
0290: leftList.add(providerName);
0291: break;
0292: }
0293: break;
0294:
0295: case ProviderWidths.WIDTH_THICK:
0296: switch (layout) {
0297: case Layout.LAYOUT_THIN_THICK:
0298: rightList.add(providerName);
0299: break;
0300: case Layout.LAYOUT_THICK_THIN:
0301: leftList.add(providerName);
0302: break;
0303: case Layout.LAYOUT_THIN_THICK_THIN:
0304: centerList.add(providerName);
0305: break;
0306: default:
0307: rightList.add(providerName);
0308: break;
0309: }
0310: break;
0311:
0312: case ProviderWidths.WIDTH_FULL_TOP:
0313: fullTopList.add(providerName);
0314: break;
0315:
0316: case ProviderWidths.WIDTH_FULL_BOTTOM:
0317: fullBottomList.add(providerName);
0318: break;
0319:
0320: default:
0321: if (logger.isLoggable(Level.SEVERE))
0322: logger.log(Level.SEVERE, "PSDT_CSPPCJT0005",
0323: providerName);
0324: break;
0325: }
0326: }
0327: }
0328:
0329: Map columnMap = new HashMap();
0330:
0331: columnMap.put(Integers.get(LEFT), leftList);
0332: columnMap.put(Integers.get(RIGHT), rightList);
0333: columnMap.put(Integers.get(CENTER), centerList);
0334: columnMap.put(Integers.get(TOP), fullTopList);
0335: columnMap.put(Integers.get(BOTTOM), fullBottomList);
0336:
0337: return columnMap;
0338: }
0339:
0340: /**
0341: * Gets table's left,center,right width based of the table container's
0342: * layout property.
0343: * @param column. column for which the width is requested.
0344: * either <code>LEFT</code> or <code>RIGHT</code> or <code>Center</code>
0345: *
0346: * @return Column width. either left or right or center width.
0347: *
0348: * @exception ProviderException If the column width cannot be returned
0349: */
0350: public int getWidths(int column) throws ProviderException {
0351:
0352: int centerWidth = -1;
0353: int rightWidth = -1;
0354: int leftWidth = -1;
0355:
0356: ProviderContext pc = getProviderContext();
0357: int layout = getLayout();
0358: switch (layout) {
0359: case Layout.LAYOUT_THIN_THICK:
0360: leftWidth = 30;
0361: rightWidth = 70;
0362: break;
0363: case Layout.LAYOUT_THICK_THIN:
0364: rightWidth = 30;
0365: leftWidth = 70;
0366: break;
0367: case Layout.LAYOUT_THIN_THICK_THIN:
0368: rightWidth = 25;
0369: centerWidth = 50;
0370: leftWidth = 25;
0371: break;
0372: default:
0373: rightWidth = 30;
0374: leftWidth = 70;
0375: break;
0376: }
0377:
0378: switch (column) {
0379: case LEFT:
0380: return leftWidth;
0381: case RIGHT:
0382: return rightWidth;
0383: case CENTER:
0384: return centerWidth;
0385: default:
0386: if (logger.isLoggable(Level.SEVERE))
0387: logger.log(Level.SEVERE, "PSDT_CSPPCJT0006", ""
0388: + column);
0389: return -1;
0390: }
0391:
0392: }
0393:
0394: /**
0395: * Gets the column in which this channel should be displayed in.
0396: * The desktop calls this method when the front page is drawn, and when
0397: * the layout page is drawn.
0398: *
0399: * @param req An HttpServletRequest that contains information related to this
0400: * request for content.
0401: * @param channel Channel for which the column is requested
0402: * @return The column for this channel; either "1", "2", or "3".
0403: * @see com.sun.portal.providers.containers.jsp.table.JSPTableContainerProvider#setColumn
0404: */
0405: public String getColumn(HttpServletRequest req, String channel)
0406: throws ProviderException {
0407:
0408: return getChStringAttrFromMap(req, channel,
0409: ProviderProperties.CHANNELS_COLUMN, null, "1");
0410:
0411: }
0412:
0413: /**
0414: * Gets the row in which this channel should be displayed in.
0415: * The desktop calls this method when the front page is drawn, and when
0416: * the layout page is drawn.
0417: *
0418: * @param req An HttpServletRequest that contains information related to this
0419: * request for content.
0420: * @param channel Channel for which the row is requested
0421: * @return The row for this channel; either "1", "2", ....
0422: * @see com.sun.portal.providers.containers.jsp.table.JSPTableContainerProvider#setRow
0423: */
0424: public String getRow(HttpServletRequest req, String channel)
0425: throws ProviderException {
0426:
0427: return getChStringAttrFromMap(req, channel,
0428: ProviderProperties.CHANNELS_ROW, null, "1");
0429:
0430: }
0431:
0432: /**
0433: * Gets a string property from a map for the contained channel in the container
0434: *
0435: * @param req An HttpServletRequest that contains information related to this
0436: * request for content
0437: * @param channel.channel for which the property is requested.
0438: * @param mapKey. property name of the collection in the display profile
0439: * from which the string property is requested.
0440: * @param defKey. default property name in display profile for the property.
0441: * @param def. default value to return if the property cannot be returned.
0442: * @return <code>String</code> string property from map for the channel.
0443: */
0444: private String getChStringAttrFromMap(HttpServletRequest req,
0445: String channel, String mapKey, String defKey, String def)
0446: throws ProviderException {
0447: String defVal = null;
0448: Map mapVal = new HashMap();
0449: String val = def;
0450: ProviderContext pc = getProviderContext();
0451:
0452: try {
0453: mapVal = pc.getCollectionProperty(getName(), mapKey);
0454: if (defKey != null
0455: && pc.existsStringProperty(getName(), defKey)) {
0456: defVal = pc.getStringProperty(getName(), defKey);
0457: val = PropertyUtil.getStringValueFromMap(mapVal,
0458: channel, defVal);
0459: } else {
0460: val = PropertyUtil.getStringValueFromMap(mapVal,
0461: channel, def);
0462: }
0463: } catch (ProviderContextException pce) {
0464: throw new ProviderException(
0465: "JSPTableContainerProvider.getChStringAttrFromMap() ",
0466: pce);
0467: }
0468:
0469: return val;
0470:
0471: }
0472:
0473: /**
0474: * Sets the column for this channel to be displayed in.
0475: * Either 1, 2, or 3.
0476: * The desktop calls this method when the user changes the channel's
0477: * display column from the layout page.
0478: *
0479: * @param req An HttpServletRequest that contains information related to this
0480: * request for content.
0481: * @param channel Channel for which the column is to be set
0482: * @param column The new column.
0483: *
0484: * @see com.sun.portal.providers.containers.jsp.table.JSPTableContainerProvider#getColumn
0485: */
0486: public void setColumn(HttpServletRequest req, String channel,
0487: int column) throws ProviderException {
0488: setChStringAttrInMap(req, channel,
0489: ProviderProperties.CHANNELS_COLUMN, Integer
0490: .toString(column));
0491: }
0492:
0493: /**
0494: * Sets the row for this channel to be displayed in.
0495: * Either 1, 2,...
0496: * The desktop calls this method when the user changes the channel's
0497: * display row from the layout page.
0498: *
0499: * @param req An HttpServletRequest that contains information related to this
0500: * request for content.
0501: * @param channel Channel for which the row is to be set
0502: * @param row The new row.
0503: *
0504: * @see com.sun.portal.providers.containers.jsp.table.JSPTableContainerProvider#getRow
0505: */
0506: public void setRow(HttpServletRequest req, String channel, int row)
0507: throws ProviderException {
0508: setChStringAttrInMap(req, channel,
0509: ProviderProperties.CHANNELS_ROW, (new Integer(row))
0510: .toString());
0511: }
0512:
0513: /**
0514: * sets a string property in a map for the contained channel in the container
0515: *
0516: * @param req An HttpServletRequest that contains information related to this
0517: * request for content
0518: * @param channel.channel for which the property needs to be set.
0519: * @param mapKey. property name of the collection in the display profile
0520: * in which the string property is to be set.
0521: * @param value. The new value
0522: */
0523: private void setChStringAttrInMap(HttpServletRequest req,
0524: String channel, String mapKey, String value)
0525: throws ProviderException {
0526:
0527: ProviderContext pc = getProviderContext();
0528: try {
0529: Map mapVal = pc.getCollectionProperty(getName(), mapKey);
0530: String val = (String) mapVal.get(channel);
0531: if (val != null) {
0532: mapVal.remove(channel);
0533: }
0534: mapVal.put(channel, value);
0535: pc.setCollectionProperty(getName(), mapKey, mapVal);
0536: } catch (ProviderContextException pce) {
0537: throw new ProviderException(
0538: "JSPTableContainerProvider.setChStringAttrInMap() ",
0539: pce);
0540: }
0541: }
0542:
0543: /**
0544: * sets the empty page warning messages in the request.
0545: * This method is called when there are no selected channels
0546: * in the selected channel list for the container.
0547: * @param req An HttpServletRequest that contains information related to this
0548: * request for content
0549: */
0550: private void setupEmptyPage(HttpServletRequest req)
0551: throws ProviderException {
0552: StringBuffer content = new StringBuffer();
0553: ResourceBundle bundle = getResourceBundle();
0554: String warning = "WARNING: No provider is available!!";
0555:
0556: if (bundle != null) {
0557: warning = bundle
0558: .getString("warning_no_providers_available");
0559: }
0560:
0561: req.setAttribute("emptyPage", (Object) "true");
0562: req.setAttribute("errorMsg", (Object) warning);
0563:
0564: }
0565:
0566: /**
0567: * Processes data for this container.
0568: * This method is called to process data associated with the
0569: * provider.
0570: * <p>
0571: * When the desktop servlet receives a request where the action is
0572: * "process", it looks at the
0573: * parameters to identify which provider will handle the action, through
0574: * this method. The request passed in contains the parameters.
0575: * <p>
0576: * After calling this method, the desktop servlet will re-direct to the URL
0577: * returned from this method. Therefore, the result of a provider post
0578: * can be any desktop serlvet action, or the content of an arbitrary URL.
0579: * For more information on constructing desktop serlvet URLs, see
0580: * <code>DesktopSerlvet</code>.
0581: *
0582: *
0583: * @param request An HttpServletRequest that contains
0584: * information related to this
0585: * request for content.
0586: *
0587: * @param response An HttpServletResponse that allows the
0588: * provider to influence the
0589: * overall response for the desktop page (besides generating the content).
0590: *
0591: * @exception ProviderException If there was an error processing
0592: * the data. How this exception is handled is up to the client of the
0593: * provider object.
0594: *
0595: * @return The URL that the iPS desktop will re-direct to. A value
0596: * of null should indicate to the client that it should return to its
0597: * default view.
0598: *
0599: * @see com.sun.portal.desktop.DesktopServlet
0600: */
0601: public URL processEdit(HttpServletRequest req,
0602: HttpServletResponse res) throws ProviderException {
0603: String channelAction = req.getParameter(getName()
0604: + ".channelAction");
0605: String targetProvider = req.getParameter(getName()
0606: + ".targetProvider");
0607:
0608: ContainerProviderContext cpc = getContainerProviderContext();
0609: ProviderContext pc = getProviderContext();
0610: int IwindowState = getWindowState(targetProvider);
0611: try {
0612: if (channelAction != null) {
0613: Map channelsIsDetached = pc.getCollectionProperty(
0614: getName(),
0615: ProviderProperties.CHANNELS_IS_DETACHED);
0616:
0617: Map channelsIsMinimizable = getMapProperty(ProviderProperties.CHANNELS_IS_MINIMIZABLE);
0618: Map channelsIsMaximizable = getMapProperty(ProviderProperties.CHANNELS_IS_MAXIMIZABLE);
0619: Map channelsIsDetachable = getMapProperty(ProviderProperties.CHANNELS_IS_DETACHABLE);
0620: Map channelsIsRemovable = getMapProperty(ProviderProperties.CHANNELS_IS_REMOVABLE);
0621: boolean dIsMinimizable = getBooleanProperty(ProviderProperties.DEFAULT_CHANNEL_IS_MINIMIZABLE);
0622: boolean dIsMaximizable = getBooleanProperty(ProviderProperties.DEFAULT_CHANNEL_IS_MAXIMIZABLE);
0623: boolean dIsDetachable = getBooleanProperty(ProviderProperties.DEFAULT_CHANNEL_IS_DETACHABLE);
0624: boolean dIsRemovable = getBooleanProperty(ProviderProperties.DEFAULT_CHANNEL_IS_REMOVABLE);
0625:
0626: if (channelAction.equals("detach")) {
0627: boolean shouldDetach = PropertyUtil
0628: .getBooleanValueFromMap(
0629: channelsIsDetachable,
0630: targetProvider, dIsDetachable);
0631: if (shouldDetach) {
0632: // Channel is detached, turn the flag to true
0633: Boolean detach_value = new Boolean(true);
0634: channelsIsDetached.put(targetProvider,
0635: detach_value);
0636: pc
0637: .setCollectionProperty(
0638: getName(),
0639: ProviderProperties.CHANNELS_IS_DETACHED,
0640: channelsIsDetached);
0641: }
0642: } else if (channelAction.equals("attach")) {
0643: //only if its detachable, it can be attached. so use DETACHABLE PROPERTY
0644: boolean shouldDetach = PropertyUtil
0645: .getBooleanValueFromMap(
0646: channelsIsDetachable,
0647: targetProvider, dIsDetachable);
0648: if (shouldDetach) {
0649: // Channel is attached back, turn the flag to false
0650: Boolean detach_value = new Boolean(false);
0651: channelsIsDetached.put(targetProvider,
0652: detach_value);
0653: pc
0654: .setCollectionProperty(
0655: getName(),
0656: ProviderProperties.CHANNELS_IS_DETACHED,
0657: channelsIsDetached);
0658: }
0659: } else if (channelAction.equals("minimize")) {
0660: boolean shouldMinimize = PropertyUtil
0661: .getBooleanValueFromMap(
0662: channelsIsMinimizable,
0663: targetProvider, dIsMinimizable);
0664: if (shouldMinimize) {
0665: setWindowState(targetProvider,
0666: ProviderWindowStates.MINIMIZE);
0667: }
0668: } else if (channelAction.equals("maximize")) {
0669: setWindowState(targetProvider,
0670: ProviderWindowStates.NORMAL);
0671: } else if (channelAction.equals("truemaximize")) {
0672: boolean shouldMaximize = PropertyUtil
0673: .getBooleanValueFromMap(
0674: channelsIsMaximizable,
0675: targetProvider, dIsMaximizable);
0676: if (shouldMaximize) {
0677: setWindowState(targetProvider,
0678: ProviderWindowStates.MAXIMIZE);
0679: }
0680: } else if (channelAction.equals("remove")) {
0681: boolean shouldRemove = PropertyUtil
0682: .getBooleanValueFromMap(
0683: channelsIsRemovable,
0684: targetProvider, dIsRemovable);
0685: if (shouldRemove) {
0686: List userProviders = getSelectedChannels();
0687: userProviders.remove(targetProvider);
0688: setSelectedChannels(userProviders);
0689: if (channelsIsDetached
0690: .containsKey(targetProvider)) {
0691: Boolean detach_value = new Boolean(false);
0692: channelsIsDetached.put(targetProvider,
0693: detach_value);
0694: pc
0695: .setCollectionProperty(
0696: getName(),
0697: ProviderProperties.CHANNELS_IS_DETACHED,
0698: channelsIsDetached);
0699: }
0700: //make sure that maximized is not set to the removed channel.
0701: if (pc.getProviderVersion(getName()) > 1) {
0702: String maximizedChannel = getStringProperty(ProviderProperties.MAXIMIZED_CHANNEL);
0703: if (maximizedChannel
0704: .equalsIgnoreCase(targetProvider)) {
0705: setStringProperty(
0706: ProviderProperties.MAXIMIZED_CHANNEL,
0707: "");
0708: }
0709: }
0710: }
0711: }
0712:
0713: try {
0714: UBTLogManager manager = UBTLogManager.getInstance();
0715: if (manager.isUBTEnabled()) {
0716: UBTEvent usrClick = UBTEvent
0717: .getInstance(DesktopEvents.USER_CLICK_CHN);
0718: usrClick.put(UBTLogField.ACTION, channelAction);
0719: usrClick.put(UBTLogField.CHANNEL_NAME,
0720: targetProvider);
0721: usrClick
0722: .put(
0723: UBTLogField.WINDOW_STATE,
0724: IwindowState > ProviderWindowStates.NORMAL ? "Maximized"
0725: : (IwindowState < ProviderWindowStates.NORMAL ? "Minimized"
0726: : "Normal"));
0727: usrClick.put(UBTLogField.MODE, "View");
0728: usrClick.put(UBTLogField.PROVIDER, this
0729: .getClass().getName());
0730: manager.logEvent(new ProviderLogRecord(
0731: usrClick, req, res, pc.getUserID()));
0732: }
0733: } catch (Exception e) {
0734: //ubt exception
0735: }
0736: }
0737: } catch (ProviderContextException pce) {
0738: throw new ProviderException(
0739: "JSPTableContainerProvider.processEdit(): ", pce);
0740: }
0741:
0742: // Remove cached content
0743: if (targetProvider != null) {
0744: getContainerProviderContext()
0745: .contentChanged(targetProvider);
0746: } else {
0747: getContainerProviderContext().contentChanged(getName());
0748: }
0749: return super .processEdit(req, res);
0750: }
0751:
0752: /**
0753: * Gets the window name for the detached window.
0754: * The detached window name is used for naming
0755: * browser windows for detached channels. The
0756: * detached window name is
0757: * guaranteed to end with "_detached".
0758: *
0759: * @param channelName Name of the channel for which
0760: * the detach window name is requested.
0761: *
0762: * @return <code>String</code> The window name as a string
0763: */
0764: public String getWindowName(String channelName) {
0765: String window_name = getName() + channelName + "_detached";
0766: String new_window_name = PropertyUtil
0767: .replaceChannelName(URLEncoder.encode(window_name));
0768: return new_window_name;
0769: }
0770:
0771: /**
0772: * Gets the popup window width for the detach window
0773: * when a channel is detached
0774: *
0775: * @param request An HttpServletRequest that contains
0776: * information related to this
0777: * request for content.
0778: * @param channelName Name of the channel for which
0779: * the detach window width is requested.
0780: *
0781: * @return </code>int</code> The detach window width as an int
0782: * based on the channel width
0783: *
0784: * @see com.sun.portal.providers.ProviderWidths#WIDTH_THIN
0785: * @see com.sun.portal.providers.ProviderWidths#WIDTH_THICK
0786: * @see com.sun.portal.providers.ProviderWidths#WIDTH_FULL_TOP
0787: * @see com.sun.portal.providers.ProviderWidths#WIDTH_FULL_BOTTOM
0788: */
0789: public int getPopupWindowWidth(HttpServletRequest req,
0790: String channelName) throws ProviderException {
0791: ContainerProviderContext cpc = getContainerProviderContext();
0792: ProviderContext pc = getProviderContext();
0793: int pwidth = 0;
0794: Provider p = null;
0795:
0796: p = cpc.getProvider(req, getName(), channelName);
0797: int width = p.getWidth();
0798: try {
0799: if (width != -1) {
0800: switch (width) {
0801: case ProviderWidths.WIDTH_FULL_TOP:
0802: pwidth = pc.getIntegerProperty(getName(),
0803: ProviderProperties.FULLWIDTH_POPUP_WIDTH);
0804: break;
0805: case ProviderWidths.WIDTH_FULL_BOTTOM:
0806: pwidth = pc.getIntegerProperty(getName(),
0807: ProviderProperties.FULLWIDTH_POPUP_WIDTH);
0808: break;
0809: case ProviderWidths.WIDTH_THIN:
0810: pwidth = pc.getIntegerProperty(getName(),
0811: ProviderProperties.THIN_POPUP_WIDTH);
0812: break;
0813: case ProviderWidths.WIDTH_THICK:
0814: pwidth = pc.getIntegerProperty(getName(),
0815: ProviderProperties.THICK_POPUP_WIDTH);
0816: break;
0817: default:
0818: if (logger.isLoggable(Level.SEVERE))
0819: logger.log(Level.SEVERE, "PSDT_CSPPCJT0007", ""
0820: + width);
0821: break;
0822: }
0823: }
0824: } catch (ProviderContextException pce) {
0825: throw new ProviderException(
0826: "JSPTableContainerProvider.getPopupWindowWidth(): ",
0827: pce);
0828: }
0829: return pwidth;
0830: }
0831:
0832: /**
0833: * gets the popup window height for the detach window
0834: * when a channel is detached
0835: *
0836: * @param request An HttpServletRequest that contains
0837: * information related to this
0838: * request for content.
0839: * @param channelName. name of the channel for which
0840: * the detach window height is requested.
0841: *
0842: * @return <code>int</code>. The detach window height as an int
0843: * based on the channel width
0844: *
0845: * @see com.sun.portal.providers.ProviderWidths#WIDTH_THIN
0846: * @see com.sun.portal.providers.ProviderWidths#WIDTH_THICK
0847: * @see com.sun.portal.providers.ProviderWidths#WIDTH_FULL_TOP
0848: * @see com.sun.portal.providers.ProviderWidths#WIDTH_FULL_BOTTOM
0849: */
0850: public int getPopupWindowHeight(HttpServletRequest req,
0851: String channelName) throws ProviderException {
0852: ContainerProviderContext cpc = getContainerProviderContext();
0853: ProviderContext pc = getProviderContext();
0854: Provider p = null;
0855: int pheight = 0;
0856:
0857: p = cpc.getProvider(req, getName(), channelName);
0858: int width = p.getWidth();
0859:
0860: try {
0861: if (width != -1) {
0862: switch (width) {
0863: case ProviderWidths.WIDTH_FULL_TOP:
0864: pheight = pc.getIntegerProperty(getName(),
0865: ProviderProperties.FULLWIDTH_POPUP_HEIGHT);
0866: break;
0867: case ProviderWidths.WIDTH_FULL_BOTTOM:
0868: pheight = pc.getIntegerProperty(getName(),
0869: ProviderProperties.FULLWIDTH_POPUP_HEIGHT);
0870: break;
0871: case ProviderWidths.WIDTH_THIN:
0872: pheight = pc.getIntegerProperty(getName(),
0873: ProviderProperties.THIN_POPUP_HEIGHT);
0874: break;
0875: case ProviderWidths.WIDTH_THICK:
0876: pheight = pc.getIntegerProperty(getName(),
0877: ProviderProperties.THICK_POPUP_HEIGHT);
0878: break;
0879: default:
0880: if (logger.isLoggable(Level.SEVERE))
0881: logger.log(Level.SEVERE, "PSDT_CSPPCJT0007", ""
0882: + width);
0883: break;
0884: }
0885: }
0886: } catch (ProviderContextException pce) {
0887: throw new ProviderException(
0888: "JSPTableContainerProvider.getPopupWindowHeight(): ",
0889: pce);
0890: }
0891: return pheight;
0892: }
0893:
0894: /**
0895: * Generates the minimized content for the
0896: * channels that are minimized
0897: * This method puts an empty stringbuffer in the content Map for the
0898: * channels that are minimized in the table container.
0899: * @param channelsIsMinimized <code>Map</code> of channelNames which are minimized.
0900: * @param nonMinimizedList <code>List</code> of channel names which are nonminimized.
0901: * @param content <code>Map</code> of channel contents, a map of StringBuffers.
0902: * @param dIsMinimized Default value for isMinimized property.
0903: */
0904: public void genMinimizedContent(Map channelsIsMinimized,
0905: List nonMinimizedList, Map content, boolean dIsMinimized)
0906: throws ProviderException {
0907: List pList = getSelectedChannels();
0908: for (int i = 0; i < pList.size(); i++) {
0909: String provider = (String) pList.get(i);
0910: boolean isMinimized = PropertyUtil.getBooleanValueFromMap(
0911: channelsIsMinimized, provider, dIsMinimized);
0912: if (isMinimized) {
0913: nonMinimizedList.remove(provider);
0914: content.put(provider, new StringBuffer(""));
0915: }
0916:
0917: }
0918: }
0919:
0920: /**
0921: * Gets the window state of the channel.
0922: *
0923: * @param channelName channel for which the window state is requested.
0924: *
0925: * @return window state either <code>ProviderWindowStates.Maximize</code> or
0926: * <code>ProviderWindowStates.Minimize</code> or <code>ProviderWindowStates.NORMAL</code>
0927: *
0928: * @exception ProviderException
0929: * @see com.sun.portal.providers.containers.ProviderWindowStates#Minimize
0930: * @see com.sun.portal.providers.containers.ProviderWindowStates#Maximize
0931: * @see com.sun.portal.providers.containers.ProviderWindowStates#NORMAL
0932: * @see com.sun.portal.providers.containers.JSPTableContainerProvider#getWindowState
0933: */
0934: public int getWindowState(String channelName)
0935: throws ProviderException {
0936: try {
0937: Map channelsIsMinimized = getProviderContext()
0938: .getCollectionProperty(getName(),
0939: ProviderProperties.CHANNELS_IS_MINIMIZED);
0940: String maximizedChannel = "";
0941: if (getProviderContext().getProviderVersion(getName()) > 1) {
0942: maximizedChannel = getStringProperty(ProviderProperties.MAXIMIZED_CHANNEL);
0943: }
0944: if (channelsIsMinimized.containsKey(channelName)
0945: && ((Boolean) channelsIsMinimized.get(channelName))
0946: .booleanValue()) {
0947: return ProviderWindowStates.MINIMIZE;
0948: } else if (maximizedChannel.equalsIgnoreCase(channelName)) {
0949: return ProviderWindowStates.MAXIMIZE;
0950: } else {
0951: return ProviderWindowStates.NORMAL;
0952: }
0953: } catch (ProviderContextException pce) {
0954: throw new ProviderException(
0955: "JSPTableContainerProvider.getWindowState: ", pce);
0956: }
0957: }
0958:
0959: /**
0960: * Sets the window state of a channel.
0961: *
0962: * @param channelName channel for which the window state needs to be set
0963: * @param windowState The new window state either <code>ProviderWindowStates.Maximize</code> or
0964: * <code>ProviderWindowStates.Minimize</code> or <code>ProviderWindowStates.NORMAL</code>
0965: *
0966: * @exception UnsupportedWindowStateException if the window state passed in is not in
0967: * supported window states list.
0968: * @see com.sun.portal.providers.containers.ProviderWindowStates#Minimize
0969: * @see com.sun.portal.providers.containers.ProviderWindowStates#Maximize
0970: * @see com.sun.portal.providers.containers.ProviderWindowStates#NORMAL
0971: * @see com.sun.portal.providers.containers.JSPTableContainerProvider#getWindowState
0972: * @see com.sun.portal.providers.containers.JSPTableContainerProvider#getSupportedWindowStates()
0973: */
0974: public void setWindowState(String channelName, int windowState)
0975: throws UnsupportedWindowStateException {
0976: try {
0977: Map channelsIsMinimized = getProviderContext()
0978: .getCollectionProperty(getName(),
0979: ProviderProperties.CHANNELS_IS_MINIMIZED);
0980: String maximizedChannel = "";
0981: if (getProviderContext().getProviderVersion(getName()) > 1) {
0982: maximizedChannel = getStringProperty(ProviderProperties.MAXIMIZED_CHANNEL);
0983: }
0984: if (windowState == ProviderWindowStates.MINIMIZE) {
0985: Boolean minimize_value = Boolean.TRUE;
0986: channelsIsMinimized.put(channelName, minimize_value);
0987: getProviderContext().setCollectionProperty(getName(),
0988: ProviderProperties.CHANNELS_IS_MINIMIZED,
0989: channelsIsMinimized);
0990: //if this channel is previously maximized, remove it from maximized.
0991: if (maximizedChannel.equalsIgnoreCase(channelName)) {
0992: setStringProperty(
0993: ProviderProperties.MAXIMIZED_CHANNEL, "");
0994: }
0995: } else if (windowState == ProviderWindowStates.NORMAL) {
0996: Boolean maximize_value = Boolean.FALSE;
0997: channelsIsMinimized.put(channelName, maximize_value);
0998: getProviderContext().setCollectionProperty(getName(),
0999: ProviderProperties.CHANNELS_IS_MINIMIZED,
1000: channelsIsMinimized);
1001: //remove it from maximized
1002: if (maximizedChannel.equalsIgnoreCase(channelName)) {
1003: setStringProperty(
1004: ProviderProperties.MAXIMIZED_CHANNEL, "");
1005: }
1006: } else if (windowState == ProviderWindowStates.MAXIMIZE) {
1007: if (getProviderContext().getProviderVersion(getName()) > 1) {
1008: setStringProperty(
1009: ProviderProperties.MAXIMIZED_CHANNEL,
1010: channelName);
1011: } else {
1012: throw new UnsupportedWindowStateException(
1013: "window state MAXIMIZE is not supported");
1014: }
1015: Boolean minimize_value = Boolean.FALSE;
1016: channelsIsMinimized.put(channelName, minimize_value);
1017: getProviderContext().setCollectionProperty(getName(),
1018: ProviderProperties.CHANNELS_IS_MINIMIZED,
1019: channelsIsMinimized);
1020: } else {
1021: throw new UnsupportedWindowStateException(
1022: "window state passed in is not supported");
1023: }
1024: } catch (ProviderContextException pce) {
1025: throw new UnsupportedWindowStateException(
1026: "JSPTableContainerProvider.setWindowState: ", pce);
1027: } catch (ProviderException pe) {
1028: throw new UnsupportedWindowStateException(
1029: "JSPTableContainerProvider.setWindowState: ", pe);
1030: }
1031: }
1032:
1033: /**
1034: * Gets the supported window states.
1035: *
1036: * @return Supported Window States as an integer array containing
1037: * <code>ProviderWindowStates.Maximize</code>,
1038: * <code>ProviderWindowStates.Minimize</code>, <code>ProviderWindowStates.NORMAL</code>
1039: *
1040: * @exception ProviderException If the window states cannot be returned.
1041: *
1042: * @see com.sun.portal.providers.containers.ProviderWindowStates#Minimize
1043: * @see com.sun.portal.providers.containers.ProviderWindowStates#Maximize
1044: * @see com.sun.portal.providers.containers.ProviderWindowStates#NORMAL
1045: * @see com.sun.portal.providers.containers.ContainerProvider#getWindowState()
1046: * @see com.sun.portal.providers.containers.ContainerProvider#setWindowState()
1047: */
1048: public int[] getSupportedWindowStates() throws ProviderException {
1049: return supportedStates;
1050: }
1051:
1052: /**
1053: * Gets the channels under the specified category.
1054: * @param categoryName Name of the category for which
1055: * the contained channels are requested.
1056: *
1057: * @exception ProviderException
1058: *
1059: * @return <code>Map</code> The channel names under the specified category , as a Map of Strings.
1060: */
1061: public Map getChannelsInCategory(String categoryName)
1062: throws ProviderException {
1063: Map channels = null;
1064: ProviderContext pc = getProviderContext();
1065: String channelName = getName();
1066: try {
1067: if (pc.existsCollectionProperty(channelName,
1068: CATEGORY_CONTENT)) {
1069: Map categories = (Map) pc.getCollectionProperty(
1070: channelName, CATEGORY_CONTENT);
1071: channels = (Map) categories.get(categoryName);
1072: } else {
1073: channels = (Map) pc.getCollectionProperty(channelName,
1074: categoryName);
1075: }
1076: } catch (ProviderContextException pce) {
1077: throw new ProviderException(
1078: "JSPTableContainerProvider.getChannelsInCategory(): ",
1079: pce);
1080: }
1081: return channels;
1082: }
1083:
1084: }
|