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