01: /*
02: * Copyright 2005-2006 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package edu.iu.uis.eden.engine.node.var.schemes;
19:
20: import java.io.IOException;
21: import java.io.InputStream;
22: import java.net.URL;
23:
24: import org.apache.log4j.Logger;
25:
26: import edu.iu.uis.eden.engine.RouteContext;
27: import edu.iu.uis.eden.engine.node.PropertiesUtil;
28: import edu.iu.uis.eden.engine.node.var.Property;
29: import edu.iu.uis.eden.engine.node.var.PropertyScheme;
30:
31: /**
32: * A property scheme that interprets the locator as a URL.
33: *
34: * @author Aaron Hamid (arh14 at cornell dot edu)
35: */
36: public class URLScheme implements PropertyScheme {
37: private static final Logger LOG = Logger.getLogger(URLScheme.class);
38:
39: public String getName() {
40: return "url";
41: }
42:
43: public String getShortName() {
44: return "url";
45: }
46:
47: public Object load(Property property, RouteContext context) {
48: LOG.info("Reading url '" + property.locator + "'...");
49: InputStream is;
50: try {
51: is = new URL(property.locator).openStream();
52: if (is == null) {
53: throw new RuntimeException("Unable to access URL: "
54: + property.locator);
55: }
56: return PropertiesUtil.readResource(is);
57: } catch (IOException ioe) {
58: throw new RuntimeException("Error loading resource: "
59: + property.locator, ioe);
60: }
61: }
62:
63: public String toString() {
64: return "[URLScheme]";
65: }
66: }
|