Source Code Cross Referenced for PortletManagementManagerImpl.java in  » Portal » Open-Portal » com » sun » portal » wsrp » producer » portletmanagement » impl » 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.wsrp.producer.portletmanagement.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * Copyright 2003 Sun Microsystems, Inc. All
0003:         * rights reserved. Use of this product is subject
0004:         * to license terms. Federal Acquisitions:
0005:         * Commercial Software -- Government Users
0006:         * Subject to Standard License Terms and
0007:         * Conditions.
0008:         *
0009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0010:         * are trademarks or registered trademarks of Sun Microsystems,
0011:         * Inc. in the United States and other countries.
0012:         */package com.sun.portal.wsrp.producer.portletmanagement.impl;
0013:
0014:        import com.sun.portal.wsrp.common.stubs.GetPortletDescription;
0015:        import com.sun.portal.wsrp.common.stubs.AccessDeniedFault;
0016:        import com.sun.portal.wsrp.common.stubs.InconsistentParametersFault;
0017:        import com.sun.portal.wsrp.common.stubs.InvalidHandleFault;
0018:        import com.sun.portal.wsrp.common.stubs.InvalidRegistrationFault;
0019:        import com.sun.portal.wsrp.common.stubs.InvalidUserCategoryFault;
0020:        import com.sun.portal.wsrp.common.stubs.MissingParametersFault;
0021:        import com.sun.portal.wsrp.common.stubs.OperationFailedFault;
0022:        import com.sun.portal.wsrp.common.stubs.PortletContext;
0023:        import com.sun.portal.wsrp.common.stubs.DestroyPortletsResponse;
0024:        import com.sun.portal.wsrp.common.stubs.PropertyList;
0025:        import com.sun.portal.wsrp.common.stubs.ClonePortlet;
0026:        import com.sun.portal.wsrp.common.stubs.DestroyPortlets;
0027:        import com.sun.portal.wsrp.common.stubs.SetPortletProperties;
0028:        import com.sun.portal.wsrp.common.stubs.GetPortletProperties;
0029:        import com.sun.portal.wsrp.common.stubs.GetPortletPropertyDescription;
0030:        import com.sun.portal.wsrp.common.stubs.PortletPropertyDescriptionResponse;
0031:        import com.sun.portal.wsrp.common.stubs.DestroyFailed;
0032:
0033:        import com.sun.portal.wsrp.producer.portletmanagement.PortletManagementManager;
0034:
0035:        import com.sun.portal.wsrp.producer.servicedescription.ServiceDescriptionManager;
0036:
0037:        import com.sun.portal.wsrp.producer.servicedescription.impl.ServiceDescriptionManagerImpl;
0038:
0039:        import com.sun.portal.wsrp.common.stubs.RegistrationContext;
0040:        import com.sun.portal.wsrp.common.stubs.UserContext;
0041:        import com.sun.portal.wsrp.common.stubs.PortletDescriptionResponse;
0042:
0043:        import com.sun.portal.wsrp.common.WSRPSpecKeys;
0044:
0045:        import com.sun.portal.portletcontainercommon.PortletActions;
0046:
0047:        import com.sun.portal.providers.context.ProviderContext;
0048:        import com.sun.portal.providers.context.ContainerProviderContext;
0049:        import com.sun.portal.providers.context.ProviderContextException;
0050:
0051:        import com.sun.portal.portlet.impl.DPPortletPreferencesImpl;
0052:        import com.sun.portal.portlet.impl.PortletMetaDataResource;
0053:        import com.sun.portal.portlet.cli.PDProviderEntryGenerator;
0054:
0055:        import com.sun.portal.desktop.context.DesktopContext;
0056:
0057:        import com.sun.portal.desktop.dp.DPRoot;
0058:        import com.sun.portal.log.common.PortalLogger;
0059:
0060:        import java.util.logging.LogRecord;
0061:        import java.util.logging.Level;
0062:        import java.util.logging.Logger;
0063:
0064:        import com.sun.portal.wsrp.common.stubs.Property;
0065:        import com.sun.portal.wsrp.common.stubs.PropertyDescription;
0066:        import com.sun.portal.wsrp.common.stubs.ModelDescription;
0067:        import com.sun.portal.wsrp.common.stubs.ResourceValue;
0068:        import com.sun.portal.wsrp.common.stubs.ResourceList;
0069:        import com.sun.portal.wsrp.common.stubs.Resource;
0070:        import com.sun.portal.wsrp.common.stubs.LocalizedString;
0071:        import com.sun.portal.wsrp.producer.ProducerException;
0072:        import com.sun.portal.wsrp.producer.UserManager;
0073:        import com.sun.portal.wsrp.producer.UserIdentityDetector;
0074:        import com.sun.portal.wsrp.producer.ProducerDN;
0075:        import com.sun.portal.wsrp.producer.PortletResourceMap;
0076:        import com.sun.portal.desktop.dp.DPChannel;
0077:        import com.sun.portal.desktop.dp.DPString;
0078:        import java.util.Enumeration;
0079:        import java.util.Set;
0080:        import java.util.HashSet;
0081:        import java.util.Map;
0082:        import java.util.HashMap;
0083:        import java.util.Iterator;
0084:        import java.util.ResourceBundle;
0085:        import java.util.MissingResourceException;
0086:        import java.util.Arrays;
0087:        import java.util.List;
0088:
0089:        import java.util.regex.Pattern;
0090:        import java.util.regex.Matcher;
0091:
0092:        import java.io.IOException;
0093:
0094:        import javax.servlet.ServletContext;
0095:        import javax.servlet.http.HttpServletRequest;
0096:
0097:        import javax.portlet.ReadOnlyException;
0098:        import javax.portlet.ValidatorException;
0099:
0100:        import com.iplanet.sso.SSOToken;
0101:        import javax.xml.namespace.QName;
0102:
0103:        import com.iplanet.am.util.Locale;
0104:
0105:        public class PortletManagementManagerImpl implements 
0106:                PortletManagementManager {
0107:
0108:            private static String PORTLET_PROPERTY_DESC_LABEL_RES_PREFIX = "portletPropertyDescription.label.";
0109:            private static String PORTLET_PROPERTY_DESC_HINT_RES_PREFIX = "portletPropertyDescription.hint.";
0110:
0111:            //
0112:            // prefixes to index into the portlet res bundles to
0113:            // find localized property names, values, and descriptions
0114:            // see PLT.14.3.1 from the portlet spec v1.0.
0115:            //
0116:            private static String RES_PREF_NAME_PREFIX = "javax.portlet.preference.name.";
0117:            private static String RES_PREF_DESC_PREFIX = "javax.portlet.preference.description.";
0118:            private static String RES_PREF_VALUE_PREFIX = "javax.portlet.preference.value.";
0119:            //
0120:            // cache timeout for desktop context objects. this should probably
0121:            // come from a config file at some point
0122:            //
0123:            private static final int DEFAULT_CACHE_TIMEOUT = 3600;
0124:            //
0125:            // patterns used for matching cloned channel names
0126:            //
0127:
0128:            //
0129:            // patterns used for matching cloned channel names
0130:            //
0131:            // __WSRP_CLONED__<POP handle>_<reg handle>_<timestamp>
0132:            //
0133:
0134:            private static final String ALPHA_NUMERIC_PAT = "((?:[a-z]|[A-Z]|[0-9])+)";
0135:            private static final String NUMERIC_PAT = "((?:[0-9])+)";
0136:            private static final String CLONED_PREFIX_PAT = "__WSRP_CLONED__";
0137:            private static final Pattern CLONED_PORTLET_HANDLE_PATTERN = Pattern
0138:                    .compile("^" + CLONED_PREFIX_PAT + ALPHA_NUMERIC_PAT + "_"
0139:                            + "(.+)_" + NUMERIC_PAT);
0140:
0141:            //
0142:            // pattern group numberings used to parse cloned
0143:            // channel names
0144:            //
0145:            private static final int PORTLET_HANDLE_GROUP = 1;
0146:            private static final int REG_HANDLE_GROUP = 2;
0147:            private static final int USER_CONTEXT_KEY_GROUP = 3;
0148:
0149:            // default type
0150:            private static QName DEFAULT_TYPE = new QName(
0151:                    "http://www.w3.org/2001/XMLSchema", "string", "xsd");
0152:
0153:            private String producerKey = null;
0154:            private ServletContext servletContext = null;
0155:            private HttpServletRequest req = null;
0156:            private SSOToken token = null;
0157:
0158:            private DesktopContext desktopContext = null;
0159:            private ContainerProviderContext containerProviderContext = null;
0160:
0161:            //
0162:            // used to build resource list in calls to
0163:            // getPortletPropertyDescription()
0164:            //
0165:            private Map resourceListMap = new HashMap();
0166:            private static Logger logger = PortalLogger
0167:                    .getLogger(PortletManagementManagerImpl.class);
0168:
0169:            public PortletManagementManagerImpl(HttpServletRequest req,
0170:                    ServletContext servletContext, SSOToken token,
0171:                    String producerKey) throws ProducerException {
0172:                this .producerKey = producerKey;
0173:                this .servletContext = servletContext;
0174:                this .token = token;
0175:                this .req = req;
0176:            }
0177:
0178:            private DesktopContext getDesktopContext(String uck, String rh)
0179:                    throws ProducerException {
0180:                if (desktopContext == null) {
0181:                    UserManager um = new UserManager(servletContext, req,
0182:                            token, producerKey, rh);
0183:                    desktopContext = um.getDesktopContext(uck,
0184:                            DEFAULT_CACHE_TIMEOUT);
0185:
0186:                    //
0187:                    // refresh, to make sure we pick up any changes
0188:                    // from external sources, and to make sure we
0189:                    //
0190:                    desktopContext.refresh();
0191:                }
0192:
0193:                return desktopContext;
0194:            }
0195:
0196:            private DPRoot getDPRoot(String uck, String rh)
0197:                    throws ProducerException {
0198:                DesktopContext dc = getDesktopContext(uck, rh);
0199:                return dc.getDPRoot();
0200:            }
0201:
0202:            private DPChannel getDPChannel(String uck, String rh,
0203:                    String channelName) throws ProducerException {
0204:                DPRoot dpr = getDPRoot(uck, rh);
0205:                DPChannel dpch = dpr.getChannel(channelName);
0206:                if (dpch == null) {
0207:                    throw new ProducerException(
0208:                            "could not get dp channel for channelName="
0209:                                    + channelName);
0210:                }
0211:
0212:                if (dpch.getProviderName().indexOf(
0213:                        PDProviderEntryGenerator.PORTLET_PREFIX) == -1) {
0214:                    throw new ProducerException(
0215:                            "was not a portlet channel channelName="
0216:                                    + channelName);
0217:                }
0218:
0219:                return dpch;
0220:            }
0221:
0222:            private String getDPStringProperty(String uck, String rh,
0223:                    String channelName, String key) throws ProducerException {
0224:                DPChannel dpch = getDPChannel(uck, rh, channelName);
0225:                DPString dpString = dpch.getProperties().getString(key);
0226:
0227:                if (dpString == null) {
0228:                    //
0229:                    // allow caller to determine if this
0230:                    // constitutes an error
0231:                    //
0232:                    return null;
0233:                }
0234:
0235:                String s = dpString.getStringValue();
0236:
0237:                if (s == null) {
0238:                    //
0239:                    // this should never happen
0240:                    //
0241:                    throw new ProducerException(
0242:                            "could not get supportedLocalesMap for channelName="
0243:                                    + channelName);
0244:                }
0245:
0246:                return s;
0247:            }
0248:
0249:            private ContainerProviderContext getContainerProviderContext(
0250:                    String uck, String rh) throws ProducerException {
0251:                if (containerProviderContext == null) {
0252:                    containerProviderContext = getDesktopContext(uck, rh)
0253:                            .getContainerProviderContext();
0254:                }
0255:
0256:                return containerProviderContext;
0257:            }
0258:
0259:            private ProviderContext getProviderContext(String uck, String rh)
0260:                    throws ProducerException {
0261:                return getContainerProviderContext(uck, rh);
0262:            }
0263:
0264:            public PortletDescriptionResponse getPortletDescription(
0265:                    GetPortletDescription getPortletDescription)
0266:                    throws InvalidHandleFault, ProducerException {
0267:                String rh = getPortletDescription.getRegistrationContext()
0268:                        .getRegistrationHandle();
0269:                UserContext userContext = getPortletDescription
0270:                        .getUserContext();
0271:                UserIdentityDetector uid = new UserIdentityDetector(userContext);
0272:                String uck = userContext.getUserContextKey();
0273:                SSOToken remoteToken = uid.getSSOToken();
0274:
0275:                String ph = getPortletDescription.getPortletContext()
0276:                        .getPortletHandle();
0277:                String[] dl = getPortletDescription.getDesiredLocales();
0278:                DesktopContext dc = null;
0279:                if (remoteToken != null) {
0280:                    checkChannelExists(remoteToken, rh, ph);
0281:                    checkChannelPortlet(remoteToken, rh, ph);
0282:                    //
0283:                    // get the USER dp root to hande off to the SDM
0284:                    // PM port type works within the context of a user
0285:                    //
0286:                    dc = getDesktopContext(remoteToken, rh);
0287:                } else {
0288:                    checkChannelExists(uck, rh, ph);
0289:                    checkChannelPortlet(uck, rh, ph);
0290:                    //
0291:                    // get the USER dp root to hande off to the SDM
0292:                    // PM port type works within the context of a user
0293:                    //
0294:                    dc = getDesktopContext(uck, rh);
0295:                }
0296:
0297:                DPRoot dpr = dc.getDPRoot();
0298:
0299:                ServiceDescriptionManager sdm = new ServiceDescriptionManagerImpl(
0300:                        servletContext, req, token, producerKey, dpr);
0301:                PortletDescriptionResponse pdr = sdm.getPortletDescription(ph,
0302:                        dl);
0303:
0304:                return pdr;
0305:            }
0306:
0307:            private void checkChannelPortlet(SSOToken remoteToken, String rh,
0308:                    String name) throws InvalidHandleFault, ProducerException {
0309:                ContainerProviderContext cpc = getContainerProviderContext(
0310:                        remoteToken, rh);
0311:
0312:                try {
0313:                    String providerName = cpc.getProviderName(name);
0314:                    if (!providerName
0315:                            .startsWith(PDProviderEntryGenerator.PORTLET_PREFIX)) {
0316:                        logger.log(Level.SEVERE, "PSWS_CSPWPPI0002", name);
0317:                        throw new InvalidHandleFault();
0318:                    }
0319:                } catch (ProviderContextException pce) {
0320:                    throw new ProducerException(pce);
0321:                }
0322:
0323:            }
0324:
0325:            private void checkChannelExists(SSOToken remoteToken, String rh,
0326:                    String name) throws InvalidHandleFault, ProducerException {
0327:                ContainerProviderContext cpc = getContainerProviderContext(
0328:                        remoteToken, rh);
0329:
0330:                if (!cpc.existsChannel(name)) {
0331:                    logger.log(Level.SEVERE, "PSWS_CSPWPPI0001", name);
0332:                    throw new InvalidHandleFault();
0333:                }
0334:            }
0335:
0336:            private ContainerProviderContext getContainerProviderContext(
0337:                    SSOToken remoteToken, String rh) throws ProducerException {
0338:                if (containerProviderContext == null) {
0339:                    containerProviderContext = getDesktopContext(remoteToken,
0340:                            rh).getContainerProviderContext();
0341:                }
0342:
0343:                return containerProviderContext;
0344:            }
0345:
0346:            private DesktopContext getDesktopContext(SSOToken remoteToken,
0347:                    String rh) throws ProducerException {
0348:                if (desktopContext == null) {
0349:                    UserManager um = new UserManager(servletContext, req,
0350:                            token, producerKey, rh);
0351:                    desktopContext = um.getDesktopContext(remoteToken,
0352:                            DEFAULT_CACHE_TIMEOUT);
0353:
0354:                    //
0355:                    // refresh, to make sure we pick up any changes
0356:                    // from external sources, and to make sure we
0357:                    //
0358:                    desktopContext.refresh();
0359:                }
0360:
0361:                return desktopContext;
0362:
0363:            }
0364:
0365:            private void checkRegContext(String portletHandle, String rh)
0366:                    throws InvalidHandleFault, ProducerException {
0367:                String portletRegContext = getRegHandle(portletHandle);
0368:                if (!portletRegContext.equals(rh)) {
0369:                    logger.log(Level.INFO, "PSWS_CSPWPPI0003", new Object[] {
0370:                            portletHandle, rh });
0371:                    throw new InvalidHandleFault();
0372:                }
0373:            }
0374:
0375:            private void checkChannelExists(String uck, String rh, String name)
0376:                    throws InvalidHandleFault, ProducerException {
0377:                ContainerProviderContext cpc = getContainerProviderContext(uck,
0378:                        rh);
0379:
0380:                if (!cpc.existsChannel(name)) {
0381:                    logger.log(Level.SEVERE, "PSWS_CSPWPPI0001", name);
0382:                    throw new InvalidHandleFault();
0383:                }
0384:            }
0385:
0386:            private void checkChannelPortlet(String uck, String rh, String name)
0387:                    throws ProducerException, InvalidHandleFault {
0388:                ContainerProviderContext cpc = getContainerProviderContext(uck,
0389:                        rh);
0390:
0391:                try {
0392:                    String providerName = cpc.getProviderName(name);
0393:                    if (!providerName
0394:                            .startsWith(PDProviderEntryGenerator.PORTLET_PREFIX)) {
0395:                        logger.log(Level.SEVERE, "PSWS_CSPWPPI0002", name);
0396:                        throw new InvalidHandleFault();
0397:                    }
0398:                } catch (ProviderContextException pce) {
0399:                    throw new ProducerException(pce);
0400:                }
0401:            }
0402:
0403:            public PortletContext clonePortlet(ClonePortlet cp)
0404:                    throws InvalidHandleFault, ProducerException {
0405:                RegistrationContext rc = cp.getRegistrationContext();
0406:                UserContext uc = cp.getUserContext();
0407:                UserIdentityDetector uid = new UserIdentityDetector(uc);
0408:                PortletContext pc = cp.getPortletContext();
0409:                String portletHandle = pc.getPortletHandle();
0410:                String rh = rc.getRegistrationHandle();
0411:                String uck = uc.getUserContextKey();
0412:                SSOToken remoteToken = uid.getSSOToken();
0413:                String providerName = null;
0414:                String roleDN = null;
0415:                String cloneChannelName = null;
0416:                if (remoteToken == null) {
0417:                    //            ContainerProviderContext containerProviderContext = getContainerProviderContext( uck, rh );
0418:                    checkChannelExists(uck, rh, portletHandle);
0419:                    checkChannelPortlet(uck, rh, portletHandle);
0420:                    //
0421:                    // create clone channel
0422:                    //
0423:                    cloneChannelName = getCloneChannelName(portletHandle, uck,
0424:                            rh);
0425:                    roleDN = getRoleDN(uck, rh);
0426:                } else {
0427:                    //            ContainerProviderContext containerProviderContext = getContainerProviderContext( uck, rh );
0428:                    checkChannelExists(remoteToken, rh, portletHandle);
0429:                    checkChannelPortlet(remoteToken, rh, portletHandle);
0430:                    //
0431:                    // create clone channel
0432:                    // Passing null for the userContextKey as it is not being used in the
0433:                    // method implementation.
0434:                    //
0435:                    cloneChannelName = getCloneChannelName(portletHandle, null,
0436:                            rh);
0437:                    roleDN = getRoleDN(remoteToken, rh);
0438:
0439:                }
0440:                DPWSRPRoleContext roleContext = new DPWSRPRoleContext(roleDN,
0441:                        req);
0442:
0443:                try {
0444:                    providerName = containerProviderContext
0445:                            .getProviderName(portletHandle);
0446:                    roleContext.createChannel(cloneChannelName, providerName);
0447:                } catch (ProviderContextException pe) {
0448:                    throw new ProducerException(pe);
0449:                }
0450:
0451:                //
0452:                // copy portlet properties to clone channel
0453:                //
0454:                DPPortletPreferencesImpl origPrefs = new DPPortletPreferencesImpl(
0455:                        req, containerProviderContext, portletHandle, false,
0456:                        logger);
0457:                DPWSRPPreferences clonePrefs = new DPWSRPPreferences(req,
0458:                        roleContext, cloneChannelName, false, logger);
0459:
0460:                try {
0461:                    for (Enumeration e = origPrefs.getNames(); e
0462:                            .hasMoreElements();) {
0463:                        //
0464:                        // copy each PORTLET preference from original to
0465:                        // clone
0466:                        //
0467:
0468:                        String name = (String) e.nextElement();
0469:                        String[] vals = origPrefs.getValues(name, null);
0470:                        System.out.println("setting name=" + name + ", vals="
0471:                                + arrayToString(vals));
0472:
0473:                        //
0474:                        // handle case where val of the DP string is ""
0475:                        // this is abnormal but nonetheless appears.
0476:                        //
0477:                        // if the val of a DP string property is ""
0478:                        // DPPortletPreferencesImpl returns null here
0479:                        // we want to set the value back to "" in the DP,
0480:                        // otherwise, we'll pass a null to the DP API
0481:                        // and die
0482:                        //
0483:                        if (vals == null) {
0484:                            vals = new String[] { "" };
0485:                        }
0486:                        clonePrefs.setValues(name, vals);
0487:                    }
0488:
0489:                } catch (Exception e) {
0490:                    throw new ProducerException(e);
0491:                }
0492:
0493:                storePrefs(clonePrefs, roleContext);
0494:                PortletContext newPC = new PortletContext(cloneChannelName,
0495:                        null, null);
0496:                return newPC;
0497:            }
0498:
0499:            private String getRoleDN(SSOToken remoteToken, String rh)
0500:                    throws ProducerException {
0501:                DesktopContext dc = getDesktopContext(remoteToken, rh);
0502:                Iterator rolesIterator = dc.getRoles().iterator();
0503:                String role = null;
0504:                while (rolesIterator.hasNext()) {
0505:                    role = rolesIterator.next().toString();
0506:                    if (role.startsWith(ProducerDN.WSRP_ROLE_CN_PREFIX)) {
0507:                        return role;
0508:                    }
0509:                }
0510:                return null;
0511:            }
0512:
0513:            private void storePrefs(DPPortletPreferencesImpl prefs, String uck,
0514:                    String rh) throws ProducerException {
0515:                try {
0516:                    //
0517:                    // DPPortletPreferencesImpl is meant to be used
0518:                    // in a different context so it requires a portlet
0519:                    // action ... we fake that here
0520:                    //
0521:                    req.setAttribute(DPPortletPreferencesImpl.CURRENT_ACTION,
0522:                            PortletActions.RENDER);
0523:                    prefs.store();
0524:
0525:                    DesktopContext dc = getDesktopContext(uck, rh);
0526:                    dc.store();
0527:                } catch (IOException ioe) {
0528:                    throw new ProducerException(ioe);
0529:                } catch (ValidatorException ioe) {
0530:                    throw new ProducerException(ioe);
0531:                }
0532:            }
0533:
0534:            private void storePrefs(DPWSRPPreferences prefs,
0535:                    DPWSRPRoleContext ctx) throws ProducerException {
0536:                try {
0537:                    //
0538:                    // DPPortletPreferencesImpl is meant to be used
0539:                    // in a different context so it requires a portlet
0540:                    // action ... we fake that here
0541:                    //
0542:                    req.setAttribute(DPPortletPreferencesImpl.CURRENT_ACTION,
0543:                            PortletActions.RENDER);
0544:                    prefs.store();
0545:                    ctx.store();
0546:
0547:                } catch (IOException ioe) {
0548:                    throw new ProducerException(ioe);
0549:                } catch (ValidatorException ioe) {
0550:                    throw new ProducerException(ioe);
0551:                }
0552:            }
0553:
0554:            private static String arrayToString(Object[] a) {
0555:                if (a == null) {
0556:                    return "<null>";
0557:                }
0558:
0559:                StringBuffer b = new StringBuffer();
0560:                b.append("{");
0561:                for (int i = 0; i < a.length; i++) {
0562:                    if (a[i] == null) {
0563:                        b.append(" <null>");
0564:                    } else {
0565:                        b.append(" ");
0566:                        b.append(a[i].toString());
0567:                    }
0568:                }
0569:                b.append(" }");
0570:
0571:                return b.toString();
0572:            }
0573:
0574:            private static String getCloneChannelName(String portletHandle,
0575:                    String userContextKey, String regHandle) {
0576:
0577:                String ph = null;
0578:
0579:                if (isClonedChannelName(portletHandle)) {
0580:                    ph = getPOPortletHandle(portletHandle);
0581:                } else {
0582:                    ph = portletHandle;
0583:                }
0584:
0585:                return CLONED_PREFIX_PAT + ph + "_" + regHandle + "_"
0586:                        + System.currentTimeMillis();
0587:
0588:            }
0589:
0590:            public static String decodeClonedChannelName(
0591:                    String clonedPortletHandle) {
0592:
0593:                String ph = null;
0594:
0595:                if (!isClonedChannelName(clonedPortletHandle)) {
0596:                    return clonedPortletHandle;
0597:                }
0598:
0599:                return getPOPortletHandle(clonedPortletHandle);
0600:
0601:            }
0602:
0603:            private static boolean isClonedChannelName(String portletHandle) {
0604:                Matcher m = CLONED_PORTLET_HANDLE_PATTERN
0605:                        .matcher(portletHandle);
0606:                if (m.matches()) {
0607:                    return true;
0608:                }
0609:
0610:                return false;
0611:            }
0612:
0613:            private static String getPOPortletHandle(String clonedPortletHandle) {
0614:                Matcher m = CLONED_PORTLET_HANDLE_PATTERN
0615:                        .matcher(clonedPortletHandle);
0616:                if (m.matches()) {
0617:                    return m.group(PORTLET_HANDLE_GROUP);
0618:                }
0619:
0620:                return null;
0621:            }
0622:
0623:            private static String getUserContextKey(String clonedPortletHandle) {
0624:                Matcher m = CLONED_PORTLET_HANDLE_PATTERN
0625:                        .matcher(clonedPortletHandle);
0626:                if (m.matches()) {
0627:                    return m.group(USER_CONTEXT_KEY_GROUP);
0628:                }
0629:
0630:                return null;
0631:            }
0632:
0633:            private static String getRegHandle(String clonedPortletHandle) {
0634:                Matcher m = CLONED_PORTLET_HANDLE_PATTERN
0635:                        .matcher(clonedPortletHandle);
0636:                if (m.matches()) {
0637:                    return m.group(REG_HANDLE_GROUP);
0638:                }
0639:                return null;
0640:            }
0641:
0642:            public DestroyPortletsResponse destroyPortlets(
0643:                    DestroyPortlets destroyPortlets) throws ProducerException {
0644:                String[] portletHandles = destroyPortlets.getPortletHandles();
0645:                String rh = destroyPortlets.getRegistrationContext()
0646:                        .getRegistrationHandle();
0647:
0648:                Set destroyFailed = new HashSet();
0649:
0650:                for (int i = 0; i < portletHandles.length; i++) {
0651:                    String uck = getUserContextKey(portletHandles[i]);
0652:                    if (uck != null) {
0653:                        //
0654:                        // remove channel from user DP
0655:                        //
0656:                        ContainerProviderContext cpc = getContainerProviderContext(
0657:                                uck, rh);
0658:                        try {
0659:                            if (cpc.existsChannel(portletHandles[i])) {
0660:                                cpc.removeChannel(portletHandles[i]);
0661:                            } else {
0662:                                destroyFailed.add(new DestroyFailed(
0663:                                        portletHandles[i],
0664:                                        WSRPSpecKeys.INVALID_HANDLE));
0665:                            }
0666:
0667:                            //
0668:                            // save the changes.
0669:                            // we have to do this in the loop, because the UCK
0670:                            // can be different for each portlet handle
0671:                            //
0672:                            DesktopContext dc = getDesktopContext(uck, rh);
0673:                            dc.store();
0674:                        } catch (ProviderContextException pce) {
0675:                            destroyFailed.add(new DestroyFailed(
0676:                                    portletHandles[i],
0677:                                    WSRPSpecKeys.OPERATION_FAILED));
0678:                            if (logger.isLoggable(Level.SEVERE)) {
0679:                                LogRecord rec = new LogRecord(Level.SEVERE,
0680:                                        "PSWS_CSPWPPI0004");
0681:                                rec.setLoggerName(logger.getName());
0682:                                String[] param = { portletHandles[i] };
0683:                                rec.setThrown(pce);
0684:                                rec.setParameters(param);
0685:                                logger.log(rec);
0686:                            }
0687:                        }
0688:                    } else {
0689:                        destroyFailed.add(new DestroyFailed(portletHandles[i],
0690:                                WSRPSpecKeys.INVALID_HANDLE));
0691:                    }
0692:                }
0693:
0694:                DestroyPortletsResponse dpr = new DestroyPortletsResponse(
0695:                        (DestroyFailed[]) destroyFailed
0696:                                .toArray(new DestroyFailed[0]), null);
0697:                return dpr;
0698:            }
0699:
0700:            public PortletContext setPortletProperties(
0701:                    SetPortletProperties setPortletProperties)
0702:                    throws MissingParametersFault, InvalidRegistrationFault,
0703:                    InvalidUserCategoryFault, OperationFailedFault,
0704:                    AccessDeniedFault, InconsistentParametersFault,
0705:                    InvalidHandleFault, ProducerException {
0706:                //ISConnection.debug.error("PortletManagementManagerImpl.setPortletProperties(): entered");
0707:
0708:                PortletContext pc = setPortletProperties.getPortletContext();
0709:                UserContext uc = setPortletProperties.getUserContext();
0710:                RegistrationContext rc = setPortletProperties
0711:                        .getRegistrationContext();
0712:                PropertyList pl = setPortletProperties.getPropertyList();
0713:
0714:                String rh = rc.getRegistrationHandle();
0715:                UserIdentityDetector uid = new UserIdentityDetector(uc);
0716:                SSOToken ssoToken = uid.getSSOToken();
0717:                String uck = uc.getUserContextKey();
0718:                String portletHandle = pc.getPortletHandle();
0719:
0720:                if (ssoToken == null) {
0721:                    checkChannelExists(uck, rh, portletHandle);
0722:                    checkChannelPortlet(uck, rh, portletHandle);
0723:
0724:                    if (!isClonedChannelName(portletHandle)) {
0725:                        logger.log(Level.INFO, "PSWS_CSPWPPI0005",
0726:                                portletHandle);
0727:                        throw new InvalidHandleFault();
0728:                    }
0729:
0730:                    ProviderContext providerContext = getProviderContext(uck,
0731:                            rh);
0732:
0733:                    DPPortletPreferencesImpl prefs = new DPPortletPreferencesImpl(
0734:                            req, providerContext, portletHandle, false, logger);
0735:
0736:                    Property[] ps = pl.getProperties();
0737:                    try {
0738:                        for (int i = 0; i < ps.length; i++) {
0739:                            String key = ps[i].getName();
0740:                            String val = ps[i].getStringValue();
0741:
0742:                            prefs.setValue(key, val);
0743:                        }
0744:                    } catch (ReadOnlyException roe) {
0745:                        throw new ProducerException(roe);
0746:                    }
0747:
0748:                    storePrefs(prefs, uck, rh);
0749:                } else {
0750:                    checkChannelExists(ssoToken, rh, portletHandle);
0751:                    checkChannelPortlet(ssoToken, rh, portletHandle);
0752:
0753:                    if (!isClonedChannelName(portletHandle)) {
0754:                        logger.log(Level.INFO, "PSWS_CSPWPPI0005",
0755:                                portletHandle);
0756:                        throw new InvalidHandleFault();
0757:                    }
0758:
0759:                    ProviderContext providerContext = getProviderContext(
0760:                            ssoToken, rh);
0761:
0762:                    DPPortletPreferencesImpl prefs = new DPPortletPreferencesImpl(
0763:                            req, providerContext, portletHandle, false, logger);
0764:
0765:                    Property[] ps = pl.getProperties();
0766:                    try {
0767:                        for (int i = 0; i < ps.length; i++) {
0768:                            String key = ps[i].getName();
0769:                            String val = ps[i].getStringValue();
0770:
0771:                            prefs.setValue(key, val);
0772:                        }
0773:                    } catch (ReadOnlyException roe) {
0774:                        throw new ProducerException(roe);
0775:                    }
0776:
0777:                    storePrefs(prefs, ssoToken, rh);
0778:                }
0779:
0780:                return pc;
0781:            }
0782:
0783:            private void storePrefs(DPPortletPreferencesImpl prefs,
0784:                    SSOToken ssoToken, String rh) throws ProducerException {
0785:                try {
0786:                    //
0787:                    // DPPortletPreferencesImpl is meant to be used
0788:                    // in a different context so it requires a portlet
0789:                    // action ... we fake that here
0790:                    //
0791:                    req.setAttribute(DPPortletPreferencesImpl.CURRENT_ACTION,
0792:                            PortletActions.RENDER);
0793:                    prefs.store();
0794:
0795:                    DesktopContext dc = getDesktopContext(ssoToken, rh);
0796:                    dc.store();
0797:                } catch (IOException ioe) {
0798:                    throw new ProducerException(ioe);
0799:                } catch (ValidatorException ioe) {
0800:                    throw new ProducerException(ioe);
0801:                }
0802:
0803:            }
0804:
0805:            private ProviderContext getProviderContext(SSOToken ssoToken,
0806:                    String rh) throws ProducerException {
0807:                if (containerProviderContext == null) {
0808:                    containerProviderContext = getDesktopContext(ssoToken, rh)
0809:                            .getContainerProviderContext();
0810:                }
0811:
0812:                return containerProviderContext;
0813:            }
0814:
0815:            public PropertyList getPortletProperties(
0816:                    GetPortletProperties getPortletProperties)
0817:                    throws InvalidRegistrationFault, AccessDeniedFault,
0818:                    OperationFailedFault, MissingParametersFault,
0819:                    InvalidHandleFault, InvalidUserCategoryFault,
0820:                    InconsistentParametersFault, ProducerException {
0821:                //ISConnection.debug.error("PortletManagementManagerImpl.getPortletProperties(): entered");
0822:
0823:                PortletContext pc = getPortletProperties.getPortletContext();
0824:                UserContext uc = getPortletProperties.getUserContext();
0825:                RegistrationContext rc = getPortletProperties
0826:                        .getRegistrationContext();
0827:
0828:                String rh = rc.getRegistrationHandle();
0829:                UserIdentityDetector uid = new UserIdentityDetector(uc);
0830:                String uck = uc.getUserContextKey();
0831:                String portletHandle = pc.getPortletHandle();
0832:
0833:                String[] names = getPortletProperties.getNames();
0834:
0835:                SSOToken ssoToken = uid.getSSOToken();
0836:                ProviderContext providerContext = null;
0837:                if (ssoToken == null) {
0838:                    checkChannelExists(uck, rh, portletHandle);
0839:                    checkChannelPortlet(uck, rh, portletHandle);
0840:
0841:                    providerContext = getProviderContext(uck, rh);
0842:                } else {
0843:                    checkChannelExists(ssoToken, rh, portletHandle);
0844:                    checkChannelPortlet(ssoToken, rh, portletHandle);
0845:
0846:                    providerContext = getProviderContext(ssoToken, rh);
0847:                }
0848:
0849:                DPPortletPreferencesImpl prefs = new DPPortletPreferencesImpl(
0850:                        req, providerContext, portletHandle, false, logger);
0851:
0852:                Set properties = new HashSet();
0853:                String defLang = getDefaultLang();
0854:                //ISConnection.debug.error("PortletManagementManagerImpl.getPortletProperties(): defLang=" + defLang);
0855:
0856:                for (Enumeration e = prefs.getNames(); e.hasMoreElements();) {
0857:                    //
0858:                    // for each name,
0859:                    // 1. get the value from the DP. this is inserted
0860:                    // under the system default locale
0861:                    // 2. see if the value is in the portlet's
0862:                    // resource bundle, if so, insert the value
0863:                    // under the respective locale
0864:                    //
0865:                    String key = (String) e.nextElement();
0866:                    //ISConnection.debug.error("PortletManagementManagerImpl.getPortletProperties(): key=" + key);
0867:
0868:                    if (!(names == null) && !arrayContains(names, key)) {
0869:                        continue;
0870:                    }
0871:
0872:                    String defValue = prefs.getValue(key, "");
0873:                    //ISConnection.debug.error("PortletManagementManagerImpl.getPortletProperties(): defValue=" + defValue);
0874:
0875:                    Property defaultProperty = new Property(key, defLang,
0876:                            defValue, null);
0877:                    properties.add(defaultProperty);
0878:
0879:                    Map portletResources = null;
0880:                    if (ssoToken == null) {
0881:                        portletResources = getPortletResourceMap(uck, rh,
0882:                                portletHandle);
0883:                    } else {
0884:                        portletResources = getPortletResourceMap(ssoToken, rh,
0885:                                portletHandle);
0886:                    }
0887:                    if (portletResources != null) {
0888:                        //ISConnection.debug.error("PortletManagementManagerImpl.getPortletProperties(): got portlet resources map");
0889:                        for (Iterator i = portletResources.keySet().iterator(); i
0890:                                .hasNext();) {
0891:                            String locale = (String) i.next();
0892:                            //ISConnection.debug.error("PortletManagementManagerImpl.getPortletProperties(): l=" + l);
0893:
0894:                            //                    ResourceBundle rb = (ResourceBundle)portletResources.get(locale);
0895:                            PortletMetaDataResource rb = (PortletMetaDataResource) portletResources
0896:                                    .get(locale);
0897:                            String resKey = RES_PREF_VALUE_PREFIX + key;
0898:                            String resVal = null;
0899:                            try {
0900:                                resVal = rb.getString(resKey);
0901:                            } catch (MissingResourceException mre) {
0902:                                // nothing, resVal = null
0903:                            }
0904:                            //ISConnection.debug.error("PortletManagementManagerImpl.getPortletProperties(): resVal=" + resVal);
0905:
0906:                            if (resVal != null) {
0907:                                Property resProperty = new Property(resKey,
0908:                                        toXMLLang(locale), resVal, null);
0909:                                properties.add(resProperty);
0910:                            }
0911:                        }
0912:                    }
0913:                }
0914:
0915:                PropertyList pl = new PropertyList((Property[]) properties
0916:                        .toArray(new Property[0]), null, null);
0917:                return pl;
0918:            }
0919:
0920:            private Map getPortletResourceMap(SSOToken ssoToken, String rh,
0921:                    String portletName) throws ProducerException {
0922:                String entityIDPrefix = getDPStringProperty(ssoToken, rh,
0923:                        portletName,
0924:                        PDProviderEntryGenerator.ENTITY_ID_PREFIX_NAME);
0925:                //ISConnection.debug.error("ServiceDescriptionManagerImpl.getPortletResourceMap(): entityIDPrefix=" + entityIDPrefix);
0926:
0927:                if (entityIDPrefix == null) {
0928:                    throw new ProducerException(
0929:                            "could not get entity id prefix for portletName="
0930:                                    + portletName);
0931:                }
0932:
0933:                return PortletResourceMap.get(servletContext, portletName,
0934:                        entityIDPrefix);
0935:            }
0936:
0937:            private String getDPStringProperty(SSOToken ssoToken, String rh,
0938:                    String channelName, String key) throws ProducerException {
0939:                DPChannel dpch = getDPChannel(ssoToken, rh, channelName);
0940:                DPString dpString = dpch.getProperties().getString(key);
0941:
0942:                if (dpString == null) {
0943:                    //
0944:                    // allow caller to determine if this
0945:                    // constitutes an error
0946:                    //
0947:                    return null;
0948:                }
0949:
0950:                String s = dpString.getStringValue();
0951:
0952:                if (s == null) {
0953:                    //
0954:                    // this should never happen
0955:                    //
0956:                    throw new ProducerException(
0957:                            "could not get supportedLocalesMap for channelName="
0958:                                    + channelName);
0959:                }
0960:
0961:                return s;
0962:            }
0963:
0964:            private DPChannel getDPChannel(SSOToken ssoToken, String rh,
0965:                    String channelName) throws ProducerException {
0966:                DPRoot dpr = getDPRoot(ssoToken, rh);
0967:                DPChannel dpch = dpr.getChannel(channelName);
0968:                if (dpch == null) {
0969:                    throw new ProducerException(
0970:                            "could not get dp channel for channelName="
0971:                                    + channelName);
0972:                }
0973:
0974:                if (dpch.getProviderName().indexOf(
0975:                        PDProviderEntryGenerator.PORTLET_PREFIX) == -1) {
0976:                    throw new ProducerException(
0977:                            "was not a portlet channel channelName="
0978:                                    + channelName);
0979:                }
0980:
0981:                return dpch;
0982:            }
0983:
0984:            private DPRoot getDPRoot(SSOToken ssoToken, String rh)
0985:                    throws ProducerException {
0986:                DesktopContext dc = getDesktopContext(ssoToken, rh);
0987:                return dc.getDPRoot();
0988:            }
0989:
0990:            private static boolean arrayContains(String[] a, String s) {
0991:                if (a == null) {
0992:                    return false;
0993:                }
0994:
0995:                for (int i = 0; i < a.length; i++) {
0996:                    if (a[i].equals(s)) {
0997:                        return true;
0998:                    }
0999:                }
1000:
1001:                return false;
1002:            }
1003:
1004:            private Map getPortletResourceMap(String uck, String rh,
1005:                    String portletName) throws ProducerException {
1006:                String entityIDPrefix = getDPStringProperty(uck, rh,
1007:                        portletName,
1008:                        PDProviderEntryGenerator.ENTITY_ID_PREFIX_NAME);
1009:                //ISConnection.debug.error("ServiceDescriptionManagerImpl.getPortletResourceMap(): entityIDPrefix=" + entityIDPrefix);
1010:
1011:                if (entityIDPrefix == null) {
1012:                    throw new ProducerException(
1013:                            "could not get entity id prefix for portletName="
1014:                                    + portletName);
1015:                }
1016:
1017:                return PortletResourceMap.get(servletContext, portletName,
1018:                        entityIDPrefix);
1019:            }
1020:
1021:            private String getDefaultLocale() {
1022:                String l = Locale.getDefaultLocale().toString();
1023:                return l;
1024:            }
1025:
1026:            private String getDefaultLang() {
1027:                String l = toXMLLang(getDefaultLocale());
1028:                return l;
1029:            }
1030:
1031:            private static String toXMLLang(String javaLang) {
1032:                return javaLang.replace('_', '-');
1033:            }
1034:
1035:            public PortletPropertyDescriptionResponse getPortletPropertyDescription(
1036:                    GetPortletPropertyDescription getPortletPropertyDescription)
1037:                    throws OperationFailedFault, MissingParametersFault,
1038:                    InvalidUserCategoryFault, InconsistentParametersFault,
1039:                    AccessDeniedFault, InvalidHandleFault,
1040:                    InvalidRegistrationFault, ProducerException {
1041:                PortletContext pc = getPortletPropertyDescription
1042:                        .getPortletContext();
1043:                UserContext uc = getPortletPropertyDescription.getUserContext();
1044:                RegistrationContext rc = getPortletPropertyDescription
1045:                        .getRegistrationContext();
1046:                String[] dl = getPortletPropertyDescription.getDesiredLocales();
1047:                List desiredLocales = null;
1048:                if (dl != null) {
1049:                    desiredLocales = Arrays.asList(dl);
1050:                    //ISConnection.debug.error("PortletManagementManagerImpl.getPortletPropertyDescription(): desiredLocales=" + desiredLocales);
1051:                } else {
1052:                    //ISConnection.debug.error("PortletManagementManagerImpl.getPortletPropertyDescription(): desiredLocales is null");
1053:                }
1054:
1055:                String rh = rc.getRegistrationHandle();
1056:                UserIdentityDetector uid = new UserIdentityDetector(uc);
1057:                String uck = uc.getUserContextKey();
1058:                String portletHandle = pc.getPortletHandle();
1059:                SSOToken ssoToken = uid.getSSOToken();
1060:                DPPortletPreferencesImpl prefs = null;
1061:                Map portletResources = null;
1062:                if (ssoToken == null) {
1063:                    checkChannelExists(uck, rh, portletHandle);
1064:                    checkChannelPortlet(uck, rh, portletHandle);
1065:                    ProviderContext providerContext = getProviderContext(uck,
1066:                            rh);
1067:                    prefs = new DPPortletPreferencesImpl(req, providerContext,
1068:                            portletHandle, false, logger);
1069:                    portletResources = getPortletResourceMap(uck, rh,
1070:                            portletHandle);
1071:                } else {
1072:                    checkChannelExists(ssoToken, rh, portletHandle);
1073:                    checkChannelPortlet(ssoToken, rh, portletHandle);
1074:                    ProviderContext providerContext = getProviderContext(
1075:                            ssoToken, rh);
1076:                    prefs = new DPPortletPreferencesImpl(req, providerContext,
1077:                            portletHandle, false, logger);
1078:                    portletResources = getPortletResourceMap(ssoToken, rh,
1079:                            portletHandle);
1080:                }
1081:                logger.log(Level.INFO, "PSWS_CSPWPPI0006", portletResources);
1082:
1083:                Set pds = new HashSet();
1084:
1085:                for (Enumeration names = prefs.getNames(); names
1086:                        .hasMoreElements();) {
1087:                    String name = (String) names.nextElement();
1088:                    //ISConnection.debug.error("PortletManagementManagerImpl.getPortletPropertyDescription(): name=" + name);
1089:
1090:                    PropertyDescription pd = null;
1091:
1092:                    for (Iterator locales = portletResources.keySet()
1093:                            .iterator(); locales.hasNext();) {
1094:                        String locale = (String) locales.next();
1095:                        String lang = toXMLLang(locale);
1096:                        //ISConnection.debug.error("PortletManagementManagerImpl.getPortletPropertyDescription(): lang=" + lang);
1097:
1098:                        if (desiredLocales != null && desiredLocales.size() > 0
1099:                                && !desiredLocales.contains(locale)) {
1100:                            //ISConnection.debug.error("PortletManagementManagerImpl.getPortletPropertyDescription(): skipping out from desired locales");
1101:                            continue;
1102:                        }
1103:
1104:                        //                ResourceBundle rb = (ResourceBundle)portletResources.get(locale);
1105:                        PortletMetaDataResource rb = (PortletMetaDataResource) portletResources
1106:                                .get(locale);
1107:                        LocalizedString label = null;
1108:                        LocalizedString hint = null;
1109:
1110:                        // get label
1111:                        String resKey = RES_PREF_NAME_PREFIX + name;
1112:                        try {
1113:                            //                    String s = rb.getString(resKey);
1114:                            String s = prefs.getValue(name, null);
1115:                            //ISConnection.debug.error("PortletManagementManagerImpl.getPortletPropertyDescription(): got label s=" + s);
1116:
1117:                            if (s == null) {
1118:                                continue;
1119:                            }
1120:                            label = new LocalizedString(lang,
1121:                                    PORTLET_PROPERTY_DESC_LABEL_RES_PREFIX
1122:                                            + name, s);
1123:                            addResource(label);
1124:                        } catch (MissingResourceException mre) {
1125:                            // label is required
1126:                            continue;
1127:                        }
1128:
1129:                        // get hint (optional)
1130:                        resKey = RES_PREF_DESC_PREFIX + name;
1131:                        try {
1132:                            String s = rb.getString(resKey);
1133:                            //ISConnection.debug.error("PortletManagementManagerImpl.getPortletPropertyDescription(): got hint s=" + s);
1134:
1135:                            if (s != null) {
1136:                                hint = new LocalizedString(lang,
1137:                                        PORTLET_PROPERTY_DESC_HINT_RES_PREFIX
1138:                                                + name, s);
1139:                                addResource(hint);
1140:                            }
1141:                        } catch (MissingResourceException mre) {
1142:                            // nothing. hint is optional
1143:                        }
1144:
1145:                        if (pd == null) {
1146:                            //
1147:                            // if pd is null, then we have not get added a PD for this
1148:                            // locale.
1149:                            //
1150:                            // in that case, add it, but never add another because
1151:                            // we've already found the best match. we must keep
1152:                            // processing the list though to add the non-best
1153:                            // match PDs to the resource list
1154:                            //
1155:                            pd = new PropertyDescription(name, DEFAULT_TYPE,
1156:                                    label, hint, null);
1157:                            pds.add(pd);
1158:                        }
1159:                    }
1160:                }
1161:
1162:                PropertyDescription[] propertyDescriptions = (PropertyDescription[]) pds
1163:                        .toArray(new PropertyDescription[0]);
1164:                ModelDescription md = new ModelDescription(
1165:                        propertyDescriptions, null, null);
1166:                ResourceList rl = getResourceList();
1167:                PortletPropertyDescriptionResponse ppdr = new PortletPropertyDescriptionResponse(
1168:                        md, rl, null);
1169:
1170:                return ppdr;
1171:            }
1172:
1173:            private void addResource(LocalizedString ls) {
1174:                ResourceValue rv = new ResourceValue(ls.getLang(), ls
1175:                        .getValue(), null);
1176:
1177:                String resourceName = ls.getResourceName();
1178:
1179:                Set resources = (Set) resourceListMap.get(resourceName);
1180:                if (resources == null) {
1181:                    resources = new HashSet();
1182:                    resourceListMap.put(resourceName, resources);
1183:                }
1184:
1185:                //
1186:                // make sure we don't add the same resource >1x
1187:                //
1188:
1189:                if (!containsResource(resources, rv)) {
1190:                    //ISConnection.debug.error("ServideDescriptionManagerImpl.addResource(): added resourceName=" + resourceName);
1191:                    resources.add(rv);
1192:                }
1193:            }
1194:
1195:            public boolean containsResource(Set resources,
1196:                    ResourceValue resourceValue) {
1197:                for (Iterator i = resources.iterator(); i.hasNext();) {
1198:                    ResourceValue rv = (ResourceValue) i.next();
1199:
1200:                    if (rv.getLang().equals(resourceValue.getLang())
1201:                            && rv.getValue().equals(resourceValue.getValue())) {
1202:                        return true;
1203:                    }
1204:                }
1205:
1206:                return false;
1207:            }
1208:
1209:            protected ResourceList getResourceList() {
1210:                ResourceList rl = null;
1211:                int size = resourceListMap.keySet().size();
1212:
1213:                if (size > 0) {
1214:                    Resource[] rs = new Resource[size];
1215:
1216:                    int index = 0;
1217:                    for (Iterator i = resourceListMap.keySet().iterator(); i
1218:                            .hasNext();) {
1219:                        String resourceName = (String) i.next();
1220:                        //ISConnection.debug.error("ServideDescriptionManagerImpl.getResourceList(): resourceName=" + resourceName);
1221:                        Set resourceSet = (Set) resourceListMap
1222:                                .get(resourceName);
1223:                        ResourceValue[] rvs = (ResourceValue[]) resourceSet
1224:                                .toArray(new ResourceValue[0]);
1225:                        Resource r = new Resource(resourceName, rvs, null);
1226:                        rs[index++] = r;
1227:                    }
1228:
1229:                    rl = new ResourceList(rs, null);
1230:                }
1231:
1232:                return rl;
1233:            }
1234:
1235:            private String getRoleDN(String userContextKey, String rh)
1236:                    throws ProducerException {
1237:                DesktopContext dc = getDesktopContext(userContextKey, rh);
1238:                Iterator rolesIterator = dc.getRoles().iterator();
1239:                String role = null;
1240:                while (rolesIterator.hasNext()) {
1241:                    role = rolesIterator.next().toString();
1242:                    if (role.startsWith(ProducerDN.WSRP_ROLE_CN_PREFIX)) {
1243:                        return role;
1244:                    }
1245:                }
1246:                return userContextKey;
1247:            }
1248:        }
w_w___w__.___ja_va__2___s_._com_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.