1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.application;
20
21 import java.io.IOException;
22 import java.util.HashMap;
23 import java.util.Map;
24 import java.util.stream.Stream;
25
26 import javax.faces.context.FacesContext;
27
28 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
29
30
31
32
33 public abstract class ResourceHandler
34 {
35 public static final String LOCALE_PREFIX = "javax.faces.resource.localePrefix";
36 public static final String RESOURCE_EXCLUDES_DEFAULT_VALUE = ".class .jsp .jspx .properties .xhtml .groovy";
37
38
39
40
41 @JSFWebConfigParam(defaultValue=".class .jsp .jspx .properties .xhtml .groovy",since="2.0", group="resources")
42 public static final String RESOURCE_EXCLUDES_PARAM_NAME = "javax.faces.RESOURCE_EXCLUDES";
43 public static final String RESOURCE_IDENTIFIER = "/javax.faces.resource";
44
45
46
47
48 public static final String RESOURCE_CONTRACT_XML = "javax.faces.contract.xml";
49
50
51
52
53 public static final String WEBAPP_CONTRACTS_DIRECTORY_PARAM_NAME = "javax.faces.WEBAPP_CONTRACTS_DIRECTORY";
54
55
56
57
58 public static final String WEBAPP_RESOURCES_DIRECTORY_PARAM_NAME = "javax.faces.WEBAPP_RESOURCES_DIRECTORY";
59
60
61
62
63 public static final String JSF_SCRIPT_RESOURCE_NAME = "jsf.js";
64
65
66
67
68 public static final String JSF_SCRIPT_LIBRARY_NAME = "javax.faces";
69
70 private final static String MYFACES_JS_RESOURCE_NAME = "oamSubmit.js";
71 private final static String MYFACES_JS_RESOURCE_NAME_UNCOMPRESSED = "oamSubmit-uncompressed.js";
72 private final static String RENDERED_RESOURCES_SET = "org.apache.myfaces.RENDERED_RESOURCES_SET";
73 private final static String MYFACES_LIBRARY_NAME = "org.apache.myfaces";
74 private final static String RENDERED_MYFACES_JS = "org.apache.myfaces.RENDERED_MYFACES_JS";
75
76 public abstract Resource createResource(String resourceName);
77
78 public abstract Resource createResource(String resourceName, String libraryName);
79
80 public abstract Resource createResource(String resourceName, String libraryName, String contentType);
81
82 public abstract String getRendererTypeForResourceName(String resourceName);
83
84 public abstract void handleResourceRequest(FacesContext context) throws IOException;
85
86 public abstract boolean isResourceRequest(FacesContext context);
87
88 public abstract boolean libraryExists(String libraryName);
89
90
91
92
93
94
95 public Resource createResourceFromId(String resourceId)
96 {
97 return null;
98 }
99
100
101
102
103
104
105
106
107 public ViewResource createViewResource(FacesContext context,
108 String resourceName)
109 {
110 return context.getApplication().getResourceHandler().createResource(resourceName);
111 }
112
113 public boolean isResourceURL(java.lang.String url)
114 {
115 if (url == null)
116 {
117 throw new NullPointerException();
118 }
119 return url.contains(RESOURCE_IDENTIFIER);
120 }
121
122
123
124
125
126
127
128
129 public Stream<java.lang.String> getViewResources(
130 FacesContext facesContext, String path, ResourceVisitOption... options)
131 {
132 return getViewResources(facesContext, path, Integer.MAX_VALUE, options);
133 }
134
135
136
137
138
139
140
141
142
143 public Stream<java.lang.String> getViewResources(FacesContext facesContext,
144 String path, int maxDepth, ResourceVisitOption... options)
145 {
146 return null;
147 }
148
149
150
151
152
153
154
155
156 public boolean isResourceRendered(FacesContext facesContext, String resourceName, String libraryName)
157 {
158 return getRenderedResources(facesContext).containsKey(
159 libraryName != null ? libraryName+'/'+resourceName : resourceName);
160 }
161
162
163
164
165
166
167
168 public void markResourceRendered(FacesContext facesContext, String resourceName, String libraryName)
169 {
170 getRenderedResources(facesContext).put(
171 libraryName != null ? libraryName+'/'+resourceName : resourceName, Boolean.TRUE);
172 if (ResourceHandler.JSF_SCRIPT_LIBRARY_NAME.equals(libraryName) &&
173 ResourceHandler.JSF_SCRIPT_RESOURCE_NAME.equals(resourceName))
174 {
175
176
177 getRenderedResources(facesContext).put(
178 MYFACES_LIBRARY_NAME+'/'+MYFACES_JS_RESOURCE_NAME, Boolean.TRUE);
179 }
180 }
181
182
183
184
185
186
187
188
189 @SuppressWarnings("unchecked")
190 private static Map<String, Boolean> getRenderedResources(FacesContext facesContext)
191 {
192 Map<String, Boolean> map = (Map<String, Boolean>) facesContext.getViewRoot().getTransientStateHelper()
193 .getTransient(RENDERED_RESOURCES_SET);
194 if (map == null)
195 {
196 map = new HashMap<String, Boolean>();
197 facesContext.getViewRoot().getTransientStateHelper().putTransient(RENDERED_RESOURCES_SET,map);
198 }
199 return map;
200 }
201
202 }