Search in sources :

Example 1 with FlowBuilderImpl

use of com.sun.faces.flow.builder.FlowBuilderImpl 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)

Aggregations

ApplicationAssociate (com.sun.faces.application.ApplicationAssociate)1 FlowImpl (com.sun.faces.flow.FlowImpl)1 FlowBuilderImpl (com.sun.faces.flow.builder.FlowBuilderImpl)1 Application (jakarta.faces.application.Application)1 FlowHandler (jakarta.faces.flow.FlowHandler)1 FlowHandlerFactory (jakarta.faces.flow.FlowHandlerFactory)1 FlowNode (jakarta.faces.flow.FlowNode)1 MalformedURLException (java.net.MalformedURLException)1 XPath (javax.xml.xpath.XPath)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1