Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2015 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.sun.faces.config;
import com.sun.faces.RIConstants;
import static com.sun.faces.RIConstants.ANNOTATED_CLASSES;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.ValidateFacesConfigFiles;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.DisableFaceletJSFViewHandler;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.DisableFaceletJSFViewHandlerDeprecated;
import static com.sun.faces.config.WebConfiguration.BooleanWebContextInitParameter.EnableThreading;
import com.sun.faces.spi.ConfigurationResourceProvider;
import com.sun.faces.spi.ConfigurationResourceProviderFactory;
import com.sun.faces.spi.AnnotationProvider;
import com.sun.faces.spi.AnnotationProviderFactory;
import com.sun.faces.spi.HighAvailabilityEnabler;
import static com.sun.faces.spi.ConfigurationResourceProviderFactory.ProviderType.*;
import com.sun.faces.config.configprovider.MetaInfFacesConfigResourceProvider;
import com.sun.faces.config.configprovider.MojarraFacesConfigResourceProvider;
import com.sun.faces.config.configprovider.WebFacesConfigResourceProvider;
import com.sun.faces.config.configprovider.MetaInfFaceletTaglibraryConfigProvider;
import com.sun.faces.config.configprovider.WebAppFlowConfigResourceProvider;
import com.sun.faces.config.configprovider.WebFaceletTaglibResourceProvider;
import com.sun.faces.config.processor.ApplicationConfigProcessor;
import com.sun.faces.config.processor.BehaviorConfigProcessor;
import com.sun.faces.config.processor.ComponentConfigProcessor;
import com.sun.faces.config.processor.ConfigProcessor;
import com.sun.faces.config.processor.ConverterConfigProcessor;
import com.sun.faces.config.processor.FactoryConfigProcessor;
import com.sun.faces.config.processor.LifecycleConfigProcessor;
import com.sun.faces.config.processor.ManagedBeanConfigProcessor;
import com.sun.faces.config.processor.NavigationConfigProcessor;
import com.sun.faces.config.processor.RenderKitConfigProcessor;
import com.sun.faces.config.processor.ValidatorConfigProcessor;
import com.sun.faces.config.processor.FaceletTaglibConfigProcessor;
import com.sun.faces.config.processor.FacesConfigExtensionProcessor;
import com.sun.faces.config.processor.FacesFlowDefinitionConfigProcessor;
import com.sun.faces.config.processor.ProtectedViewsConfigProcessor;
import com.sun.faces.config.processor.ResourceLibraryContractsConfigProcessor;
import com.sun.faces.el.ELContextImpl;
import com.sun.faces.el.ELUtils;
import com.sun.faces.spi.InjectionProvider;
import com.sun.faces.spi.InjectionProviderFactory;
import com.sun.faces.util.FacesLogger;
import com.sun.faces.util.Timer;
import com.sun.faces.util.Util;
import org.xml.sax.InputSource;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
import javax.faces.event.PostConstructApplicationEvent;
import javax.faces.application.Application;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.lang.annotation.Annotation;
import java.net.URI;
import java.util.Iterator;
import java.util.ServiceLoader;
import javax.el.ELContext;
import javax.el.ELContextEvent;
import javax.el.ELContextListener;
import javax.el.ExpressionFactory;
import javax.faces.application.ApplicationConfigurationPopulator;
import javax.faces.component.UIViewRoot;
import javax.xml.validation.Schema;
import org.w3c.dom.*;
import org.xml.sax.SAXParseException;
/**
*
* This class manages the initialization of each web application that uses
* JSF.
*
*/
public class ConfigManager {
private static final Logger LOGGER = FacesLogger.CONFIG.getLogger();
private static final Pattern JAR_PATTERN = Pattern.compile("(.*/(\\S*\\.jar)).*(/faces-config.xml|/*.\\.faces-config.xml)");
/**
*
* A List of resource providers that search for faces-config documents.
* By default, this contains a provider for the Mojarra, and two other
* providers to satisfy the requirements of the specification.
*
*/
private final List FACES_CONFIG_RESOURCE_PROVIDERS;
/**
*
* A List of resource providers that search for faces-config documents.
* By default, this contains a provider for the Mojarra, and one other
* providers to satisfy the requirements of the specification.
*
*/
private final List FACELET_TAGLIBRARY_RESOURCE_PROVIDERS;
/**
*
* The ConfigManager will multithread the calls to the
* ConfigurationResourceProviders as well as any calls
* to parse a resources into a DOM. By default, we'll use only 5 threads
* per web application.
*
*/
private static final int NUMBER_OF_TASK_THREADS = 5;
private static final String CONFIG_MANAGER_INSTANCE_KEY = RIConstants.FACES_PREFIX + "CONFIG_MANAGER_KEY";
/**
* The application-scoped key under which the Future responsible for annotation
* scanning is associated with.
*/
private static final String ANNOTATIONS_SCAN_TASK_KEY =
ConfigManager.class.getName() + "_ANNOTATION_SCAN_TASK";
/**
* The initialization time FacesContext scoped key under which the
* InjectionProvider is stored.
*/
public static final String INJECTION_PROVIDER_KEY =
ConfigManager.class.getName() + "_INJECTION_PROVIDER_TASK";
/**
* Name of the attribute added by ParseTask to indicate a
* {@link Document} instance as a representation of
* /WEB-INF/faces-config.xml.
*/
public static final String WEB_INF_MARKER = "com.sun.faces.webinf";
/**
*
* Contains each ServletContext that we've initialized.
* The ServletContext will be removed when the application
* is destroyed.
*
*/
@SuppressWarnings({"CollectionWithoutInitialCapacity"})
private List initializedContexts =
new CopyOnWriteArrayList<>();
/**
*
* The chain of {@link ConfigProcessor} instances to processing of
* faces-config documents.
*
*/
private final ConfigProcessor FACES_CONFIG_PROCESSOR_CHAIN;
/**
*
* The chain of {@link ConfigProcessor} instances to processing of
* facelet-taglib documents.
*
*/
private final ConfigProcessor FACELET_TAGLIB_CONFIG_PROCESSOR_CHAIN;
/**
* Stylesheet to convert 1.0 and 1.1 based faces-config documents
* to our private 1.1 schema for validation.
*/
private static final String FACES_TO_1_1_PRIVATE_XSL =
"/com/sun/faces/jsf1_0-1_1toSchema.xsl";
/**
* Stylesheet to convert 1.0 facelet-taglib documents
* from 1.0 to 2.0 for schema validation purposes.
*/
private static final String FACELETS_TO_2_0_XSL =
"/com/sun/faces/facelets1_0-2_0toSchema.xsl";
private static final String FACES_CONFIG_1_X_DEFAULT_NS =
"http://java.sun.com/JSF/Configuration";
private static final String FACELETS_1_0_DEFAULT_NS =
"http://java.sun.com/JSF/Facelet";
public ConfigManager() {
// initialize the resource providers for faces-config documents
List facesConfigProviders =
new ArrayList<>(3);
facesConfigProviders.add(new MojarraFacesConfigResourceProvider());
facesConfigProviders.add(new MetaInfFacesConfigResourceProvider());
facesConfigProviders.add(new WebAppFlowConfigResourceProvider());
facesConfigProviders.add(new WebFacesConfigResourceProvider());
FACES_CONFIG_RESOURCE_PROVIDERS = Collections.unmodifiableList(facesConfigProviders);
// initialize the resource providers for facelet-taglib documents
List faceletTaglibProviders =
new ArrayList<>(3);
faceletTaglibProviders.add(new MetaInfFaceletTaglibraryConfigProvider());
faceletTaglibProviders.add(new WebFaceletTaglibResourceProvider());
FACELET_TAGLIBRARY_RESOURCE_PROVIDERS = Collections.unmodifiableList(faceletTaglibProviders);
// initialize the config processors for faces-config documents
ConfigProcessor[] configProcessors = {
new FactoryConfigProcessor(),
new LifecycleConfigProcessor(),
new ApplicationConfigProcessor(),
new ComponentConfigProcessor(),
new ConverterConfigProcessor(),
new ValidatorConfigProcessor(),
new ManagedBeanConfigProcessor(),
new RenderKitConfigProcessor(),
new NavigationConfigProcessor(),
new BehaviorConfigProcessor(),
new FacesConfigExtensionProcessor(),
new ProtectedViewsConfigProcessor(),
new FacesFlowDefinitionConfigProcessor(),
new ResourceLibraryContractsConfigProcessor()
};
for (int i = 0; i < configProcessors.length; i++) {
ConfigProcessor p = configProcessors[i];
if ((i + 1) < configProcessors.length) {
p.setNext(configProcessors[i + 1]);
}
}
FACES_CONFIG_PROCESSOR_CHAIN = configProcessors[0];
// initialize the config processor for facelet-taglib documents
FACELET_TAGLIB_CONFIG_PROCESSOR_CHAIN = new FaceletTaglibConfigProcessor();
}
// ---------------------------------------------------------- Public Methods
/**
* @return a ConfigManager instance
*/
public static ConfigManager getInstance(ServletContext sc) {
return (ConfigManager) sc.getAttribute(CONFIG_MANAGER_INSTANCE_KEY);
}
public static ConfigManager createInstance(ServletContext sc) {
ConfigManager result = new ConfigManager();
sc.setAttribute(CONFIG_MANAGER_INSTANCE_KEY, result);
return result;
}
public static void removeInstance(ServletContext sc) {
sc.removeAttribute(CONFIG_MANAGER_INSTANCE_KEY);
}
private void initializeConfigProcessers(ServletContext sc) {
ConfigProcessor p = FACES_CONFIG_PROCESSOR_CHAIN;
do {
p.initializeClassMetadataMap(sc);
} while (null != (p = p.getNext()));
}
/**
*
* This method bootstraps JSF based on the parsed configuration resources.
*
*
* @param sc the ServletContext for the application that
* requires initialization
*/
public void initialize(ServletContext sc) {
if (!hasBeenInitialized(sc)) {
initializedContexts.add(sc);
initializeConfigProcessers(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 lastFacesConfigInfo =
new FacesConfigInfo(facesDocuments[facesDocuments.length - 1]);
facesDocuments = sortDocuments(facesDocuments, lastFacesConfigInfo);
InitFacesContext context = (InitFacesContext) FacesContext.getCurrentInstance();
InjectionProvider containerConnector =
InjectionProviderFactory.createInstance(context.getExternalContext());
context.getAttributes().put(INJECTION_PROVIDER_KEY, containerConnector);
boolean isFaceletsDisabled;
// Don't perform the check unless lastFacesConfigInfo is indeed
// *the* WEB-INF/faces-config.xml
if (lastFacesConfigInfo.isWebInfFacesConfig()) {
isFaceletsDisabled =
isFaceletsDisabled(webConfig, lastFacesConfigInfo);
} else {
isFaceletsDisabled = webConfig.isOptionEnabled(DisableFaceletJSFViewHandler) ||
webConfig.isOptionEnabled(DisableFaceletJSFViewHandlerDeprecated);
}
if (!lastFacesConfigInfo.isWebInfFacesConfig() || !lastFacesConfigInfo.isMetadataComplete()) {
// execute the Task responsible for finding annotation classes
ProvideMetadataToAnnotationScanTask taskMetadata = new ProvideMetadataToAnnotationScanTask(facesDocuments, containerConnector);
Futurefase
*/
public boolean hasBeenInitialized(ServletContext sc) {
return (initializedContexts.contains(sc));
}
/**
* @return the results of the annotation scan task
*/
public static Map,Set>> getAnnotatedClasses(FacesContext ctx) {
Map appMap =
ctx.getExternalContext().getApplicationMap();
//noinspection unchecked
Future