001: package com.sun.portal.providers.app;
002:
003: import java.net.URL;
004:
005: import java.util.List;
006: import java.util.ArrayList;
007: import java.util.Vector;
008: import java.util.Hashtable;
009: import java.util.ResourceBundle;
010: import java.util.StringTokenizer;
011: import java.util.logging.Level;
012: import java.util.logging.Logger;
013:
014: import javax.servlet.http.HttpServletRequest;
015: import javax.servlet.http.HttpServletResponse;
016:
017: import com.sun.portal.providers.ProviderException;
018: import com.sun.portal.providers.ProfileProviderAdapter;
019: import com.sun.portal.providers.context.ProviderContext;
020: import com.sun.portal.providers.context.ProviderContextException;
021:
022: import com.sun.portal.desktop.util.Target;
023:
024: import com.sun.portal.log.common.PortalLogger;
025:
026: public class AppProvider extends ProfileProviderAdapter {
027: private ResourceBundle bundle = null;
028: private static Logger logger = PortalLogger
029: .getLogger(AppProvider.class);
030:
031: public AppProvider() {
032: }
033:
034: public void init(String n, HttpServletRequest req)
035: throws ProviderException {
036: super .init(n, req);
037: }
038:
039: public StringBuffer getContent(HttpServletRequest req,
040: HttpServletResponse res) throws ProviderException {
041:
042: boolean localized = true;
043: StringBuffer content = new StringBuffer();
044: Hashtable tableTags = new Hashtable();
045: List userApps = null;
046: List targets = null;
047: // generate the application list
048: ProviderContext pc = getProviderContext();
049:
050: try {
051: userApps = new ArrayList(pc.getCollectionProperty(
052: getName(), "userApps", localized).values());
053: targets = new ArrayList(pc.getCollectionProperty(getName(),
054: "targets", localized).values());
055: } catch (ProviderContextException pce) {
056: throw new ProviderException(
057: "AppProvider.getContent(): Error getting app properties",
058: pce);
059: }
060:
061: String cellPadding = "0"; // default
062: String cellSpacing = "0"; // default
063:
064: // Get Resource Bundle if it is null
065: if (bundle == null) {
066: bundle = getResourceBundle();
067: }
068: cellPadding = bundle.getString("cellPadding");
069: cellSpacing = bundle.getString("cellSpacing");
070:
071: if (userApps.size() >= 1) {
072: content
073: .append("<TABLE CELLPADDING=\"")
074: .append(cellPadding)
075: .append("\" CELLSPACING=\"")
076: .append(cellSpacing)
077: .append(
078: "\" WIDTH=\"100%\"><TR><TD><FONT FACE=\"[tag:fontFace1]\" SIZE=\"+0\">\n");
079: }
080:
081: for (int i = 0; i < targets.size(); i++) {
082: String targ = (String) targets.get(i);
083: Target target = new Target(targ);
084:
085: //
086: // see if they've included optional js launch code
087: //
088: StringTokenizer tok = new StringTokenizer(
089: target.getValue(), "^");
090: String url = (String) tok.nextElement();
091: StringBuffer onClick = new StringBuffer();
092: if (tok.hasMoreElements()) {
093: onClick.append((String) tok.nextElement());
094: }
095:
096: if (!userApps.contains(target.getName())) {
097: continue;
098: }
099:
100: //
101: // build the window target name from the app name
102: // remove special characters from name and replace them
103: // with underbars
104: //
105: StringBuffer windowName = new StringBuffer();
106:
107: StringTokenizer tokens = new StringTokenizer(target
108: .getName(), " (),=+#[]@<>$%./!");
109: while (tokens.hasMoreTokens()) {
110: windowName.append((String) tokens.nextToken());
111: if (tokens.hasMoreElements()) {
112: windowName.append("_");
113: }
114: }
115:
116: StringBuffer winTarget = new StringBuffer().append(
117: " TARGET=\"").append(windowName.toString()).append(
118: "\"");
119:
120: if (onClick == null) {
121: onClick.append("openAppURL('").append(url).append(
122: "', '").append(windowName).append(
123: "'); return false;");
124: }
125:
126: StringBuffer theHref = new StringBuffer().append(
127: "<A HREF=\"").append(url).append("\"").append(
128: winTarget.toString()).append(" onClick=\"").append(
129: onClick).append("\">").append(target.getName())
130: .append("</A><BR>");
131:
132: String appBG = bundle.getString("appBackground");
133: content.append("<TR><TD BGCOLOR=\"").append(appBG).append(
134: "\">").append("<FONT FACE=\"[tag:fontFace1]\" ")
135: .append("SIZE=\"-1\">").append(theHref.toString())
136: .append("</FONT></TD></TR>");
137: }
138:
139: if (userApps.size() >= 1) {
140: content.append("</TABLE>");
141: }
142:
143: tableTags.put("apps", content.toString());
144: tableTags.put("fontFace1", getStringProperty("fontFace1",
145: localized));
146: content = getTemplate("display.template", tableTags);
147:
148: return content;
149: }
150:
151: public StringBuffer getEdit(HttpServletRequest req,
152: HttpServletResponse res) throws ProviderException {
153: List userApps;
154: List targets;
155: boolean localized = true;
156: ProviderContext pc = getProviderContext();
157:
158: try {
159: userApps = new ArrayList(pc.getCollectionProperty(
160: getName(), "userApps", localized).values());
161: targets = new ArrayList(pc.getCollectionProperty(getName(),
162: "targets", localized).values());
163: } catch (ProviderContextException pce) {
164: throw new ProviderException(
165: "AppProvider.getContent(): Error getting app properties",
166: pce);
167: }
168:
169: // Get the application list.
170: int scrollingListSize = targets.size();
171:
172: StringBuffer content = new StringBuffer("<TABLE>\n");
173:
174: // create the HTML
175: content.append("<TR><TD>\n");
176: content.append("<FONT FACE=\"[tag:fontFace1]\" SIZE=\"-1\">");
177: content.append("<SELECT NAME=\"coreapps\" SIZE=\"").append(
178: scrollingListSize).append("\" MULTIPLE>\n");
179:
180: for (int i = 0; i < targets.size(); i++) {
181: String appSelected = "";
182:
183: String targ = (String) targets.get(i);
184: Target target = new Target(targ);
185:
186: if (userApps.contains(target.getName())) {
187: appSelected = "SELECTED";
188: }
189: content.append("<OPTION ").append(appSelected).append(">")
190: .append(target.getName()).append("</OPTION>\n");
191: }
192: content.append("</SELECT></font></TD></TR>\n");
193: content.append("</TABLE>\n");
194:
195: return content;
196: }
197:
198: public URL processEdit(HttpServletRequest req,
199: HttpServletResponse res) throws ProviderException {
200:
201: ProviderContext pc = getProviderContext();
202:
203: pc.contentChanged(getName());
204:
205: List localeFilters = null;
206:
207: Vector coreAppList = new Vector();
208: String[] coreapps = req.getParameterValues("coreapps");
209:
210: if (coreapps != null) {
211: for (int i = 0; i < coreapps.length; i++) {
212: String appName = coreapps[i];
213: coreAppList.add(appName);
214: }
215: }
216:
217: try {
218: localeFilters = pc.getLocalePropertiesFilters();
219: pc.setCollectionProperty(getName(), "userApps",
220: coreAppList, localeFilters);
221:
222: } catch (ProviderContextException pce) {
223: if (logger.isLoggable(Level.WARNING))
224: logger.log(Level.WARNING, "PSDT_CSPPA0001", pce);
225: }
226:
227: return null;
228: }
229: }
|