01: /*
02: * Copyright 2005-2007 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: // Created on May 8, 2006
18: package edu.iu.uis.eden.test.web.framework.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.test.web.framework.Property;
27: import edu.iu.uis.eden.test.web.framework.PropertyScheme;
28: import edu.iu.uis.eden.test.web.framework.ScriptState;
29: import edu.iu.uis.eden.test.web.framework.Util;
30:
31: /**
32: * A property scheme that interprets the locator as a URL
33: * @author Aaron Hamid (arh14 at cornell dot edu)
34: */
35: public class URLScheme implements PropertyScheme {
36: private static final Logger LOG = Logger.getLogger(URLScheme.class);
37:
38: public String getName() {
39: return "url";
40: }
41:
42: public String getShortName() {
43: return "url";
44: }
45:
46: public Object load(Property property, ScriptState state) {
47: LOG.info("Reading url '" + property.locator + "'...");
48: InputStream is;
49: try {
50: is = new URL(property.locator).openStream();
51: if (is == null) {
52: throw new RuntimeException("Unable to access URL: "
53: + property.locator);
54: }
55: return Util.readResource(is);
56: } catch (IOException ioe) {
57: throw new RuntimeException("Error loading resource: "
58: + property.locator, ioe);
59: }
60: }
61:
62: public String toString() {
63: return "[URLScheme]";
64: }
65: }
|