KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > mock > web > portlet > MockActionRequest


1 /*
2  * Copyright 2002-2006 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.mock.web.portlet;
18
19 import java.io.BufferedReader JavaDoc;
20 import java.io.ByteArrayInputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.InputStreamReader JavaDoc;
24 import java.io.Reader JavaDoc;
25 import java.io.UnsupportedEncodingException JavaDoc;
26
27 import javax.portlet.ActionRequest;
28 import javax.portlet.PortalContext;
29 import javax.portlet.PortletContext;
30
31 /**
32  * Mock implementation of the {@link javax.portlet.ActionRequest} interface.
33  *
34  * @author John A. Lewis
35  * @author Juergen Hoeller
36  * @since 2.0
37  */

38 public class MockActionRequest extends MockPortletRequest implements ActionRequest {
39
40     private String JavaDoc characterEncoding;
41
42     private byte[] content;
43
44     private String JavaDoc contentType;
45
46
47     /**
48      * Create a new MockActionRequest with a default {@link MockPortalContext}
49      * and a default {@link MockPortletContext}.
50      * @see MockPortalContext
51      * @see MockPortletContext
52      */

53     public MockActionRequest() {
54         super();
55     }
56
57     /**
58      * Create a new MockActionRequest with a default {@link MockPortalContext}.
59      * @param portletContext the PortletContext that the request runs in
60      * @see MockPortalContext
61      */

62     public MockActionRequest(PortletContext portletContext) {
63         super(portletContext);
64     }
65
66     /**
67      * Create a new MockActionRequest.
68      * @param portalContext the PortalContext that the request runs in
69      * @param portletContext the PortletContext that the request runs in
70      */

71     public MockActionRequest(PortalContext portalContext, PortletContext portletContext) {
72         super(portalContext, portletContext);
73     }
74
75
76     public void setContent(byte[] content) {
77         this.content = content;
78     }
79
80     public InputStream JavaDoc getPortletInputStream() throws IOException JavaDoc {
81         if (this.content != null) {
82             return new ByteArrayInputStream JavaDoc(this.content);
83         }
84         else {
85             return null;
86         }
87     }
88
89     public void setCharacterEncoding(String JavaDoc characterEncoding) {
90         this.characterEncoding = characterEncoding;
91     }
92
93     public BufferedReader JavaDoc getReader() throws UnsupportedEncodingException JavaDoc {
94         if (this.content != null) {
95             InputStream JavaDoc sourceStream = new ByteArrayInputStream JavaDoc(this.content);
96             Reader JavaDoc sourceReader = (this.characterEncoding != null) ?
97                 new InputStreamReader JavaDoc(sourceStream, this.characterEncoding) : new InputStreamReader JavaDoc(sourceStream);
98             return new BufferedReader JavaDoc(sourceReader);
99         }
100         else {
101             return null;
102         }
103     }
104
105     public String JavaDoc getCharacterEncoding() {
106         return characterEncoding;
107     }
108
109     public void setContentType(String JavaDoc contentType) {
110         this.contentType = contentType;
111     }
112
113     public String JavaDoc getContentType() {
114         return contentType;
115     }
116
117     public int getContentLength() {
118         return (this.content != null ? content.length : -1);
119     }
120
121 }
122
Popular Tags