| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ResourceScheme |
|
| 2.5;2.5 |
| 1 | /** | |
| 2 | * Copyright 2005-2011 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 | ||
| 21 | import org.apache.log4j.Logger; | |
| 22 | import org.kuali.rice.kew.engine.RouteContext; | |
| 23 | import org.kuali.rice.kew.engine.node.PropertiesUtil; | |
| 24 | import org.kuali.rice.kew.engine.node.var.Property; | |
| 25 | import org.kuali.rice.kew.engine.node.var.PropertyScheme; | |
| 26 | ||
| 27 | ||
| 28 | /** | |
| 29 | * A property scheme that loads resources from the class loader. | |
| 30 | * | |
| 31 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
| 32 | */ | |
| 33 | 0 | public class ResourceScheme implements PropertyScheme { |
| 34 | 0 | private static final Logger LOG = Logger.getLogger(ResourceScheme.class); |
| 35 | ||
| 36 | public String getName() { | |
| 37 | 0 | return "resource"; |
| 38 | } | |
| 39 | public String getShortName() { | |
| 40 | 0 | return "res"; |
| 41 | } | |
| 42 | ||
| 43 | public Object load(Property property, RouteContext context) { | |
| 44 | String resource; | |
| 45 | 0 | boolean relative = false; |
| 46 | // if (property.locator.startsWith("/")) { | |
| 47 | 0 | resource = property.locator; |
| 48 | // } else { | |
| 49 | // relative = true; | |
| 50 | // String prefix; | |
| 51 | // /* if a resource prefix is set, use it */ | |
| 52 | // if (state.getResourcePrefix() != null) { | |
| 53 | // prefix = state.getResourcePrefix(); | |
| 54 | // } else { | |
| 55 | // /* otherwise use the location of the Script class */ | |
| 56 | // prefix = Script.class.getPackage().getName().replace('.', '/'); | |
| 57 | // } | |
| 58 | // if (!prefix.endsWith("/")) { | |
| 59 | // prefix += "/"; | |
| 60 | // } | |
| 61 | // resource = prefix + property.locator; | |
| 62 | // } | |
| 63 | 0 | String resStr = property.locator + (relative ? "(" + resource + ")" : ""); |
| 64 | 0 | LOG.info("Reading resource " + resStr + "..."); |
| 65 | ||
| 66 | 0 | InputStream is = getClass().getResourceAsStream(resource); |
| 67 | 0 | if (is == null) { |
| 68 | 0 | throw new RuntimeException("Resource not found: " + resStr); |
| 69 | } | |
| 70 | try { | |
| 71 | 0 | return PropertiesUtil.readResource(is); |
| 72 | 0 | } catch (IOException ioe) { |
| 73 | 0 | throw new RuntimeException("Error loading resource: " + resStr, ioe); |
| 74 | } | |
| 75 | } | |
| 76 | ||
| 77 | public String toString() { | |
| 78 | 0 | return "[ResourceScheme]"; |
| 79 | } | |
| 80 | } |