1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.eclipse.jetty.osgi.boot.utils;
21
22 import java.net.MalformedURLException;
23 import java.net.URL;
24 import java.util.ArrayList;
25 import java.util.Dictionary;
26 import java.util.List;
27 import java.util.StringTokenizer;
28
29
30
31
32
33
34 public class Util
35 {
36 public static final String DEFAULT_DELIMS = ",;";
37
38
39
40
41
42
43
44
45
46
47
48 public static List<URL> fileNamesAsURLs(String val, String delims)
49 throws Exception
50 {
51 String separators = DEFAULT_DELIMS;
52 if (delims == null)
53 delims = separators;
54
55 StringTokenizer tokenizer = new StringTokenizer(val, delims, false);
56 List<URL> urls = new ArrayList<URL>();
57 while (tokenizer.hasMoreTokens())
58 {
59 urls.add(BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(new URL(tokenizer.nextToken())));
60 }
61 return urls;
62 }
63
64
65
66 public static void setProperty(Dictionary<String,String> properties, String key, String value)
67 {
68 if (value != null)
69 {
70 properties.put(key, value);
71 }
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85 public static String resolvePropertyValue(String value)
86 {
87 int ind = value.indexOf("${");
88 if (ind == -1) { return value; }
89 int ind2 = value.indexOf('}', ind);
90 if (ind2 == -1) { return value; }
91 String sysprop = value.substring(ind + 2, ind2);
92 String defaultValue = null;
93 int comma = sysprop.indexOf(',');
94 if (comma != -1 && comma + 1 != sysprop.length())
95 {
96 defaultValue = sysprop.substring(comma + 1);
97 defaultValue = resolvePropertyValue(defaultValue);
98 sysprop = sysprop.substring(0, comma);
99 }
100 else
101 {
102 defaultValue = "${" + sysprop + "}";
103 }
104
105 String v = System.getProperty(sysprop);
106
107 String reminder = value.length() > ind2 + 1 ? value.substring(ind2 + 1) : "";
108 reminder = resolvePropertyValue(reminder);
109 if (v != null)
110 {
111 return value.substring(0, ind) + v + reminder;
112 }
113 else
114 {
115 return value.substring(0, ind) + defaultValue + reminder;
116 }
117 }
118 }