1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.rice.kew.engine.node;
17  
18  import java.io.IOException;
19  import java.io.InputStream;
20  import java.io.InputStreamReader;
21  import java.util.Iterator;
22  
23  import org.apache.log4j.Logger;
24  import org.kuali.rice.kew.engine.RouteContext;
25  import org.kuali.rice.kew.engine.node.var.Property;
26  import org.kuali.rice.kew.engine.node.var.PropertyScheme;
27  
28  
29  
30  
31  
32  
33  
34  public final class PropertiesUtil {
35      private static final Logger LOG = Logger.getLogger(PropertiesUtil.class);
36  
37  	private PropertiesUtil() {
38  		throw new UnsupportedOperationException("do not call");
39  	}
40  
41      public static String readResource(InputStream stream) throws IOException {
42          StringBuffer sb = new StringBuffer(2048);
43          InputStreamReader reader = new InputStreamReader(stream);
44          char[] buf = new char[1024];
45          int read;
46          try {
47              while ((read = reader.read(buf)) != -1) {
48                  sb.append(buf, 0, read);
49              }
50          } finally {
51              reader.close();
52          }
53          return sb.toString();
54      }
55  
56      
57  
58  
59  
60  
61      public static Object retrieveProperty(String name, RouteContext context) {
62          return retrieveProperty(new Property(name), context);
63      }
64  
65      
66  
67  
68  
69  
70  
71      public static Object retrieveProperty(String name, PropertyScheme defaultScheme, RouteContext context) {
72          return retrieveProperty(new Property(name), defaultScheme, context);
73      }
74  
75      
76  
77  
78  
79  
80  
81      public static Object retrieveProperty(Property prop, PropertyScheme defaultScheme, RouteContext context) {
82          if (prop.scheme == null && defaultScheme != null) {
83              prop.scheme = defaultScheme.getName();
84          }
85          return retrieveProperty(prop, context);
86      }
87  
88      
89  
90  
91  
92  
93      public static Object retrieveProperty(Property prop, RouteContext context) {
94          Iterator schemes = PropertyScheme.SCHEMES.iterator();
95          while (schemes.hasNext()) {
96              PropertyScheme scheme = (PropertyScheme) schemes.next();
97              if (scheme.getName().equals(prop.scheme) ||
98                  scheme.getShortName().equals(prop.scheme)) {
99                  LOG.debug("Loading prop " + prop + " with scheme " + scheme);
100                 return scheme.load(prop, context);
101             }
102         }
103         String message = "Invalid property scheme: '" + prop.scheme + "'"; 
104         LOG.error(message);
105         throw new RuntimeException(message);
106     }
107 }