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