| 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 class PropertiesUtil { |
| 36 | 0 | private static final Logger LOG = Logger.getLogger(PropertiesUtil.class); |
| 37 | |
|
| 38 | 0 | private PropertiesUtil() {} |
| 39 | |
|
| 40 | |
public static String readResource(InputStream stream) throws IOException { |
| 41 | 0 | StringBuffer sb = new StringBuffer(2048); |
| 42 | 0 | InputStreamReader reader = new InputStreamReader(stream); |
| 43 | 0 | char[] buf = new char[1024]; |
| 44 | |
int read; |
| 45 | |
try { |
| 46 | 0 | while ((read = reader.read(buf)) != -1) { |
| 47 | 0 | sb.append(buf, 0, read); |
| 48 | |
} |
| 49 | 0 | } finally { |
| 50 | 0 | reader.close(); |
| 51 | 0 | } |
| 52 | 0 | return sb.toString(); |
| 53 | |
} |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
public static Object retrieveProperty(String name, RouteContext context) { |
| 61 | 0 | return retrieveProperty(new Property(name), context); |
| 62 | |
} |
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
public static Object retrieveProperty(String name, PropertyScheme defaultScheme, RouteContext context) { |
| 71 | 0 | return retrieveProperty(new Property(name), defaultScheme, context); |
| 72 | |
} |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
public static Object retrieveProperty(Property prop, PropertyScheme defaultScheme, RouteContext context) { |
| 81 | 0 | if (prop.scheme == null && defaultScheme != null) { |
| 82 | 0 | prop.scheme = defaultScheme.getName(); |
| 83 | |
} |
| 84 | 0 | return retrieveProperty(prop, context); |
| 85 | |
} |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
public static Object retrieveProperty(Property prop, RouteContext context) { |
| 93 | 0 | Iterator schemes = PropertyScheme.SCHEMES.iterator(); |
| 94 | 0 | while (schemes.hasNext()) { |
| 95 | 0 | PropertyScheme scheme = (PropertyScheme) schemes.next(); |
| 96 | 0 | if (scheme.getName().equals(prop.scheme) || |
| 97 | |
scheme.getShortName().equals(prop.scheme)) { |
| 98 | 0 | LOG.debug("Loading prop " + prop + " with scheme " + scheme); |
| 99 | 0 | return scheme.load(prop, context); |
| 100 | |
} |
| 101 | 0 | } |
| 102 | 0 | String message = "Invalid property scheme: '" + prop.scheme + "'"; |
| 103 | 0 | LOG.error(message); |
| 104 | 0 | throw new RuntimeException(message); |
| 105 | |
} |
| 106 | |
} |