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 public class Util
33 {
34 public static final String DEFAULT_DELIMS = ",;";
35
36
37
38
39
40
41
42
43
44
45 public static String getManifestHeaderValue (String name, String altName, Dictionary manifest)
46 {
47 if (manifest == null)
48 return null;
49 if (name == null && altName == null)
50 return null;
51 if (name != null)
52 return (String)manifest.get(name);
53 return (String)manifest.get(altName);
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67
68 public static List<URL> fileNamesAsURLs(String val, String delims)
69 throws Exception
70 {
71 String separators = DEFAULT_DELIMS;
72 if (delims == null)
73 delims = separators;
74
75 StringTokenizer tokenizer = new StringTokenizer(val, delims, false);
76 List<URL> urls = new ArrayList<URL>();
77 while (tokenizer.hasMoreTokens())
78 {
79 urls.add(BundleFileLocatorHelperFactory.getFactory().getHelper().getLocalURL(new URL(tokenizer.nextToken())));
80 }
81 return urls;
82 }
83
84
85
86 public static void setProperty(Dictionary<String,String> properties, String key, String value)
87 {
88 if (value != null)
89 {
90 properties.put(key, value);
91 }
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105 public static String resolvePropertyValue(String value)
106 {
107 int ind = value.indexOf("${");
108 if (ind == -1) { return value; }
109 int ind2 = value.indexOf('}', ind);
110 if (ind2 == -1) { return value; }
111 String sysprop = value.substring(ind + 2, ind2);
112 String defaultValue = null;
113 int comma = sysprop.indexOf(',');
114 if (comma != -1 && comma + 1 != sysprop.length())
115 {
116 defaultValue = sysprop.substring(comma + 1);
117 defaultValue = resolvePropertyValue(defaultValue);
118 sysprop = sysprop.substring(0, comma);
119 }
120 else
121 {
122 defaultValue = "${" + sysprop + "}";
123 }
124
125 String v = System.getProperty(sysprop);
126
127 String reminder = value.length() > ind2 + 1 ? value.substring(ind2 + 1) : "";
128 reminder = resolvePropertyValue(reminder);
129 if (v != null)
130 {
131 return value.substring(0, ind) + v + reminder;
132 }
133 else
134 {
135 return value.substring(0, ind) + defaultValue + reminder;
136 }
137 }
138 }