Source Code Cross Referenced for EditPropertiesBean.java in  » Portal » Open-Portal » com » sun » portal » admin » console » desktop » 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.admin.console.desktop 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * $Id: EditPropertiesBean.java,v 1.44 2006/08/23 02:56:24 rt94277 Exp $
0003:         * Copyright 2005 Sun Microsystems, Inc. All
0004:         * rights reserved. Use of this product is subject
0005:         * to license terms. Federal Acquisitions:
0006:         * Commercial Software -- Government Users
0007:         * Subject to Standard License Terms and
0008:         * Conditions.
0009:         *
0010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0011:         * are trademarks or registered trademarks of Sun Microsystems,
0012:         * Inc. in the United States and other countries.
0013:         */package com.sun.portal.admin.console.desktop;
0014:
0015:        import java.util.Collections;
0016:        import java.util.Map;
0017:        import java.util.HashMap;
0018:        import java.util.Iterator;
0019:        import java.util.List;
0020:        import java.util.LinkedList;
0021:        import java.util.Arrays;
0022:        import java.util.ArrayList;
0023:        import java.util.logging.Level;
0024:        import java.util.Locale;
0025:        import java.text.MessageFormat;
0026:
0027:        import java.net.URLEncoder;
0028:        import java.net.URLDecoder;
0029:        import java.io.UnsupportedEncodingException;
0030:
0031:        import javax.management.MBeanServerConnection;
0032:        import javax.management.ObjectName;
0033:        import javax.management.MBeanException;
0034:
0035:        import com.sun.portal.admin.common.util.AdminClientUtil;
0036:        import com.sun.portal.admin.common.PSMBeanException;
0037:
0038:        import javax.servlet.http.HttpSession;
0039:        import javax.servlet.http.HttpServletRequest;
0040:
0041:        import com.sun.portal.admin.console.common.PortalBaseBean;
0042:        import com.sun.portal.admin.common.DesktopConstants;
0043:
0044:        import com.sun.data.provider.DataProvider;
0045:        import com.sun.data.provider.impl.ObjectListDataProvider;
0046:        import com.sun.data.provider.impl.ListDataProvider;
0047:        import com.sun.data.provider.TableDataProvider;
0048:        import com.sun.data.provider.TableDataListener;
0049:        import com.sun.data.provider.FieldKey;
0050:        import com.sun.data.provider.RowKey;
0051:
0052:        import com.sun.web.ui.component.Hyperlink;
0053:        import com.sun.web.ui.component.Checkbox;
0054:
0055:        import javax.faces.context.FacesContext;
0056:        import javax.faces.component.UIComponent;
0057:        import javax.faces.component.UIParameter;
0058:        import javax.faces.el.MethodBinding;
0059:
0060:        public class EditPropertiesBean extends PortalBaseBean implements 
0061:                DesktopConstants, TableDataListener {
0062:
0063:            //TODO: should these be defined a level higher
0064:            public static final char CHANNEL_NAME_SEPARATOR_CHAR = '/';
0065:            public static final String COLLECTION_NAME_SEPARATOR = "|";
0066:            public static final String LIST_PROPERTY_NAME = "listProperty";
0067:            //TODO: do not hardcode form id?
0068:            private static final String FORM_ID = "dtomgr:";
0069:
0070:            /**
0071:             * A list of Property Objects
0072:             */
0073:            protected DataProvider properties = null;
0074:
0075:            /**
0076:             * A list of Preference Objects
0077:             */
0078:            private DataProvider preferences = null;
0079:
0080:            /**
0081:             * the dn for the fqcn
0082:             */
0083:            private String dn = null;
0084:
0085:            /**
0086:             * the portalId for the current fqcn and dn
0087:             */
0088:            private String portalId = null;
0089:
0090:            /**
0091:             * Fully Qualified Channel Name
0092:             */
0093:            protected String fqcn = null;
0094:
0095:            /**
0096:             * Relative Path Name
0097:             */
0098:            private String rpn = null;
0099:
0100:            /**
0101:             * map of name-value pairs of modified properties
0102:             * used by save() method and built by TableDataListner
0103:             */
0104:            private Map modifiedMap = new HashMap();
0105:
0106:            /**
0107:             * The list of DNs that contributed in the merger of the DP document
0108:             * for this node
0109:             */
0110:            List mergedDNs = null;
0111:
0112:            private String BEAN_ALREADY_RESET_THIS_REQ = "alreadyreset";
0113:
0114:            public EditPropertiesBean() {
0115:            }
0116:
0117:            /**
0118:             * checks to see if the request has any params and if they are different
0119:             * from the ones set in the bean.
0120:             * 1. no fqcn params and bean's fqcn != null - nothing
0121:             * 2. no fqcn params and bean's fqcn == null - set properties to empty list
0122:             * 3. fqcn param different than bean's - set bean members and reset bean
0123:             * 4. fqcn/rpn params same as bean's - nothing
0124:             * 5. if dn has changed - reset bean
0125:             * 6. if portalId has changed - reset bean
0126:             *
0127:             * Assumption: rpn w/o fqcn is not allowed since rpn is relative, so when
0128:             * non-null rpn is specified, fqcn must also be specified
0129:             */
0130:            private void checkReqParams() {
0131:                HttpServletRequest req = (HttpServletRequest) FacesContext
0132:                        .getCurrentInstance().getExternalContext().getRequest();
0133:
0134:                //first get and process the req params
0135:                String req_fqcn = (String) req
0136:                        .getParameter(ATTR_SELECTED_CHANNEL_NAME);
0137:                if (req_fqcn != null) {
0138:                    try {
0139:                        req_fqcn = URLDecoder.decode(req_fqcn, DEFAULT_CHARSET);
0140:                    } catch (UnsupportedEncodingException uee) {
0141:                    }
0142:                }
0143:                String req_rpn = (String) req
0144:                        .getParameter(ATTR_NESTED_PROPERTY_NAME);
0145:                //empty rpn needs to be null
0146:                if (req_rpn != null && req_rpn.length() == 0) {
0147:                    req_rpn = null;
0148:                }
0149:                //rpn can not start with COLLECTION_NAME_SEPARATOR
0150:                if (req_rpn != null
0151:                        && req_rpn.startsWith(COLLECTION_NAME_SEPARATOR)) {
0152:                    req_rpn = req_rpn.substring(1);
0153:                }
0154:
0155:                //fqcn never changes as a result of postback
0156:                //it always changes as a result of initial access when this page is
0157:                //accessed from the tree. So the DataProvider can be changed 
0158:                //immidiately (instead of waiting till invoke-app or render-response phases) 
0159:                //by resetting the bean
0160:                if (req_fqcn == null) {
0161:                    //1. no fqcn param and bean's fqcn != null - nothing
0162:                    //2. no fqcn params and bean's fqcn == null - set properties to empty list
0163:                    if (fqcn == null) {
0164:                        properties = new ListDataProvider();
0165:                    }
0166:                } else {
0167:                    //  fqcn/rpn params different than bean's - set bean params and
0168:                    //   reset bean (only if fqcn has changed, i.e. initial request)
0169:                    //3. fqcn param same as bean's - nothing
0170:                    //4. if dn has changed, reset bean
0171:                    //5. if portalId has changed, reset bean
0172:                    if (!req_fqcn.equals(fqcn) || !getCurrentDN().equals(dn)
0173:                            || !getPortalId().equals(portalId)) {
0174:                        dn = (String) getCurrentDN();
0175:                        portalId = getPortalId();
0176:                        fqcn = req_fqcn;
0177:                        rpn = null;
0178:                        if (DP_ROOT_NODE.equals(fqcn)) {
0179:                            dpRoot = true;
0180:                        } else {
0181:                            dpRoot = false;
0182:                        }
0183:                    }
0184:
0185:                    //do not reset the bean when rpn changes (always due to postback)
0186:                    //as the DataProvider will change
0187:                    //and this should not happen since the table component needs
0188:                    //the cached DataProvider from the previous request if it is
0189:                    //a postback. The DataProvider can be changed during invoke
0190:                    //application phase when the action handler is called.
0191:                    //This is the reason all action handlers reset the bean.
0192:                    if (req_rpn != null && !req_rpn.equals(rpn)) {
0193:                        //rpn can be changed as a result of a postback. But it may be set to
0194:                        //null even from the tree which is a initial request and no a postback
0195:                        //To handle these 2 situations, let the req_rpn be set by the tree to
0196:                        //"null" instead of "". So we recognize the initial request and reset
0197:                        //the bean rightaway. Before reseting the bean, check for the request
0198:                        //attribute BEAN_ALREADY_RESET and if it is null, reset the bean.
0199:                        //Once reset, it will not be reset again even if
0200:                        //checkReqParam is called multiple times.
0201:                        if ("null".equals(req_rpn)) {
0202:                            //initial request
0203:                            if (rpn != null) {
0204:                                rpn = null;
0205:                            }
0206:                            //check for the request attribute before resetting
0207:                            //the bean in the initial request.
0208:                            if (req.getAttribute(BEAN_ALREADY_RESET_THIS_REQ) == null) {
0209:                                log(Level.FINEST, "resetting bean");
0210:                                resetBean();
0211:                                req.setAttribute(BEAN_ALREADY_RESET_THIS_REQ,
0212:                                        BEAN_ALREADY_RESET_THIS_REQ);
0213:                            }
0214:                        } else {
0215:                            rpn = req_rpn;
0216:                        }
0217:                    } else if (req_rpn == null && rpn != null) { //basically comparing nulls
0218:                        rpn = null;
0219:                    }
0220:
0221:                }
0222:            }
0223:
0224:            private void resetBean() {
0225:                resetBean(true);
0226:            }
0227:
0228:            private void resetBean(boolean resetAlert) {
0229:                links = null;
0230:                properties = null;
0231:                listCollectionName = null;
0232:                listCollection = null;
0233:                emptyMessage = null;
0234:                modifiedMap.clear();
0235:                providerName = null;
0236:                portletChannel = false;
0237:
0238:                preferences = null;
0239:                preferenceName = null;
0240:                preference = null;
0241:
0242:                if (resetAlert) {
0243:                    alert = false;
0244:                    successAlert = false;
0245:                    alertType = null;
0246:                    alertSummary = null;
0247:                    alertDetail = null;
0248:                    logMessage = null;
0249:                }
0250:                Map propsMap = getProperties(fqcn, rpn);
0251:                processExtraNodeInfo(propsMap);
0252:                List propsList = buildPropsList(propsMap);
0253:                if (propsList.isEmpty()) {
0254:                    properties = new ListDataProvider();
0255:                } else {
0256:                    properties = new ObjectListDataProvider(propsList);
0257:                    ((TableDataProvider) properties).addTableDataListener(this );
0258:                }
0259:            }
0260:
0261:            /**
0262:             * reads the node related info from the map which is passed in addition
0263:             * to the properties map. It sets the bean's members appropriately
0264:             * and then removed those keys from the map so that it can then be
0265:             * processed as a pure properties map. This is done so that all the 
0266:             * info is received from one single mbean call.
0267:             */
0268:            private void processExtraNodeInfo(Map propInfo) {
0269:
0270:                if (propInfo == null || propInfo.isEmpty()) {
0271:                    return;
0272:                }
0273:                providerName = (String) propInfo.get(KEY_PROVIDER_NAME);
0274:                propInfo.remove(KEY_PROVIDER_NAME);
0275:
0276:                Boolean bool = (Boolean) propInfo.get(KEY_IS_CONTAINER);
0277:                container = bool == null ? false : bool.booleanValue();
0278:                propInfo.remove(KEY_IS_CONTAINER);
0279:
0280:                bool = (Boolean) propInfo.get(KEY_IS_TAB_CONTAINER);
0281:                tabContainer = bool == null ? false : bool.booleanValue();
0282:                propInfo.remove(KEY_IS_TAB_CONTAINER);
0283:
0284:                bool = (Boolean) propInfo.get(KEY_IS_PORTLET_CHANNEL);
0285:                portletChannel = bool == null ? false : bool.booleanValue();
0286:                propInfo.remove(KEY_IS_PORTLET_CHANNEL);
0287:
0288:                mergedDNs = (List) propInfo.get(KEY_MERGED_DNS);
0289:                mergedDNs = mergedDNs == null ? Collections.EMPTY_LIST
0290:                        : mergedDNs;
0291:                //replace _!global!_ with "TopLevel"
0292:                if (mergedDNs.contains(GLOBAL_LOCATION_DN)) {
0293:                    mergedDNs.remove(GLOBAL_LOCATION_DN);
0294:                    mergedDNs.add(GLOBAL_LABEL);
0295:                }
0296:                propInfo.remove(KEY_MERGED_DNS);
0297:            }
0298:
0299:            /**
0300:             * returns the map received from the mbean call
0301:             */
0302:            private Map getProperties(String fqcn, String rpn) {
0303:                Map propsMap = null;
0304:                String dn = (String) getSessionAttribute(ATTR_CURRENT_LOCATION_DN);
0305:                try {
0306:                    // Get the Domain MBean object
0307:                    ObjectName objName = AdminClientUtil
0308:                            .getDisplayProfileMBeanObjectName(
0309:                                    AdminClientUtil.DEFAULT_DOMAIN,
0310:                                    getPortalId());
0311:
0312:                    // Setting the params and signature
0313:                    Object[] params = { fqcn, rpn, dn, client,
0314:                            lang + "_" + country + "_" + variant };
0315:                    String[] signature = { "java.lang.String",
0316:                            "java.lang.String", "java.lang.String",
0317:                            "java.lang.String", "java.lang.String" };
0318:
0319:                    // Invoke the get method on the portal's dp mbean
0320:                    propsMap = (Map) getMBeanServerConnection().invoke(objName,
0321:                            "getNodeProperties", params, signature);
0322:
0323:                } catch (MBeanException me) {
0324:                    log(
0325:                            Level.SEVERE,
0326:                            "EditPropertiesBean.getProperties(): Failed to get properties for a dp node of "
0327:                                    + getPortalId(), me);
0328:                    alert = true;
0329:                    alertType = "error";
0330:                    alertSummary = getLocalizedString("desktop",
0331:                            "edit.properties.alert.summary");
0332:                    if (me.getCause() instanceof  PSMBeanException) {
0333:                        PSMBeanException psmbe = (PSMBeanException) me
0334:                                .getCause();
0335:                        log(
0336:                                Level.SEVERE,
0337:                                "Exception in EditPropertiesBean.getProperties()",
0338:                                psmbe);
0339:                        String i18nKey = psmbe.getErrorKey();
0340:                        if (i18nKey != null && i18nKey.length() != 0) {
0341:                            alertDetail = getLocalizedString("desktop", i18nKey);
0342:                            //if it was not possible to localize the message from the 
0343:                            //mbean then show a generic message
0344:                            if (alertDetail.startsWith("???")) {
0345:                                alertDetail = getLocalizedString("desktop",
0346:                                        "edit.properties.misconfig.detail");
0347:                            } else {
0348:                                Object[] tokens = psmbe.getTokens();
0349:                                if (tokens != null && tokens.length > 0) {
0350:                                    Locale locale = FacesContext
0351:                                            .getCurrentInstance().getViewRoot()
0352:                                            .getLocale();
0353:                                    MessageFormat mf = new MessageFormat(
0354:                                            alertDetail, locale);
0355:                                    StringBuffer msg = mf.format(tokens,
0356:                                            new StringBuffer(), null);
0357:                                    alertDetail = msg.toString();
0358:                                }
0359:                            }
0360:                        } else {
0361:                            alertDetail = getLocalizedString("desktop",
0362:                                    "edit.properties.misconfig.detail");
0363:                        }
0364:                        logMessage = psmbe.getMessage();
0365:                    } else {
0366:                        alertDetail = getLocalizedString("desktop",
0367:                                "edit.properties.alert.detail");
0368:                        logMessage = getStackTrace(me);
0369:                    }
0370:                    propsMap = Collections.EMPTY_MAP;
0371:                } catch (Exception e) {
0372:                    log(
0373:                            Level.SEVERE,
0374:                            "EditPropertiesBean.getProperties(): Failed to get properties for a dp node of "
0375:                                    + getPortalId(), e);
0376:                    alertType = "error";
0377:                    alertSummary = getLocalizedString("desktop",
0378:                            "edit.properties.alert.summary");
0379:                    alertDetail = getLocalizedString("desktop",
0380:                            "edit.properties.alert.detail");
0381:                    alert = true;
0382:                    logMessage = getStackTrace(e);
0383:                    propsMap = Collections.EMPTY_MAP;
0384:                }
0385:                return propsMap;
0386:            }
0387:
0388:            /**
0389:             * set the modified named properties in the backend thru mbean call
0390:             */
0391:            private void setProperties(Map modifiedMap) {
0392:                String dn = (String) getSessionAttribute(ATTR_CURRENT_LOCATION_DN);
0393:                try {
0394:                    // Get the Domain MBean object
0395:                    ObjectName objName = AdminClientUtil
0396:                            .getDisplayProfileMBeanObjectName(
0397:                                    AdminClientUtil.DEFAULT_DOMAIN,
0398:                                    getPortalId());
0399:
0400:                    // Setting the params and signature
0401:                    Object[] params = { fqcn, rpn, dn, client,
0402:                            lang + "_" + country + "_" + variant, modifiedMap };
0403:                    String[] signature = { "java.lang.String",
0404:                            "java.lang.String", "java.lang.String",
0405:                            "java.lang.String", "java.lang.String",
0406:                            "java.lang.Object" };
0407:
0408:                    // Invoke the get method on the portal's dp mbean
0409:                    getMBeanServerConnection().invoke(objName,
0410:                            "setNodeProperties", params, signature);
0411:                    alert = false;
0412:                } catch (MBeanException me) {
0413:                    log(
0414:                            Level.SEVERE,
0415:                            "EditPropertiesBean.setProperties(): Failed to set properties for a dp node of "
0416:                                    + getPortalId() + " due to MBeanException ",
0417:                            me);
0418:                    alert = true;
0419:                    alertType = "error";
0420:                    alertSummary = getLocalizedString("desktop",
0421:                            "edit.properties.alert.summary");
0422:                    if (me.getCause() instanceof  PSMBeanException) {
0423:                        PSMBeanException psmbe = (PSMBeanException) me
0424:                                .getCause();
0425:                        log(
0426:                                Level.SEVERE,
0427:                                "Exception in EditPropertiesBean.setProperties()",
0428:                                me);
0429:                        String i18nKey = psmbe.getErrorKey();
0430:                        if (i18nKey != null && i18nKey.length() != 0) {
0431:                            alertDetail = getLocalizedString("desktop", i18nKey);
0432:                            //if it was not possible to localize the message from the 
0433:                            //mbean then show a generic message
0434:                            if (alertDetail.startsWith("???")) {
0435:                                alertDetail = getLocalizedString("desktop",
0436:                                        "edit.properties.misconfig.detail");
0437:                            } else {
0438:                                Object[] tokens = psmbe.getTokens();
0439:                                if (tokens != null && tokens.length > 0) {
0440:                                    Locale locale = FacesContext
0441:                                            .getCurrentInstance().getViewRoot()
0442:                                            .getLocale();
0443:                                    MessageFormat mf = new MessageFormat(
0444:                                            alertDetail, locale);
0445:                                    StringBuffer msg = mf.format(tokens,
0446:                                            new StringBuffer(), null);
0447:                                    alertDetail = msg.toString();
0448:                                }
0449:                            }
0450:                        } else {
0451:                            alertDetail = getLocalizedString("desktop",
0452:                                    "edit.properties.misconfig.detail");
0453:                        }
0454:                        logMessage = psmbe.getMessage();
0455:                    } else {
0456:                        alertDetail = getLocalizedString("desktop",
0457:                                "edit.properties.alert.detail");
0458:                        logMessage = getStackTrace(me);
0459:                    }
0460:                } catch (Exception e) {
0461:                    log(
0462:                            Level.SEVERE,
0463:                            "EditPropertiesBean.setProperties(): Failed to set properties for a dp node of "
0464:                                    + getPortalId() + " due to Exception ", e);
0465:                    alertType = "error";
0466:                    alertSummary = getLocalizedString("desktop",
0467:                            "edit.properties.alert.summary");
0468:                    alertDetail = getLocalizedString("desktop",
0469:                            "edit.properties.alert.detail");
0470:                    alert = true;
0471:                    logMessage = getStackTrace(e);
0472:                }
0473:            }
0474:
0475:            /**
0476:             * set the modified list(un-named) properties in the backend thru mbean call
0477:             */
0478:            private void setProperties(String cName, List list) {
0479:                String dn = (String) getSessionAttribute(ATTR_CURRENT_LOCATION_DN);
0480:                try {
0481:                    // Get the Domain MBean object
0482:                    ObjectName objName = AdminClientUtil
0483:                            .getDisplayProfileMBeanObjectName(
0484:                                    AdminClientUtil.DEFAULT_DOMAIN,
0485:                                    getPortalId());
0486:
0487:                    cName = (rpn == null) ? cName : (rpn
0488:                            + COLLECTION_NAME_SEPARATOR + cName);
0489:                    // Setting the params and signature
0490:                    Object[] params = { fqcn, cName, dn, client,
0491:                            lang + "_" + country + "_" + variant, list };
0492:                    String[] signature = { "java.lang.String",
0493:                            "java.lang.String", "java.lang.String",
0494:                            "java.lang.String", "java.lang.String",
0495:                            "java.lang.Object" };
0496:
0497:                    // Invoke the get method on the portal's dp mbean
0498:                    getMBeanServerConnection().invoke(objName,
0499:                            "setNodeProperties", params, signature);
0500:                    alert = false;
0501:                } catch (MBeanException me) {
0502:                    log(
0503:                            Level.SEVERE,
0504:                            "EditPropertiesBean.setProperties(): Failed to set list properties for a dp node of "
0505:                                    + getPortalId() + " due to MBeanException ",
0506:                            me);
0507:                    alert = true;
0508:                    alertType = "error";
0509:                    alertSummary = getLocalizedString("desktop",
0510:                            "edit.properties.alert.summary");
0511:                    if (me.getCause() instanceof  PSMBeanException) {
0512:                        PSMBeanException psmbe = (PSMBeanException) me
0513:                                .getCause();
0514:                        log(
0515:                                Level.SEVERE,
0516:                                "Exception in EditPropertiesBean.setProperties()",
0517:                                me);
0518:                        String i18nKey = psmbe.getErrorKey();
0519:                        if (i18nKey != null && i18nKey.length() != 0) {
0520:                            alertDetail = getLocalizedString("desktop", i18nKey);
0521:                            //if it was not possible to localize the message from the 
0522:                            //mbean then show a generic message
0523:                            if (alertDetail.startsWith("???")) {
0524:                                alertDetail = getLocalizedString("desktop",
0525:                                        "edit.properties.misconfig.detail");
0526:                            } else {
0527:                                Object[] tokens = psmbe.getTokens();
0528:                                if (tokens != null && tokens.length > 0) {
0529:                                    Locale locale = FacesContext
0530:                                            .getCurrentInstance().getViewRoot()
0531:                                            .getLocale();
0532:                                    MessageFormat mf = new MessageFormat(
0533:                                            alertDetail, locale);
0534:                                    StringBuffer msg = mf.format(tokens,
0535:                                            new StringBuffer(), null);
0536:                                    alertDetail = msg.toString();
0537:                                }
0538:                            }
0539:                        } else {
0540:                            alertDetail = getLocalizedString("desktop",
0541:                                    "edit.properties.misconfig.detail");
0542:                        }
0543:                        logMessage = psmbe.getMessage();
0544:                    } else {
0545:                        alertDetail = getLocalizedString("desktop",
0546:                                "edit.properties.alert.detail");
0547:                        logMessage = getStackTrace(me);
0548:                    }
0549:                } catch (Exception e) {
0550:                    log(
0551:                            Level.SEVERE,
0552:                            "EditPropertiesBean.setProperties(): Failed to set list properties for a dp node of "
0553:                                    + getPortalId() + " due to Exception ", e);
0554:                    alertType = "error";
0555:                    alertSummary = getLocalizedString("desktop",
0556:                            "edit.properties.alert.summary");
0557:                    alertDetail = getLocalizedString("desktop",
0558:                            "edit.properties.alert.detail");
0559:                    alert = true;
0560:                    logMessage = getStackTrace(e);
0561:                }
0562:            }
0563:
0564:            /**
0565:             * mbean call for removeCustomization
0566:             */
0567:            private void removeCustomization(List list) {
0568:                String dn = (String) getSessionAttribute(ATTR_CURRENT_LOCATION_DN);
0569:                try {
0570:                    // Get the Domain MBean object
0571:                    ObjectName objName = AdminClientUtil
0572:                            .getDisplayProfileMBeanObjectName(
0573:                                    AdminClientUtil.DEFAULT_DOMAIN,
0574:                                    getPortalId());
0575:
0576:                    // Setting the params and signature
0577:                    Object[] params = { fqcn, rpn, dn, client,
0578:                            lang + "_" + country + "_" + variant, list };
0579:                    String[] signature = { "java.lang.String",
0580:                            "java.lang.String", "java.lang.String",
0581:                            "java.lang.String", "java.lang.String",
0582:                            "java.util.List" };
0583:
0584:                    // Invoke the get method on the portal's dp mbean
0585:                    getMBeanServerConnection().invoke(objName,
0586:                            "removeCustomization", params, signature);
0587:                    alert = false;
0588:                } catch (MBeanException me) {
0589:                    log(
0590:                            Level.SEVERE,
0591:                            "EditPropertiesBean.removeCustomization(): Failed to remove customization for a dp node of "
0592:                                    + getPortalId() + " due to MBeanException ",
0593:                            me);
0594:                    alert = true;
0595:                    alertType = "error";
0596:                    alertSummary = getLocalizedString("desktop",
0597:                            "edit.properties.alert.summary");
0598:                    if (me.getCause() instanceof  PSMBeanException) {
0599:                        PSMBeanException psmbe = (PSMBeanException) me
0600:                                .getCause();
0601:                        log(
0602:                                Level.SEVERE,
0603:                                "Exception in EditPropertiesBean.removeCustomization()",
0604:                                me);
0605:                        String i18nKey = psmbe.getErrorKey();
0606:                        if (i18nKey != null && i18nKey.length() != 0) {
0607:                            alertDetail = getLocalizedString("desktop", i18nKey);
0608:                            //if it was not possible to localize the message from the 
0609:                            //mbean then show a generic message
0610:                            if (alertDetail.startsWith("???")) {
0611:                                alertDetail = getLocalizedString("desktop",
0612:                                        "edit.properties.misconfig.detail");
0613:                            } else {
0614:                                Object[] tokens = psmbe.getTokens();
0615:                                if (tokens != null && tokens.length > 0) {
0616:                                    Locale locale = FacesContext
0617:                                            .getCurrentInstance().getViewRoot()
0618:                                            .getLocale();
0619:                                    MessageFormat mf = new MessageFormat(
0620:                                            alertDetail, locale);
0621:                                    StringBuffer msg = mf.format(tokens,
0622:                                            new StringBuffer(), null);
0623:                                    alertDetail = msg.toString();
0624:                                }
0625:                            }
0626:                        } else {
0627:                            alertDetail = getLocalizedString("desktop",
0628:                                    "edit.properties.misconfig.detail");
0629:                        }
0630:                        logMessage = psmbe.getMessage();
0631:                    } else {
0632:                        alertDetail = getLocalizedString("desktop",
0633:                                "edit.properties.alert.detail");
0634:                        logMessage = getStackTrace(me);
0635:                    }
0636:                } catch (Exception e) {
0637:                    log(
0638:                            Level.SEVERE,
0639:                            "EditPropertiesBean.removeCustomization(): Failed to remove customization for a dp node of "
0640:                                    + getPortalId() + " due to Exception ", e);
0641:                    alertType = "error";
0642:                    alertSummary = getLocalizedString("desktop",
0643:                            "edit.properties.alert.summary");
0644:                    alertDetail = getLocalizedString("desktop",
0645:                            "edit.properties.alert.detail");
0646:                    alert = true;
0647:                    logMessage = getStackTrace(e);
0648:                }
0649:            }
0650:
0651:            /**
0652:             * returns a list of Property objects for constructing DataProvider
0653:             * builds the Property objects from the data in map returned by mbean
0654:             */
0655:            private List buildPropsList(Map propsMap) {
0656:                if (propsMap == null || propsMap.isEmpty()) {
0657:                    log(Level.INFO,
0658:                            "Properties map was empty or null, could not build a list");
0659:                    return Collections.EMPTY_LIST;
0660:                }
0661:                int nProps = propsMap.size();
0662:                List propsList = new ArrayList(nProps);
0663:                Iterator iter = propsMap.keySet().iterator();
0664:                while (iter.hasNext()) {
0665:                    String name = (String) iter.next();
0666:                    Map info = (Map) propsMap.get(name);
0667:                    Boolean adv = (Boolean) info.get(KEY_IS_ADVANCED);
0668:                    boolean advanced = adv == null ? false : adv.booleanValue();
0669:                    if (portletChannel) {
0670:                        if (!advanced) {
0671:                            propsList.add(new Property(name, ((Boolean) info
0672:                                    .get(KEY_NAMED)).booleanValue(),
0673:                                    ((Short) info.get(KEY_TYPE)).shortValue(),
0674:                                    info.get(KEY_VALUE), advanced,
0675:                                    (String) info.get(KEY_STATE)));
0676:                        }
0677:                    } else {
0678:                        boolean named = ((Boolean) info.get(KEY_NAMED))
0679:                                .booleanValue();
0680:                        //a colletion should not (engg recommendation, although possible)
0681:                        //contain a mix of named and unnamed
0682:                        //properties. HIE recommends that this be shown as error.
0683:                        if (rpn != null && !named) {
0684:                            emptyMessage = getLocalizedString("desktop",
0685:                                    "edit.properties.error.mixedCollection");
0686:                            return Collections.EMPTY_LIST;
0687:                        }
0688:                        propsList.add(new Property(name, named, ((Short) info
0689:                                .get(KEY_TYPE)).shortValue(), info
0690:                                .get(KEY_VALUE), advanced, (String) info
0691:                                .get(KEY_STATE)));
0692:                    }
0693:                }
0694:                return propsList;
0695:            }
0696:
0697:            ///////////// begin getters/setters /////////////////
0698:            public DataProvider getProperties() {
0699:                checkReqParams();
0700:                return properties;
0701:            }
0702:
0703:            private String emptyMessage = null;
0704:
0705:            public String getEmptyMessage() {
0706:                checkReqParams();
0707:                return emptyMessage;
0708:            }
0709:
0710:            public String getChannelName() {
0711:                checkReqParams();
0712:                return fqcn;
0713:            }
0714:
0715:            public String getEncodedChannelName() {
0716:                String name = getChannelName();
0717:                String encodedName = null;
0718:                try {
0719:                    encodedName = URLEncoder.encode(name, DEFAULT_CHARSET);
0720:                } catch (UnsupportedEncodingException uee) {
0721:                    encodedName = name;
0722:                }
0723:                return encodedName;
0724:            }
0725:
0726:            public String getRpn() {
0727:                checkReqParams();
0728:                return rpn;
0729:            }
0730:
0731:            private String providerName = null;
0732:
0733:            public String getProviderName() {
0734:                checkReqParams();
0735:                String name = providerName;
0736:                if (providerName != null) {
0737:                    if (portletChannel) {
0738:                        String[] a = providerName.split("__Portlet__");
0739:                        if (a.length == 2) {
0740:                            name = a[1];
0741:                        }
0742:                    } else if (providerName.startsWith("_WSRPProvider")) {
0743:                        name = getLocalizedString("desktop",
0744:                                "edit.properties.wsrpProvider.label");
0745:                    }
0746:                }
0747:                return name;
0748:            }
0749:
0750:            public boolean isDisaster() {
0751:                boolean disaster = false;
0752:                if (((providerName == null || providerName.length() == 0) && !"_root"
0753:                        .equals(fqcn))
0754:                        || getLocalizedString("desktop",
0755:                                "label.content.unavailable").equals(fqcn)) {
0756:                    disaster = true;
0757:                }
0758:                return disaster;
0759:            }
0760:
0761:            public String getMergedDNs() {
0762:                String mergeList = "";
0763:                Iterator iter = mergedDNs.iterator();
0764:                int i = 1;
0765:                while (iter.hasNext()) {
0766:                    mergeList += "(" + i++ + ")" + (String) iter.next()
0767:                            + "<br>";
0768:                }
0769:                return mergeList;
0770:            }
0771:
0772:            private boolean container = false;
0773:
0774:            public boolean isContainer() {
0775:                checkReqParams();
0776:                return container;
0777:            }
0778:
0779:            private boolean tabContainer = false;
0780:
0781:            public boolean isTabContainer() {
0782:                checkReqParams();
0783:                return tabContainer;
0784:            }
0785:
0786:            /**
0787:             * whether current channel is portlet channel
0788:             */
0789:
0790:            private boolean portletChannel = false;
0791:
0792:            public boolean isPortletChannel() {
0793:                checkReqParams();
0794:                return portletChannel;
0795:            }
0796:
0797:            /**
0798:             * whether current node is dp root.
0799:             */
0800:            private boolean dpRoot = false;
0801:
0802:            public boolean isDpRoot() {
0803:                checkReqParams();
0804:                return dpRoot;
0805:            }
0806:
0807:            /**
0808:             * Called by the create new property wizard
0809:             * to display the collection name for which new property
0810:             * is being created
0811:             */
0812:            public String getCurrentCollectionName() {
0813:                checkReqParams();
0814:                String cName = null;
0815:                if (rpn != null) {
0816:                    int index = rpn.lastIndexOf(COLLECTION_NAME_SEPARATOR);
0817:                    if (index != -1) {
0818:                        cName = rpn.substring(index + 1);
0819:                    } else {
0820:                        cName = rpn;
0821:                    }
0822:                }
0823:                return cName;
0824:            }
0825:
0826:            public boolean isCollection() {
0827:                checkReqParams();
0828:                return rpn != null;
0829:            }
0830:
0831:            public boolean isDefaultLocale() {
0832:                boolean def = (client == null && lang == null);
0833:                return def;
0834:            }
0835:
0836:            private String client = null;
0837:
0838:            public String getClient() {
0839:                return client;
0840:            }
0841:
0842:            public void setClient(String client) {
0843:                if (client != null && client.length() == 0) {
0844:                    client = null;
0845:                }
0846:                this .client = client;
0847:            }
0848:
0849:            private String lang = null;
0850:
0851:            public String getLang() {
0852:                return lang;
0853:            }
0854:
0855:            public void setLang(String lang) {
0856:                if (lang != null && lang.length() == 0) {
0857:                    lang = null;
0858:                }
0859:                this .lang = lang;
0860:            }
0861:
0862:            private String country = null;
0863:
0864:            public String getCountry() {
0865:                return country;
0866:            }
0867:
0868:            public void setCountry(String country) {
0869:                if (country != null && country.length() == 0) {
0870:                    country = null;
0871:                }
0872:                this .country = country;
0873:            }
0874:
0875:            private String variant = null;
0876:
0877:            public String getVariant() {
0878:                return variant;
0879:            }
0880:
0881:            public void setVariant(String variant) {
0882:                if (variant != null && variant.length() == 0) {
0883:                    variant = null;
0884:                }
0885:                this .variant = variant;
0886:            }
0887:
0888:            public String getCurrentClientLocale() {
0889:                String cLocale = "";
0890:                if (client != null && client.length() != 0) {
0891:                    cLocale += client;
0892:                }
0893:                if (lang != null && lang.length() != 0) {
0894:                    if (cLocale.length() == 0) {
0895:                        cLocale += lang;
0896:                    } else {
0897:                        cLocale += "_" + lang;
0898:                    }
0899:                    if (country != null && country.length() != 0) {
0900:                        cLocale += "_" + country;
0901:                        if (variant != null && variant.length() != 0) {
0902:                            cLocale += "_" + variant;
0903:                        }
0904:                    }
0905:                }
0906:                return cLocale.length() == 0 ? getLocalizedString("desktop",
0907:                        "edit.properties.currentLocale.default") : cLocale;
0908:            }
0909:
0910:            public String getCurrentClient() {
0911:                return (client == null || client.length() == 0) ? getLocalizedString(
0912:                        "desktop", "edit.properties.currentLocale.default")
0913:                        : client;
0914:            }
0915:
0916:            public String getCurrentLocale() {
0917:                String locale = "";
0918:                if (lang != null && lang.length() != 0) {
0919:                    locale += lang;
0920:                    if (country != null && country.length() != 0) {
0921:                        locale += "_" + country;
0922:                        if (variant != null && variant.length() != 0) {
0923:                            locale += "_" + variant;
0924:                        }
0925:                    }
0926:                }
0927:                return locale.length() == 0 ? getLocalizedString("desktop",
0928:                        "edit.properties.currentLocale.default") : locale;
0929:            }
0930:
0931:            private String listCollectionName = null;
0932:
0933:            public String getListCollectionName() {
0934:                if (listCollectionName == null) {
0935:                    //make a deliberate call to getListValue
0936:                    //so that it will populate the value for listCollectionName
0937:                    //appropriately from the request
0938:                    getListValue();
0939:                }
0940:                return listCollectionName;
0941:            }
0942:
0943:            private Property listCollection = null;
0944:
0945:            public String[] getListValue() {
0946:                String[] sa = new String[0];
0947:                String pName = getNameFromQuery();
0948:                if (pName != null) {
0949:                    if (listCollectionName == null
0950:                            || !pName.equals(listCollectionName)) {
0951:                        listCollectionName = pName;
0952:                        listCollection = null;
0953:                    }
0954:                }
0955:                if (listCollection == null) {
0956:                    listCollection = getPropertyFromList(listCollectionName);
0957:                }
0958:
0959:                return listCollection == null ? sa : listCollection
0960:                        .getValueArray();
0961:            }
0962:
0963:            public void setListValue(String[] strList) {
0964:                if (listCollectionName != null && listCollection != null) {
0965:                    listCollection.setValueArray(strList);
0966:                }
0967:            }
0968:
0969:            private boolean successAlert = false;
0970:
0971:            public boolean isSuccessAlert() {
0972:                checkReqParams();
0973:                return successAlert;
0974:            }
0975:
0976:            private boolean alert = false;
0977:
0978:            public boolean isAlert() {
0979:                checkReqParams();
0980:                return alert;
0981:            }
0982:
0983:            private String alertDetail = null;
0984:
0985:            public String getAlertDetail() {
0986:                checkReqParams();
0987:                return alertDetail;
0988:            }
0989:
0990:            public void setAlertDetail(String detail) {
0991:                alertDetail = detail;
0992:            }
0993:
0994:            private String alertSummary = null;
0995:
0996:            public String getAlertSummary() {
0997:                checkReqParams();
0998:                return alertSummary;
0999:            }
1000:
1001:            public void setAlertSummary(String summary) {
1002:                alertSummary = summary;
1003:            }
1004:
1005:            private String alertType = null;
1006:
1007:            public String getAlertType() {
1008:                checkReqParams();
1009:                return alertType;
1010:            }
1011:
1012:            public void setAlertType(String aType) {
1013:                alertType = aType;
1014:            }
1015:
1016:            private String logMessage = null;
1017:
1018:            public String getLogMessage() {
1019:                String logDisplay = logMessage == null ? "" : logMessage;
1020:                return logDisplay.replaceAll("\n", "<br>");
1021:            }
1022:
1023:            //// getters/setters for portlet preferences ////
1024:            public DataProvider getPreferences() {
1025:                checkReqParams();
1026:
1027:                if (isPortletChannel()) {
1028:                    if (preferences == null) {
1029:                        Map prefMap = getPortletPreferences(fqcn);
1030:                        List prefList = buildPrefList(prefMap);
1031:                        if (prefList.isEmpty()) {
1032:                            preferences = new ListDataProvider();
1033:                        } else {
1034:                            preferences = new ObjectListDataProvider(prefList);
1035:                            ((TableDataProvider) preferences)
1036:                                    .addTableDataListener(this );
1037:                        }
1038:                    }
1039:                } else {
1040:                    preferences = new ListDataProvider();
1041:                }
1042:                return preferences;
1043:            }
1044:
1045:            private String preferenceName = null;
1046:
1047:            public String getPreferenceName() {
1048:                if (preferenceName == null) {
1049:                    //make a deliberate call to getPreferenceValue
1050:                    //so that it will populate the value for preferenceName
1051:                    //appropriately from the request
1052:                    getPreferenceValue();
1053:                }
1054:                return preferenceName;
1055:            }
1056:
1057:            private Preference preference = null;
1058:
1059:            public String[] getPreferenceValue() {
1060:                String[] sa = new String[0];
1061:                String pName = getPrefNameFromQuery();
1062:                if (pName != null) {
1063:                    if (preference == null || !pName.equals(preferenceName)) {
1064:                        preferenceName = pName;
1065:                        preference = null;
1066:                    }
1067:                }
1068:                if (preference == null) {
1069:                    preference = getPreferenceFromList(preferenceName);
1070:                }
1071:                return preference == null ? sa : preference.getValueArray();
1072:            }
1073:
1074:            public void setPreferenceValue(String[] strList) {
1075:                if (preferenceName != null && preference != null) {
1076:                    preference.setValueArray(strList);
1077:                }
1078:            }
1079:
1080:            ///////////// end getters/setters /////////////////
1081:
1082:            private String getNameFromQuery() {
1083:                HttpServletRequest req = (HttpServletRequest) FacesContext
1084:                        .getCurrentInstance().getExternalContext().getRequest();
1085:                String name = (String) req.getParameter(LIST_PROPERTY_NAME);
1086:                return name;
1087:            }
1088:
1089:            private Property getPropertyFromList(String name) {
1090:                Property collection = null;
1091:                if (properties != null) {
1092:                    Iterator iter = ((ObjectListDataProvider) properties)
1093:                            .getList().iterator();
1094:                    while (iter.hasNext()) {
1095:                        Property prop = (Property) iter.next();
1096:                        if (prop.getName().equals(name)) {
1097:                            collection = prop;
1098:                            break;
1099:                        }
1100:                    }
1101:                }
1102:                return collection;
1103:            }
1104:
1105:            ////////// begin actions //////////////
1106:
1107:            /**
1108:             * called when locale is changed and OK button in the table
1109:             * preferences is clicked
1110:             */
1111:            public String changeClientLocale() {
1112:                //fetch data from backend
1113:                resetBean();
1114:                return null;
1115:            }
1116:
1117:            /**
1118:             * reset action button for the table actions is clicked
1119:             */
1120:            public String reset() {
1121:                resetBean();
1122:                return null;
1123:            }
1124:
1125:            /**
1126:             * save action button for the table actions is clicked
1127:             */
1128:            public String save() {
1129:                if (!modifiedMap.isEmpty()) {
1130:                    //store and refresh properties
1131:                    setProperties(modifiedMap);
1132:                    //fetch data from backend
1133:                    resetBean(!alert);
1134:                    if (!alert) {
1135:                        setSuccessAlert();
1136:                        successAlert = true;
1137:                        //unset the error alert set by setSuccessAlert
1138:                        alert = false;
1139:                    }
1140:                }
1141:                return null;
1142:            }
1143:
1144:            /**
1145:             * save action called from the pop-up to save un-named properties
1146:             */
1147:            public String saveList() {
1148:                if (listCollectionName != null && listCollection != null) {
1149:                    List list = Arrays.asList(listCollection.getValueArray());
1150:                    //store the new values
1151:                    setProperties(listCollectionName, list);
1152:                    //save off the collection name before reset in a tmp var 
1153:                    String name = listCollectionName;
1154:                    //fetch data from backend
1155:                    resetBean(!alert);
1156:                    if (!alert) {
1157:                        setSuccessAlert();
1158:                        successAlert = true;
1159:                        //unset the error alert set by setSuccessAlert
1160:                        alert = false;
1161:                    }
1162:                    //now restore the collection name from tmp var
1163:                    listCollectionName = name;
1164:                }
1165:                return null;
1166:            }
1167:
1168:            public String removeCustomization() {
1169:                List names = Checkbox.getSelected("selectGroup");
1170:
1171:                if (names == null || names.size() == 0) {
1172:                    //nothing to do, but reset the bean to clear out any entered data
1173:                    //in the widgets
1174:                    resetBean(true);
1175:                    return null;
1176:                }
1177:
1178:                //remove the names which are not customized
1179:                List propList = null;
1180:                if (properties instanceof  ObjectListDataProvider) {
1181:                    propList = ((ObjectListDataProvider) properties).getList();
1182:                }
1183:
1184:                if (propList == null) {
1185:                    log(
1186:                            Level.INFO,
1187:                            "EditPropertiesBean.removeCustomization(): "
1188:                                    + "Failed to remove customization - properties list is null");
1189:                    return null;
1190:                }
1191:
1192:                int nProps = propList.size();
1193:                for (int i = 0; i < nProps; i++) {
1194:                    Property prop = (Property) propList.get(i);
1195:                    if (prop != null && !prop.isCustomized()) {
1196:                        String name = prop.getName();
1197:                        if (names.contains(name)) {
1198:                            names.remove(name);
1199:                        }
1200:                    }
1201:                }
1202:
1203:                log(Level.FINEST, "EditPropertiesBean.removeCustomization(): "
1204:                        + "Removing customization for " + names);
1205:
1206:                removeCustomization(names);
1207:                resetBean(!alert);
1208:                if (!alert) {
1209:                    setSuccessAlert();
1210:                    successAlert = true;
1211:                    //unset the error alert set by setSuccessAlert
1212:                    alert = false;
1213:                }
1214:                return null;
1215:            }
1216:
1217:            /**
1218:             * save action called from the pop-up to save un-named properties
1219:             */
1220:            public String savePreferenceValues() {
1221:                if (preferenceName != null && preference != null) {
1222:                    setPortletPreferences(preferenceName, preference
1223:                            .getValueArray());
1224:                    if (!alert) {
1225:                        setSuccessAlert();
1226:                        successAlert = true;
1227:                        //unset the error alert set by setSuccessAlert
1228:                        alert = false;
1229:                    }
1230:                }
1231:                return null;
1232:            }
1233:
1234:            ////////// end actions //////////////
1235:
1236:            //////////////////begin TableDataListener methods///////////////////
1237:
1238:            public void rowAdded(TableDataProvider provider, RowKey row) {
1239:            }
1240:
1241:            public void rowRemoved(TableDataProvider provider, RowKey row) {
1242:            }
1243:
1244:            public void providerChanged(DataProvider provider) {
1245:            }
1246:
1247:            public void valueChanged(TableDataProvider provider,
1248:                    FieldKey fieldKey, RowKey row, Object oldValue,
1249:                    Object newValue) {
1250:                Property prop = (Property) ((ObjectListDataProvider) provider)
1251:                        .getObject(row);
1252:                if (newValue != null) {
1253:                    if (prop.isBool()) {
1254:                        /*
1255:                         *This is a real hack
1256:                         *radioButtonGroup is not degsined to be used in a table
1257:                         *so it renders borders around the radios and the label area.
1258:                         *Lockhart advised to use radioButton instead
1259:                         *There are 2 radios and we want the value to be set only for
1260:                         *one of them as this is to behave as boolean.
1261:                         *The true radio is bound to Property.boolTrueValue
1262:                         *and false radio is bound to Property.boolFalseValue
1263:                         *and we check and set it only once for true radio
1264:                         */
1265:                        String id = fieldKey.getFieldId();
1266:                        if (id.equals("boolTrueValue")) {
1267:                            modifiedMap.put(prop.getName(), newValue);
1268:                        }
1269:                    } else if (prop.isNumeric()) {
1270:                        try {
1271:                            modifiedMap.put(prop.getName(), new Integer(
1272:                                    (String) newValue));
1273:                        } catch (NumberFormatException nfe) {
1274:                            //ignore this value
1275:                            log(
1276:                                    Level.FINE,
1277:                                    "EditPropertiesBean.valueChanged(): Incorrect integer value, ignored setting property "
1278:                                            + prop.getName());
1279:                        }
1280:                    } else if (prop.isString()) {
1281:                        modifiedMap.put(prop.getName(), newValue);
1282:                    } else {
1283:                        //unknown type - should never happen
1284:                        log(Level.INFO,
1285:                                "Unknown type, ignored setting property "
1286:                                        + prop.getName());
1287:                    }
1288:                }
1289:            }
1290:
1291:            public void valueChanged(DataProvider provider, FieldKey fieldKey,
1292:                    Object oldValue, Object newValue) {
1293:            }
1294:
1295:            ////////////////////end TableDataListener//////////////////////
1296:
1297:            private Hyperlink[] links = null;
1298:
1299:            public Hyperlink[] getCrumbs() {
1300:                if (fqcn != null) {
1301:                    String id = "_channel";
1302:                    String[] names = getNames(rpn);
1303:                    links = new Hyperlink[1 + names.length];
1304:                    Hyperlink lnk = new Hyperlink();
1305:                    lnk.setId(id);
1306:                    if ("_root".equals(fqcn)) {
1307:                        lnk.setText(getLocalizedString("desktop",
1308:                                "edit.properties.dproot.label"));
1309:                    } else {
1310:                        lnk.setText(fqcn);
1311:                    }
1312:
1313:                    MethodBinding action = null;
1314:                    try {
1315:                        action = FacesContext.getCurrentInstance()
1316:                                .getApplication().createMethodBinding(
1317:                                        "#{EditPropertiesBean.reset}", null);
1318:                    } catch (Exception e) {
1319:                        /* should never happen as long as 
1320:                         * as long as someonce renames the method                       
1321:                         */
1322:                    }
1323:                    lnk.setAction(action);
1324:
1325:                    //create a UIComp for addition as child
1326:                    String encodedName = null;
1327:                    try {
1328:                        encodedName = URLEncoder.encode(fqcn, DEFAULT_CHARSET);
1329:                    } catch (UnsupportedEncodingException uee) {
1330:                        encodedName = fqcn;
1331:                    }
1332:                    UIParameter fparam = new UIParameter();
1333:                    fparam.setId(id + "p");
1334:                    fparam.setName(ATTR_SELECTED_CHANNEL_NAME);
1335:                    fparam.setValue(encodedName);
1336:                    lnk.getChildren().add(fparam);
1337:                    fparam = new UIParameter();
1338:                    fparam.setId(id + "q");
1339:                    fparam.setName(ATTR_NESTED_PROPERTY_NAME);
1340:                    fparam.setValue("");
1341:                    lnk.getChildren().add(fparam);
1342:                    links[0] = lnk;
1343:                    for (int i = 1; i <= names.length; i++) {
1344:                        lnk = new Hyperlink();
1345:                        String id_base = "_collection_" + i;
1346:                        lnk.setId(id_base);
1347:                        lnk.setText(names[i - 1]);
1348:                        lnk.setAction(action);
1349:                        fparam = new UIParameter();
1350:                        fparam.setId(id_base + "p");
1351:                        fparam.setName(ATTR_SELECTED_CHANNEL_NAME);
1352:                        fparam.setValue(encodedName);
1353:                        //add the child
1354:                        lnk.getChildren().add(fparam);
1355:                        fparam = new UIParameter();
1356:                        fparam.setId(id_base + "q");
1357:                        fparam.setName(ATTR_NESTED_PROPERTY_NAME);
1358:                        //construct the property path
1359:                        String value = names[0];
1360:                        for (int j = 1; j < i; j++) {
1361:                            value = value + COLLECTION_NAME_SEPARATOR
1362:                                    + names[j];
1363:                        }
1364:                        fparam.setValue(value);
1365:                        lnk.getChildren().add(fparam);
1366:                        links[i] = lnk;
1367:                    }
1368:                }
1369:                return links;
1370:            }
1371:
1372:            private String[] getNames(String rpn) {
1373:                if (rpn == null) {
1374:                    return new String[0];
1375:                }
1376:                //the separator is a pipe '|' and needs to be escaped in regex
1377:                String names[] = rpn.split("\\" + COLLECTION_NAME_SEPARATOR);
1378:                if (names.length == 1 && names[0].length() == 0) {
1379:                    names = new String[0];
1380:                }
1381:                return names;
1382:            }
1383:
1384:            private ObjectName getPortletAdminMBeanObjectName() {
1385:                ObjectName objName = null;
1386:                try {
1387:                    // Get the Domain MBean object
1388:                    LinkedList path = new LinkedList();
1389:                    path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
1390:                    path.addFirst(getPortalId());
1391:                    path.addFirst("PortletAdmin");
1392:
1393:                    objName = AdminClientUtil
1394:                            .getResourceMBeanObjectName(
1395:                                    AdminClientUtil.PORTAL_MBEAN_TYPE
1396:                                            + ".PortletAdmin", path);
1397:                } catch (Exception e) {
1398:                    log(Level.SEVERE,
1399:                            "EditPropertiesBean.getPortletAdminMBeanObjectName(): Failed "
1400:                                    + "to get portlet admin object name ", e);
1401:                }
1402:                return objName;
1403:            }
1404:
1405:            /**
1406:             * returns a list of Preference objects for constructing DataProvider
1407:             * builds the Preference objects from the data in map returned by mbean
1408:             */
1409:            private List buildPrefList(Map prefMap) {
1410:                if (prefMap == null || prefMap.isEmpty()) {
1411:                    log(Level.INFO,
1412:                            "Preferences map was empty or null, could not build a list");
1413:                    return Collections.EMPTY_LIST;
1414:                }
1415:                int nPrefs = prefMap.size();
1416:                List prefsList = new ArrayList(nPrefs);
1417:                Iterator iter = prefMap.keySet().iterator();
1418:                while (iter.hasNext()) {
1419:                    String name = (String) iter.next();
1420:                    Map info = (Map) prefMap.get(name);
1421:                    boolean readOnly = ((Boolean) info.get("isReadOnly"))
1422:                            .booleanValue();
1423:                    List values = (List) info.get("values");
1424:                    prefsList.add(new Preference(name, readOnly, values));
1425:                }
1426:                return prefsList;
1427:            }
1428:
1429:            private Map getPortletPreferences(String channelName) {
1430:                Map prefs = new HashMap();
1431:                String dn = (String) getSessionAttribute(ATTR_CURRENT_LOCATION_DN);
1432:                try {
1433:                    ObjectName objName = getPortletAdminMBeanObjectName();
1434:
1435:                    // Setting the params and signature
1436:                    Object[] params = { dn, channelName };
1437:                    String[] signature = { "java.lang.String",
1438:                            "java.lang.String" };
1439:
1440:                    // Invoke the get method on the portal's dp mbean
1441:                    prefs = (Map) getMBeanServerConnection().invoke(objName,
1442:                            "getPortletPreferenceMap", params, signature);
1443:
1444:                } catch (MBeanException me) {
1445:                    System.out.println("mbean exception in prefs" + me);
1446:                    log(
1447:                            Level.SEVERE,
1448:                            "EditPropertiesBean.getPortletPreferences(): Failed to get preference map for portlet channel "
1449:                                    + channelName, me);
1450:                    if (me.getCause() instanceof  PSMBeanException) {
1451:                        log(
1452:                                Level.SEVERE,
1453:                                "Exception in EditPropertiesBean.getPortletPreferences()",
1454:                                me);
1455:                    }
1456:                } catch (Exception e) {
1457:                    System.out.println("exception in prefs " + e);
1458:                    log(
1459:                            Level.SEVERE,
1460:                            "EditPropertiesBean.getPortletPreferences(): Failed to get preference map for portlet channel "
1461:                                    + channelName, e);
1462:                }
1463:                return prefs;
1464:            }
1465:
1466:            private String getPrefNameFromQuery() {
1467:                HttpServletRequest req = (HttpServletRequest) FacesContext
1468:                        .getCurrentInstance().getExternalContext().getRequest();
1469:                String name = (String) req.getParameter("preferenceName");
1470:                return name;
1471:            }
1472:
1473:            private Preference getPreferenceFromList(String name) {
1474:                Preference p = null;
1475:                if (preferences != null) {
1476:                    Iterator iter = ((ObjectListDataProvider) preferences)
1477:                            .getList().iterator();
1478:                    while (iter.hasNext()) {
1479:                        Preference pref = (Preference) iter.next();
1480:                        if (pref.getName().equals(name)) {
1481:                            p = pref;
1482:                            break;
1483:                        }
1484:                    }
1485:                }
1486:                return p;
1487:            }
1488:
1489:            private void setPortletPreferences(String prefName,
1490:                    String[] valueArray) {
1491:                String dn = (String) getSessionAttribute(ATTR_CURRENT_LOCATION_DN);
1492:                try {
1493:                    ObjectName objName = getPortletAdminMBeanObjectName();
1494:
1495:                    // Setting the params and signature
1496:                    Object[] params = { dn, fqcn, prefName, valueArray };
1497:                    String[] signature = { "java.lang.String",
1498:                            "java.lang.String", "java.lang.String",
1499:                            "[Ljava.lang.String;" };
1500:
1501:                    // Invoke the get method on the portal's dp mbean
1502:                    getMBeanServerConnection().invoke(objName,
1503:                            "setPortletPreferenceValues", params, signature);
1504:                } catch (MBeanException me) {
1505:                    log(
1506:                            Level.SEVERE,
1507:                            "EditPropertiesBean.setPortletPreferences(): Failed to set preference map for portlet channel "
1508:                                    + fqcn, me);
1509:                    if (me.getCause() instanceof  PSMBeanException) {
1510:                        log(
1511:                                Level.SEVERE,
1512:                                "Exception in EditPropertiesBean.setPortletPreferences()",
1513:                                me);
1514:                    }
1515:
1516:                } catch (Exception e) {
1517:                    log(
1518:                            Level.SEVERE,
1519:                            "EditPropertiesBean.setPortletPreferences():  Failed to set preference map for portlet channel "
1520:                                    + fqcn, e);
1521:                }
1522:            }
1523:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.