Source Code Cross Referenced for EditNetletRuleViewBean.java in  » Portal » Open-Portal » com » sun » portal » netlet » admin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.netlet.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         * @ Author Bhavanishankar
014:         */package com.sun.portal.netlet.admin;
015:
016:        // JDK classes
017:
018:        import java.io.IOException;
019:        import java.net.URLEncoder;
020:        import java.text.MessageFormat;
021:        import java.util.HashMap;
022:        import java.util.HashSet;
023:        import java.util.Map;
024:        import java.util.NoSuchElementException;
025:        import java.util.Set;
026:        import java.util.StringTokenizer;
027:        import java.util.Vector;
028:
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpServletResponse;
031:
032:        import com.iplanet.am.console.base.AMMessageViewBean;
033:        import com.iplanet.am.console.base.AMViewBeanBase;
034:        import com.iplanet.am.console.components.view.html.IPlanetButton;
035:        import com.iplanet.am.console.components.view.html.MessageBox;
036:        import com.iplanet.jato.model.ModelControlException;
037:        import com.iplanet.jato.view.View;
038:        import com.iplanet.jato.view.event.DisplayEvent;
039:        import com.iplanet.jato.view.event.RequestInvocationEvent;
040:        import com.iplanet.jato.view.html.CheckBox;
041:        import com.iplanet.jato.view.html.HREF;
042:        import com.iplanet.jato.view.html.HiddenField;
043:        import com.iplanet.jato.view.html.ListBox;
044:        import com.iplanet.jato.view.html.OptionList;
045:        import com.iplanet.jato.view.html.StaticTextField;
046:        import com.iplanet.jato.view.html.TextField;
047:        import com.sun.portal.netlet.admin.model.NetletAdminServiceModel;
048:        import com.sun.portal.netlet.admin.model.NetletAdminServiceModelImpl;
049:        import com.sun.portal.netlet.util.NetletConstants;
050:
051:        public class EditNetletRuleViewBean extends AMViewBeanBase {
052:            public static final String PAGE_NAME = "EditNetletRule";
053:            public static final String DEFAULT_DISPLAY_URL = "/ps/netletadmin/EditNetletRule.jsp";
054:            public static final String PAGE_TITLE = "titleHtmlPage";
055:            public static final String PAGE_DESC = "serviceDescription"; // Netlet
056:            public static final String PAGE_DESC_HREF = "serviceDescHref";
057:            public static final String PAGE_DESC_ACTION = "serviceDescAction"; // > Edit Rule
058:
059:            public static final String CHILD_RULENAME_LBL = "rulenameLabel";
060:            public static final String CHILD_RULENAME = "rulename";
061:            public static final String CHILD_ALGORITHMS_LBL = "algorithmsLabel";
062:            public static final String CHILD_ALGO_DEFAULT = "algorithmDefault";
063:            public static final String CHILD_ALGO_OTHER = "algorithmOther";
064:            public static final String CHILD_ALGORITHMS = "algorithms";
065:            public static final String CHILD_URL_LBL = "urlLabel";
066:            public static final String CHILD_URL = "url";
067:            public static final String CHILD_DOWNLOADAPPLET_LBL = "downloadappletLabel";
068:            public static final String CHILD_DOWNLOADAPPLET_CB = "downloadappletcb";
069:            public static final String CHILD_DOWNLOADAPPLET_NAME = "downloadappletname";
070:            public static final String CHILD_EXTEND_LBL = "extendLabel";
071:            public static final String CHILD_EXTEND = "extend";
072:            public static final String CHILD_PHPLIST_LBL = "phplistLabel";
073:            public static final String CHILD_PHPLIST_LBL_HELP = "phplistLabelHelp";
074:            public static final String CHILD_PHPLIST = "phplist";
075:            public static final String CHILD_CLIENTPORT_LBL = "clientportLabel";
076:            public static final String CHILD_CLIENTPORT = "clientport";
077:            public static final String CHILD_TARGETHOST_LBL = "targethostLabel";
078:            public static final String CHILD_TARGETHOST = "targethost";
079:            public static final String CHILD_TARGETPORT_LBL = "targetportLabel";
080:            public static final String CHILD_TARGETPORT = "targetport";
081:            public static final String CHILD_SELECTED_ALGOS = "selectedAlgos";
082:            public static final String CHILD_RULE_INDEX = "ruleIndex";
083:            public static final String CHILD_ERRORMSGS = "errorMessages";
084:            public static final String CHILD_SAVE_BTN = "saveButton";
085:            public static final String CHILD_CANCEL_BTN = "cancelButton";
086:            public static final String CHILD_REMOVE_BTN = "removeButton";
087:            public static final String CHILD_ADDTOLIST_BTN = "addtolistButton";
088:
089:            private NetletAdminModelManager modelManager = null;
090:            private NetletAdminServiceModel model = null;
091:
092:            private Vector netletRules = null;
093:            private int currentRow = -1;
094:
095:            public static final String RULE_DELIM = "|";
096:            public static final String ALGO_DELIM = "^";
097:            private final String SAMPLE_RULE = "MyRule|/ps/sample.html|50000:machinename:80|40000|TARGET|11041|EXTEND";
098:
099:            /**
100:             * Default Constructor
101:             */
102:            public EditNetletRuleViewBean() {
103:                super (PAGE_NAME);
104:                setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
105:                registerChildren();
106:            }
107:
108:            public EditNetletRuleViewBean(String pageName) {
109:                super (pageName);
110:                registerChildren();
111:            }
112:
113:            /**
114:             * Creates the child view objects for this viewbean.
115:             * @param name the name of the child view object to be created.
116:             * @return the child view object.
117:             */
118:            protected View createChild(String name) {
119:                getModelMgr();
120:                if (name.equals(PAGE_TITLE)) {
121:                    return new StaticTextField(this , PAGE_TITLE, modelManager
122:                            .getString("HTMLPage.title"));
123:                } else if (name.equals(PAGE_DESC)) {
124:                    return new StaticTextField(this , PAGE_DESC, "");
125:                } else if (name.equals(PAGE_DESC_HREF)) {
126:                    return new HREF(this , PAGE_DESC_HREF, "");
127:                } else if (name.equals(PAGE_DESC_ACTION)) {
128:                    return new StaticTextField(this , PAGE_DESC_ACTION,
129:                            modelManager.getString("editrule.pagetitle"));
130:                } else if (name.equals(CHILD_RULENAME_LBL)) {
131:                    return new StaticTextField(this , CHILD_RULENAME_LBL,
132:                            modelManager.getString("rulename.label"));
133:                } else if (name.equals(CHILD_RULENAME)) {
134:                    return new TextField(this , CHILD_RULENAME, "");
135:                } else if (name.equals(CHILD_ALGORITHMS_LBL)) {
136:                    return new StaticTextField(this , CHILD_ALGORITHMS_LBL,
137:                            modelManager.getString("algorithms.label"));
138:                } else if (name.equals(CHILD_ALGORITHMS)) {
139:                    return new ListBox(this , CHILD_ALGORITHMS, "");
140:                } else if (name.equals(CHILD_ALGO_DEFAULT)) {
141:                    return new StaticTextField(this , CHILD_ALGO_DEFAULT,
142:                            modelManager.getString("algorithm.default"));
143:                } else if (name.equals(CHILD_ALGO_OTHER)) {
144:                    return new StaticTextField(this , CHILD_ALGO_OTHER,
145:                            modelManager.getString("algorithm.other"));
146:                } else if (name.equals(CHILD_URL_LBL)) {
147:                    return new StaticTextField(this , CHILD_URL_LBL,
148:                            modelManager.getString("url.label"));
149:                } else if (name.equals(CHILD_URL)) {
150:                    return new TextField(this , CHILD_URL, "");
151:                } else if (name.equals(CHILD_DOWNLOADAPPLET_LBL)) {
152:                    return new StaticTextField(this , CHILD_DOWNLOADAPPLET_LBL,
153:                            modelManager.getString("downloadapplet.label"));
154:                } else if (name.equals(CHILD_DOWNLOADAPPLET_CB)) {
155:                    return new CheckBox(this , CHILD_DOWNLOADAPPLET_CB, "true",
156:                            "false", false);
157:                } else if (name.equals(CHILD_DOWNLOADAPPLET_NAME)) {
158:                    return new TextField(this , CHILD_DOWNLOADAPPLET_NAME, "");
159:                } else if (name.equals(CHILD_EXTEND_LBL)) {
160:                    return new StaticTextField(this , CHILD_EXTEND_LBL,
161:                            modelManager.getString("extend.label"));
162:                } else if (name.equals(CHILD_EXTEND)) {
163:                    return new CheckBox(this , CHILD_EXTEND, "true", "false",
164:                            false);
165:                } else if (name.equals(CHILD_PHPLIST_LBL)) {
166:                    return new StaticTextField(this , CHILD_PHPLIST_LBL,
167:                            modelManager.getString("phplist.label"));
168:                } else if (name.equals(CHILD_PHPLIST_LBL_HELP)) {
169:                    return new StaticTextField(this , CHILD_PHPLIST_LBL_HELP,
170:                            modelManager.getString("phplist.label.help"));
171:                } else if (name.equals(CHILD_PHPLIST)) {
172:                    return new ListBox(this , CHILD_PHPLIST, "");
173:                } else if (name.equals(CHILD_CLIENTPORT_LBL)) {
174:                    return new StaticTextField(this , CHILD_CLIENTPORT_LBL,
175:                            modelManager.getString("clientport.label"));
176:                } else if (name.equals(CHILD_CLIENTPORT)) {
177:                    return new TextField(this , CHILD_CLIENTPORT, "");
178:                } else if (name.equals(CHILD_CLIENTPORT_LBL)) {
179:                    return new StaticTextField(this , CHILD_CLIENTPORT_LBL,
180:                            modelManager.getString("clientport.label"));
181:                } else if (name.equals(CHILD_CLIENTPORT)) {
182:                    return new TextField(this , CHILD_CLIENTPORT, "");
183:                } else if (name.equals(CHILD_TARGETHOST_LBL)) {
184:                    return new StaticTextField(this , CHILD_TARGETHOST_LBL,
185:                            modelManager.getString("targethost.label"));
186:                } else if (name.equals(CHILD_TARGETHOST)) {
187:                    return new TextField(this , CHILD_TARGETHOST, "");
188:                } else if (name.equals(CHILD_TARGETPORT_LBL)) {
189:                    return new StaticTextField(this , CHILD_TARGETPORT_LBL,
190:                            modelManager.getString("targetport.label"));
191:                } else if (name.equals(CHILD_TARGETPORT)) {
192:                    return new TextField(this , CHILD_TARGETPORT, "");
193:                } else if (name.equals(CHILD_SELECTED_ALGOS)) {
194:                    return new HiddenField(this , CHILD_SELECTED_ALGOS, "");
195:                } else if (name.equals(CHILD_RULE_INDEX)) {
196:                    return new HiddenField(this , CHILD_RULE_INDEX, "");
197:                } else if (name.equals(CHILD_SAVE_BTN)) {
198:                    return new IPlanetButton(this , CHILD_SAVE_BTN, modelManager
199:                            .getString("ok.button"));
200:                } else if (name.equals(CHILD_CANCEL_BTN)) {
201:                    return new IPlanetButton(this , CHILD_CANCEL_BTN,
202:                            modelManager.getString("cancel.button"));
203:                } else if (name.equals(CHILD_REMOVE_BTN)) {
204:                    return new StaticTextField(this , CHILD_REMOVE_BTN,
205:                            modelManager.getString("remove.button"));
206:                } else if (name.equals(CHILD_ADDTOLIST_BTN)) {
207:                    return new StaticTextField(this , CHILD_ADDTOLIST_BTN,
208:                            modelManager.getString("addtolist.button"));
209:                } else if (name.equals(CHILD_ERRORMSGS)) {
210:                    return new StaticTextField(this , CHILD_ERRORMSGS, "");
211:                } else {
212:                    return super .createChild(name);
213:                }
214:            }
215:
216:            /**
217:             * To register all the child view objects and their classes.
218:             */
219:            protected void registerChildren() {
220:                registerChild(PAGE_TITLE, StaticTextField.class);
221:                registerChild(PAGE_DESC, StaticTextField.class);
222:                registerChild(PAGE_DESC_HREF, HREF.class);
223:                registerChild(PAGE_DESC_ACTION, StaticTextField.class);
224:                registerChild(CHILD_RULENAME_LBL, StaticTextField.class);
225:                registerChild(CHILD_RULENAME, TextField.class);
226:                registerChild(CHILD_ALGORITHMS_LBL, StaticTextField.class);
227:                registerChild(CHILD_ALGO_DEFAULT, StaticTextField.class);
228:                registerChild(CHILD_ALGO_OTHER, StaticTextField.class);
229:                registerChild(CHILD_ALGORITHMS, ListBox.class);
230:                registerChild(CHILD_URL_LBL, StaticTextField.class);
231:                registerChild(CHILD_URL, TextField.class);
232:                registerChild(CHILD_DOWNLOADAPPLET_LBL, StaticTextField.class);
233:                registerChild(CHILD_DOWNLOADAPPLET_CB, CheckBox.class);
234:                registerChild(CHILD_DOWNLOADAPPLET_NAME, TextField.class);
235:                registerChild(CHILD_EXTEND_LBL, StaticTextField.class);
236:                registerChild(CHILD_EXTEND, CheckBox.class);
237:                registerChild(CHILD_PHPLIST_LBL, StaticTextField.class);
238:                registerChild(CHILD_PHPLIST_LBL_HELP, StaticTextField.class);
239:                registerChild(CHILD_PHPLIST, ListBox.class);
240:                registerChild(CHILD_CLIENTPORT_LBL, StaticTextField.class);
241:                registerChild(CHILD_CLIENTPORT, TextField.class);
242:                registerChild(CHILD_TARGETHOST_LBL, StaticTextField.class);
243:                registerChild(CHILD_TARGETHOST, TextField.class);
244:                registerChild(CHILD_TARGETPORT_LBL, StaticTextField.class);
245:                registerChild(CHILD_TARGETPORT, TextField.class);
246:                registerChild(CHILD_SELECTED_ALGOS, HiddenField.class);
247:                registerChild(CHILD_RULE_INDEX, HiddenField.class);
248:                registerChild(CHILD_ERRORMSGS, StaticTextField.class);
249:                registerChild(CHILD_SAVE_BTN, IPlanetButton.class);
250:                registerChild(CHILD_CANCEL_BTN, IPlanetButton.class);
251:                registerChild(CHILD_REMOVE_BTN, StaticTextField.class);
252:                registerChild(CHILD_ADDTOLIST_BTN, StaticTextField.class);
253:            }
254:
255:            /**
256:             * Initialize display field values, which require backend data.
257:             */
258:            public void beginDisplay(DisplayEvent event)
259:                    throws ModelControlException {
260:                getModel();
261:                setChildValues(model);
262:                model.process();
263:                Set s = model.getNetletRules();
264:                netletRules = new Vector(s);
265:                currentRow = modelManager.getCurrentNetletRulesRow();
266:                setDisplayFieldValue(PAGE_DESC, model.getServiceDisplayName());
267:                setDisplayFieldValue(CHILD_ERRORMSGS, getErrorMessages());
268:                setDisplayFieldValue(HELP_DOC_URL, modelManager
269:                        .getString(NetletAdminService.SRA_BASE_HLP_URL));
270:                setDisplayFieldValue(HELP_ANCHOR_TAG, model
271:                        .getHelpUrl(modelManager
272:                                .getString(NetletAdminService.SRA_NL_HLP_URL)));
273:                setAlgorithmOptions(model);
274:                String currentRule = null;
275:
276:                if (currentRow == -1) { // Adding new rule
277:                    currentRule = SAMPLE_RULE;
278:                    setDisplayFieldValue(PAGE_DESC_ACTION, modelManager
279:                            .getString("addrule.pagetitle"));
280:                } else { // Editing an existing rule
281:                    currentRule = (String) netletRules.get(currentRow);
282:                    setDisplayFieldValue(PAGE_DESC_ACTION, modelManager
283:                            .getString("editrule.pagetitle"));
284:                }
285:                setDisplayFieldValue(CHILD_RULE_INDEX, currentRow);
286:
287:                if (currentRule.endsWith("EXTEND")) {
288:                    currentRule = currentRule.substring(0,
289:                            currentRule.lastIndexOf("EXTEND")).trim();
290:                    setDisplayFieldValue(CHILD_EXTEND, "true");
291:                } else {
292:                    setDisplayFieldValue(CHILD_EXTEND, "false");
293:                }
294:                StringTokenizer st = new StringTokenizer(currentRule,
295:                        RULE_DELIM);
296:                String tmp = null;
297:                try {
298:                    tmp = st.nextToken();
299:                    setDisplayFieldValue(CHILD_SELECTED_ALGOS, tmp); // Set the hidden field value required for JS 
300:                    // to select appropriate algorithms for this rule
301:                    tmp = (new StringTokenizer(tmp, ALGO_DELIM)).nextToken();
302:                    setDisplayFieldValue(CHILD_RULENAME, tmp);
303:
304:                    tmp = st.nextToken();
305:                    setDisplayFieldValue(CHILD_URL, tmp);
306:
307:                    tmp = st.nextToken();
308:                    if (tmp.equalsIgnoreCase("false")) {
309:                        setDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB, "false");
310:                    } else if (tmp.equalsIgnoreCase("true")) {
311:                        setDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB, "true");
312:                    } else {
313:                        setDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB, "true");
314:                        setDisplayFieldValue(CHILD_DOWNLOADAPPLET_NAME, tmp);
315:                    }
316:
317:                    OptionList optList = new OptionList();
318:                    ListBox lb = (ListBox) getChild(CHILD_PHPLIST);
319:                    String phpentry = null;
320:                    while (st.hasMoreTokens()) {
321:                        phpentry = st.nextToken();
322:                        phpentry += " " + st.nextToken();
323:                        phpentry += " " + st.nextToken();
324:                        optList.add(phpentry, phpentry);
325:                    }
326:                    optList.add("_______________________________________", "");
327:                    lb.setOptions(optList);
328:                } catch (NoSuchElementException nsee) {
329:                    NetletAdminModelManager
330:                            .debugError("Error parsing netlet rules " + nsee);
331:                }
332:            }
333:
334:            /**
335:             * Sets the default algotithms for Netlet rule.
336:             */
337:            public void setAlgorithmOptions(NetletAdminServiceModel m) {
338:                OptionList optList = new OptionList();
339:                String ciphers[] = NetletConstants.NETLET_CIPHERS;
340:                for (int i = 0; i < ciphers.length; i++) {
341:                    String option = ciphers[i];
342:                    optList.add(option, option);
343:                }
344:                ListBox lb = (ListBox) getChild(CHILD_ALGORITHMS);
345:                lb.setOptions(optList);
346:            }
347:
348:            /**
349:             * Creates a new NetletAdminServiceModel and returns the same,
350:             * if the model is not already been created.
351:             */
352:            public NetletAdminServiceModel getModel() {
353:                if (model == null) {
354:                    HttpServletRequest req = getRequestContext().getRequest();
355:                    req.setAttribute(
356:                            NetletAdminModelManager.SRAP_NETLET_MODEL_MGR_KEY,
357:                            getModelMgr());
358:                    getModelMgr();
359:                    model = new NetletAdminServiceModelImpl(req,
360:                            "srapnetletadminmsgs", getPageSessionAttributes(),
361:                            getServiceName(), isTemplate());
362:                }
363:                return model;
364:            }
365:
366:            /**
367:             * Creates a new NetletAdminModelManager and returns the same,
368:             * if the model is not already been created.
369:             */
370:            public NetletAdminModelManager getModelMgr() {
371:                if (modelManager == null) {
372:                    modelManager = (NetletAdminModelManager) getRequestContext()
373:                            .getModelManager();
374:                }
375:                return modelManager;
376:            }
377:
378:            /**
379:             * Tests whether the given rule name is already in the list of Netlet rules.
380:             * @ Returns true if the rule name is duplicate, false otherwise
381:             */
382:            public boolean isDuplicate(String ruleName) {
383:                if (netletRules != null && ruleName != null) {
384:                    for (int i = 0; i < netletRules.size(); i++) {
385:                        if (i == currentRow) {
386:                            continue;
387:                        }
388:                        StringTokenizer st1 = new StringTokenizer(
389:                                (String) netletRules.get(i), RULE_DELIM);
390:                        String str2 = null;
391:                        if (st1.hasMoreTokens()) {
392:                            str2 = st1.nextToken();
393:                            st1 = new StringTokenizer(str2, ALGO_DELIM);
394:                            if (st1.hasMoreTokens()) {
395:                                str2 = st1.nextToken();
396:                                if (ruleName.equals(str2)) {
397:                                    return true;
398:                                }
399:                            }
400:                        }
401:                    }
402:                }
403:                return false;
404:            }
405:
406:            /**
407:             * Returns the vector of all configured client ports. 
408:             */
409:            private Vector getClientPorts() {
410:                Vector clientPorts = new Vector();
411:                if (netletRules != null) {
412:                    for (int i = 0; i < netletRules.size(); ++i) {
413:                        if (i == currentRow) {
414:                            continue;
415:                        }
416:                        String nr = (String) netletRules.get(i);
417:                        if (nr.endsWith("EXTEND"))
418:                            nr = nr.substring(0, nr.lastIndexOf("|"));
419:                        StringTokenizer tok = new StringTokenizer(nr, "|");
420:                        try {
421:                            String func = (String) tok.nextElement();
422:                            String tmp = (String) tok.nextElement(); // url
423:                            tmp = (String) tok.nextElement(); // loopback
424:                            while (tok.hasMoreElements()) {
425:                                tmp = (String) tok.nextElement(); // local port
426:                                clientPorts.addElement(tmp);
427:                                tmp = (String) tok.nextElement(); // dest host
428:                                tmp = (String) tok.nextElement(); // dest port
429:                            }
430:                        } catch (NoSuchElementException nsee) {
431:                            continue; // skip non-parsable rules
432:                        }
433:                    }
434:                }
435:                return clientPorts;
436:            }
437:
438:            /**
439:             * Tests whether the given client port is already in the list of Netlet rules.
440:             * @ Returns true if the client port is duplicate, false otherwise
441:             8 @ Returns the StringBuffer with the list of client ports which are in use.
442:             */
443:            public boolean isClientPortDuplicate(StringBuffer result) {
444:                boolean duplicateFound = false;
445:                int indexOfDuplicate = 0;
446:                Vector clientPorts = getClientPorts();
447:                ListBox lb = (ListBox) getDisplayField(CHILD_PHPLIST);
448:                Object[] objValues = (Object[]) lb.getValues();
449:                if ((objValues != null)) {
450:                    int size = objValues.length;
451:                    for (int i = 0; i < size && !duplicateFound; i++) {
452:                        String phpentry = (String) objValues[i];
453:                        StringTokenizer tok = new StringTokenizer(phpentry, " ");
454:                        try {
455:                            String tmp = tok.nextToken();
456:                            if (clientPorts.contains(tmp)) {
457:                                duplicateFound = true;
458:                                indexOfDuplicate = clientPorts.indexOf(tmp);
459:                            }
460:                        } catch (NoSuchElementException nsee) {
461:                        } catch (NumberFormatException nfe) {
462:                        }
463:                    }
464:                }
465:                if (duplicateFound) {
466:                    result.append("<ul>");
467:                    for (int i = 0; i < clientPorts.size(); ++i) {
468:                        result.append("<li>");
469:                        if (i == indexOfDuplicate) {
470:                            result.append("<font color=red>").append(
471:                                    clientPorts.get(i)).append("</font>");
472:                        } else {
473:                            result.append(clientPorts.get(i));
474:                        }
475:                        result.append("</li>");
476:                    }
477:                    result.append("</ul>");
478:                }
479:                return duplicateFound;
480:            }
481:
482:            /**
483:             * Appends the selected algorithms to the Netlet rule buffer.
484:             */
485:            public void appendAlgorithm(StringBuffer nrBuffer) {
486:                ListBox lb = (ListBox) getDisplayField(CHILD_ALGORITHMS);
487:                Object[] objValues = (Object[]) lb.getValues();
488:                if (objValues != null) {
489:                    int size = objValues.length;
490:                    if (size > 1) {
491:                        nrBuffer.append(ALGO_DELIM + "ALGO");
492:                    }
493:                    boolean firstAlgo = true;
494:                    for (int i = 0; i < size; i++) {
495:                        if ((objValues[i] != null)
496:                                && (((String) objValues[i]).trim().length() != 0)) {
497:                            if (firstAlgo) {
498:                                firstAlgo = false;
499:                                nrBuffer.append(ALGO_DELIM
500:                                        + (String) objValues[i]);
501:                            } else {
502:                                nrBuffer.append("+" + (String) objValues[i]);
503:                            }
504:                        }
505:                    }
506:                }
507:            }
508:
509:            /**
510:             * Appends the "Download Applet" field value to the netlet rule.
511:             */
512:            public void appendDownloadApplet(StringBuffer nrBuffer) {
513:                String str1 = (String) getDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB);
514:                if (str1.equals("false")) {
515:                    nrBuffer.append(RULE_DELIM + str1);
516:                } else {
517:                    str1 = (String) getDisplayFieldValue(CHILD_DOWNLOADAPPLET_NAME);
518:                    if ((str1 == null) || (str1.trim().length() == 0)) {
519:                        nrBuffer.append(RULE_DELIM + "true");
520:                    } else {
521:                        StringTokenizer tok = new StringTokenizer(str1, ":");
522:                        StringBuffer sb = new StringBuffer();
523:                        try {
524:                            String tmp = tok.nextToken();
525:                            int port = Integer.parseInt(tmp);
526:                            sb.append(tmp);
527:                            sb.append(":" + tok.nextToken());
528:                            tmp = tok.nextToken();
529:                            port = Integer.parseInt(tmp);
530:                            sb.append(":" + tmp);
531:                            nrBuffer.append(RULE_DELIM + sb.toString());
532:                        } catch (NoSuchElementException nse) {
533:                            nrBuffer.append(RULE_DELIM + "true");
534:                        } catch (NumberFormatException nfe) {
535:                            nrBuffer.append(RULE_DELIM + "true");
536:                        }
537:                    }
538:                }
539:            }
540:
541:            /**
542:             * Appends the Port-Host-Port list to the rule.
543:             * @ Returns true on success, false if error occurs.
544:             */
545:            public boolean appendPortHostPort(StringBuffer nrBuffer) {
546:                ListBox lb = (ListBox) getDisplayField(CHILD_PHPLIST);
547:                Object[] objValues = (Object[]) lb.getValues();
548:                if ((objValues == null) || (objValues.length == 0)) {
549:                    return false;
550:                } else {
551:                    int size = objValues.length;
552:                    boolean atleastOne = false;
553:                    for (int i = 0; i < size; i++) {
554:                        String phpentry = (String) objValues[i];
555:                        StringTokenizer tok = new StringTokenizer(phpentry, " ");
556:                        StringBuffer sb = new StringBuffer();
557:                        try {
558:                            String tmp = tok.nextToken();
559:                            int port = Integer.parseInt(tmp);
560:                            sb.append(tmp);
561:                            sb.append(RULE_DELIM + tok.nextToken());
562:                            sb.append(RULE_DELIM + tok.nextToken());
563:                            nrBuffer.append(RULE_DELIM + sb.toString());
564:                            atleastOne = true;
565:                        } catch (NoSuchElementException nsee) {
566:                        } catch (NumberFormatException nfe) {
567:                        }
568:                    }
569:                    if (!atleastOne) {
570:                        return false;
571:                    }
572:                }
573:                return true;
574:            }
575:
576:            /**
577:             * Handles Save button request in EditNetletRule Page.
578:             */
579:            public void handleSaveButtonRequest(RequestInvocationEvent event)
580:                    throws ModelControlException {
581:                /**
582:                 *  Get all the display field values and store it to the backend
583:                 */
584:                getModel();
585:                model.process();
586:                Set s = model.getNetletRules();
587:                netletRules = new Vector(s);
588:                String currRow = (String) getDisplayFieldValue(CHILD_RULE_INDEX);
589:                try {
590:                    currentRow = Integer.parseInt(currRow);
591:                } catch (NumberFormatException nfe) {
592:                    currentRow = -1;
593:                    NetletAdminModelManager
594:                            .debugError("Error getting rule index : " + nfe);
595:                }
596:                StringBuffer nrBuffer = new StringBuffer();
597:                String newRule = null;
598:                Set newRuleSet = null;
599:                Map newMap = null;
600:
601:                String str1 = (String) getDisplayFieldValue(CHILD_RULENAME);
602:
603:                /**
604:                 * Test whether the Netlet rule name is null or empty.
605:                 */
606:                if ((str1 == null) || (str1.trim().length() == 0)) {
607:                    redirectToMsgVB("invalidrule.title", "rulename.error", null);
608:                    return;
609:                }
610:
611:                /**
612:                 *  Test for duplicate rulenames when adding a new Netlet rule
613:                 */
614:                if (isDuplicate(str1)) {
615:                    redirectToMsgVB("invalidrule.title",
616:                            "duplicaterulename.error", null);
617:                    return;
618:                }
619:                nrBuffer.append(str1);
620:
621:                /**
622:                 * Append the selected algorithms to the Netlet rule.
623:                 */
624:                appendAlgorithm(nrBuffer);
625:
626:                /**
627:                 * Append the URL to the Netlet rule.
628:                 */
629:                str1 = (String) getDisplayFieldValue(CHILD_URL);
630:                if ((str1 == null) || (str1.trim().length() == 0)) {
631:                    str1 = "null";
632:                }
633:                nrBuffer.append(RULE_DELIM + str1);
634:
635:                /**
636:                 * Append "Download applet" field value to the Netlet rule.
637:                 */
638:                appendDownloadApplet(nrBuffer);
639:
640:                /**
641:                 *  Test for duplicate client ports when adding a new Netlet rule
642:                 */
643:                StringBuffer sb = new StringBuffer();
644:                if (isClientPortDuplicate(sb)) {
645:                    redirectToMsgVB("invalidrule.title",
646:                            "duplicateclientport.error", new Object[] { sb });
647:                    return;
648:                }
649:
650:                /**
651:                 * Append the port-host-port list to the Netlet rule.
652:                 */
653:                if (!appendPortHostPort(nrBuffer)) {
654:                    redirectToMsgVB("invalidrule.title", "phplist.error", null);
655:                    return;
656:                }
657:
658:                /**
659:                 * Append "Extend Session" field value to the Netlet rule.
660:                 */
661:                str1 = (String) getDisplayFieldValue(CHILD_EXTEND);
662:                if (str1.equals("true")) {
663:                    nrBuffer.append(RULE_DELIM + "EXTEND");
664:                }
665:
666:                /**
667:                 * Now that we have a valid Netlet rule.
668:                 * Convert this rule to String object and store it to the backend.
669:                 */
670:                newRule = nrBuffer.toString();
671:                NetletAdminModelManager.debugMessage("newRule = " + newRule);
672:
673:                if (netletRules == null) {
674:                    netletRules = new Vector();
675:                }
676:
677:                if (currentRow == -1) { // New rule             
678:                    netletRules.add(netletRules.size(), newRule);
679:                } else {
680:                    netletRules.set(currentRow, newRule);
681:                }
682:
683:                newRuleSet = new HashSet(netletRules);
684:                newMap = new HashMap();
685:                newMap.put("sunPortalNetletRules", newRuleSet);
686:                model.store(NetletAdminServiceModel.DYNAMIC_TYPE, newMap);
687:
688:                /**
689:                 *  Forward the request to the NetletAdminServiceViewBean
690:                 */
691:                redirectToNASURL();
692:            }
693:
694:            /**
695:             * Handles Cancel button request.
696:             */
697:            public void handleCancelButtonRequest(RequestInvocationEvent event)
698:                    throws ModelControlException {
699:                redirectToNASURL();
700:            }
701:
702:            /**
703:             * Handles the page title HREF link request.
704:             */
705:            public void handleServiceDescHrefRequest(
706:                    RequestInvocationEvent event) throws ModelControlException {
707:                redirectToNASURL();
708:            }
709:
710:            /**
711:             * Returns true if we are processing at template level, false otherwise.
712:             */
713:            public boolean isTemplate() {
714:                Map attributes = getPageSessionAttributes();
715:                String template = null;
716:                if (attributes != null)
717:                    template = (String) attributes
718:                            .get(NetletAdminServiceViewBean.TEMPLATE_ATTR);
719:                if (template != null && template.equals("true")) {
720:                    return true;
721:                } else {
722:                    return false;
723:                }
724:            }
725:
726:            /**
727:             * Returns the localized service name for Netlet Service.
728:             */
729:            public String getServiceName() {
730:                Map attributes = getPageSessionAttributes();
731:                String svcName = (String) attributes
732:                        .get(NetletAdminServiceViewBean.SVC_NAME_ATTR);
733:                return svcName;
734:            }
735:
736:            /**
737:             * Returns NetletAdminServiceViewBean URL.
738:             */
739:            public String getNetletAdminServiceURL() {
740:                String nasURL = null;
741:                getModel();
742:                if (model != null) {
743:                    nasURL = model.getPropsUrl();
744:                    String queryParam = "?ServiceName="
745:                            + getPageSessionAttribute(NetletAdminServiceViewBean.SVC_NAME_ATTR)
746:                            + "&Location="
747:                            + URLEncoder
748:                                    .encode((String) getPageSessionAttribute(NetletAdminServiceViewBean.LOCATION_DN))
749:                            + "&Template="
750:                            + getPageSessionAttribute(NetletAdminServiceViewBean.TEMPLATE_ATTR);
751:                    nasURL += queryParam;
752:                }
753:                return nasURL;
754:            }
755:
756:            /**
757:             * Redirects the Request to NetletAdminServiceViewBean.
758:             */
759:            public void redirectToNASURL() {
760:                String nasURL = getNetletAdminServiceURL();
761:                HttpServletResponse response = getRequestContext()
762:                        .getResponse();
763:                try {
764:                    response.sendRedirect(nasURL);
765:                } catch (IOException ioe) {
766:                    forwardTo();
767:                }
768:            }
769:
770:            /**
771:             * Redirects request to Message view bean.
772:             */
773:            public void redirectToMsgVB(String title, String msgKey,
774:                    Object objs[]) {
775:                AMMessageViewBean msgVB = (AMMessageViewBean) getViewBean(com.iplanet.am.console.base.AMMessageViewBean.class);
776:                msgVB.setMessageType(MessageBox.TYPE_WARNING);
777:                msgVB.setTitle(modelManager.getString(title));
778:                if (objs != null) {
779:                    msgVB.setMessage(MessageFormat.format(modelManager
780:                            .getString(msgKey), objs));
781:                } else {
782:                    msgVB.setMessage(modelManager.getString(msgKey));
783:                }
784:                msgVB.addButton(modelManager.getString("ok.button"),
785:                        getNetletAdminServiceURL());
786:                msgVB.forwardTo(getRequestContext());
787:            }
788:
789:            /**
790:             * Returns localized JavaScript error messages.
791:             */
792:            private String getErrorMessages() {
793:                getModelMgr();
794:                StringBuffer sb = new StringBuffer();
795:                sb.append("errorMessages['emptyFields'] = '"
796:                        + modelManager.getString("emptyFields") + "';\n");
797:                sb.append("errorMessages['invalidclientport'] = '"
798:                        + modelManager.getString("invalidclientport") + "';\n");
799:                sb.append("errorMessages['invalidtargethost'] = '"
800:                        + modelManager.getString("invalidtargethost") + "';\n");
801:                sb.append("errorMessages['invalidtargetport'] = '"
802:                        + modelManager.getString("invalidtargetport") + "';\n");
803:                sb.append("errorMessages['dynamictargetport'] = '"
804:                        + modelManager.getString("dynamictargetport") + "';\n");
805:                sb.append("errorMessages['targetportlist'] = '"
806:                        + modelManager.getString("targetportlist") + "';\n");
807:                sb.append("errorMessages['duplicatetargets'] = '"
808:                        + modelManager.getString("duplicatetargets") + "';\n");
809:                sb.append("errorMessages['duplicateclientport'] = '"
810:                        + modelManager.getString("duplicateclientport") + "';");
811:                return sb.toString();
812:            }
813:
814:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.