use of com.sun.faces.config.WebConfiguration in project mojarra by eclipse-ee4j.
the class AbstractConfigProcessor method getProjectStage.
private ProjectStage getProjectStage(ServletContext sc, FacesContext facesContext) {
final String projectStageKey = AbstractConfigProcessor.class.getName() + ".PROJECTSTAGE";
ProjectStage projectStage = (ProjectStage) sc.getAttribute(projectStageKey);
if (projectStage == null) {
WebConfiguration webConfig = WebConfiguration.getInstance(facesContext.getExternalContext());
String value = webConfig.getEnvironmentEntry(WebConfiguration.WebEnvironmentEntry.ProjectStage);
if (value != null) {
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, "ProjectStage configured via JNDI: {0}", value);
}
} else {
value = webConfig.getOptionValue(JakartaFacesProjectStage);
if (value != null) {
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, "ProjectStage configured via servlet context init parameter: {0}", value);
}
}
}
if (value != null) {
try {
projectStage = ProjectStage.valueOf(value);
} catch (IllegalArgumentException iae) {
if (LOGGER.isLoggable(INFO)) {
LOGGER.log(INFO, "Unable to discern ProjectStage for value {0}.", value);
}
}
}
if (projectStage == null) {
projectStage = Production;
}
sc.setAttribute(projectStageKey, projectStage);
}
return projectStage;
}
use of com.sun.faces.config.WebConfiguration in project mojarra by eclipse-ee4j.
the class FilterClassesFromFacesInitializerAnnotationProvider method createAnnotatedMap.
// ---------------------------------------------------------- Private Methods
/**
* Go over the annotated set and converter it to a hash map.
*
* @param annotatedMap
* @param annotatedSet
*/
private Map<Class<? extends Annotation>, Set<Class<?>>> createAnnotatedMap(Set<Class<?>> annotatedSet) {
HashMap<Class<? extends Annotation>, Set<Class<?>>> annotatedMap = new HashMap<>();
if (isEmpty(annotatedSet)) {
return annotatedMap;
}
WebConfiguration webConfig = WebConfiguration.getInstance();
boolean annotationScanPackagesSet = webConfig.isSet(AnnotationScanPackages);
String[] annotationScanPackages = annotationScanPackagesSet ? webConfig.getOptionValue(AnnotationScanPackages).split("\\s+") : null;
Iterator<Class<?>> iterator = annotatedSet.iterator();
while (iterator.hasNext()) {
try {
Class<?> clazz = iterator.next();
stream(clazz.getAnnotations()).map(annotation -> annotation.annotationType()).filter(annotationType -> FACES_ANNOTATION_TYPE.contains(annotationType)).forEach(annotationType -> {
Set<Class<?>> classes = annotatedMap.computeIfAbsent(annotationType, e -> new HashSet<>());
if (annotationScanPackagesSet) {
if (matchesAnnotationScanPackages(clazz, annotationScanPackages)) {
classes.add(clazz);
}
} else {
classes.add(clazz);
}
});
} catch (NoClassDefFoundError ncdfe) {
}
}
return annotatedMap;
}
use of com.sun.faces.config.WebConfiguration in project mojarra by eclipse-ee4j.
the class BaseWebConfigResourceProvider method getResources.
// ------------------------------ Methods from ConfigurationResourceProvider
@Override
public Collection<URI> getResources(ServletContext context) {
WebConfiguration webConfig = WebConfiguration.getInstance(context);
String paths = webConfig.getOptionValue(getParameter());
Set<URI> urls = new LinkedHashSet<>(6);
if (paths != null) {
for (String token : split(context, paths.trim(), getSeparatorRegex())) {
String path = token.trim();
if (!isExcluded(path) && path.length() != 0) {
URI u = getContextURLForPath(context, path);
if (u != null) {
urls.add(u);
} else {
if (LOGGER.isLoggable(WARNING)) {
LOGGER.log(WARNING, "faces.config.web_resource_not_found", new Object[] { path, JakartaFacesConfigFiles.getQualifiedName() });
}
}
}
}
}
return urls;
}
use of com.sun.faces.config.WebConfiguration in project mojarra by eclipse-ee4j.
the class MetaInfFacesConfigResourceProvider method getResources.
// ------------------------------ Methods From ConfigurationResourceProvider
/**
* @see com.sun.faces.spi.ConfigurationResourceProvider#getResources(jakarta.servlet.ServletContext)
*/
@Override
public Collection<URI> getResources(ServletContext context) {
WebConfiguration webConfig = WebConfiguration.getInstance(context);
String duplicateJarPattern = webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.DuplicateJARPattern);
Pattern duplicatePattern = null;
if (duplicateJarPattern != null) {
duplicatePattern = Pattern.compile(duplicateJarPattern);
}
SortedMap<String, Set<URI>> sortedJarMap = new TreeMap<>();
// noinspection CollectionWithoutInitialCapacity
List<URI> unsortedResourceList = new ArrayList<>();
try {
for (URI uri : loadURLs(context)) {
String jarUrl = uri.toString();
String jarName = null;
Matcher m = JAR_PATTERN.matcher(jarUrl);
if (m.matches()) {
jarName = m.group(1);
}
if (jarName != null) {
if (duplicatePattern != null) {
m = duplicatePattern.matcher(jarName);
if (m.matches()) {
jarName = m.group(1);
}
}
Set<URI> uris = sortedJarMap.get(jarName);
if (uris == null) {
uris = new HashSet<>();
sortedJarMap.put(jarName, uris);
}
uris.add(uri);
} else {
unsortedResourceList.add(0, uri);
}
}
} catch (IOException e) {
throw new FacesException(e);
}
// Load the sorted resources first:
List<URI> result = new ArrayList<>(sortedJarMap.size() + unsortedResourceList.size());
for (Map.Entry<String, Set<URI>> entry : sortedJarMap.entrySet()) {
result.addAll(entry.getValue());
}
// Then load the unsorted resources
result.addAll(unsortedResourceList);
return result;
}
use of com.sun.faces.config.WebConfiguration in project mojarra by eclipse-ee4j.
the class ScriptStyleBaseRenderer method encodeEnd.
@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
Map<String, Object> attributes = component.getAttributes();
String name = (String) attributes.get("name");
if (null == name) {
return;
}
// Special case of resource names that have query strings.
// These resources actually use their query strings internally, not externally, so we don't need the resource to know
// about them.
int queryPos = name.indexOf("?");
String query = null;
if (queryPos > -1 && name.length() > queryPos) {
query = name.substring(queryPos + 1);
name = name.substring(0, queryPos);
}
String library = (String) attributes.get("library");
// Ensure this resource is not rendered more than once per request.
ResourceHandler resourceHandler = context.getApplication().getResourceHandler();
if (resourceHandler.isResourceRendered(context, name, library)) {
return;
}
Resource resource = resourceHandler.createResource(name, library);
String resourceUrl = "RES_NOT_FOUND";
ResponseWriter writer = context.getResponseWriter();
startExternalElement(context, writer, component);
WebConfiguration webConfig = WebConfiguration.getInstance();
if (library == null && name != null && name.startsWith(webConfig.getOptionValue(WebConfiguration.WebContextInitParameter.WebAppContractsDirectory))) {
if (context.isProjectStage(ProjectStage.Development)) {
String msg = "Illegal path, direct contract references are not allowed: " + name;
context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
}
resource = null;
}
if (resource == null) {
if (context.isProjectStage(ProjectStage.Development)) {
String msg = "Unable to find resource " + (library == null ? "" : library + ", ") + name;
context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
}
} else {
resourceUrl = resource.getRequestPath();
if (query != null) {
resourceUrl = resourceUrl + (resourceUrl.indexOf("?") > -1 ? "&" : "?") + query;
}
resourceUrl = context.getExternalContext().encodeResourceURL(resourceUrl);
}
endExternalElement(writer, component, resourceUrl);
resourceHandler.markResourceRendered(context, name, library);
// Remove the key to prevent issues with state saving.
String ccID = (String) component.getAttributes().get(COMP_KEY);
if (ccID != null) {
// the first pop maps to the component we're rendering.
// the second pop maps to the composite component that was pushed
// in this renderer's encodeBegin implementation.
// re-push the current component to reset the original context
component.popComponentFromEL(context);
component.popComponentFromEL(context);
component.pushComponentToEL(context, component);
}
}
Aggregations