/** * Sort the <code>faces-config</code> documents found on the classpath and those specified by the * <code>javax.faces.CONFIG_FILES</code> context init parameter. * * @param facesDocuments an array of <em>all</em> <code>faces-config</code> documents * @param webInfFacesConfig FacesConfigInfo representing the WEB-INF/faces-config.xml for this app * @return the sorted documents */ private DocumentInfo[] sortDocuments( DocumentInfo[] facesDocuments, FacesConfigInfo webInfFacesConfig) { int len = (webInfFacesConfig.isWebInfFacesConfig() ? facesDocuments.length - 1 : facesDocuments.length); List<String> absoluteOrdering = webInfFacesConfig.getAbsoluteOrdering(); if (len > 1) { List<DocumentOrderingWrapper> list = new ArrayList<DocumentOrderingWrapper>(); for (int i = 1; i < len; i++) { list.add(new DocumentOrderingWrapper(facesDocuments[i])); } DocumentOrderingWrapper[] ordering = list.toArray(new DocumentOrderingWrapper[list.size()]); if (absoluteOrdering == null) { DocumentOrderingWrapper.sort(ordering); // sorting complete, now update the appropriate locations within // the original array with the sorted documentation. for (int i = 1; i < len; i++) { facesDocuments[i] = ordering[i - 1].getDocument(); } return facesDocuments; } else { DocumentOrderingWrapper[] result = DocumentOrderingWrapper.sort(ordering, absoluteOrdering); DocumentInfo[] ret = new DocumentInfo [((webInfFacesConfig.isWebInfFacesConfig()) ? (result.length + 2) : (result.length + 1))]; for (int i = 1; i < len; i++) { ret[i] = result[i - 1].getDocument(); } // add the impl specific config file ret[0] = facesDocuments[0]; // add the WEB-INF if necessary if (webInfFacesConfig.isWebInfFacesConfig()) { ret[ret.length - 1] = facesDocuments[facesDocuments.length - 1]; } return ret; } } return facesDocuments; }
/** * Utility method to check if JSF 2.0 Facelets should be disabled. If it's not explicitly disabled * by the context init parameter, then check the version of the WEB-INF/faces-config.xml document. * If the version is less than 2.0, then override the default value for the context init parameter * so that other parts of the system that use that config option will know it has been disabled. * * <p>NOTE: Since this method overrides a configuration value, it should be called before *any* * document parsing is performed the configuration value may be queried by the <code>ConfigParser * </code>s. * * @param webconfig configuration for this application * @param facesConfigInfo object representing WEB-INF/faces-config.xml * @return <code>true</code> if Facelets should be disabled */ private boolean isFaceletsDisabled(WebConfiguration webconfig, FacesConfigInfo facesConfigInfo) { boolean isFaceletsDisabled = webconfig.isOptionEnabled(DisableFaceletJSFViewHandler); if (!isFaceletsDisabled) { // if not explicitly disabled, make a sanity check against // /WEB-INF/faces-config.xml isFaceletsDisabled = !facesConfigInfo.isVersionGreaterOrEqual(2.0); webconfig.overrideContextInitParameter(DisableFaceletJSFViewHandler, isFaceletsDisabled); } return isFaceletsDisabled; }
private void initializeIvars() { if (null != uris || null != jarNames) { assert (null != uris && null != jarNames); return; } uris = new HashSet<URI>(documentInfos.length); jarNames = new HashSet<String>(documentInfos.length); for (DocumentInfo docInfo : documentInfos) { URI sourceURI = docInfo.getSourceURI(); Matcher m = JAR_PATTERN.matcher(sourceURI.toString()); if (m.matches()) { String jarName = m.group(2); if (!jarNames.contains(jarName)) { FacesConfigInfo configInfo = new FacesConfigInfo(docInfo); if (!configInfo.isMetadataComplete()) { uris.add(sourceURI); jarNames.add(jarName); } } } } }
/** * This method bootstraps JSF based on the parsed configuration resources. * * @param sc the <code>ServletContext</code> for the application that requires initialization */ public void initialize(ServletContext sc) { if (!hasBeenInitialized(sc)) { initializedContexts.add(sc); ExecutorService executor = null; try { WebConfiguration webConfig = WebConfiguration.getInstance(sc); boolean validating = webConfig.isOptionEnabled(ValidateFacesConfigFiles); if (useThreads(sc)) { executor = createExecutorService(); } DocumentInfo[] facesDocuments = getConfigDocuments(sc, getFacesConfigResourceProviders(), executor, validating); FacesConfigInfo webInfFacesConfigInfo = new FacesConfigInfo(facesDocuments[facesDocuments.length - 1]); facesDocuments = sortDocuments(facesDocuments, webInfFacesConfigInfo); InitFacesContext context = (InitFacesContext) FacesContext.getCurrentInstance(); InjectionProvider containerConnector = InjectionProviderFactory.createInstance(context.getExternalContext()); context.getAttributes().put(INJECTION_PROVIDER_KEY, containerConnector); boolean isFaceletsDisabled = isFaceletsDisabled(webConfig, webInfFacesConfigInfo); if (!webInfFacesConfigInfo.isWebInfFacesConfig() || !webInfFacesConfigInfo.isMetadataComplete()) { // execute the Task responsible for finding annotation classes ProvideMetadataToAnnotationScanTask taskMetadata = new ProvideMetadataToAnnotationScanTask(facesDocuments, containerConnector); Future<Map<Class<? extends Annotation>, Set<Class<?>>>> annotationScan; if (executor != null) { annotationScan = executor.submit(new AnnotationScanTask(sc, context, taskMetadata)); pushTaskToContext(sc, annotationScan); } else { annotationScan = new FutureTask<Map<Class<? extends Annotation>, Set<Class<?>>>>( new AnnotationScanTask(sc, context, taskMetadata)); ((FutureTask) annotationScan).run(); } pushTaskToContext(sc, annotationScan); } // see if the app is running in a HA enabled env if (containerConnector instanceof HighAvailabilityEnabler) { ((HighAvailabilityEnabler) containerConnector).enableHighAvailability(sc); } // process the ordered documents FACES_CONFIG_PROCESSOR_CHAIN.process(sc, facesDocuments); if (!isFaceletsDisabled) { FACELET_TAGLIB_CONFIG_PROCESSOR_CHAIN.process( sc, getConfigDocuments(sc, getFaceletConfigResourceProviders(), executor, validating)); } publishPostConfigEvent(); } catch (Exception e) { // clear out any configured factories releaseFactories(); Throwable t = e; if (!(e instanceof ConfigurationException)) { t = new ConfigurationException("CONFIGURATION FAILED! " + t.getMessage(), t); } throw (ConfigurationException) t; } finally { if (executor != null) { executor.shutdown(); } sc.removeAttribute(ANNOTATIONS_SCAN_TASK_KEY); } } }