2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.remoting.impl;
19
20 import java.net.URL;
21 import java.util.ResourceBundle;
22 import javax.faces.context.FacesContext;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.shale.remoting.Constants;
26 import org.apache.shale.remoting.Processor;
27
28 /***
29 * <p>Implementation of {@link Processor} which serves resources from the
30 * class path of the web application. View identifiers shoud be a fully
31 * qualified path, beginning with a slash ("/") character (for example,
32 * <code>/org/apache/shale/remoting/MyResource.css</code>).</p>
33 */
34 public class ClassResourceProcessor extends AbstractResourceProcessor {
35
36
37
38
39
40
41
42
43
44 /***
45 * <p><code>ResourceBundle</code> containing our localized messages.</p>
46 */
47 private ResourceBundle bundle = ResourceBundle.getBundle("org.apache.shale.remoting.Bundle");
48
49
50 /***
51 * <p>Log instance for this class.</p>
52 */
53 private transient Log log = null;
54
55
56
57
58
59 /***
60 * <p>Force our default excludes list to be included.</p>
61 *
62 * @param excludes Application specified excludes list
63 */
64 public void setExcludes(String excludes) {
65
66 if ((excludes != null) && (excludes.length() > 0)) {
67 super.setExcludes(Constants.CLASS_RESOURCES_EXCLUDES_DEFAULT
68 + "," + excludes);
69 } else {
70 super.setExcludes(Constants.CLASS_RESOURCES_EXCLUDES_DEFAULT);
71 }
72
73 }
74
75
76
77
78
79 /*** {@inheritDoc} */
80 protected URL getResourceURL(FacesContext context, String resourceId) {
81
82
83 String resourceIdLower = resourceId.toLowerCase();
84 if (resourceIdLower.endsWith(".class")) {
85 if (log().isWarnEnabled()) {
86 log().warn(bundle.getString("resource.refuse"));
87 log().warn(resourceId);
88 }
89 return null;
90 }
91
92
93 ClassLoader cl = Thread.currentThread().getContextClassLoader();
94
95
96 try {
97 URL url = cl.getResource(resourceId.substring(1));
98 if (log().isDebugEnabled()) {
99 log().debug("getResource(" + resourceId + ") --> " + url);
100 }
101 return url;
102 } catch (Exception e) {
103 if (log().isErrorEnabled()) {
104 log().error(bundle.getString("resource.exception"), e);
105 log().error(resourceId);
106 }
107 return null;
108 }
109
110 }
111
112
113
114
115
116
117
118 /***
119 * <p>Return the <code>Log</code> instance to use, creating one if needed.</p>
120 */
121 private Log log() {
122
123 if (this.log == null) {
124 log = LogFactory.getLog(ClassResourceProcessor.class);
125 }
126 return log;
127
128 }
129
130
131 }