Source Code Cross Referenced for PortletContentGenerator.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » portlet » handler » 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 » J2EE » spring framework 2.0.6 » org.springframework.web.portlet.handler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.web.portlet.handler;
018:
019:        import javax.portlet.PortletException;
020:        import javax.portlet.PortletRequest;
021:        import javax.portlet.PortletResponse;
022:        import javax.portlet.RenderRequest;
023:        import javax.portlet.RenderResponse;
024:
025:        import org.springframework.web.portlet.context.PortletApplicationObjectSupport;
026:
027:        /**
028:         * Convenient superclass for any kind of web content generator,
029:         * like AbstractController. Can also be used for custom handlers 
030:         * that have their own HandlerAdapter.
031:         *
032:         * <p>Supports portlet cache control options.
033:         *
034:         * @author Juergen Hoeller
035:         * @author John A. Lewis
036:         * @since 2.0
037:         * @see org.springframework.web.portlet.mvc.AbstractController
038:         */
039:        public abstract class PortletContentGenerator extends
040:                PortletApplicationObjectSupport {
041:
042:            private boolean requireSession = false;
043:
044:            private int cacheSeconds = -1;
045:
046:            /**
047:             * Set whether a session should be required to handle requests.
048:             */
049:            public final void setRequireSession(boolean requireSession) {
050:                this .requireSession = requireSession;
051:            }
052:
053:            /**
054:             * Return whether a session is required to handle requests.
055:             */
056:            public final boolean isRequireSession() {
057:                return requireSession;
058:            }
059:
060:            /**
061:             * Cache content for the given number of seconds. Default is -1,
062:             * indicating no override of portlet content caching.
063:             * <p>Only if this is set to 0 (no cache) or a positive value (cache for
064:             * this many seconds) will this class override the portlet settings.
065:             * <p>The cache setting can be overwritten by subclasses, before content is generated.
066:             */
067:            public final void setCacheSeconds(int seconds) {
068:                this .cacheSeconds = seconds;
069:            }
070:
071:            /**
072:             * Return the number of seconds that content is cached.
073:             */
074:            public final int getCacheSeconds() {
075:                return cacheSeconds;
076:            }
077:
078:            /**
079:             * Check and prepare the given request and response according to the settings
080:             * of this generator. Checks for a required session, and applies the number of
081:             * cache seconds configured for this generator (if it is a render request/response).
082:             * @param request current portlet request
083:             * @param response current portlet response
084:             * @throws PortletException if the request cannot be handled because a check failed
085:             */
086:            protected final void check(PortletRequest request,
087:                    PortletResponse response) throws PortletException {
088:                if (this .requireSession) {
089:                    if (request.getPortletSession(false) == null) {
090:                        throw new PortletSessionRequiredException(
091:                                "Pre-existing session required but none found");
092:                    }
093:                }
094:            }
095:
096:            /**
097:             * Check and prepare the given request and response according to the settings
098:             * of this generator. Checks for a required session, and applies the number of 
099:             * cache seconds configured for this generator (if it is a render request/response).
100:             * @param request current portlet request
101:             * @param response current portlet response
102:             * @throws PortletException if the request cannot be handled because a check failed
103:             */
104:            protected final void checkAndPrepare(RenderRequest request,
105:                    RenderResponse response) throws PortletException {
106:
107:                checkAndPrepare(request, response, this .cacheSeconds);
108:            }
109:
110:            /**
111:             * Check and prepare the given request and response according to the settings
112:             * of this generator. Checks for a required session, and applies the given 
113:             * number of cache seconds (if it is a render request/response).
114:             * @param request current portlet request
115:             * @param response current portlet response
116:             * @param cacheSeconds positive number of seconds into the future that the
117:             * response should be cacheable for, 0 to prevent caching
118:             * @throws PortletException if the request cannot be handled because a check failed
119:             */
120:            protected final void checkAndPrepare(RenderRequest request,
121:                    RenderResponse response, int cacheSeconds)
122:                    throws PortletException {
123:
124:                check(request, response);
125:                applyCacheSeconds(response, cacheSeconds);
126:            }
127:
128:            /**
129:             * Prevent the render response from being cached.
130:             */
131:            protected final void preventCaching(RenderResponse response) {
132:                cacheForSeconds(response, 0);
133:            }
134:
135:            /**
136:             * Set portlet response to allow caching for the given number of seconds.
137:             * @param response current portlet render response
138:             * @param seconds number of seconds into the future that the response
139:             * should be cacheable for
140:             */
141:            protected final void cacheForSeconds(RenderResponse response,
142:                    int seconds) {
143:                response.setProperty(RenderResponse.EXPIRATION_CACHE, Integer
144:                        .toString(seconds));
145:            }
146:
147:            /**
148:             * Apply the given cache seconds to the render response
149:             * @param response current portlet render response
150:             * @param seconds positive number of seconds into the future that the
151:             * response should be cacheable for, 0 to prevent caching
152:             */
153:            protected final void applyCacheSeconds(RenderResponse response,
154:                    int seconds) {
155:                if (seconds > 0) {
156:                    cacheForSeconds(response, seconds);
157:                } else if (seconds == 0) {
158:                    preventCaching(response);
159:                }
160:                // Leave caching to the portlet configuration otherwise.
161:            }
162:
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.