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:
014: package com.sun.portal.providers.containers;
015:
016: import java.util.List;
017: import java.util.Iterator;
018: import java.util.Map;
019: import java.util.logging.Level;
020: import java.util.logging.LogRecord;
021: import java.util.logging.Logger;
022:
023: import java.net.URL;
024:
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.http.HttpServletResponse;
027:
028: import com.sun.portal.desktop.context.ContextException;
029:
030: import com.sun.portal.providers.context.ProviderContext;
031: import com.sun.portal.providers.context.ContainerProviderContext;
032: import com.sun.portal.providers.context.ProviderContextException;
033: import com.sun.portal.providers.containers.ContainerProvider;
034: import com.sun.portal.providers.ProviderException;
035: import com.sun.portal.providers.jsp.JSPProvider;
036: import com.sun.portal.providers.Provider;
037:
038: import com.sun.portal.desktop.DesktopRequestThreadLocalizer;
039: import com.sun.portal.log.common.PortalLogger;
040:
041: // Code in this class is duplicated in ContainerProviderAdapter. Changes
042: // applied to this class should also be considered for
043: // ContainerProviderAdapter.
044:
045: /**
046: * This class provides default implementations of methods in the
047: * ContainerProvider
048: * interface implemented using a containerProviderContext object as the
049: * persistent store and extends <code>JSPProvider</code> to facilitate
050: * the execution of JSPs
051: * <p>
052: * For method details, see the descriptions in the <code>ContainerProvider</code>
053: * interface.
054: *
055: * @see com.sun.portal.providers.context.ContainerProviderContext
056: * @see com.sun.portal.providers.jsp.JSPProvider
057: */
058:
059: public class JSPContainerProviderAdapter extends JSPProvider implements
060: ContainerProvider {
061:
062: private static Logger logger = PortalLogger
063: .getLogger(JSPContainerProviderAdapter.class);
064:
065: public ContainerProviderContext getContainerProviderContext()
066: throws ProviderException {
067: ProviderContext pc = getProviderContext();
068:
069: if (!(pc instanceof ContainerProviderContext)) {
070: throw new ProviderException(
071: "JSPContainerProviderAdapter.getContainerProviderContext(): "
072: + "not a container provider context");
073: }
074:
075: return (ContainerProviderContext) pc;
076: }
077:
078: public List getSelectedChannels() throws ProviderException {
079: try {
080: return getContainerProviderContext().getSelectedChannels(
081: getName());
082: } catch (ProviderContextException pce) {
083: throw new ProviderException(
084: "JSPContainerProviderAdapter.getSelectedChannels()",
085: pce);
086: }
087: }
088:
089: public List getAvailableChannels() throws ProviderException {
090: try {
091: return getContainerProviderContext().getAvailableChannels(
092: getName());
093: } catch (ProviderContextException pce) {
094: throw new ProviderException(
095: "JSPContainerProviderAdapter.getAvailableChannels()",
096: pce);
097: }
098: }
099:
100: /**
101: * Gets the list of available and user defined channel names.
102: *
103: * Available Channels are channels that are available to be added to the portal page.
104: * User Defined Channels are channels the user has created.
105: *
106: * @return The list of available and user defined channel names, a list of string names.
107: *
108: * @exception ProviderException If the list of channel names cannot be returned.
109: */
110: public List getAvailableAndUserDefinedChannels()
111: throws ProviderException {
112: try {
113: List availableChannels = getAvailableChannels();
114: Map userDefinedChannels = getProviderContext()
115: .getCollectionProperty(getName(),
116: "userDefinedChannels");
117:
118: // Remove all elements from availableChannels contained in userDefinedChannels collection.
119: availableChannels.removeAll(userDefinedChannels.values());
120:
121: // Add all elements from userDefinedChannels to availableChannels.
122: Iterator itr = userDefinedChannels.keySet().iterator();
123: while (itr.hasNext()) {
124: availableChannels.add((String) itr.next());
125: }
126: return availableChannels;
127: } catch (ProviderContextException pce) {
128: throw new ProviderException(
129: "JSPContainerProviderAdapter.getAvailableAndUserDefinedChannels()",
130: pce);
131: }
132: }
133:
134: public void setSelectedChannels(List sel) throws ProviderException {
135: try {
136: getContainerProviderContext().setSelectedChannels(
137: getName(), sel);
138: } catch (ProviderContextException pce) {
139: throw new ProviderException(
140: "JSPContainerProviderAdapter.setSelectedChannels()",
141: pce);
142: }
143: }
144:
145: public void setAvailableChannels(List avail)
146: throws ProviderException {
147: try {
148: getContainerProviderContext().setAvailableChannels(
149: getName(), avail);
150: } catch (ProviderContextException pce) {
151: throw new ProviderException(
152: "JSPContainerProviderAdapter.setAvailableChannels()",
153: pce);
154: }
155: }
156:
157: public long getRefreshTime() throws ProviderException {
158: String refreshTime = getStringProperty("refreshTime");
159: long refreshTimelong = 0;
160: if (refreshTime != null && refreshTime.length() != 0) {
161: return Long.parseLong(refreshTime);
162: } else {
163: //calculate the refreshTime from selected channels
164: List selected = getSelectedChannels();
165: int size = selected.size();
166: for (int i = 0; i < size; i++) {
167: String channel = (String) selected.get(i);
168: Provider p = getContainerProviderContext().getProvider(
169: DesktopRequestThreadLocalizer.getRequest(),
170: getName(), channel);
171: if (p != null) {
172: try {
173: long rt = p.getRefreshTime();
174: if (i == 0) {
175: refreshTimelong = rt;
176: } else {
177: refreshTimelong = Math.min(refreshTimelong,
178: rt);
179: }
180: } catch (ProviderException pe) {
181: if (logger.isLoggable(Level.SEVERE)) {
182: LogRecord rec = new LogRecord(Level.SEVERE,
183: "PSDT_CSPPC0001");
184: rec.setLoggerName(logger.getName());
185: String[] param = { channel };
186: rec.setParameters(param);
187: rec.setThrown(pe);
188: logger.log(rec);
189: }
190: }
191: } else {
192: if (logger.isLoggable(Level.SEVERE))
193: logger.log(Level.SEVERE, "PSDT_CSPPC0002",
194: channel);
195: }
196:
197: if (refreshTimelong == 0) {
198: break;
199: } else {
200: continue;
201: }
202: }
203:
204: String[] param = { new Long(refreshTimelong).toString(),
205: getName() };
206: if (logger.isLoggable(Level.FINEST)) {
207: logger.log(Level.FINEST, "PSDT_CSPPC0003", param);
208: }
209:
210: return refreshTimelong;
211: }
212: }
213:
214: /**
215: * Gets the window state of the channel.
216: *
217: * This method is a default implementation of the ContainerProvider.getWindowState()
218: * This method currently has no effect and just returns ProviderWindowStates.NOT_DEFINED.
219: *
220: * Subclasses that wish to allow getting a WindowState should
221: * override this method.
222: *
223: * @param channelName channel for which the window state is requested.
224: *
225: * @return window state
226: * @exception ProviderException
227: * @see com.sun.portal.providers.containers.ProviderWindowStates#NOT_DEFINED
228: */
229: public int getWindowState(String channelName)
230: throws ProviderException {
231: return ProviderWindowStates.NOT_DEFINED;
232: }
233:
234: /**
235: * Sets the window state of a channel.
236: *
237: * This method is a default implementation of the ContainerProvider.setWindowState()
238: * This method currently has no effect and just throws UnsupportedWindowStateException.
239: *
240: * Subclasses that wish to allow setting a WindowState should
241: * override this method.
242: * @param channelName channel for which the window state needs to be set
243: * @param windowState The new window state
244: *
245: * @exception UnsupportedWindowStateException.
246: */
247: public void setWindowState(String channelName, int windowState)
248: throws UnsupportedWindowStateException {
249: throw new UnsupportedWindowStateException(
250: "Setting a window state is not supported in the default impl of containerprovider");
251: }
252:
253: /**
254: * Gets the supported window states.
255: *
256: * This method is a default implementation of the ContainerProvider.getSupportedWindowStates()
257: * This method currently has no effect and just returns an integer array containing
258: * ProviderWindowStates.NOT_DEFINED.
259: *
260: * Subclasses that wish to allow getting supported WindowStates should
261: * override this method.
262: *
263: * @return Supported Window States as an integer array.
264: *
265: * @exception ProviderException If the window states cannot be returned.
266: *
267: * @see com.sun.portal.providers.containers.JSPContainerProviderAdapter#getWindowState()
268: * @see com.sun.portal.providers.containers.JSPContainerProviderAdapter#setWindowState()
269: */
270: public int[] getSupportedWindowStates() throws ProviderException {
271: int[] winstates = new int[1];
272: winstates[0] = ProviderWindowStates.NOT_DEFINED;
273: return winstates;
274: }
275:
276: }
|