001: /**
002: * $Id: ProxyletBean.java,v 1.20 2006/11/28 13:10:18 aa147324 Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.console.sra.proxylet;
014:
015: import java.io.Serializable;
016: import java.util.*;
017:
018: import com.sun.portal.admin.console.sra.ISraBean;
019: import com.sun.portal.admin.console.sra.SraBaseBean;
020: import com.sun.portal.admin.console.sra.accesslist.ACL;
021: import com.sun.portal.admin.console.sra.utils.SraObjectListDataProvider;
022: import com.sun.data.provider.DataProvider;
023: import com.sun.data.provider.impl.ObjectListDataProvider;
024:
025: /**
026: * author: Noble Paul Date: May 19, 2005, 11:35:23 AM
027: */
028: public class ProxyletBean extends SraBaseBean implements Serializable {
029: private static final String BIND_IP = "sunPortalProxyletBindIP";
030:
031: private static final String BIND_PORT = "sunPortalProxyletPort";
032:
033: private static final String AUTO_DWNLD = "sunPortalProxyletDownloadDefault";
034:
035: private static final String LAUNCH_MODE = "sunPortalProxyletLaunchMode";
036:
037: //private static final String APP_URLS = "sunPortalProxyletAppUrls";
038:
039: private static final String PAC_LOC = "sunPortalProxyletPacLocation";
040:
041: private static final String RULES = "sunPortalProxyletRules";
042:
043: private static final String JNLP = "Java Web Start";
044:
045: private static final String APPLET = "Applet";
046:
047: //private static final String[] ATTR_LIST = {BIND_IP, BIND_PORT, APP_URLS , AUTO_DWNLD, LAUNCH_MODE, PAC_LOC, RULES};
048: private static final String[] ATTR_LIST = { COS_PRIORITY, BIND_IP,
049: BIND_PORT, AUTO_DWNLD, LAUNCH_MODE, PAC_LOC, RULES };
050:
051: private String bindIP;//sunPortalProxyletBindIP
052:
053: private String bindPort;//sunPortalProxyletPort
054:
055: private boolean autoDownload;//sunPortalProxyletDownloadDefault
056:
057: private boolean appletLaunchMode = true;//sunPortalProxyletLaunchMode
058:
059: private String pacFileLocation;//sunPortalProxyletPacLocation
060:
061: //private List appURLList;//sunPortalProxyletAppUrls
062:
063: //private ObjectListDataProvider appURLData;
064:
065: private List rulesList;//sunPortalProxyletRules
066:
067: private SraObjectListDataProvider rulesData;
068: static {
069: setPropertyVisibility(BIND_IP, SHOW, SHOW, SHOW);
070: setPropertyVisibility(BIND_PORT, SHOW, SHOW, SHOW);
071: setPropertyVisibility(AUTO_DWNLD, SHOW, SHOW, SHOW);
072: setPropertyVisibility(LAUNCH_MODE, SHOW, SHOW, SHOW);
073:
074: //setPropertyVisibility(APP_URLS, SHOW, SHOW, HIDE);
075: setPropertyVisibility(PAC_LOC, SHOW, SHOW, HIDE);
076: setPropertyVisibility(RULES, SHOW, SHOW, HIDE);
077: setPropertyVisibility(COS_PRIORITY, HIDE, SHOW, HIDE);
078:
079: }
080:
081: public ProxyletBean() {
082: super (PROXYLET_SVC, ATTR_LIST);
083: initData();
084: }
085:
086: public void initData() {
087: autoDownload = getBooleanValue(AUTO_DWNLD);
088: bindIP = getStringValue(BIND_IP);
089: bindPort = getStringValue(BIND_PORT);
090: //appURLList = getListValue(APP_URLS);
091: pacFileLocation = getStringValue(PAC_LOC);
092: rulesList = new ArrayList();
093: for (StringTokenizer stringTokenizer = new StringTokenizer(
094: getStringValue(RULES), "|", false); stringTokenizer
095: .hasMoreTokens();) {
096: rulesList.add(Rule.decode(stringTokenizer.nextToken()));
097: }
098: if (rulesList.isEmpty()) {
099: rulesList.add(new Rule());
100: }
101: appletLaunchMode = APPLET
102: .equalsIgnoreCase(getStringValue(LAUNCH_MODE));
103: }
104:
105: /*public DataProvider getAppUrlData(){
106: List result = new ArrayList();
107: if(appURLData == null){
108: for (int i = 0; i < appURLList.size(); i++) {
109: result.add(AppUrl.decode((String) appURLList.get(i)));
110: }
111: if(result.isEmpty()){
112: result.add(new AppUrl());
113: }
114: appURLData = new SraObjectListDataProvider(AppUrl.class.getName(), result);
115: }
116: return appURLData;
117: }
118:
119: public void addAppUrl(){
120: appURLData.appendRow(new AppUrl());
121: appURLData.commitChanges();
122: }
123: public void removeAppurl(){
124: appURLData.commitChanges();
125: List l = appURLData.getList();
126: for (int i = 0; i < l.size(); i++) {
127: AppUrl appUrl = (AppUrl) l.get(i);
128: if(appUrl.getSelected()) {
129: appURLData.removeObject(appUrl);
130: appURLData.commitChanges();
131: }
132: }
133: saveAppUrls();
134:
135: }
136:
137: private void saveAppUrls() {
138: List l = appURLData.getList();
139: List result = new ArrayList();
140: for (int i = 0; i < l.size(); i++) {
141: AppUrl appUrl = (AppUrl) l.get(i);
142: if(!appUrl.isEmpty()){
143: result.add(AppUrl.encode(appUrl));
144: }
145: }
146: if ( result.isEmpty() )
147: result.add("");
148:
149: appURLList = result;
150: updateAttributeNVMap(APP_URLS,result);
151: storeDataToStore(APP_URLS);
152: }*/
153:
154: public String getPacFileLocation() {
155: return pacFileLocation;
156: }
157:
158: public void setPacFileLocation(String pacFileLocation) {
159: this .pacFileLocation = pacFileLocation;
160: updateAttributeNVMap(PAC_LOC, pacFileLocation);
161: }
162:
163: public boolean getAppletLaunchMode() {
164: return appletLaunchMode;
165: }
166:
167: public void setAppletLaunchMode(boolean appletLaunchMode) {
168: this .appletLaunchMode = appletLaunchMode;
169: updateAttributeNVMap(LAUNCH_MODE, appletLaunchMode ? APPLET
170: : JNLP);
171:
172: }
173:
174: public boolean getJnlpLaunchMode() {
175: return !appletLaunchMode;
176: }
177:
178: public void setJnlpLaunchMode(boolean jnlpLaunchMode) {
179: this .appletLaunchMode = !jnlpLaunchMode;
180: updateAttributeNVMap(LAUNCH_MODE, jnlpLaunchMode ? JNLP
181: : APPLET);
182: }
183:
184: public String getBindIP() {
185: return bindIP;
186: }
187:
188: public void setBindIP(String val) {
189: this .bindIP = val;
190: updateAttributeNVMap(BIND_IP, val);
191: }
192:
193: public boolean getAutoDownload() {
194: return autoDownload;
195: }
196:
197: public void setAutoDownload(boolean val) {
198: this .autoDownload = val;
199: updateAttributeNVMap(AUTO_DWNLD, Boolean.toString(val));
200:
201: }
202:
203: public boolean getDontAutoDownload() {
204: return !autoDownload;
205: }
206:
207: public void setDontAutoDownload(boolean val) {
208: this .autoDownload = !val;
209: updateAttributeNVMap(AUTO_DWNLD, Boolean.toString(!val));
210:
211: }
212:
213: public String getBindPort() {
214: return bindPort;
215: }
216:
217: public void setBindPort(String val) {
218: this .bindPort = val;
219: updateAttributeNVMap(BIND_PORT, val);
220: }
221:
222: public String submit() {
223: if (rulesData != null) {
224: rulesData.commitChanges();
225: saveRules();
226: }
227: //appURLData.commitChanges();
228: //saveAppUrls();
229: storeDataToStore();
230: return "success";
231:
232: }
233:
234: public String storeData() {
235: return submit();
236:
237: }
238:
239: private void saveRules() {
240: List rulesArray = rulesData.getList();
241: StringBuffer sb = new StringBuffer();
242: for (int i = 0; i < rulesArray.size(); i++) {
243: Rule rule = (Rule) rulesArray.get(i);
244: if (!rule.isEmpty()) {
245: sb.append(Rule.encode(rule)).append("|");
246: }
247: }
248: updateAttributeNVMap(RULES, sb.toString());
249: storeDataToStore(RULES);
250: }
251:
252: public void addRule() {
253: rulesData.appendRow(new Rule());
254: rulesData.commitChanges();
255: }
256:
257: public DataProvider getRulesData() {
258: if (rulesData == null) {
259: rulesData = new SraObjectListDataProvider(Rule.class
260: .getName(), rulesList);
261: }
262: return rulesData;
263: }
264:
265: public void removeRule() {
266: rulesData.commitChanges();
267: List l = rulesData.getList();
268: for (int i = 0; i < l.size(); i++) {
269: Rule rule = (Rule) l.get(i);
270: if (rule.getSelected()) {
271: rulesData.removeObject(rule);
272: }
273: }
274: rulesData.commitChanges();
275: saveRules();
276:
277: }
278:
279: public boolean isServiceAssigned() {
280: return isServiceAssigned("srapProxyletService");
281: }
282: }
|