Lines 20-31
Link Here
|
20 |
|
20 |
|
21 |
|
21 |
|
22 |
import java.io.File; |
22 |
import java.io.File; |
23 |
import java.io.FileInputStream; |
|
|
24 |
import java.io.FileOutputStream; |
25 |
import java.io.IOException; |
23 |
import java.io.IOException; |
26 |
import java.io.InputStream; |
24 |
import java.io.InputStream; |
27 |
import java.io.ObjectInputStream; |
|
|
28 |
import java.io.ObjectOutputStream; |
29 |
import java.net.URISyntaxException; |
25 |
import java.net.URISyntaxException; |
30 |
import java.net.URL; |
26 |
import java.net.URL; |
31 |
import java.net.URLClassLoader; |
27 |
import java.net.URLClassLoader; |
Lines 47-53
Link Here
|
47 |
import javax.servlet.ServletException; |
43 |
import javax.servlet.ServletException; |
48 |
|
44 |
|
49 |
import org.apache.catalina.Context; |
45 |
import org.apache.catalina.Context; |
50 |
import org.apache.catalina.Globals; |
|
|
51 |
import org.apache.catalina.Lifecycle; |
46 |
import org.apache.catalina.Lifecycle; |
52 |
import org.apache.catalina.LifecycleEvent; |
47 |
import org.apache.catalina.LifecycleEvent; |
53 |
import org.apache.catalina.LifecycleListener; |
48 |
import org.apache.catalina.LifecycleListener; |
Lines 255-278
Link Here
|
255 |
public void execute() throws Exception { |
250 |
public void execute() throws Exception { |
256 |
long t1=System.currentTimeMillis(); |
251 |
long t1=System.currentTimeMillis(); |
257 |
|
252 |
|
258 |
File tldCache=null; |
|
|
259 |
|
260 |
if (context instanceof StandardContext) { |
261 |
File workDir= (File) |
262 |
((StandardContext)context).getServletContext().getAttribute(Globals.WORK_DIR_ATTR); |
263 |
//tldCache=new File( workDir, "tldCache.ser"); |
264 |
} |
265 |
|
266 |
// Option to not rescan |
267 |
if( ! rescan ) { |
268 |
// find the cache |
269 |
if( tldCache!= null && tldCache.exists()) { |
270 |
// just read it... |
271 |
processCache(tldCache); |
272 |
return; |
273 |
} |
274 |
} |
275 |
|
276 |
/* |
253 |
/* |
277 |
* Acquire the list of TLD resource paths, possibly embedded in JAR |
254 |
* Acquire the list of TLD resource paths, possibly embedded in JAR |
278 |
* files, to be processed |
255 |
* files, to be processed |
Lines 280-294
Link Here
|
280 |
Set resourcePaths = tldScanResourcePaths(); |
257 |
Set resourcePaths = tldScanResourcePaths(); |
281 |
Map jarPaths = getJarPaths(); |
258 |
Map jarPaths = getJarPaths(); |
282 |
|
259 |
|
283 |
// Check to see if we can use cached listeners |
|
|
284 |
if (tldCache != null && tldCache.exists()) { |
285 |
long lastModified = getLastModified(resourcePaths, jarPaths); |
286 |
if (lastModified < tldCache.lastModified()) { |
287 |
processCache(tldCache); |
288 |
return; |
289 |
} |
290 |
} |
291 |
|
292 |
// Scan each accumulated resource path for TLDs to be processed |
260 |
// Scan each accumulated resource path for TLDs to be processed |
293 |
Iterator paths = resourcePaths.iterator(); |
261 |
Iterator paths = resourcePaths.iterator(); |
294 |
while (paths.hasNext()) { |
262 |
while (paths.hasNext()) { |
Lines 308-325
Link Here
|
308 |
|
276 |
|
309 |
String list[] = getTldListeners(); |
277 |
String list[] = getTldListeners(); |
310 |
|
278 |
|
311 |
if( tldCache!= null ) { |
|
|
312 |
log.debug( "Saving tld cache: " + tldCache + " " + list.length); |
313 |
try { |
314 |
FileOutputStream out=new FileOutputStream(tldCache); |
315 |
ObjectOutputStream oos=new ObjectOutputStream( out ); |
316 |
oos.writeObject( list ); |
317 |
oos.close(); |
318 |
} catch( IOException ex ) { |
319 |
ex.printStackTrace(); |
320 |
} |
321 |
} |
322 |
|
323 |
if( log.isDebugEnabled() ) |
279 |
if( log.isDebugEnabled() ) |
324 |
log.debug( "Adding tld listeners:" + list.length); |
280 |
log.debug( "Adding tld listeners:" + list.length); |
325 |
for( int i=0; list!=null && i<list.length; i++ ) { |
281 |
for( int i=0; list!=null && i<list.length; i++ ) { |
Lines 335-401
Link Here
|
335 |
|
291 |
|
336 |
// -------------------------------------------------------- Private Methods |
292 |
// -------------------------------------------------------- Private Methods |
337 |
|
293 |
|
338 |
/* |
|
|
339 |
* Returns the last modification date of the given sets of resources. |
340 |
* |
341 |
* @param resourcePaths |
342 |
* @param jarPaths |
343 |
* |
344 |
* @return Last modification date |
345 |
*/ |
346 |
private long getLastModified(Set resourcePaths, Map jarPaths) |
347 |
throws Exception { |
348 |
|
349 |
long lastModified = 0; |
350 |
|
351 |
Iterator paths = resourcePaths.iterator(); |
352 |
while (paths.hasNext()) { |
353 |
String path = (String) paths.next(); |
354 |
URL url = context.getServletContext().getResource(path); |
355 |
if (url == null) { |
356 |
log.debug( "Null url "+ path ); |
357 |
break; |
358 |
} |
359 |
long lastM = url.openConnection().getLastModified(); |
360 |
if (lastM > lastModified) lastModified = lastM; |
361 |
if (log.isDebugEnabled()) { |
362 |
log.debug( "Last modified " + path + " " + lastM); |
363 |
} |
364 |
} |
365 |
|
366 |
if (jarPaths != null) { |
367 |
paths = jarPaths.values().iterator(); |
368 |
while (paths.hasNext()) { |
369 |
File jarFile = (File) paths.next(); |
370 |
long lastM = jarFile.lastModified(); |
371 |
if (lastM > lastModified) lastModified = lastM; |
372 |
if (log.isDebugEnabled()) { |
373 |
log.debug("Last modified " + jarFile.getAbsolutePath() |
374 |
+ " " + lastM); |
375 |
} |
376 |
} |
377 |
} |
378 |
|
379 |
return lastModified; |
380 |
} |
381 |
|
382 |
private void processCache(File tldCache ) throws IOException { |
383 |
// read the cache and return; |
384 |
try { |
385 |
FileInputStream in=new FileInputStream(tldCache); |
386 |
ObjectInputStream ois=new ObjectInputStream( in ); |
387 |
String list[]=(String [])ois.readObject(); |
388 |
if( log.isDebugEnabled() ) |
389 |
log.debug("Reusing tldCache " + tldCache + " " + list.length); |
390 |
for( int i=0; list!=null && i<list.length; i++ ) { |
391 |
context.addApplicationListener(list[i]); |
392 |
} |
393 |
ois.close(); |
394 |
} catch( ClassNotFoundException ex ) { |
395 |
ex.printStackTrace(); |
396 |
} |
397 |
} |
398 |
|
399 |
/** |
294 |
/** |
400 |
* Scan the JAR file at the specified resource path for TLDs in the |
295 |
* Scan the JAR file at the specified resource path for TLDs in the |
401 |
* <code>META-INF</code> subdirectory, and scan each TLD for application |
296 |
* <code>META-INF</code> subdirectory, and scan each TLD for application |