Search in sources :

Example 16 with ApplicationAssociate

use of com.sun.faces.application.ApplicationAssociate in project mojarra by eclipse-ee4j.

the class FacesFlowDefinitionConfigProcessor method processFacesFlowDefinitions.

private void processFacesFlowDefinitions(FacesContext context, URI definingDocumentURI, Document document) throws XPathExpressionException {
    String namespace = document.getDocumentElement().getNamespaceURI();
    NodeList flowDefinitions = document.getDocumentElement().getElementsByTagNameNS(namespace, FACES_FLOW_DEFINITION);
    if (flowDefinitions.getLength() == 0) {
        return;
    }
    Application application = context.getApplication();
    FlowHandler flowHandler = application.getFlowHandler();
    if (flowHandler == null) {
        FlowHandlerFactory flowHandlerFactory = (FlowHandlerFactory) FactoryFinder.getFactory(FactoryFinder.FLOW_HANDLER_FACTORY);
        application.setFlowHandler(flowHandler = flowHandlerFactory.createFlowHandler(context));
    }
    XPath xpath = XPathFactory.newInstance().newXPath();
    xpath.setNamespaceContext(new FacesConfigNamespaceContext(namespace));
    String nameStr = "";
    NodeList nameList = (NodeList) xpath.evaluate("./ns1:name/text()", document.getDocumentElement(), XPathConstants.NODESET);
    if (null != nameList && 1 < nameList.getLength()) {
        throw new XPathExpressionException("<faces-config> must have at most one <name> element.");
    }
    if (null != nameList && 1 == nameList.getLength()) {
        nameStr = nameList.item(0).getNodeValue().trim();
        if (0 < nameStr.length()) {
            ApplicationAssociate associate = ApplicationAssociate.getInstance(context.getExternalContext());
            try {
                associate.relateUrlToDefiningDocumentInJar(definingDocumentURI.toURL(), nameStr);
            } catch (MalformedURLException ex) {
                throw new XPathExpressionException(ex);
            }
        }
    }
    for (int c = 0, size = flowDefinitions.getLength(); c < size; c++) {
        Node flowDefinition = flowDefinitions.item(c);
        String flowId = getIdAttribute(flowDefinition);
        String uriStr = definingDocumentURI.toASCIIString();
        if (uriStr.endsWith(RIConstants.FLOW_DEFINITION_ID_SUFFIX)) {
            nameStr = "";
        }
        FlowBuilderImpl flowBuilder = new FlowBuilderImpl(context);
        flowBuilder.id(nameStr, flowId);
        processViews(xpath, flowDefinition, flowBuilder);
        processNavigationRules(xpath, flowDefinition, flowBuilder);
        processReturns(xpath, flowDefinition, flowBuilder);
        processInboundParameters(xpath, flowDefinition, flowBuilder);
        processFlowCalls(xpath, flowDefinition, flowBuilder);
        processSwitches(xpath, flowDefinition, flowBuilder);
        processMethodCalls(context, xpath, flowDefinition, flowBuilder);
        processInitializerFinalizer(xpath, flowDefinition, flowBuilder);
        String startNodeId = processStartNode(xpath, flowDefinition, flowBuilder);
        if (null != startNodeId) {
            FlowImpl toAdd = flowBuilder._getFlow();
            FlowNode startNode = toAdd.getNode(startNodeId);
            if (null == startNode) {
                throw new XPathExpressionException("Unable to find flow node with id " + startNodeId + " to mark as start node");
            } else {
                toAdd.setStartNodeId(startNodeId);
            }
        } else {
            flowBuilder.viewNode(flowId, "/" + flowId + "/" + flowId + ".xhtml").markAsStartNode();
        }
        flowHandler.addFlow(context, flowBuilder.getFlow());
    }
}
Also used : XPath(javax.xml.xpath.XPath) ApplicationAssociate(com.sun.faces.application.ApplicationAssociate) MalformedURLException(java.net.MalformedURLException) FlowImpl(com.sun.faces.flow.FlowImpl) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) FlowNode(jakarta.faces.flow.FlowNode) Node(org.w3c.dom.Node) FlowHandlerFactory(jakarta.faces.flow.FlowHandlerFactory) FlowBuilderImpl(com.sun.faces.flow.builder.FlowBuilderImpl) FlowHandler(jakarta.faces.flow.FlowHandler) Application(jakarta.faces.application.Application) FlowNode(jakarta.faces.flow.FlowNode)

Example 17 with ApplicationAssociate

use of com.sun.faces.application.ApplicationAssociate in project mojarra by eclipse-ee4j.

