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.Set;
26
27 import javax.servlet.jsp.JspFactory;
28
29 import org.eclipse.jetty.deploy.DeploymentManager;
30 import org.eclipse.jetty.osgi.boot.JettyBootstrapActivator;
31 import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelper;
32 import org.eclipse.jetty.osgi.boot.utils.TldBundleDiscoverer;
33 import org.eclipse.jetty.util.log.Log;
34 import org.eclipse.jetty.util.log.Logger;
35 import org.osgi.framework.Bundle;
36 import org.osgi.framework.FrameworkUtil;
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public class JSTLBundleDiscoverer implements TldBundleDiscoverer
51 {
52 private static final Logger LOG = Log.getLogger(JSTLBundleDiscoverer.class);
53
54
55
56
57
58
59
60 private static String DEFAULT_JSTL_BUNDLE_CLASS = "org.apache.taglibs.standard.tag.el.core.WhenTag";
61
62
63
64
65
66
67
68
69 private static String DEFAULT_JSP_FACTORY_IMPL_CLASS = "org.apache.jasper.runtime.JspFactoryImpl";
70
71 private static final Set<URL> __tldBundleCache = new HashSet<URL>();
72
73 public JSTLBundleDiscoverer()
74 {
75 try
76 {
77
78 Class cl = getClass().getClassLoader().loadClass("org.apache.jasper.servlet.JspServlet");
79 }
80 catch (Exception e)
81 {
82 LOG.warn("Unable to locate the JspServlet: jsp support unavailable.", e);
83 return;
84 }
85 try
86 {
87 Class<javax.servlet.ServletContext> servletContextClass = javax.servlet.ServletContext.class;
88
89 JspFactory fact = JspFactory.getDefaultFactory();
90 if (fact == null)
91 {
92
93
94
95
96 fact = (JspFactory) JettyBootstrapActivator.class.getClassLoader().loadClass(DEFAULT_JSP_FACTORY_IMPL_CLASS).newInstance();
97 JspFactory.setDefaultFactory(fact);
98 }
99
100 }
101 catch (Exception e)
102 {
103 LOG.warn("Unable to set the JspFactory: jsp support incomplete.", e);
104 }
105 }
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125 public URL[] getUrlsForBundlesWithTlds(DeploymentManager deployer, BundleFileLocatorHelper locatorHelper) throws Exception
126 {
127
128 ArrayList<URL> urls = new ArrayList<URL>();
129 Class<?> jstlClass = null;
130
131
132
133
134
135 try
136 {
137 jstlClass = JSTLBundleDiscoverer.class.getClassLoader().loadClass(DEFAULT_JSTL_BUNDLE_CLASS);
138 }
139 catch (ClassNotFoundException e)
140 {
141 LOG.info("jstl not on classpath", e);
142 }
143
144 if (jstlClass != null)
145 {
146
147 Bundle tldBundle = FrameworkUtil.getBundle(jstlClass);
148 File tldBundleLocation = locatorHelper.getBundleInstallLocation(tldBundle);
149
150 if (tldBundleLocation != null && tldBundleLocation.isDirectory())
151 {
152
153 for (File f : tldBundleLocation.listFiles())
154 {
155 if (f.getName().endsWith(".jar") && f.isFile())
156 {
157 urls.add(f.toURI().toURL());
158 }
159 else if (f.isDirectory() && f.getName().equals("lib"))
160 {
161 for (File f2 : tldBundleLocation.listFiles())
162 {
163 if (f2.getName().endsWith(".jar") && f2.isFile())
164 {
165 urls.add(f2.toURI().toURL());
166 }
167 }
168 }
169 }
170
171 }
172 else if (tldBundleLocation != null)
173 {
174 urls.add(tldBundleLocation.toURI().toURL());
175
176 String pattern = (String)deployer.getContextAttribute("org.eclipse.jetty.server.webapp.containerIncludeBundlePattern");
177 pattern = (pattern==null?"":pattern);
178 if (!pattern.contains(tldBundle.getSymbolicName()))
179 {
180 pattern += "|"+tldBundle.getSymbolicName();
181 deployer.setContextAttribute("org.eclipse.jetty.server.webapp.containerIncludeBundlePattern", pattern);
182 }
183 }
184 }
185
186 return urls.toArray(new URL[urls.size()]);
187 }
188
189 }