1 package org.apache.turbine.services.upload;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Turbine" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * "Apache Turbine", nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import javax.servlet.http.HttpServletRequest;
58 import org.apache.turbine.services.TurbineServices;
59 import org.apache.turbine.util.ParameterParser;
60 import org.apache.turbine.util.TurbineException;
61
62 /***
63 * <p> This is a facade class for {@link UploadService}.
64 *
65 * <p> This class provides static methods that retrieve the configured
66 * (in TurbineResource.properties) implementation of {@link
67 * UploadService} and perform certain operations on it. It uses
68 * constants defined in {@link UploadService} interface for accessing
69 * the service's properties and default values for them.
70 *
71 * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
72 * @version $Id: TurbineUpload.java,v 1.2 2002/07/11 16:53:23 mpoeschl Exp $
73 */
74 public abstract class TurbineUpload
75 {
76 /***
77 * <p> Retrieves an instance of system's configured implementation
78 * of <code>UploadService</code>
79 *
80 * @return An instance of UploadService
81 */
82 public static UploadService getService()
83 {
84 return (UploadService)TurbineServices.getInstance().
85 getService(UploadService.SERVICE_NAME);
86 }
87
88 /***
89 * <p> Retrieves the value of 'automatic' property of {@link
90 * UploadService}.
91 *
92 * @return The value of 'automatic' property of {@link
93 * UploadService}.
94 */
95 public static boolean getAutomatic()
96 {
97 UploadService upload = null;
98 try
99 {
100 upload = getService();
101 }
102 catch(org.apache.turbine.services.InstantiationException ie)
103 {
104 // If the service couldn't be instantiated, it obviously
105 // can't be used for automatic uploading.
106 return false;
107 }
108 String auto = upload.getProperties()
109 .getProperty(UploadService.AUTOMATIC_KEY,
110 UploadService.AUTOMATIC_DEFAULT.toString())
111 .toLowerCase();
112 if(auto.equals("true") || auto.equals("yes") || auto.equals("1"))
113 {
114 return true;
115 }
116 if(auto.equals("false") || auto.equals("no") || auto.equals("0"))
117 {
118 return false;
119 }
120 return UploadService.AUTOMATIC_DEFAULT.booleanValue();
121 }
122
123 /***
124 * <p> Retrieves the value of 'size.max' property of {@link
125 * UploadService}.
126 *
127 * @return The value of 'size.max' property of {@link
128 * UploadService}.
129 */
130 public static int getSizeMax()
131 {
132 return getService().getSizeMax();
133 }
134
135 /***
136 * <p> Retrieves the value of <code>size.threshold</code> property of
137 * {@link org.apache.turbine.services.upload.UploadService}.
138 *
139 * @return The threshold beyond which files are written directly to disk.
140 */
141 public static int getSizeThreshold()
142 {
143 return getService().getSizeThreshold();
144 }
145
146 /***
147 * <p> Retrieves the value of the <code>repository</code> property of
148 * {@link org.apache.turbine.services.upload.UploadService}.
149 *
150 * @return The repository.
151 */
152 public static String getRepository()
153 {
154 return getService().getRepository();
155 }
156
157 /***
158 * <p> Performs parsing the request and storing files and form
159 * fields. Default file repository is used. This method is
160 * called by the {@link ParameterParser} if automatic upload is
161 * enabled.
162 *
163 * @param req The servlet request to be parsed.
164 * @param params The ParameterParser instance to insert form
165 * fields into.
166 * @exception TurbineException If there are problems reading/parsing
167 * the request or storing files.
168 */
169 public static void parseRequest( HttpServletRequest req,
170 ParameterParser params )
171 throws TurbineException
172 {
173 UploadService upload = getService();
174 upload.parseRequest(req, params, upload.getRepository());
175 }
176
177 /***
178 * <p> Performs parsing the request and storing files and form
179 * fields. Custom file repository may be specified. You can call
180 * this method in your file upload {@link
181 * org.apache.turbine.modules.Action} to if you need to specify a
182 * custom directory for storing files.
183 *
184 * @param req The servlet request to be parsed.
185 * @param params The ParameterParser instance to insert form
186 * fields into.
187 * @param path The location where the files should be stored.
188 * @exception TurbineException If there are problems reading/parsing
189 * the request or storing files.
190 */
191 public static void parseRequest( HttpServletRequest req,
192 ParameterParser params,
193 String path )
194 throws TurbineException
195 {
196 UploadService upload = getService();
197 upload.parseRequest(req, params, path);
198 }
199 }
This page was automatically generated by Maven