01: /*
02: * Copyright 2005-2007 Noelios Consulting.
03: *
04: * The contents of this file are subject to the terms of the Common Development
05: * and Distribution License (the "License"). You may not use this file except in
06: * compliance with the License.
07: *
08: * You can obtain a copy of the license at
09: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
10: * language governing permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL HEADER in each file and
13: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
14: * applicable, add the following below this CDDL HEADER, with the fields
15: * enclosed by brackets "[]" replaced with your own identifying information:
16: * Portions Copyright [yyyy] [name of copyright owner]
17: */
18:
19: package org.restlet.ext.fileupload;
20:
21: import java.io.IOException;
22: import java.io.InputStream;
23:
24: import org.apache.commons.fileupload.RequestContext;
25: import org.restlet.resource.Representation;
26:
27: /**
28: * Provides access to the representation information needed by the FileUpload
29: * processor.
30: *
31: * @author Jerome Louvel (contact@noelios.com)
32: */
33: public class RepresentationContext implements RequestContext {
34: /** The representation to adapt. */
35: private Representation multipartForm;
36:
37: /**
38: * Constructor.
39: *
40: * @param multipartForm
41: * The multipart form to parse.
42: */
43: public RepresentationContext(Representation multipartForm) {
44: this .multipartForm = multipartForm;
45: }
46:
47: /**
48: * Returns the character encoding for the form.
49: *
50: * @return The character encoding for the form.
51: */
52: public String getCharacterEncoding() {
53: if (!this .multipartForm.getEncodings().isEmpty()) {
54: return this .multipartForm.getEncodings().get(0).getName();
55: } else {
56: return null;
57: }
58: }
59:
60: /**
61: * Returns the content length of the form.
62: *
63: * @return The content length of the form.
64: */
65: public int getContentLength() {
66: return (int) this .multipartForm.getSize();
67: }
68:
69: /**
70: * Returns the content type of the form.
71: *
72: * @return The content type of the form.
73: */
74: public String getContentType() {
75: if (this .multipartForm.getMediaType() != null) {
76: return this .multipartForm.getMediaType().toString();
77: } else {
78: return null;
79: }
80: }
81:
82: /**
83: * Returns the input stream.
84: *
85: * @return The input stream.
86: */
87: public InputStream getInputStream() throws IOException {
88: return this.multipartForm.getStream();
89: }
90:
91: }
|