protected static Application getApplication() { FacesContext context = FacesContext.getCurrentInstance(); if (context != null) { return (FacesContext.getCurrentInstance().getApplication()); } ApplicationFactory afactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY); return (afactory.getApplication()); }
public void shutdown() { this.application = null; this.servletConfig = null; this.containerConfig = null; this.lifecycle = null; this.renderKit = null; this.servletContext = null; FactoryFinder.releaseFactories(); }
private void setFactories(String factoryName, Collection<String> factories, String defaultFactory) { FactoryFinder.setFactory(factoryName, defaultFactory); for (String factory : factories) { if (!factory.equals(defaultFactory)) { FactoryFinder.setFactory(factoryName, factory); } } }
@Override public void processEvent(SystemEvent event) throws AbortProcessingException { ApplicationAssociate.this.initializeFacelets(); if (null == ApplicationAssociate.this.flowHandler) { FlowHandlerFactory flowHandlerFactory = (FlowHandlerFactory) FactoryFinder.getFactory(FactoryFinder.FLOW_HANDLER_FACTORY); ApplicationAssociate.this.flowHandler = flowHandlerFactory.createFlowHandler(FacesContext.getCurrentInstance()); } FacesContext context = FacesContext.getCurrentInstance(); if (Util.isCDIAvailable(context.getExternalContext().getApplicationMap())) { try { JavaFlowLoaderHelper flowLoader = new JavaFlowLoaderHelper(); flowLoader.loadFlows(context, ApplicationAssociate.this.flowHandler); } catch (IOException ex) { LOGGER.log(Level.SEVERE, null, ex); } } // cause the Facelet VDL to be instantiated eagerly, so it can // become aware of the resource library contracts ViewHandler viewHandler = context.getApplication().getViewHandler(); // FindBugs: ignore the return value, this is just to get the // ctor called at this time. viewHandler.getViewDeclarationLanguage(context, RIConstants.FACES_PREFIX + "xhtml"); }
private Renderer getRenderer(FacesContext context, UIComponent foreignComponent) { if (context == null) throw new NullPointerException("context"); String rendererType = foreignComponent.getRendererType(); if (rendererType == null) return null; String renderKitId = context.getViewRoot().getRenderKitId(); RenderKitFactory rkf = (RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); RenderKit renderKit = rkf.getRenderKit(context, renderKitId); Renderer renderer = renderKit.getRenderer(foreignComponent.getFamily(), rendererType); if (renderer == null) { getFacesContext().getExternalContext().log("No Renderer found for component " + foreignComponent + " (component-family=" + foreignComponent.getFamily() + ", renderer-type=" + rendererType + ")"); } return renderer; }
/** * <p>Return the {@link RenderKit} for the current request.</p> * @param context the {@link FacesContext} of the current request * @return the {@link RenderKit} for the current request. */ public static RenderKit getCurrentRenderKit(FacesContext context) { RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); return renderKitFactory.getRenderKit(context, context .getViewRoot().getRenderKitId()); }
/** * Gets the current Lifecycle instance from the LifecycleFactory * @param facesContext * @return */ private Lifecycle _getLifecycle(FacesContext facesContext) { LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); String id = facesContext.getExternalContext().getInitParameter(FacesServlet.LIFECYCLE_ID_ATTR); if (id == null) { id = LifecycleFactory.DEFAULT_LIFECYCLE; } return factory.getLifecycle(id); }
/** * @see Faces#getRenderKit() */ public static RenderKit getRenderKit(FacesContext context) { String renderKitId = null; UIViewRoot view = context.getViewRoot(); if (view != null) { renderKitId = view.getRenderKitId(); } if (renderKitId == null) { Application application = context.getApplication(); ViewHandler viewHandler = application.getViewHandler(); if (viewHandler != null) { renderKitId = viewHandler.calculateRenderKitId(context); } if (renderKitId == null) { renderKitId = application.getDefaultRenderKitId(); if (renderKitId == null) { renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT; } } } return ((RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY)).getRenderKit(context, renderKitId); }
@Override protected void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final LifecycleFactory lFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); final Lifecycle lifecycle = lFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); final FacesContextFactory fcFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); final FacesContext facesContext = fcFactory.getFacesContext(getServletContext(), request, response, lifecycle); try { // invoke application final String outcome = invokeApplication(facesContext); if (facesContext.getResponseComplete()) { return; } if (LOG.isDebugEnabled()) { LOG.debug("outcome = '" + outcome + "'"); } final Application application = facesContext.getApplication(); if (facesContext.getViewRoot() == null) { facesContext.setViewRoot(createViewRoot(facesContext)); } final NavigationHandler navigationHandler = application.getNavigationHandler(); navigationHandler.handleNavigation(facesContext, null, outcome); lifecycle.render(facesContext); } finally { facesContext.release(); } }
public static ResponseWriter buildResponseWriter(FacesContext facesContext, PageContext pageContext) { RenderKitFactory factory = (RenderKitFactory) FactoryFinder .getFactory(FactoryFinder.RENDER_KIT_FACTORY); RenderKit renderKit = factory.getRenderKit(facesContext, facesContext .getViewRoot().getRenderKitId()); PageContextOutWriter writer = new PageContextOutWriter(pageContext); String encoding = pageContext.getRequest().getCharacterEncoding(); FacesContext context = FacesContext.getCurrentInstance(); String acceptContentTypes = getAcceptHeader(context); return renderKit.createResponseWriter(writer, acceptContentTypes, encoding); }
private RenderKit getDefaultRenderKit() { if (defaultRenderKit == null) { RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); FacesContext facesContext = FacesContext.getCurrentInstance(); defaultRenderKit = renderKitFactory.getRenderKit(facesContext, RenderKitFactory.HTML_BASIC_RENDER_KIT); } return defaultRenderKit; } }
String renderKitId = facesContext.getApplication().getViewHandler().calculateRenderKitId(facesContext); if (_renderKitFactory == null) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); renderKit = _renderKitFactory.getRenderKit(facesContext, renderKitId); return renderKit.getResponseStateManager().isPostback(facesContext);
protected ExpressionFactory getExpressionFactory() { if (expressionFactory == null) { ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder .getFactory(FactoryFinder.APPLICATION_FACTORY); expressionFactory = appFactory.getApplication().getExpressionFactory(); } return expressionFactory; }
/** * This method follows JSF Spec section 2.1.1. It renders a view from a non-faces * request. This is useful for a default view as well as for views that need to * be rendered from the portlet's edit and help buttons. * * @param request The portlet render request. * @param response The portlet render response. * @param view The name of the view that needs to be rendered. */ protected void nonFacesRequest(RenderRequest request, RenderResponse response, String view) throws PortletException { if (log.isTraceEnabled()) log.trace("Non-faces request: contextPath = " + request.getContextPath()); setContentType(request, response); // do this in case nonFacesRequest is called by a subclass ApplicationFactory appFactory = (ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY); Application application = appFactory.getApplication(); ViewHandler viewHandler = application.getViewHandler(); FacesContext facesContext = facesContext(request, response); UIViewRoot viewRoot = viewHandler.createView(facesContext, view); viewRoot.setViewId(view); facesContext.setViewRoot(viewRoot); lifecycle.render(facesContext); }
private Lifecycle createFacesLifecycle() { LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder .getFactory(FactoryFinder.LIFECYCLE_FACTORY); return lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); }
private Renderer getInputTextRenderer(FacesContext context) { if (null == inputTextRenderer) { RenderKitFactory rkf = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); RenderKit standard = rkf.getRenderKit(context, RenderKitFactory.HTML_BASIC_RENDER_KIT); inputTextRenderer = standard. getRenderer("javax.faces.Input", "javax.faces.Text"); } assert(null != inputTextRenderer); return inputTextRenderer; }
public FacesRequest start() { if (connection.isStarted() || connection.isFinished()) { throw new IllegalStateException(); } connection.start(); FacesContextFactory facesContextFactory = (FacesContextFactory) FactoryFinder .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); facesContext = facesContextFactory.getFacesContext(facesServer.getContext(), connection.getRequest(), connection.getResponse(), lifecycle); if (null != viewId) { facesContext.setViewRoot(application.getViewHandler().createView(facesContext, viewId)); } return this; }
public void registerPhaseListener(PhaseListener phaseListener) throws IllegalStateException { LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory( FactoryFinder.LIFECYCLE_FACTORY); for (Iterator<String> lifecycleIds = lifecycleFactory.getLifecycleIds(); lifecycleIds.hasNext();) { String lifecycleId = lifecycleIds.next(); lifecycleFactory.getLifecycle(lifecycleId).addPhaseListener(phaseListener); } }
/** * Setup this test class instance * Must be run for each test class instance (e.g. @BeforeClass) * @throws Exception */ protected void setupClass() throws Exception { servletContext = ServletLifecycle.getServletContext(); // FactoryFinder cannot be reliably used, as something could have called getFactory sooner applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY); //applicationFactory = new MockApplicationFactory(); application = applicationFactory.getApplication(); conversationViewRootAttributes = new HashMap<String, Map>(); seamFilter = createSeamFilter(); FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY, MockFacesContextFactory.class.getName()); for (ELResolver elResolver : getELResolvers()) { application.addELResolver(elResolver); } }
/** * Determine if the current request/FacesContext is in PostBack state */ public static boolean isPostback(final FacesContext context) { RenderKitFactory factory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY); RenderKit renderKit = factory.getRenderKit(context, RenderKitFactory.HTML_BASIC_RENDER_KIT); return renderKit.getResponseStateManager().isPostback(context); } }