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


0001:        /*
0002:         * Copyright 2002 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:         */
0013:        package com.sun.portal.providers.window;
0014:
0015:        import java.net.URL;
0016:        import java.net.MalformedURLException;
0017:
0018:        import java.util.List;
0019:        import java.util.ArrayList;
0020:        import java.util.Map;
0021:        import java.util.Collections;
0022:        import java.util.MissingResourceException;
0023:        import java.util.logging.Logger;
0024:        import java.util.logging.Level;
0025:        import java.util.logging.LogRecord;
0026:
0027:        import javax.servlet.http.HttpServletRequest;
0028:        import javax.servlet.http.HttpServletResponse;
0029:        import com.sun.portal.container.Container;
0030:        import com.sun.portal.container.impl.ContainerRequestImpl;
0031:        import com.sun.portal.container.impl.ContainerResponseImpl;
0032:        import com.sun.portal.container.impl.ExecuteActionRequestImpl;
0033:        import com.sun.portal.container.impl.ExecuteActionResponseImpl;
0034:        import com.sun.portal.container.impl.GetMarkupRequestImpl;
0035:        import com.sun.portal.container.impl.GetMarkupResponseImpl;
0036:        import com.sun.portal.container.ContainerException;
0037:        import com.sun.portal.container.ContentException;
0038:        import com.sun.portal.container.WindowState;
0039:        import com.sun.portal.container.ChannelMode;
0040:        import com.sun.portal.container.ChannelURL;
0041:        import com.sun.portal.container.ChannelURLFactory;
0042:        import com.sun.portal.container.ErrorCode;
0043:
0044:        import com.sun.portal.desktop.RequestThreadLocalizer;
0045:        import com.sun.portal.desktop.DesktopRequestThreadLocalizer;
0046:
0047:        import com.sun.portal.desktop.DesktopRequest;
0048:
0049:        import com.sun.portal.providers.Provider;
0050:        import com.sun.portal.providers.ProviderException;
0051:        import com.sun.portal.providers.jsp.JSPProvider;
0052:        import com.sun.portal.providers.context.ProviderContextException;
0053:        import com.sun.portal.providers.context.ContainerProviderContext;
0054:        import com.sun.portal.providers.context.ProviderContext;
0055:        import com.sun.portal.providers.containers.ContainerProvider;
0056:        import com.sun.portal.providers.containers.UnsupportedWindowStateException;
0057:        import com.sun.portal.providers.window.util.*;
0058:        import com.sun.portal.log.common.PortalLogger;
0059:
0060:        import com.iplanet.sso.SSOToken;
0061:        import com.iplanet.sso.SSOException;
0062:        import com.iplanet.sso.SSOTokenManager;
0063:
0064:        import com.sun.portal.desktop.DesktopRequest;
0065:
0066:        /**
0067:         *
0068:         * This class is responsible for rendering the portlet markup fragments. 
0069:         * It retrieves the portlet markup fragments by delegating the portlet 
0070:         * execution to the a container implementation.
0071:         */
0072:        public abstract class WindowProvider extends JSPProvider {
0073:
0074:            //--------------------------------------------------------
0075:            //
0076:
0077:            public static final String KEYWORD_PREFIX = DesktopRequest.PREFIX
0078:                    + "windowProvider.";
0079:
0080:            //----------------------------------------------------------
0081:            //
0082:
0083:            public static final String CURRENT_CHANNEL_MODE_KEY = KEYWORD_PREFIX
0084:                    + "currentChannelMode";
0085:
0086:            public static final String TARGET_PORTLET_CHANNEL_KEY = KEYWORD_PREFIX
0087:                    + "targetPortletChannel";
0088:
0089:            public static final List _localParamKeyList = initParamKeyList();
0090:
0091:            //--------------------------------------------------------
0092:            // Static String used for storing render parameters  
0093:            //-------------------------------------------------------
0094:
0095:            public static final String RENDER_PARAM_PREFIX = KEYWORD_PREFIX
0096:                    + "renderParams.";
0097:
0098:            private static final String PORTLET_PREFERENCE = "__Portlet__PreferenceProperties";
0099:            private static final String PS_EXTERNAL_HELP_URL = "ps.externalHelpURL";
0100:            //-----------------------------------------------------------
0101:            // Static String used for creating Error URL
0102:            //----------------------------------------------------------
0103:            private static final String ERROR_CODE = "_errorCode";
0104:
0105:            //--------------------------------------------------------
0106:            // Static String used for setting the isTarget flag
0107:            //-----------------------------------------------------
0108:
0109:            private static final String TARGET_SUFFIX = ".isTarget";
0110:
0111:            //-----------------------------------------------------------
0112:            // attribute key name to save portal context path
0113:            //-----------------------------------------------------------
0114:
0115:            public static final String PORTAL_CONTEXT_PATH = "portalContext";
0116:
0117:            //-----------------------------------------------------------
0118:            // namespace it. providerContext is put in the request using this 
0119:            // name. And need to put it where containers can read from.
0120:            //-----------------------------------------------------------
0121:
0122:            public static final String PROVIDER_CONTEXT = "provider_context";
0123:
0124:            //---------------------------------------------------------
0125:            // This is a workaround around the framework. 
0126:            // Framework doesn't allow to call processEdit unless
0127:            // the channel is editable. But here, we use processEdit
0128:            // for URL processing. So the URLs are sent to PROCESS_CHANNEL
0129:            // which delegate them back to this provider.
0130:            // Rama is that correct ?
0131:            //--------------------------------------------------------
0132:            private static final String PROCESS_CHANNEL = "PortletWindowProcessChannel";
0133:
0134:            //---------------------------------------------------------------------
0135:            // title 
0136:            //---------------------------------------------------------------------
0137:            private String _title = "";
0138:
0139:            //---
0140:            // Debug logger
0141:            //---
0142:            private static Logger logger = PortalLogger
0143:                    .getLogger(WindowProvider.class);
0144:            public static final String SSO_TOKEN = "sso_token";
0145:
0146:            //------------------------------------------------------------------
0147:            //
0148:            // Abstract methods to be implemented by the sub-class
0149:            //
0150:            //-----------------------------------------------------------------
0151:            abstract public List getRoleList(HttpServletRequest req)
0152:                    throws ProviderException;
0153:
0154:            abstract public Map getUserInfoMap(HttpServletRequest req)
0155:                    throws ProviderException;
0156:
0157:            abstract public Container getContainer(HttpServletRequest req);
0158:
0159:            abstract public String getEntityID(HttpServletRequest req)
0160:                    throws ProviderException;
0161:
0162:            abstract public WindowRequestReader getWindowRequestReader()
0163:                    throws ProviderException;
0164:
0165:            abstract public ChannelURLFactory getChannelURLFactory(
0166:                    String desktopURLPrefix, HttpServletRequest req)
0167:                    throws ProviderException;
0168:
0169:            abstract public boolean isMarkupSupported(String contentType,
0170:                    String locale, ChannelMode mode, WindowState state)
0171:                    throws ProviderException;
0172:
0173:            abstract public String getDefaultTitle() throws ProviderException;
0174:
0175:            //***************************************************************** // 
0176:            // MAIN METHODS FOR GETTING getContent
0177:            //
0178:            //******************************************************************
0179:
0180:            /**
0181:             * Initializes the provider.
0182:             * <p>
0183:             *
0184:             * @param name Unique name identifying this provider.  This value
0185:             * should always be returned from <code>getName()</code>.
0186:             *
0187:             * @param req The HTTP request object corresponding to the HTTP request
0188:             * that caused this provider object to be created. This request may be
0189:             * used to extract session or user information that could be used to
0190:             * gain access to external resources.
0191:             *
0192:             * @exception ProviderException If there was an error initializing the
0193:             * provider.
0194:             *
0195:             * @see com.sun.portal.providers.Provider#getName     
0196:             */
0197:            public void init(String n, HttpServletRequest req)
0198:                    throws ProviderException {
0199:                super .init(n, req);
0200:
0201:            }
0202:
0203:            public StringBuffer getContent(HttpServletRequest req,
0204:                    HttpServletResponse res) throws ProviderException {
0205:
0206:                return getContentInternal(req, res);
0207:
0208:            }
0209:
0210:            public StringBuffer getEdit(HttpServletRequest req,
0211:                    HttpServletResponse res) throws ProviderException {
0212:
0213:                return getContentInternal(req, res);
0214:            }
0215:
0216:            public StringBuffer getContentInternal(HttpServletRequest req,
0217:                    HttpServletResponse res) throws ProviderException {
0218:
0219:                StringBuffer markupText = null;
0220:
0221:                ErrorCode errorCode = readErrorCode(req);
0222:                if (errorCode != null) {
0223:                    //
0224:                    // First, check if request is to report errors that processEdit
0225:                    // might have ran in to, prior to getContent() request
0226:                    // Or due to explicit invocation of ErrorURL.
0227:                    if (logger.isLoggable(Level.FINE)) {
0228:                        LogRecord record = new LogRecord(Level.FINE,
0229:                                "PSDT_CSPPW0001");
0230:                        record.setLoggerName(logger.getName());
0231:                        record.setParameters(new Object[] { getName(),
0232:                                errorCode });
0233:                        logger.log(record);
0234:                    }
0235:                    markupText = getErrorMessageContent(errorCode);
0236:                } else {
0237:                    //
0238:                    // Not an error case, get the normal content 
0239:                    // 
0240:
0241:                    try {
0242:                        markupText = getPortletContent(req, res);
0243:                    } catch (WindowException ex) {
0244:                        if (logger.isLoggable(Level.INFO)) {
0245:                            LogRecord record = new LogRecord(Level.INFO,
0246:                                    "PSDT_CSPPW0002");
0247:                            record.setLoggerName(logger.getName());
0248:                            record.setParameters(new Object[] { getName() });
0249:                            record.setThrown(ex);
0250:                            logger.log(record);
0251:                        }
0252:                        markupText = getErrorMessageContent(ex.getErrorCode());
0253:                    }
0254:                }
0255:
0256:                //
0257:                // Get current portlet mode and return the markup
0258:                // processed based on the mode.
0259:                //
0260:
0261:                ChannelMode mode = getCurrentChannelMode(req);
0262:                return processMarkupBasedOnChannelMode(req, res, mode,
0263:                        markupText);
0264:            }
0265:
0266:            /**
0267:             * Gets the content for the channel based on mode from the underlying 
0268:             * container. This method is called to get content for VIEW, EDIT and 
0269:             * and HELP mode .
0270:             * 
0271:             * Note:: The reason why help content needs to be retrieved by 
0272:             * getContent instead of getHelp is that
0273:             * PAPI's getHelp expects URL as the return value instead of the actual 
0274:             * help content, whereas portlet returns the help content. 
0275:             *
0276:             * This method sets all the necessary attributes in the ContainerRequest 
0277:             * and Container Response and calls the configured container to get
0278:             * the content for the portlet.
0279:             * 
0280:             * @return StringBuffer holding the content.
0281:             *
0282:             * @param request An HttpServletRequest that contains
0283:             * information related to this request for content.
0284:             *
0285:             * @param response An HttpServletResponse that allows the provider
0286:             * to influence the 
0287:             * overall response for the desktop page (besides generating the content).
0288:             *
0289:             * @exception ProviderException If there was an error generating the
0290:             * content. 
0291:             *   
0292:             * @see com.sun.portal.providers.ProviderException
0293:             */
0294:
0295:            private StringBuffer getPortletContent(HttpServletRequest req,
0296:                    HttpServletResponse res) throws ProviderException,
0297:                    WindowException {
0298:
0299:                ProviderContext pc = getProviderContext();
0300:
0301:                //
0302:                // We need to know if it is a authless user, because 
0303:                // parameters are stored in client properties or
0304:                // in session properties based on whether this use is authless or
0305:                // not.
0306:
0307:                boolean authless = pc.isAuthless(req);
0308:
0309:                //
0310:                // Abstract method to be implemented by the dervied class
0311:                //
0312:
0313:                String portletentityId = getEntityID(req);
0314:
0315:                //
0316:                // determine if the portlet is the target of an url
0317:                // and clear it in preparation of next request.
0318:
0319:                boolean isTarget = getIsTarget(portletentityId, authless);
0320:                setIsTarget(portletentityId, authless, false);
0321:
0322:                //
0323:                // Get current portlet mode
0324:                //
0325:
0326:                ChannelMode mode = getCurrentChannelMode(req);
0327:
0328:                //
0329:                // Get current window state
0330:
0331:                WindowState windowState = getCurrentWindowState(req);
0332:
0333:                //
0334:                // Get list of allowed window states 
0335:                //
0336:                List allowableWindowStates = getAllowableWindowStates(req, mode);
0337:
0338:                //
0339:                // Get list of allowed channel modes
0340:                //
0341:                List allowableChannelModes = ProviderRules
0342:                        .getAllowableChannelModes(mode, authless);
0343:
0344:                //
0345:                // Create objects needed to call the container interface
0346:                //
0347:                GetMarkupRequestImpl creq = (GetMarkupRequestImpl) assembleContainerRequest(
0348:                        req, getParentContainerName(req), portletentityId,
0349:                        mode, windowState, allowableWindowStates,
0350:                        allowableChannelModes, true);
0351:
0352:                //
0353:                // On the first request, render parameters would 
0354:                // be null. Render params are added during processEdit
0355:                // which is invoked as a result of clicking on a
0356:                // render or action URL.
0357:                //
0358:
0359:                Map renderParams = getRenderParams(portletentityId, authless);
0360:                creq.setRenderParameters(renderParams);
0361:                creq.setIsTarget(isTarget);
0362:                creq.setCharacterEncoding(req.getCharacterEncoding());
0363:
0364:                //
0365:                // Get instance of the response object
0366:                //
0367:
0368:                GetMarkupResponseImpl cres = (GetMarkupResponseImpl) assembleContainerResponse(
0369:                        res, true);
0370:
0371:                //
0372:                // Call the container interface
0373:                //
0374:                try {
0375:                    getContainer(req).getMarkup(creq, cres);
0376:                } catch (ContainerException ce) {
0377:                    throw new ProviderException(
0378:                            "WindowProvider.getContent():container exception",
0379:                            ce);
0380:                } catch (ContentException cte) {
0381:                    throw new WindowException(getErrorCode(cte),
0382:                            "Content Exception", cte);
0383:                }
0384:
0385:                //
0386:                // save the title so getTitle can return it 
0387:                //
0388:
0389:                setTitle(cres.getTitle());
0390:
0391:                //
0392:                // Process the markup based on the mode.
0393:                //
0394:
0395:                if (cres.getMarkup() == null) {
0396:                    if (logger.isLoggable(Level.FINE)) {
0397:                        LogRecord record = new LogRecord(Level.FINE,
0398:                                "PSDT_CSPPW0003");
0399:                        record.setLoggerName(logger.getName());
0400:                        record.setParameters(new Object[] { getName() });
0401:                        logger.log(record);
0402:                    }
0403:                }
0404:
0405:                return cres.getMarkup();
0406:
0407:            }
0408:
0409:            /**
0410:             * This method processes the markup returned by the container
0411:             * according to the ChannelMode. For example, for VIEW, it is 
0412:             * returned as it is. For HELP and EDIT, 
0413:             * it is wrapped by a banner and footer. 
0414:             */
0415:
0416:            private StringBuffer processMarkupBasedOnChannelMode(
0417:                    HttpServletRequest req, HttpServletResponse res,
0418:                    ChannelMode mode, StringBuffer markupFromPortlet)
0419:                    throws ProviderException {
0420:
0421:                ContainerProviderContext cpc = (ContainerProviderContext) getProviderContext();
0422:                if (mode.equals(ChannelMode.HELP)) {
0423:                    req.setAttribute("helpContent", markupFromPortlet);
0424:                    return super .getContent(req, res);
0425:                } else if (mode.equals(ChannelMode.VIEW)) {
0426:                    return markupFromPortlet;
0427:                } else if (mode.equals(ChannelMode.EDIT)) {
0428:                    req.setAttribute("editContent", markupFromPortlet);
0429:
0430:                    //set help url of editContainer.
0431:                    URL helpURL = null;
0432:                    String editContainerName = (String) req
0433:                            .getParameter("provider");
0434:                    if (editContainerName != null
0435:                            && editContainerName.length() != 0) {
0436:                        Provider editProvider = (Provider) cpc.getProvider(req,
0437:                                null, editContainerName);
0438:                        helpURL = editProvider.getHelp(req);
0439:                    }
0440:                    if (helpURL != null) {
0441:                        req.setAttribute("editContainerHelpURL", helpURL
0442:                                .toString());
0443:                    } else {
0444:                        req.setAttribute("editContainerHelpURL", "");
0445:                    }
0446:
0447:                    return super .getEdit(req, res);
0448:
0449:                }
0450:                return null;
0451:
0452:            }
0453:
0454:            //****************************************************************
0455:            //
0456:            // MAIN METHODS FOR processEdit
0457:            //
0458:            //***************************************************************
0459:
0460:            public URL processEdit(HttpServletRequest req,
0461:                    HttpServletResponse res) throws ProviderException {
0462:
0463:                try {
0464:                    return processEditInternal(req, res);
0465:                } catch (WindowException ex) {
0466:                    if (logger.isLoggable(Level.INFO)) {
0467:                        LogRecord record = new LogRecord(Level.INFO,
0468:                                "PSDT_CSPPW0004");
0469:                        record.setLoggerName(logger.getName());
0470:                        record.setParameters(new Object[] { getName() });
0471:                        record.setThrown(ex);
0472:                        logger.log(record);
0473:                    }
0474:                    return getErrorCodeURL(ex.getErrorCode(), req);
0475:                }
0476:            }
0477:
0478:            public URL processEditInternal(HttpServletRequest req,
0479:                    HttpServletResponse res) throws ProviderException,
0480:                    WindowException {
0481:
0482:                ProviderContext pc = getProviderContext();
0483:                ContainerProviderContext cpc = (ContainerProviderContext) pc;
0484:                Map renderParameters = Collections.EMPTY_MAP;
0485:                URL returnURL = null;
0486:                ChannelMode currentChannelMode = null;
0487:                ChannelMode newChannelMode = null;
0488:                WindowState currentWindowState = null;
0489:                WindowState newWindowState = null;
0490:                HttpServletRequest dpreq = ((DesktopRequest) req)
0491:                        .getDesktopPortletRequest();
0492:
0493:                //pc.debugError("processEdit:In processEdit");
0494:
0495:                //
0496:                // We need to know if it is a authless user, because 
0497:                // parameters are stored in client properties or
0498:                // in session properties based on whether this use is authless or
0499:                // not.
0500:
0501:                boolean authless = pc.isAuthless(req);
0502:
0503:                //
0504:                // Abstract method to be implemented by the dervied class
0505:                //
0506:                String portletentityId = getEntityID(req);
0507:
0508:                //
0509:                // Get current channel mode and window state
0510:                //
0511:                currentChannelMode = getCurrentChannelMode(req);
0512:
0513:                currentWindowState = getCurrentWindowState(req);
0514:
0515:                //
0516:                // get new channel mode and window state set on the url.
0517:                //
0518:                newWindowState = getWindowRequestReader().readNewWindowState(
0519:                        req);
0520:
0521:                newChannelMode = getWindowRequestReader().readNewChannelMode(
0522:                        req);
0523:
0524:                //
0525:                // Process only the window state. 
0526:                // Won't process new ChannelMode, just check validity, 
0527:                // as an optimization
0528:                // since it might change again after the processAction is called
0529:
0530:                if (newChannelMode != null) {
0531:                    validateModeChange(currentChannelMode, newChannelMode,
0532:                            authless);
0533:                    currentChannelMode = newChannelMode;
0534:                }
0535:                if (newWindowState != null) {
0536:                    currentWindowState = processWindowStateChange(req,
0537:                            newWindowState, currentChannelMode, authless);
0538:                }
0539:
0540:                //
0541:                // See what kind of URL is it
0542:
0543:                String urlType = getWindowRequestReader().readURLType(req);
0544:
0545:                //
0546:                // Read the parameters off the request.
0547:                // This could be render or action based on what what kind of URL is
0548:                // it. 
0549:
0550:                if (ChannelURL.RENDER_URL_TYPE.equals(urlType)) {
0551:                    renderParameters = getWindowRequestReader().readParamsMap(
0552:                            ((DesktopRequest) req));
0553:
0554:                    //
0555:                    // mark the portlet as the target of the request
0556:                    // so that getContent/getEdit kinda method can use it
0557:                    // to send it out to the container. 
0558:                    // Rama again on why it is not set for ACTION_URL
0559:                    //
0560:
0561:                    setIsTarget(portletentityId, authless, true);
0562:
0563:                } else if (ChannelURL.ACTION_URL_TYPE.equals(urlType)) {
0564:
0565:                    //
0566:                    // Since it is a action URL, the params read are action params
0567:                    // setup action params.
0568:                    //
0569:
0570:                    Map actionParams = getWindowRequestReader().readParamsMap(
0571:                            ((DesktopRequest) req));
0572:
0573:                    //
0574:                    // Collect list of allowable state and modes
0575:                    //
0576:
0577:                    List allowableWindowStates = getAllowableWindowStates(req,
0578:                            currentChannelMode);
0579:                    List allowableChannelModes = ProviderRules
0580:                            .getAllowableChannelModes(currentChannelMode,
0581:                                    authless);
0582:
0583:                    //
0584:                    // Ready to constuct the objects to be passed to 
0585:                    // container implementation
0586:                    //
0587:                    ExecuteActionRequestImpl creq = (ExecuteActionRequestImpl) assembleContainerRequest(
0588:                            req, getParentContainerName(req), portletentityId,
0589:                            currentChannelMode, currentWindowState,
0590:                            allowableWindowStates, allowableChannelModes, false);
0591:
0592:                    creq.setActionParameters(actionParams);
0593:                    creq.setCharacterEncoding(req.getCharacterEncoding());
0594:
0595:                    ExecuteActionResponseImpl cres = (ExecuteActionResponseImpl) assembleContainerResponse(
0596:                            res, false);
0597:
0598:                    //
0599:                    // Call the container implementation to executeAction
0600:                    //
0601:                    try {
0602:                        getContainer(req).executeAction(creq, cres);
0603:                    } catch (ContainerException ce) {
0604:                        ce.printStackTrace();
0605:                        throw new ProviderException(
0606:                                "WindowProvider.processEdit():container exception",
0607:                                ce);
0608:                    } catch (ContentException cte) {
0609:                        throw new WindowException(getErrorCode(cte),
0610:                                "Content Exception", cte);
0611:                    }
0612:
0613:                    //
0614:                    // container.executeAction can either return a redirectURL or
0615:                    // change in mode,windowstate and new renderparams.
0616:                    // Both cases are mutually exclusive.
0617:                    //
0618:
0619:                    returnURL = cres.getRedirectURL();
0620:
0621:                    if (returnURL == null) {
0622:
0623:                        //
0624:                        // process mode changes.
0625:                        // can these be null -- rama
0626:
0627:                        newChannelMode = cres.getNewChannelMode();
0628:                        if (newChannelMode != null) {
0629:                            validateModeChange(currentChannelMode,
0630:                                    newChannelMode, authless);
0631:                            currentChannelMode = newChannelMode;
0632:                        }
0633:
0634:                        //
0635:                        // process state changes. 
0636:                        // can these be null -- rama
0637:                        //
0638:
0639:                        newWindowState = cres.getNewWindowState();
0640:                        if (newWindowState != null) {
0641:                            currentWindowState = processWindowStateChange(req,
0642:                                    newWindowState, currentChannelMode,
0643:                                    authless);
0644:                        }
0645:
0646:                        //
0647:                        // get new render params
0648:                        //
0649:
0650:                        renderParameters = cres.getRenderParameters();
0651:                    }
0652:                }
0653:
0654:                //
0655:                // Now we have new renderParams, new channel mode
0656:                // new window state
0657:                //
0658:
0659:                if (returnURL == null) {
0660:                    setRenderParams(portletentityId, authless, renderParameters);
0661:
0662:                    if (currentChannelMode != null) {
0663:                        returnURL = processModeChange(currentChannelMode, req,
0664:                                pc);
0665:
0666:                    }
0667:                }
0668:
0669:                return returnURL;
0670:            }
0671:
0672:            /**
0673:             * Gets the title  for the channel.
0674:             * This method returns the title from the portlet.
0675:             * Portlet uses javax.portlet.title namespace for its title.
0676:             *
0677:             * @return A string title.
0678:             * @exception ProviderException if error occurs when getting the title for
0679:             * the channel.
0680:             */
0681:            public String getTitle() throws ProviderException {
0682:                if (_title != null && _title.length() != 0) {
0683:                    return _title;
0684:                } else {
0685:                    return getDefaultTitle();
0686:                }
0687:            }
0688:
0689:            public void setTitle(String title) {
0690:                _title = title;
0691:            }
0692:
0693:            /**
0694:             * Gets the help URL for this provider.
0695:             * <p>
0696:             * This method constructs a help URL which will call the
0697:             * getContent() method on this provider with a parameter
0698:             * mode=HELP
0699:             *
0700:             * @return A URL pointing to the help page for the provider. A return
0701:             * value of null should signify that this provider does not have a
0702:             * help page.
0703:             *
0704:             * @see com.sun.portal.providers.portletwindow#getContent()
0705:             */
0706:            public URL getHelp(HttpServletRequest req) throws ProviderException {
0707:
0708:                boolean helpSupported = isMarkupSupported(getProviderContext()
0709:                        .getContentType(), getProviderContext()
0710:                        .getLocaleString(), ChannelMode.HELP,
0711:                        WindowState.MAXIMIZED);
0712:
0713:                // Check for an empty "helpURL" string, if so do not generate the
0714:                // help button for the channel.
0715:                if (!helpSupported) {
0716:                    return null;
0717:                }
0718:
0719:                String desktopURL = getProviderContext().getDesktopURL(req);
0720:                URL helpURL = null;
0721:                try {
0722:                    helpURL = getHelpURL(req, getProviderContext());
0723:                } catch (MalformedURLException mue) {
0724:                    throw new ProviderException(
0725:                            "WindowProvider.getHelp():couldn't build helpURL",
0726:                            mue);
0727:                } catch (ProviderContextException pce) {
0728:                    throw new ProviderException(
0729:                            "WindowProvider.getHelp():couldn't build helpURL",
0730:                            pce);
0731:                }
0732:
0733:                return helpURL;
0734:            }
0735:
0736:            /**
0737:             *
0738:             * <p>Dictates whether the provider is presentable.
0739:             *
0740:             * <p>This method checks if the current contentType is
0741:             * in the list of supportedContentTypes and returns true 
0742:             * if it is otherwise returns false<br><br>
0743:             * type and returns true.<br><br>
0744:             * TODO:
0745:             * 
0746:             * @return A boolean value dictating presentability
0747:             * @see com.sun.portal.providers.Provider#isPresentable
0748:             */
0749:            public boolean isPresentable(HttpServletRequest req) {
0750:                boolean presentable = true;
0751:                try {
0752:
0753:                    WindowState windowState = null;
0754:                    ContainerProvider parentcp = getParentContainerProvider(req);
0755:                    if (parentcp != null) {
0756:                        windowState = ProviderRules.mapToStandards(parentcp
0757:                                .getWindowState(getName()));
0758:                    }
0759:                    if (windowState == null) {
0760:                        windowState = ProviderRules
0761:                                .getDefaultWindowState(ChannelMode.VIEW);
0762:                    }
0763:
0764:                    presentable = isMarkupSupported(getProviderContext()
0765:                            .getContentType(), getProviderContext()
0766:                            .getLocaleString(), ChannelMode.VIEW, windowState);
0767:
0768:                } catch (ProviderException pe) {
0769:                    if (logger.isLoggable(Level.INFO)) {
0770:                        LogRecord record = new LogRecord(Level.INFO,
0771:                                "PSDT_CSPPW0005");
0772:                        record.setLoggerName(logger.getName());
0773:                        record.setParameters(new Object[] { getName() });
0774:                        record.setThrown(pe);
0775:                        logger.log(record);
0776:                    }
0777:                    presentable = false;
0778:                }
0779:
0780:                if (logger.isLoggable(Level.FINER)) {
0781:                    LogRecord record = new LogRecord(Level.FINER,
0782:                            "PSDT_CSPPW0006");
0783:                    record.setLoggerName(logger.getName());
0784:                    record.setParameters(new Object[] { getName(),
0785:                            presentable + "" });
0786:                    logger.log(record);
0787:                }
0788:                return presentable;
0789:
0790:            }
0791:
0792:            public boolean isEditable() throws ProviderException {
0793:
0794:                //
0795:                // Get handle to portlet description
0796:                //
0797:                HttpServletRequest req = DesktopRequestThreadLocalizer
0798:                        .getRequest();
0799:
0800:                // 
0801:                if (getProviderContext().isAuthless(req)) {
0802:                    return false;
0803:                }
0804:
0805:                Map isEditableMap = getMapProperty("isEditableByMimeType");
0806:                String contentType = getProviderContext().getContentType();
0807:                boolean supported = true;
0808:                if (isEditableMap.containsKey(contentType)) {
0809:                    supported = ((Boolean) isEditableMap.get(contentType))
0810:                            .booleanValue();
0811:                }
0812:
0813:                if (!supported) {
0814:                    return false;
0815:                }
0816:
0817:                return isMarkupSupported(contentType, getProviderContext()
0818:                        .getLocaleString(), ChannelMode.EDIT,
0819:                        WindowState.MAXIMIZED);
0820:            }
0821:
0822:            /**
0823:             * Assembles the ContainerRequest object
0824:             */
0825:            private ContainerRequestImpl assembleContainerRequest(
0826:                    HttpServletRequest req, String parent, String entityId,
0827:                    ChannelMode channelMode, WindowState winState,
0828:                    List allowableWinStates, List allowableChannelModes,
0829:                    boolean markup) throws ProviderException {
0830:
0831:                ContainerRequestImpl creq = null;
0832:                if (markup) {
0833:                    creq = new GetMarkupRequestImpl();
0834:                } else {
0835:                    creq = new ExecuteActionRequestImpl();
0836:                }
0837:
0838:                //
0839:                // get original request and set it in container request.
0840:                //
0841:                HttpServletRequest origReq = RequestThreadLocalizer
0842:                        .getRequest();
0843:                origReq.setAttribute("EVENT_PORTLET_MAP", req
0844:                        .getAttribute("EVENT_PORTLET_MAP"));
0845:                creq.setHttpServletRequest(origReq);
0846:
0847:                //
0848:                // associate the provider context with the request attribute, so that 
0849:                // the portlet container can create preference wrapper around the 
0850:                // provider context. 
0851:                //
0852:
0853:                origReq.setAttribute(PROVIDER_CONTEXT, getProviderContext());
0854:
0855:                //
0856:                // preserve portal context path
0857:                // on some webcontainers (i.e. weblogic) we cannot rely on HttpServletRequest.getContextPath()
0858:                // always returning the original context path when requestdisptaching is involved.
0859:                //
0860:
0861:                origReq.setAttribute(PORTAL_CONTEXT_PATH, req.getContextPath());
0862:
0863:                //
0864:                // set entityID defined in dp.         
0865:                //
0866:
0867:                creq.setEntityID(entityId);
0868:
0869:                //
0870:                // allowable window state and mode determines the set of window state 
0871:                // and portlet mode the portlet can switch to programmatically
0872:                //
0873:
0874:                creq.setAllowableWindowState(allowableWinStates);
0875:                creq.setAllowableChannelMode(allowableChannelModes);
0876:
0877:                //
0878:                // set allowable states, modes and contentTypes.
0879:                //
0880:
0881:                String contentType = getProviderContext().getContentType();
0882:                List allowableContentTypes = new ArrayList();
0883:                allowableContentTypes.add(contentType);
0884:                creq.setAllowableContentType(allowableContentTypes);
0885:
0886:                //
0887:                // set window state and channel mode.
0888:                //
0889:
0890:                creq.setWindowState(winState);
0891:                creq.setChannelMode(channelMode);
0892:
0893:                //
0894:                // set UserID, check if the desktop is authless. 
0895:                // If it is, set the userid to null
0896:                //
0897:                //
0898:                String userID = null;
0899:                SSOToken token = null;
0900:
0901:                if (!getProviderContext().isAuthless(req)) {
0902:                    userID = getProviderContext().getUserID();
0903:
0904:                    try {
0905:                        SSOTokenManager tokenManager = SSOTokenManager
0906:                                .getInstance();
0907:
0908:                        if (tokenManager == null) {
0909:                            throw new ProviderException(
0910:                                    "PortletWindowProvider.assembleContainerRequest(): "
0911:                                            + "Failed to getSSOTokenmanager.");
0912:                        } else {
0913:                            token = tokenManager.createSSOToken(req);
0914:                        }
0915:                    } catch (SSOException ssoe) {
0916:                        throw new ProviderException(
0917:                                "PortletWindowProvider.assembleContainerRequest():",
0918:                                ssoe);
0919:                    }
0920:                }
0921:                creq.setUserID(userID);
0922:                origReq.setAttribute(SSO_TOKEN, token);
0923:
0924:                //
0925:                // set the channel URL factory. The channel URL factory is used by the 
0926:                // portlet app engine to create the portlet url. 
0927:                //
0928:
0929:                String processURL = getProcessURL(req, parent, channelMode);
0930:
0931:                creq.setChannelURLFactory(getChannelURLFactory(processURL
0932:                        .toString(), req));
0933:
0934:                creq.setRoles(getRoleList(req));
0935:
0936:                creq.setUserInfo(getUserInfoMap(req));
0937:
0938:                return creq;
0939:            }
0940:
0941:            /**
0942:             * Assembles the ContainerResponse object
0943:             */
0944:            private ContainerResponseImpl assembleContainerResponse(
0945:                    HttpServletResponse res, boolean markup) {
0946:
0947:                // get container response.
0948:                ContainerResponseImpl cres = null;
0949:                if (markup) {
0950:                    cres = new GetMarkupResponseImpl();
0951:                } else {
0952:                    cres = new ExecuteActionResponseImpl();
0953:                }
0954:
0955:                //get original response and set it.
0956:                HttpServletResponse origRes = RequestThreadLocalizer
0957:                        .getResponse();
0958:                cres.setHttpServletResponse(origRes);
0959:
0960:                return cres;
0961:            }
0962:
0963:            /**
0964:             * Retrieve the saved render parameters from the client property or the
0965:             * session based on the user type. 
0966:             */
0967:            private Map getRenderParams(String entityId, boolean authless) {
0968:                Map renderParams = null;
0969:                ProviderContext pc = getProviderContext();
0970:                if (authless) {
0971:                    String paramString = pc
0972:                            .getClientProperty(RENDER_PARAM_PREFIX + entityId);
0973:                    if (paramString != null) {
0974:                        renderParams = Util.getMapFromString(paramString);
0975:                    }
0976:                } else {
0977:                    renderParams = (Map) pc
0978:                            .getSessionProperty(RENDER_PARAM_PREFIX + entityId);
0979:                }
0980:                if (renderParams == null) {
0981:                    renderParams = Collections.EMPTY_MAP;
0982:                }
0983:                return renderParams;
0984:            }
0985:
0986:            /**
0987:             * Save the render parameters to the client property of the session
0988:             * based on user type.
0989:             */
0990:            private void setRenderParams(String entityId, boolean authless,
0991:                    Map renderParams) {
0992:                ProviderContext pc = getProviderContext();
0993:                if (renderParams == null)
0994:                    return;
0995:                if (authless) {
0996:                    String paramString = "";
0997:                    if (!renderParams.isEmpty()) {
0998:                        paramString = Util.getStringFromMap(renderParams);
0999:                    }
1000:                    pc.setClientProperty(RENDER_PARAM_PREFIX + entityId,
1001:                            paramString);
1002:                } else {
1003:                    pc.setSessionProperty(RENDER_PARAM_PREFIX + entityId,
1004:                            renderParams);
1005:                }
1006:            }
1007:
1008:            /**
1009:             * Determine if the portlet is the target of the request.
1010:             */
1011:            private boolean getIsTarget(String entityId, boolean authless) {
1012:                ProviderContext pc = getProviderContext();
1013:                Boolean target = null;
1014:                if (authless) {
1015:                    target = new Boolean((String) pc
1016:                            .getClientProperty(KEYWORD_PREFIX + entityId
1017:                                    + TARGET_SUFFIX));
1018:                } else {
1019:                    target = new Boolean((String) pc
1020:                            .getSessionProperty(KEYWORD_PREFIX + entityId
1021:                                    + TARGET_SUFFIX));
1022:                }
1023:                return target.booleanValue();
1024:            }
1025:
1026:            /**
1027:             * Mark the current portlet as the target or not the target based 
1028:             * on isTarget parameter
1029:             */
1030:            private void setIsTarget(String entityId, boolean authless,
1031:                    boolean isTarget) {
1032:                ProviderContext pc = getProviderContext();
1033:                if (authless) {
1034:                    pc.setClientProperty(KEYWORD_PREFIX + entityId
1035:                            + TARGET_SUFFIX, String.valueOf(isTarget));
1036:                } else {
1037:                    pc.setSessionProperty(KEYWORD_PREFIX + entityId
1038:                            + TARGET_SUFFIX, String.valueOf(isTarget));
1039:                }
1040:            }
1041:
1042:            /**
1043:             * Process mode changes. In the case of a EDIT mode, 
1044:             * we need to assemble a brand new url. For all other
1045:             * mode, we will just return null which will cause the 
1046:             * whole desktop to be rendered.
1047:             */
1048:            protected URL processModeChange(ChannelMode channelMode,
1049:                    HttpServletRequest req, ProviderContext pc)
1050:                    throws ProviderException {
1051:
1052:                URL redirectURL = null;
1053:                String parent = getParentContainerName(req);
1054:
1055:                try {
1056:                    if (ChannelMode.EDIT.equals(channelMode)) {
1057:                        redirectURL = getEditURL(req, parent, pc);
1058:                    } else if (ChannelMode.HELP.equals(channelMode)) {
1059:                        redirectURL = getHelpURL(req, pc);
1060:                    }
1061:                } catch (MalformedURLException mue) {
1062:                    throw new ProviderException(
1063:                            "portletWindowProvider.processModeChange():"
1064:                                    + " couldn't generate redirect URL to page for mode "
1065:                                    + channelMode.toString(), mue);
1066:                } catch (ProviderContextException pce) {
1067:                    throw new ProviderException(
1068:                            "portletWindowProvider.processModeChange():"
1069:                                    + " couldn't generate redirect URL to page for mode "
1070:                                    + channelMode.toString(), pce);
1071:                }
1072:
1073:                return redirectURL;
1074:            }
1075:
1076:            /**
1077:             * Process window state changes. We need to let the parent container 
1078:             * know of the state change.
1079:             */
1080:            protected WindowState processWindowStateChange(
1081:                    HttpServletRequest request, WindowState newWindowState,
1082:                    ChannelMode channelMode, boolean authless)
1083:                    throws ProviderException, WindowException {
1084:
1085:                WindowState windowState = newWindowState;
1086:                boolean validState = ProviderRules.validateWindowStateChange(
1087:                        channelMode, newWindowState);
1088:
1089:                if (!validState || newWindowState == null) {
1090:
1091:                    windowState = ProviderRules
1092:                            .getDefaultWindowState(channelMode);
1093:
1094:                    if (logger.isLoggable(Level.FINER)) {
1095:                        LogRecord record = new LogRecord(Level.FINER,
1096:                                "PSDT_CSPPW0007");
1097:                        record.setLoggerName(logger.getName());
1098:                        record.setParameters(new Object[] { getName(),
1099:                                windowState, channelMode });
1100:                        logger.log(record);
1101:                    }
1102:
1103:                }
1104:
1105:                //
1106:                // Logic for authless which is not allowed to change its
1107:                // state. For authless, either it is same window state as always
1108:                // or an exception
1109:                //
1110:                WindowState currentWindowState = getCurrentWindowState(request);
1111:                if (authless) {
1112:                    if (!currentWindowState.equals(windowState)) {
1113:                        throw new WindowException(
1114:                                WindowErrorCode.INVALID_WINDOW_STATE_CHANGE_REQUEST,
1115:                                "Anonymous is not allowed to change the window state");
1116:
1117:                    } else {
1118:                        return currentWindowState;
1119:                    }
1120:                }
1121:
1122:                //
1123:                // Logic for regular user
1124:
1125:                try {
1126:
1127:                    //
1128:                    // Get the container provider
1129:                    //
1130:
1131:                    ContainerProvider parentcp = getParentContainerProvider(request);
1132:
1133:                    int providerWinState = ProviderRules
1134:                            .mapToProvider(windowState);
1135:
1136:                    // If parent is null, we just make sure that windowstate
1137:                    // is either Maximized or Normal. If not, we throw
1138:                    // exception because Maximized and Normal are
1139:                    // the valid window states no matter what the container is.
1140:                    if (parentcp != null) {
1141:                        parentcp.setWindowState(getName(), providerWinState);
1142:                    } else if (!windowState.equals(WindowState.MAXIMIZED)) {
1143:                        if (!windowState.equals(WindowState.NORMAL)) {
1144:                            throw new ProviderException(
1145:                                    "portletWindowProvider.processEdit(): "
1146:                                            + " couldn't set the window state to "
1147:                                            + providerWinState);
1148:                        }
1149:                    }
1150:                } catch (UnsupportedWindowStateException wse) {
1151:                    throw new WindowException(
1152:                            WindowErrorCode.INVALID_WINDOW_STATE_CHANGE_REQUEST,
1153:                            wse.getMessage(), wse);
1154:                }
1155:
1156:                return windowState;
1157:            }
1158:
1159:            private static List initParamKeyList() {
1160:
1161:                ArrayList localParamKeyList = new ArrayList();
1162:                localParamKeyList.add(TARGET_PORTLET_CHANNEL_KEY);
1163:                localParamKeyList.add(CURRENT_CHANNEL_MODE_KEY);
1164:                return localParamKeyList;
1165:
1166:            }
1167:
1168:            /**
1169:             * Used by subclasses to find out if key in the request
1170:             * is reserved by the window provider
1171:             */
1172:
1173:            public static boolean isWindowProviderKey(String key) {
1174:                if (key != null) {
1175:                    if (_localParamKeyList.contains(key)) {
1176:                        return true;
1177:                    }
1178:                }
1179:                return false;
1180:            }
1181:
1182:            //-----------------------------------------------------------------
1183:            // Error Handling Methods
1184:            //-----------------------------------------------------------------
1185:
1186:            /**
1187:             * Derived implementations can use this method to 
1188:             * generate a error url if needed
1189:             * We return the URL based on the current mode 
1190:             */
1191:
1192:            public URL getErrorCodeURL(ErrorCode errorCode,
1193:                    HttpServletRequest req) throws ProviderException {
1194:
1195:                String parent = getParentContainerName(req);
1196:
1197:                //
1198:                // Get current channel mode and window state
1199:                //
1200:                ChannelMode currentChannelMode = getCurrentChannelMode(req);
1201:
1202:                try {
1203:                    //
1204:                    // Get the URL for the existing mode
1205:                    //
1206:                    String startURL;
1207:                    if (ChannelMode.HELP.equals(currentChannelMode)) {
1208:                        startURL = getHelpURL(req, getProviderContext())
1209:                                .toString()
1210:                                + "&";
1211:                    } else if (ChannelMode.EDIT.equals(currentChannelMode)) {
1212:                        startURL = getEditURL(req, parent, getProviderContext())
1213:                                .toString()
1214:                                + "&";
1215:                    } else {
1216:                        startURL = getProviderContext().getDesktopURL(req)
1217:                                + "?";
1218:                    }
1219:
1220:                    //
1221:                    // Append the error code to it
1222:                    //
1223:                    return new URL(startURL + DesktopRequest.PREFIX + getName()
1224:                            + ERROR_CODE + "=" + errorCode.toString());
1225:
1226:                } catch (MalformedURLException mue) {
1227:                    throw new ProviderException(
1228:                            "WindowProvider.getErrorCodeURL():couldn't build errorURL",
1229:                            mue);
1230:                } catch (ProviderContextException pce) {
1231:                    throw new ProviderException(
1232:                            "WindowProvider.getErrorCodeURL():"
1233:                                    + " couldn't generate error URL", pce);
1234:                }
1235:            }
1236:
1237:            //
1238:            // Content rendered for error
1239:            // In later releases, this can be changed to 
1240:            // include more fancy fonts or generated via a
1241:            // jsp
1242:            protected StringBuffer getErrorMessageContent(ErrorCode errorCode)
1243:                    throws ProviderException {
1244:
1245:                try {
1246:                    return new StringBuffer(getResourceBundle("WindowProvider")
1247:                            .getString(errorCode.toString()));
1248:
1249:                } catch (MissingResourceException ex) {
1250:                    logger.log(Level.FINE, "PSDT_CSPPW0008", ex);
1251:                    return new StringBuffer(
1252:                            getResourceBundle("WindowProvider").getString(
1253:                                    WindowErrorCode.GENERIC_ERROR.toString()));
1254:                }
1255:            }
1256:
1257:            //
1258:            // This method can be overwritten by the
1259:            // derived classes based on different container implementation 
1260:            // to spit out more fine grained error codes.
1261:            // Overwriting this method IMPLIES overwriting getErrorMessageContent
1262:            // too. In that case, derived classes should create resource bundle
1263:            // with messages for the each new error code they might return from 
1264:            // getErrorCode method, and use the super class method for the rest. 
1265:            //
1266:            protected ErrorCode getErrorCode(ContentException ex) {
1267:                ErrorCode code = ex.getErrorCode();
1268:                if (code == null) {
1269:                    return WindowErrorCode.CONTENT_EXCEPTION;
1270:                } else {
1271:                    return code;
1272:                }
1273:            }
1274:
1275:            //
1276:            // Read error code from the request params
1277:            //
1278:
1279:            protected ErrorCode readErrorCode(HttpServletRequest req) {
1280:                String errorCodeStr = (String) req.getParameter(getName()
1281:                        + ERROR_CODE);
1282:
1283:                if (errorCodeStr != null && errorCodeStr.length() > 0) {
1284:                    return new ErrorCode(errorCodeStr);
1285:                } else {
1286:                    return null;
1287:                }
1288:            }
1289:
1290:            //---------------------------------------------------------------------
1291:            //
1292:            // Following methods are candidates of RFE that should
1293:            // have been provided by the framework.
1294:            // 
1295:            //
1296:            //-----------------------------------------------------------------
1297:
1298:            protected ChannelMode getCurrentChannelMode(HttpServletRequest req) {
1299:
1300:                String currentChannelMode = (String) req
1301:                        .getParameter(CURRENT_CHANNEL_MODE_KEY);
1302:
1303:                String action = (String) req.getParameter("action");
1304:
1305:                if (currentChannelMode != null) {
1306:                    return new ChannelMode(currentChannelMode);
1307:                } else if ((action != null) && action.equals("edit")) {
1308:                    return ChannelMode.EDIT;
1309:                }
1310:                return ChannelMode.VIEW;
1311:            }
1312:
1313:            //
1314:            // During the getContent() call, portal container sets the 
1315:            // providerContext.getParentContainerName(getName()).
1316:            // so we can use that to find the parent in VIEW mode.
1317:            // But for Help and Edit mode, we don't need this container,
1318:            // we need the container that is hosting the content for edit
1319:            // and help.
1320:            // That container is set as "containerName" for the Edit in the 
1321:            // request parameter.
1322:            // WindowProvider also use the same name "containerName" when 
1323:            // creating links to be used to create render/action urls.
1324:            // rama -- so what was the deal with Help ?
1325:
1326:            protected String getParentContainerName(HttpServletRequest req)
1327:                    throws ProviderException {
1328:
1329:                String parentName = null;
1330:
1331:                ChannelMode mode = getCurrentChannelMode(req);
1332:
1333:                if (ChannelMode.VIEW.equals(mode)) {
1334:                    parentName = getProviderContext().getParentContainerName(
1335:                            getName());
1336:                }
1337:
1338:                if (parentName == null) {
1339:                    parentName = req.getParameter("containerName");
1340:                }
1341:
1342:                return parentName;
1343:            }
1344:
1345:            protected ContainerProvider getParentContainerProvider(
1346:                    HttpServletRequest req) throws ProviderException {
1347:
1348:                ContainerProviderContext cpc = (ContainerProviderContext) getProviderContext();
1349:                String parent = getParentContainerName(req);
1350:                if (parent != null) {
1351:                    return (ContainerProvider) cpc.getProvider(req, null,
1352:                            parent);
1353:                }
1354:                return null;
1355:
1356:            }
1357:
1358:            protected WindowState getCurrentWindowState(HttpServletRequest req)
1359:                    throws ProviderException {
1360:
1361:                WindowState windowState = null;
1362:                ContainerProvider parentcp = getParentContainerProvider(req);
1363:                if (parentcp != null) {
1364:                    windowState = ProviderRules.mapToStandards(parentcp
1365:                            .getWindowState(getName()));
1366:                }
1367:                if (windowState == null) {
1368:                    return ProviderRules
1369:                            .getDefaultWindowState(getCurrentChannelMode(req));
1370:                }
1371:
1372:                return windowState;
1373:
1374:            }
1375:
1376:            protected List getAllowableWindowStates(HttpServletRequest req,
1377:                    ChannelMode mode) throws ProviderException {
1378:                String parentName = null;
1379:                List allowableWindowStates = null;
1380:                //
1381:                // Get the container provider
1382:                //
1383:
1384:                ContainerProvider parentcp = getParentContainerProvider(req);
1385:
1386:                //
1387:                // Ask the supported window states from the parent
1388:                // or set it to default
1389:                //
1390:                if (parentcp == null) {
1391:                    allowableWindowStates = ProviderRules
1392:                            .getDefaultAllowableWindowStates(mode);
1393:                } else {
1394:                    allowableWindowStates = ProviderRules
1395:                            .mapToStandards(parentcp.getSupportedWindowStates());
1396:                }
1397:
1398:                return allowableWindowStates;
1399:            }
1400:
1401:            protected String getProcessURL(HttpServletRequest req,
1402:                    String parent, ChannelMode channelMode) {
1403:                StringBuffer processURL = new StringBuffer(getProviderContext()
1404:                        .getDesktopURL(req));
1405:
1406:                processURL.append("?")
1407:                        .append(DesktopRequest.IS_PORTLET_REQUEST).append(
1408:                                "=true").append("&").append(
1409:                                DesktopRequest.PREFIX).append("action=process")
1410:                        .append("&").append(DesktopRequest.PREFIX).append(
1411:                                "provider=").append(PROCESS_CHANNEL)
1412:                        .append("&").append(TARGET_PORTLET_CHANNEL_KEY).append(
1413:                                "=").append(getName()).append("&").append(
1414:                                DesktopRequest.PREFIX).append("containerName=")
1415:                        .append(parent).append("&").append(
1416:                                CURRENT_CHANNEL_MODE_KEY).append("=").append(
1417:                                channelMode.toString());
1418:                return processURL.toString();
1419:
1420:            }
1421:
1422:            protected URL getEditURL(HttpServletRequest req, String parent,
1423:                    ProviderContext pc) throws ProviderContextException,
1424:                    MalformedURLException {
1425:                URL redirectURL = new URL(pc.getDesktopURL(req) + "?"
1426:                        + DesktopRequest.IS_PORTLET_REQUEST + "=true" + "&"
1427:                        + DesktopRequest.PREFIX + "action=edit" + "&"
1428:                        + DesktopRequest.PREFIX + "provider="
1429:                        + pc.getStringProperty(parent, "editContainerName")
1430:                        + "&" + DesktopRequest.PREFIX + "targetprovider="
1431:                        + getName() + "&" + DesktopRequest.PREFIX
1432:                        + "containerName=" + parent);
1433:                return redirectURL;
1434:            }
1435:
1436:            protected URL getHelpURL(HttpServletRequest req, ProviderContext pc)
1437:                    throws ProviderContextException, MalformedURLException {
1438:                try {
1439:                    Map portletPref = pc.getCollectionProperty(this .getName(),
1440:                            PORTLET_PREFERENCE);
1441:                    if (portletPref != null && portletPref.size() > 0) {
1442:                        Map defaultMap = (Map) portletPref.get("default");
1443:                        if (defaultMap != null && defaultMap.size() > 0) {
1444:                            String externalHelp = (String) defaultMap
1445:                                    .get(PS_EXTERNAL_HELP_URL);
1446:                            if (externalHelp != null
1447:                                    && externalHelp.length() > 0) {
1448:                                externalHelp = externalHelp.substring(1);
1449:                                if (("http://".equalsIgnoreCase(externalHelp
1450:                                        .substring(0, 7)))
1451:                                        || ("https://"
1452:                                                .equalsIgnoreCase(externalHelp
1453:                                                        .substring(0, 8)))) {
1454:                                    return new URL(externalHelp);
1455:                                } else if (externalHelp.charAt(0) == '/') {
1456:                                    int serverPort = req.getServerPort();
1457:                                    String serverHost = req.getServerName();
1458:                                    String entityID = getEntityID(req);
1459:                                    String appName = entityID.substring(0,
1460:                                            entityID.indexOf('|'));
1461:                                    String protocol = req.getScheme();
1462:                                    return new URL(protocol + "://"
1463:                                            + serverHost + ":"
1464:                                            + Integer.toString(serverPort)
1465:                                            + "/" + appName + externalHelp);
1466:                                } else {
1467:                                    throw new MalformedURLException(
1468:                                            "URL must either start with http:// or https:// or /");
1469:                                }
1470:                            }
1471:                        }
1472:                    }
1473:                } catch (ProviderContextException pce) {
1474:                    if (logger.isLoggable(Level.INFO)) {
1475:                        LogRecord record = new LogRecord(Level.INFO,
1476:                                "PSDT_CSPPW0005");
1477:                        record.setLoggerName(logger.getName());
1478:                        record.setParameters(new Object[] { getName() });
1479:                        record.setThrown(pce);
1480:                        logger.log(record);
1481:                    }
1482:                } catch (ProviderException pe) {
1483:                    if (logger.isLoggable(Level.INFO)) {
1484:                        LogRecord record = new LogRecord(Level.INFO,
1485:                                "PSDT_CSPPW0005");
1486:                        record.setLoggerName(logger.getName());
1487:                        record.setParameters(new Object[] { getName() });
1488:                        record.setThrown(pe);
1489:                        logger.log(record);
1490:                    }
1491:                }
1492:                URL helpURL = new URL(pc.getDesktopURL(req) + "?"
1493:                        + DesktopRequest.IS_PORTLET_REQUEST + "=true" + "&"
1494:                        + DesktopRequest.PREFIX + "action=content" + "&"
1495:                        + DesktopRequest.PREFIX + "provider=" + getName() + "&"
1496:                        + CURRENT_CHANNEL_MODE_KEY + "=" + ChannelMode.HELP
1497:                        + "&" + DesktopRequest.PREFIX + "last=false");
1498:                return helpURL;
1499:
1500:            }
1501:
1502:            /**
1503:             * Throws a provider exception if attempt is made to
1504:             * change to a new mode that is not allowed by the portal
1505:             */
1506:            private void validateModeChange(ChannelMode currentMode,
1507:                    ChannelMode newMode, boolean authless)
1508:                    throws WindowException {
1509:
1510:                List allowedList = ProviderRules.getAllowableChannelModes(
1511:                        currentMode, authless);
1512:                if (!allowedList.contains(newMode)) {
1513:                    throw new WindowException(
1514:                            WindowErrorCode.INVALID_MODE_CHANGE_REQUEST,
1515:                            "Portal doesn't allow changing mode " + " from "
1516:                                    + currentMode + " to " + newMode);
1517:                }
1518:                return;
1519:
1520:            }
1521:            //---------------------------------------------------------------------
1522:            //
1523:            // End of methods that are candidate of functionality that
1524:            // should have been provided by the framework
1525:            //
1526:            //-----------------------------------------------------------------
1527:
1528:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.