01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.http.util;
16:
17: import javax.servlet.ServletRequest;
18: import org.araneaframework.InputData;
19: import org.araneaframework.core.Assert;
20: import org.araneaframework.http.HttpInputData;
21: import org.araneaframework.http.HttpOutputData;
22: import org.araneaframework.http.filter.StandardFileImportFilterService;
23:
24: /**
25: * Utility methods for converting file names to a form which allows them to be imported with
26: * {@link StandardFileImportFilterService}.
27: *
28: * @author "Toomas Römer" <toomas@webmedia.ee>
29: */
30: public abstract class FileImportUtil {
31:
32: /**
33: * Given a filename, returns the string that can be used for importing via the
34: * file importing service {@link StandardFileImportFilterService}.
35: */
36: public final static String getImportString(String fileName) {
37: Assert.notEmptyParam(fileName, "fileName");
38:
39: StringBuffer sb = new StringBuffer("/"
40: + StandardFileImportFilterService.FILE_IMPORTER_NAME
41: + "/");
42: sb.append(fileName);
43:
44: return sb.toString();
45: }
46:
47: /**
48: * Given a filename, returns the string with absolute URL that can be used
49: * for importing via the file importing service {@link StandardFileImportFilterService}.
50: */
51: public final static String getImportString(String fileName,
52: ServletRequest req) {
53: return getImportString(fileName, ServletUtil.getInputData(req));
54: }
55:
56: /**
57: * Given a filename, returns the string with absolute URL that can be used
58: * for importing via the file importing service {@link StandardFileImportFilterService}.
59: */
60: public final static String getImportString(String fileName,
61: InputData input) {
62: Assert.notNullParam(input, "input");
63: Assert.notEmptyParam(fileName, "fileName");
64: Assert.isInstanceOfParam(HttpInputData.class, input, "input");
65:
66: StringBuffer url = new StringBuffer();
67: url.append(((HttpInputData) input).getContainerURL());
68: url.append(getImportString(fileName));
69:
70: return (url.toString());
71: }
72:
73: /**
74: * Given a filename, returns the string with absolute encoded URL that can be used
75: * for importing via the file importing service {@link StandardFileImportFilterService}.
76: */
77: public final static String getEncodedImportString(String fileName,
78: InputData input) {
79: return ((HttpOutputData) input.getOutputData())
80: .encodeURL(getImportString(fileName, input));
81: }
82: }
|