View Javadoc

1   /*
2    * Copyright 2001-2005 The Apache Software Foundation
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  package org.apache.commons.fileupload.portlet;
17  
18  import java.io.InputStream;
19  import java.io.IOException;
20  import javax.portlet.ActionRequest;
21  import org.apache.commons.fileupload.RequestContext;
22  
23  /***
24   * <p>Provides access to the request information needed for a request made to
25   * a portlet.</p>
26   *
27   * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
28   *
29   * @since FileUpload 1.1
30   *
31   * @version $Id: PortletRequestContext.java 349393 2005-11-28 06:36:35Z martinc $
32   */
33  public class PortletRequestContext implements RequestContext {
34  
35      // ----------------------------------------------------- Instance Variables
36  
37      /***
38       * The request for which the context is being provided.
39       */
40      private ActionRequest request;
41  
42  
43      // ----------------------------------------------------------- Constructors
44  
45      /***
46       * Construct a context for this request.
47       *
48       * @param request The request to which this context applies.
49       */
50      public PortletRequestContext(ActionRequest request) {
51          this.request = request;
52      }
53  
54  
55      // --------------------------------------------------------- Public Methods
56  
57      /***
58       * Retrieve the character encoding for the request.
59       *
60       * @return The character encoding for the request.
61       */
62      public String getCharacterEncoding() {
63          return request.getCharacterEncoding();
64      }
65  
66      /***
67       * Retrieve the content type of the request.
68       *
69       * @return The content type of the request.
70       */
71      public String getContentType() {
72          return request.getContentType();
73      }
74  
75      /***
76       * Retrieve the content length of the request.
77       *
78       * @return The content length of the request.
79       */
80      public int getContentLength() {
81          return request.getContentLength();
82      }
83  
84      /***
85       * Retrieve the input stream for the request.
86       *
87       * @return The input stream for the request.
88       *
89       * @throws IOException if a problem occurs.
90       */
91      public InputStream getInputStream() throws IOException {
92          return request.getPortletInputStream();
93      }
94  
95      /***
96       * Returns a string representation of this object.
97       *
98       * @return a string representation of this object.
99       */
100     public String toString() {
101         return "ContentLength="
102             + this.getContentLength()
103             + ", ContentType="
104             + this.getContentType();
105     }
106 
107 }