1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.decoration.validators;
18
19 import java.net.MalformedURLException;
20
21 import javax.servlet.ServletContext;
22
23 import org.apache.jetspeed.decoration.ResourceValidator;
24 import org.springframework.web.context.ServletContextAware;
25
26 /***
27 * This implementation uses <code>ServletContext.getResource()</code>
28 * to verify the existence of a resource.
29 *
30 * @author <href a="mailto:weaver@apache.org">Scott T. Weaver</a>
31 *
32 */
33 public class WebApplicationResourceValidator implements ResourceValidator, ServletContextAware
34 {
35 private ServletContext servletContext;
36
37
38 public boolean resourceExists(String path)
39 {
40 try
41 {
42 return servletContext.getResource(path) != null;
43 }
44 catch (MalformedURLException e)
45 {
46 IllegalArgumentException iae = new IllegalArgumentException(path+" is not a valid path.");
47 iae.initCause(e);
48 throw iae;
49 }
50 }
51
52
53 public void setServletContext(ServletContext servletContext)
54 {
55 this.servletContext = servletContext;
56
57 }
58
59 }