use of jakarta.faces.application.ProjectStage in project org.openntf.xsp.jakartaee by OpenNTF.
the class NSFJsfServlet method doInit.
public void doInit(HttpServletRequest req, ServletConfig config) throws ServletException {
try {
CDI<Object> cdi = ContainerUtil.getContainer(NotesContext.getCurrent().getNotesDatabase());
ServletContext context = config.getServletContext();
// $NON-NLS-1$
context.setAttribute("jakarta.enterprise.inject.spi.BeanManager", ContainerUtil.getBeanManager(cdi));
// TODO investigate why partial state saving doesn't work with a basic form
// $NON-NLS-1$ //$NON-NLS-2$
context.setInitParameter("jakarta.faces.PARTIAL_STATE_SAVING", "false");
Properties props = LibraryUtil.getXspProperties(module);
// $NON-NLS-1$
String projectStage = props.getProperty(ProjectStage.PROJECT_STAGE_PARAM_NAME, "");
context.setInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME, projectStage);
Bundle b = FrameworkUtil.getBundle(FacesServlet.class);
{
ServletContainerInitializer initializer = new MyFacesContainerInitializer();
Set<Class<?>> classes = null;
HandlesTypes types = initializer.getClass().getAnnotation(HandlesTypes.class);
if (types != null) {
classes = buildMatchingClasses(types, b);
}
initializer.onStartup(classes, getServletContext());
}
{
// Re-wrap the ServletContext to provide the context path
javax.servlet.ServletContext oldCtx = ServletUtil.newToOld(getServletContext());
ServletContext ctx = ServletUtil.oldToNew(req.getContextPath(), oldCtx, 5, 0);
ctx.addListener(StartupServletContextListener.class);
ServletUtil.getListeners(ctx, ServletContextListener.class).forEach(l -> l.contextInitialized(new ServletContextEvent(ctx)));
}
this.delegate = new FacesServlet();
delegate.init(config);
} catch (NotesAPIException e) {
throw new ServletException(e);
}
}
use of jakarta.faces.application.ProjectStage in project mojarra by eclipse-ee4j.
the class ResourceImpl method getRequestPath.
/**
* @see jakarta.faces.application.Resource#getRequestPath()
*/
@Override
public String getRequestPath() {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletMapping mapping = getFacesMapping(context);
String uri = null;
// Check for exact mapping first
if (mapping.getMappingMatch() == EXACT) {
String resource = RESOURCE_IDENTIFIER + '/' + getResourceName();
// Check if the FacesServlet is exact mapped to the resource
if (isResourceExactMappedToFacesServlet(context.getExternalContext(), resource)) {
uri = resource;
} else {
// No exact mapping for the requested resource, see if Facelets servlet is mapped to
// e.g. /faces/* or *.xhtml and take that mapping
mapping = getFirstWildCardMappingToFacesServlet(context.getExternalContext());
if (mapping == null) {
throw new IllegalStateException("No suitable mapping for FacesServlet found. To serve resources " + "FacesServlet should have at least one prefix or suffix mapping.");
}
}
}
if (uri == null) {
if (mapping.getMappingMatch() == PATH) {
// If it is prefix/path mapped, e.g /faces/* -> /faces/jakarta.faces.resource/name
uri = mapping.getPattern().replace("/*", RESOURCE_IDENTIFIER) + '/' + getResourceName();
} else {
// If it is prefix/path mapped, e.g *.xhtml -> /jakarta.faces.resource/name.xhtml
uri = RESOURCE_IDENTIFIER + '/' + mapping.getPattern().replace("*", getResourceName());
}
}
boolean queryStarted = false;
if (getLibraryName() != null) {
queryStarted = true;
uri += "?ln=" + getLibraryName();
}
String version = "";
initResourceInfo();
if (resourceInfo.getLibraryInfo() != null && resourceInfo.getLibraryInfo().getVersion() != null) {
version += resourceInfo.getLibraryInfo().getVersion().toString();
}
if (resourceInfo.getVersion() != null) {
version += resourceInfo.getVersion().toString();
}
if (version.length() > 0) {
uri += (queryStarted ? "&v=" : "?v=") + version;
queryStarted = true;
}
String localePrefix = resourceInfo.getLocalePrefix();
if (localePrefix != null) {
uri += (queryStarted ? "&loc=" : "?loc=") + localePrefix;
queryStarted = true;
}
String contract = resourceInfo.getContract();
if (contract != null) {
uri += (queryStarted ? "&con=" : "?con=") + contract;
queryStarted = true;
}
if (FACES_SCRIPT_RESOURCE_NAME.equals(getResourceName()) && FACES_SCRIPT_LIBRARY_NAME.equals(getLibraryName())) {
ProjectStage stage = context.getApplication().getProjectStage();
switch(stage) {
case Development:
uri += queryStarted ? "&stage=Development" : "?stage=Development";
break;
case SystemTest:
uri += queryStarted ? "&stage=SystemTest" : "?stage=SystemTest";
break;
case UnitTest:
uri += queryStarted ? "&stage=UnitTest" : "?stage=UnitTest";
break;
default:
assert stage.equals(Production);
}
}
return context.getApplication().getViewHandler().getResourceURL(context, uri);
}
use of jakarta.faces.application.ProjectStage in project myfaces by apache.
the class FacesInitializerImpl method initFaces.
/**
* Performs all necessary initialization tasks like configuring this JSF
* application.
*
* @param servletContext The current {@link ServletContext}
*/
@Override
public void initFaces(ServletContext servletContext) {
if (Boolean.TRUE.equals(servletContext.getAttribute(INITIALIZED))) {
if (log.isLoggable(Level.FINEST)) {
log.finest("MyFaces already initialized");
}
return;
}
try {
if (log.isLoggable(Level.FINEST)) {
log.finest("Initializing MyFaces");
}
long start = System.currentTimeMillis();
// Some parts of the following configuration tasks have been implemented
// by using an ExternalContext. However, that's no problem as long as no
// one tries to call methods depending on either the ServletRequest or
// the ServletResponse.
// JSF 2.0: FacesInitializer now has some new methods to
// use proper startup FacesContext and ExternalContext instances.
FacesContext facesContext = initStartupFacesContext(servletContext);
ExternalContext externalContext = facesContext.getExternalContext();
dispatchInitializationEvent(servletContext, FACES_INIT_PHASE_PREINIT);
// Setup ServiceProviderFinder
ServiceProviderFinder spf = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext);
Map<String, List<String>> spfConfig = spf.calculateKnownServiceProviderMapInfo(externalContext, ServiceProviderFinder.KNOWN_SERVICES);
if (spfConfig != null) {
spf.initKnownServiceProviderMapInfo(externalContext, spfConfig);
}
if (!WebConfigParamUtils.getBooleanInitParameter(externalContext, MyfacesConfig.INITIALIZE_ALWAYS_STANDALONE, false)) {
FacesServletMappingUtils.ServletRegistrationInfo facesServletRegistration = FacesServletMappingUtils.getFacesServletRegistration(facesContext, servletContext);
if (facesServletRegistration == null || facesServletRegistration.getMappings() == null || facesServletRegistration.getMappings().length == 0) {
// check to see if the FacesServlet was found by MyFacesContainerInitializer
Boolean mappingAdded = (Boolean) servletContext.getAttribute(MyFacesContainerInitializer.FACES_SERVLET_FOUND);
if (mappingAdded == null || !mappingAdded) {
// check if the FacesServlet has been added dynamically
// in a Servlet 3.0 environment by MyFacesContainerInitializer
mappingAdded = (Boolean) servletContext.getAttribute(MyFacesContainerInitializer.FACES_SERVLET_ADDED_ATTRIBUTE);
if (mappingAdded == null || !mappingAdded) {
if (log.isLoggable(Level.WARNING)) {
log.warning("No mappings of FacesServlet found. Abort initializing MyFaces.");
}
return;
}
}
}
}
initCDIIntegration(servletContext, externalContext);
initContainerIntegration(servletContext, externalContext);
// log environment integrations
ExternalSpecifications.isBeanValidationAvailable();
ExternalSpecifications.isCDIAvailable(externalContext);
ExternalSpecifications.isEL3Available();
ExternalSpecifications.isServlet4Available();
String useEncryption = servletContext.getInitParameter(StateUtils.USE_ENCRYPTION);
if ("false".equals(useEncryption)) {
log.warning(StateUtils.USE_ENCRYPTION + " is set to false. " + "This is unsecure and should only be used for local or intranet applications!");
} else {
StateUtils.initSecret(servletContext);
}
_dispatchApplicationEvent(servletContext, PostConstructApplicationEvent.class);
initWebsocketIntegration(servletContext, externalContext);
WebConfigParamsLogger.logWebContextParams(facesContext);
// Start ViewPoolProcessor if necessary
ViewPoolProcessor.initialize(facesContext);
MyfacesConfig config = MyfacesConfig.getCurrentInstance(facesContext.getExternalContext());
if (config.isAutomaticExtensionlessMapping()) {
initAutomaticExtensionlessMapping(facesContext, servletContext);
}
// publish resourceBundleControl to applicationMap, to make it available to the API
ResourceBundle.Control resourceBundleControl = config.getResourceBundleControl();
if (resourceBundleControl != null) {
facesContext.getExternalContext().getApplicationMap().put(MyfacesConfig.RESOURCE_BUNDLE_CONTROL, resourceBundleControl);
}
// print out a very prominent log message if the project stage is != Production
if (!facesContext.isProjectStage(ProjectStage.Production) && !facesContext.isProjectStage(ProjectStage.UnitTest)) {
ProjectStage projectStage = facesContext.getApplication().getProjectStage();
StringBuilder message = new StringBuilder("\n\n");
message.append("********************************************************************\n");
message.append("*** WARNING: Apache MyFaces Core is running in ");
message.append(projectStage.name().toUpperCase());
message.append(" mode.");
int length = projectStage.name().length();
for (int i = 0; i < 11 - length; i++) {
message.append(' ');
}
message.append(" ***\n");
message.append("*** ");
for (int i = 0; i < length; i++) {
message.append('^');
}
for (int i = 0; i < 18 - length; i++) {
message.append(' ');
}
message.append("***\n");
message.append("*** Do NOT deploy to your live server(s) without changing this. ***\n");
message.append("*** See Application#getProjectStage() for more information. ***\n");
message.append("********************************************************************\n");
message.append("\n");
log.log(Level.WARNING, message.toString());
}
cleanupAfterStartup(facesContext);
dispatchInitializationEvent(servletContext, FACES_INIT_PHASE_POSTINIT);
destroyStartupFacesContext(facesContext);
servletContext.setAttribute(INITIALIZED, Boolean.TRUE);
log.log(Level.INFO, "MyFaces Core has started, it took [" + (System.currentTimeMillis() - start) + "] ms.");
} catch (Exception ex) {
log.log(Level.SEVERE, "An error occured while initializing MyFaces: " + ex.getMessage(), ex);
}
}
use of jakarta.faces.application.ProjectStage 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;
}
Aggregations