1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.osgi.boot.jasper;
20
21 import java.io.File;
22 import java.net.URL;
23 import java.util.ArrayList;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Set;
27 import java.util.StringTokenizer;
28 import java.util.regex.Pattern;
29
30 import org.eclipse.jetty.deploy.DeploymentManager;
31 import org.eclipse.jetty.osgi.boot.OSGiWebInfConfiguration;
32 import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper;
33 import org.eclipse.jetty.osgi.boot.utils.TldBundleDiscoverer;
34 import org.osgi.framework.Bundle;
35 import org.osgi.framework.FrameworkUtil;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 public class ContainerTldBundleDiscoverer implements TldBundleDiscoverer
57 {
58
59
60
61
62
63
64 public static final String SYS_PROP_TLD_BUNDLES = "org.eclipse.jetty.osgi.tldbundles";
65
66
67
68
69
70
71
72
73
74 public URL[] getUrlsForBundlesWithTlds(DeploymentManager deploymentManager, BundleFileLocatorHelper locatorHelper) throws Exception
75 {
76
77
78
79
80
81
82
83
84
85 Bundle[] bundles = FrameworkUtil.getBundle(ContainerTldBundleDiscoverer.class).getBundleContext().getBundles();
86 HashSet<URL> urls = new HashSet<URL>();
87 String tmp = System.getProperty(SYS_PROP_TLD_BUNDLES);
88 List<String> sysNames = new ArrayList<String>();
89 if (tmp != null)
90 {
91 StringTokenizer tokenizer = new StringTokenizer(tmp, ", \n\r\t", false);
92 while (tokenizer.hasMoreTokens())
93 sysNames.add(tokenizer.nextToken());
94 }
95 tmp = (String) deploymentManager.getContextAttribute(OSGiWebInfConfiguration.CONTAINER_BUNDLE_PATTERN);
96 Pattern pattern = (tmp==null? null : Pattern.compile(tmp));
97 for (Bundle bundle : bundles)
98 {
99 if (sysNames.contains(bundle.getSymbolicName()))
100 convertBundleLocationToURL(locatorHelper, bundle, urls);
101
102 if (pattern != null && pattern.matcher(bundle.getSymbolicName()).matches())
103 convertBundleLocationToURL(locatorHelper, bundle, urls);
104 }
105
106 return urls.toArray(new URL[urls.size()]);
107
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 private void convertBundleLocationToURL(BundleFileLocatorHelper locatorHelper, Bundle bundle, Set<URL> urls) throws Exception
125 {
126 File jasperLocation = locatorHelper.getBundleInstallLocation(bundle);
127 if (jasperLocation.isDirectory())
128 {
129 for (File f : jasperLocation.listFiles())
130 {
131 if (f.getName().endsWith(".jar") && f.isFile())
132 {
133 urls.add(f.toURI().toURL());
134 }
135 else if (f.isDirectory() && f.getName().equals("lib"))
136 {
137 for (File f2 : jasperLocation.listFiles())
138 {
139 if (f2.getName().endsWith(".jar") && f2.isFile())
140 {
141 urls.add(f2.toURI().toURL());
142 }
143 }
144 }
145 }
146 urls.add(jasperLocation.toURI().toURL());
147 }
148 else
149 {
150 urls.add(jasperLocation.toURI().toURL());
151 }
152 }
153 }