View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
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   */
16  package org.kuali.rice.kew.engine.node.var.schemes;
17  
18  import java.io.IOException;
19  import java.io.InputStream;
20  import java.net.URL;
21  
22  import org.apache.log4j.Logger;
23  import org.kuali.rice.kew.engine.RouteContext;
24  import org.kuali.rice.kew.engine.node.PropertiesUtil;
25  import org.kuali.rice.kew.engine.node.var.Property;
26  import org.kuali.rice.kew.engine.node.var.PropertyScheme;
27  
28  
29  /**
30   * A property scheme that interprets the locator as a URL.
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class URLScheme implements PropertyScheme {
35      private static final Logger LOG = Logger.getLogger(URLScheme.class);
36  
37      public String getName() {
38          return "url";
39      }
40      public String getShortName() {
41          return "url";
42      }
43  
44      public Object load(Property property, RouteContext context) {
45          LOG.info("Reading url '" + property.locator + "'...");
46          InputStream is;
47          try {
48              is = new URL(property.locator).openStream();
49              if (is == null) {
50                  throw new RuntimeException("Unable to access URL: " + property.locator);
51              }
52              return PropertiesUtil.readResource(is);
53          } catch (IOException ioe) {
54              throw new RuntimeException("Error loading resource: " + property.locator, ioe);
55          }
56      }
57  
58      public String toString() {
59          return "[URLScheme]";
60      }
61  }