the class StateContext method getStateContext.

/**
 * @param ctx the <code>FacesContext</code> for the current request
 * @return <code>StateContext</code> for this request
 */
public static StateContext getStateContext(FacesContext ctx) {
    StateContext stateCtx = (StateContext) ctx.getAttributes().get(KEY);
    if (stateCtx == null) {
        ApplicationAssociate associate = ApplicationAssociate.getCurrentInstance();
        ApplicationStateInfo info = associate.getApplicationStateInfo();
        stateCtx = new StateContext(info);
        ctx.getAttributes().put(KEY, stateCtx);
    }
    return stateCtx;
}
Also used : ApplicationAssociate(com.sun.faces.application.ApplicationAssociate) ApplicationStateInfo(com.sun.faces.application.ApplicationStateInfo)

Example 18 with ApplicationAssociate

use of com.sun.faces.application.ApplicationAssociate in project mojarra by eclipse-ee4j.

the class ExceptionHandlerFactoryImpl method getExceptionHandler.

/**
 * @see jakarta.faces.context.ExceptionHandlerFactory#getExceptionHandler()
 */
@Override
public ExceptionHandler getExceptionHandler() {
    FacesContext fc = FacesContext.getCurrentInstance();
    ApplicationAssociate myAssociate = getAssociate(fc);
    ExceptionHandler result = new AjaxNoAjaxExceptionHandler(new AjaxExceptionHandlerImpl(new ExceptionHandlerImpl(Boolean.TRUE)), new ExceptionHandlerImpl(myAssociate != null ? myAssociate.isErrorPagePresent() : Boolean.TRUE));
    return result;
}
Also used : ExceptionHandler(jakarta.faces.context.ExceptionHandler) FacesContext(jakarta.faces.context.FacesContext) ApplicationAssociate(com.sun.faces.application.ApplicationAssociate)

Example 19 with ApplicationAssociate

use of com.sun.faces.application.ApplicationAssociate in project mojarra by eclipse-ee4j.

the class CdiUtils method createConverter.

/**
 * Create a converter using the FacesConverter value attribute.
 *
 * @param beanManager the bean manager.
 * @param value the value attribute.
 * @return the converter, or null if we could not match one.
 */
public static Converter<?> createConverter(BeanManager beanManager, String value) {
    Converter<?> managedConverter = createConverter(beanManager, FacesConverter.Literal.of(value, Object.class, true));
    if (managedConverter != null) {
        ApplicationAssociate associate = ApplicationAssociate.getCurrentInstance();
        // #4913
        associate.getAnnotationManager().applyConverterAnnotations(FacesContext.getCurrentInstance(), managedConverter);
        return new CdiConverter(value, Object.class, managedConverter);
    }
    return null;
}
Also used : ApplicationAssociate(com.sun.faces.application.ApplicationAssociate)

Example 20 with ApplicationAssociate

use of com.sun.faces.application.ApplicationAssociate in project mojarra by eclipse-ee4j.

the class ComponentConfigHandler method push.

/**
 * @see com.sun.faces.application.annotation.ConfigAnnotationHandler#push(jakarta.faces.context.FacesContext)
 */
@Override
public void push(FacesContext ctx) {
    if (components != null) {
        Application app = ctx.getApplication();
        ApplicationAssociate appAss = ApplicationAssociate.getCurrentInstance();
        for (Map.Entry<String, FacesComponentUsage> entry : components.entrySet()) {
            if (entry.getValue().getAnnotation().createTag()) {
                appAss.addFacesComponent(entry.getValue());
            }
            app.addComponent(entry.getKey(), entry.getValue().getTarget().getName());
        }
    }
}
Also used : ApplicationAssociate(com.sun.faces.application.ApplicationAssociate) Application(jakarta.faces.application.Application) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ApplicationAssociate (com.sun.faces.application.ApplicationAssociate)22 FacesContext (jakarta.faces.context.FacesContext)5 NodeList (org.w3c.dom.NodeList)5 Application (jakarta.faces.application.Application)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Document (org.w3c.dom.Document)3 Node (org.w3c.dom.Node)3 WebappLifecycleListener (com.sun.faces.application.WebappLifecycleListener)2 ELContextImpl (com.sun.faces.el.ELContextImpl)2 PostConstruct (jakarta.annotation.PostConstruct)2 ExternalContext (jakarta.faces.context.ExternalContext)2 ServletContext (jakarta.servlet.ServletContext)2 HttpSession (jakarta.servlet.http.HttpSession)2 URL (java.net.URL)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Element (org.w3c.dom.Element)2