Source Code Cross Referenced for MockRenderResponse.java in  » J2EE » spring-framework-2.0.6 » org » springframework » mock » web » portlet » 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.mock.web.portlet 
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.mock.web.portlet;
018:
019:        import java.io.ByteArrayOutputStream;
020:        import java.io.IOException;
021:        import java.io.OutputStream;
022:        import java.io.OutputStreamWriter;
023:        import java.io.PrintWriter;
024:        import java.io.UnsupportedEncodingException;
025:        import java.io.Writer;
026:        import java.util.Locale;
027:
028:        import javax.portlet.PortalContext;
029:        import javax.portlet.PortletURL;
030:        import javax.portlet.RenderResponse;
031:
032:        import org.springframework.web.util.WebUtils;
033:
034:        /**
035:         * Mock implementation of the {@link javax.portlet.RenderResponse} interface.
036:         *
037:         * @author John A. Lewis
038:         * @author Juergen Hoeller
039:         * @since 2.0
040:         */
041:        public class MockRenderResponse extends MockPortletResponse implements 
042:                RenderResponse {
043:
044:            private String contentType;
045:
046:            private String namespace = "MockPortlet";
047:
048:            private String title;
049:
050:            private String characterEncoding = WebUtils.DEFAULT_CHARACTER_ENCODING;
051:
052:            private PrintWriter writer;
053:
054:            private Locale locale = Locale.getDefault();
055:
056:            private int bufferSize = 4096;
057:
058:            private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
059:
060:            private boolean committed;
061:
062:            private String includedUrl;
063:
064:            /**
065:             * Create a new MockRenderResponse with a default {@link MockPortalContext}.
066:             * @see MockPortalContext
067:             */
068:            public MockRenderResponse() {
069:                super ();
070:            }
071:
072:            /**
073:             * Create a new MockRenderResponse.
074:             * @param portalContext the PortalContext defining the supported
075:             * PortletModes and WindowStates
076:             */
077:            public MockRenderResponse(PortalContext portalContext) {
078:                super (portalContext);
079:            }
080:
081:            //---------------------------------------------------------------------
082:            // RenderResponse methods
083:            //---------------------------------------------------------------------
084:
085:            public String getContentType() {
086:                return this .contentType;
087:            }
088:
089:            public PortletURL createRenderURL() {
090:                PortletURL url = new MockPortletURL(getPortalContext(),
091:                        MockPortletURL.URL_TYPE_RENDER);
092:                return url;
093:            }
094:
095:            public PortletURL createActionURL() {
096:                PortletURL url = new MockPortletURL(getPortalContext(),
097:                        MockPortletURL.URL_TYPE_ACTION);
098:                return url;
099:            }
100:
101:            public String getNamespace() {
102:                return this .namespace;
103:            }
104:
105:            public void setTitle(String title) {
106:                this .title = title;
107:            }
108:
109:            public String getTitle() {
110:                return title;
111:            }
112:
113:            public void setContentType(String contentType) {
114:                this .contentType = contentType;
115:            }
116:
117:            public void setCharacterEncoding(String characterEncoding) {
118:                this .characterEncoding = characterEncoding;
119:            }
120:
121:            public String getCharacterEncoding() {
122:                return this .characterEncoding;
123:            }
124:
125:            public PrintWriter getWriter() throws UnsupportedEncodingException {
126:                if (this .writer == null) {
127:                    Writer targetWriter = (this .characterEncoding != null ? new OutputStreamWriter(
128:                            this .outputStream, this .characterEncoding)
129:                            : new OutputStreamWriter(this .outputStream));
130:                    this .writer = new PrintWriter(targetWriter);
131:                }
132:                return this .writer;
133:            }
134:
135:            public byte[] getContentAsByteArray() {
136:                flushBuffer();
137:                return this .outputStream.toByteArray();
138:            }
139:
140:            public String getContentAsString()
141:                    throws UnsupportedEncodingException {
142:                flushBuffer();
143:                return (this .characterEncoding != null) ? this .outputStream
144:                        .toString(this .characterEncoding) : this .outputStream
145:                        .toString();
146:            }
147:
148:            public void setLocale(Locale locale) {
149:                this .locale = locale;
150:            }
151:
152:            public Locale getLocale() {
153:                return this .locale;
154:            }
155:
156:            public void setBufferSize(int bufferSize) {
157:                this .bufferSize = bufferSize;
158:            }
159:
160:            public int getBufferSize() {
161:                return this .bufferSize;
162:            }
163:
164:            public void flushBuffer() {
165:                if (this .writer != null) {
166:                    this .writer.flush();
167:                }
168:                if (this .outputStream != null) {
169:                    try {
170:                        this .outputStream.flush();
171:                    } catch (IOException ex) {
172:                        throw new IllegalStateException(
173:                                "Could not flush OutputStream: "
174:                                        + ex.getMessage());
175:                    }
176:                }
177:                this .committed = true;
178:            }
179:
180:            public void resetBuffer() {
181:                if (this .committed) {
182:                    throw new IllegalStateException(
183:                            "Cannot reset buffer - response is already committed");
184:                }
185:                this .outputStream.reset();
186:            }
187:
188:            public void setCommitted(boolean committed) {
189:                this .committed = committed;
190:            }
191:
192:            public boolean isCommitted() {
193:                return this .committed;
194:            }
195:
196:            public void reset() {
197:                resetBuffer();
198:                this .characterEncoding = null;
199:                this .contentType = null;
200:                this .locale = null;
201:            }
202:
203:            public OutputStream getPortletOutputStream() throws IOException {
204:                return this .outputStream;
205:            }
206:
207:            //---------------------------------------------------------------------
208:            // Methods for MockPortletRequestDispatcher
209:            //---------------------------------------------------------------------
210:
211:            public void setIncludedUrl(String includedUrl) {
212:                this .includedUrl = includedUrl;
213:            }
214:
215:            public String getIncludedUrl() {
216:                return includedUrl;
217:            }
218:
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.