01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.base.config;
19:
20: import java.net.*;
21: import java.io.*;
22: import org.ofbiz.base.util.*;
23:
24: /**
25: * Loads resources from the file system
26: *
27: */
28: public class FileLoader extends ResourceLoader implements
29: java.io.Serializable {
30:
31: public URL getURL(String location) throws GenericConfigException {
32: String fullLocation = fullLocation(location);
33: URL fileUrl = null;
34:
35: fileUrl = UtilURL.fromFilename(fullLocation);
36: if (fileUrl == null) {
37: throw new GenericConfigException(
38: "File Resource not found: " + fullLocation);
39: }
40: return fileUrl;
41: }
42:
43: public InputStream loadResource(String location)
44: throws GenericConfigException {
45: URL fileUrl = getURL(location);
46: try {
47: return fileUrl.openStream();
48: } catch (java.io.IOException e) {
49: throw new GenericConfigException(
50: "Error opening file at location ["
51: + fileUrl.toExternalForm() + "]", e);
52: }
53: }
54: }
|