Search in sources :

Example 1 with ApplicationAssociate

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

the class FaceletTaglibConfigProcessor method process.

// -------------------------------------------- Methods from ConfigProcessor
@Override
public void process(ServletContext sc, FacesContext facesContext, DocumentInfo[] documentInfos) throws Exception {
    ApplicationAssociate associate = ApplicationAssociate.getInstance(facesContext.getExternalContext());
    Compiler compiler = associate.getCompiler();
    for (int i = 0, length = documentInfos.length; i < length; i++) {
        if (LOGGER.isLoggable(FINE)) {
            LOGGER.log(FINE, format("Processing facelet-taglibrary document: ''{0}''", documentInfos[i].getSourceURI()));
        }
        Document document = documentInfos[i].getDocument();
        String namespace = document.getDocumentElement().getNamespaceURI();
        Element documentElement = document.getDocumentElement();
        NodeList libraryClass = documentElement.getElementsByTagNameNS(namespace, LIBRARY_CLASS);
        if (libraryClass != null && libraryClass.getLength() > 0) {
            processTaglibraryClass(sc, facesContext, libraryClass, compiler);
        } else {
            processTagLibrary(sc, facesContext, documentElement, namespace, compiler);
        }
    }
}
Also used : Compiler(com.sun.faces.facelets.compiler.Compiler) ApplicationAssociate(com.sun.faces.application.ApplicationAssociate) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 2 with ApplicationAssociate

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

the class NavigationConfigProcessor method addNavigationCasesForRule.

private void addNavigationCasesForRule(String fromViewId, List<Node> navigationCases, NavigationHandler navHandler, ServletContext sc) {
    if (navigationCases != null && !navigationCases.isEmpty()) {
        ApplicationAssociate associate = ApplicationAssociate.getInstance(sc);
        for (Node navigationCase : navigationCases) {
            if (navigationCase.getNodeType() != Node.ELEMENT_NODE) {
                continue;
            }
            NodeList children = navigationCase.getChildNodes();
            String outcome = null;
            String action = null;
            String condition = null;
            String toViewId = null;
            String toFlowDocumentId = null;
            Map<String, List<String>> parameters = null;
            boolean redirect = false;
            boolean includeViewParams = false;
            for (int i = 0, size = children.getLength(); i < size; i++) {
                Node n = children.item(i);
                if (n.getNodeType() == Node.ELEMENT_NODE) {
                    switch(n.getLocalName()) {
                        case FROM_OUTCOME:
                            outcome = getNodeText(n);
                            break;
                        case FROM_ACTION:
                            action = getNodeText(n);
                            break;
                        case IF:
                            String expression = getNodeText(n);
                            if (SharedUtils.isExpression(expression) && !SharedUtils.isMixedExpression(expression)) {
                                condition = expression;
                            } else {
                                if (LOGGER.isLoggable(Level.WARNING)) {
                                    LOGGER.log(Level.WARNING, "faces.config.navigation.if_invalid_expression", new String[] { expression, fromViewId });
                                }
                            }
                            break;
                        case TO_VIEW_ID:
                            String toViewIdString = getNodeText(n);
                            if (toViewIdString.charAt(0) != '/' && toViewIdString.charAt(0) != '#') {
                                if (LOGGER.isLoggable(Level.WARNING)) {
                                    LOGGER.log(Level.WARNING, "faces.config.navigation.to_view_id_leading_slash", new String[] { toViewIdString, fromViewId });
                                }
                                toViewId = '/' + toViewIdString;
                            } else {
                                toViewId = toViewIdString;
                            }
                            break;
                        case TO_FLOW_DOCUMENT_ID:
                            toFlowDocumentId = getNodeText(n);
                            break;
                        case REDIRECT:
                            parameters = processParameters(n.getChildNodes());
                            includeViewParams = isIncludeViewParams(n);
                            redirect = true;
                            break;
                    }
                }
            }
            NavigationCase cnc = new NavigationCase(fromViewId, action, outcome, condition, toViewId, toFlowDocumentId, parameters, redirect, includeViewParams);
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.log(Level.FINE, MessageFormat.format("Adding NavigationCase: {0}", cnc.toString()));
            }
            // defined navigation mappings.
            if (navHandler instanceof ConfigurableNavigationHandler) {
                ConfigurableNavigationHandler cnav = (ConfigurableNavigationHandler) navHandler;
                Set<NavigationCase> cases = cnav.getNavigationCases().get(fromViewId);
                if (cases == null) {
                    cases = new LinkedHashSet<>();
                    cnav.getNavigationCases().put(fromViewId, cases);
                }
                cases.add(cnc);
            }
            associate.addNavigationCase(cnc);
        }
    }
}
Also used : ApplicationAssociate(com.sun.faces.application.ApplicationAssociate) NavigationCase(jakarta.faces.application.NavigationCase) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) ConfigurableNavigationHandler(jakarta.faces.application.ConfigurableNavigationHandler)

Example 3 with ApplicationAssociate

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

the class ApplicationConfigProcessor method process.

// -------------------------------------------- Methods from ConfigProcessor
@Override
public void process(ServletContext servletContext, FacesContext facesContext, DocumentInfo[] documentInfos) throws Exception {
    Application application = getApplication();
    ApplicationAssociate associate = ApplicationAssociate.getInstance(facesContext.getExternalContext());
    LinkedHashMap<String, Node> viewHandlers = new LinkedHashMap<>();
    LinkedHashSet<String> defaultValidatorIds = null;
    for (int i = 0; i < documentInfos.length; i++) {
        if (LOGGER.isLoggable(FINE)) {
            LOGGER.log(FINE, format("Processing application elements for document: ''{0}''", documentInfos[i].getSourceURI()));
        }
        Document document = documentInfos[i].getDocument();
        String namespace = document.getDocumentElement().getNamespaceURI();
        NodeList applicationElements = document.getDocumentElement().getElementsByTagNameNS(namespace, APPLICATION);
        if (applicationElements != null && applicationElements.getLength() > 0) {
            for (int a = 0, asize = applicationElements.getLength(); a < asize; a++) {
                Node appElement = applicationElements.item(a);
                NodeList children = ((Element) appElement).getElementsByTagNameNS(namespace, "*");
                if (children != null && children.getLength() > 0) {
                    for (int c = 0, csize = children.getLength(); c < csize; c++) {
                        Node n = children.item(c);
                        switch(n.getLocalName()) {
                            case MESSAGE_BUNDLE:
                                setMessageBundle(application, n);
                                break;
                            case DEFAULT_RENDERKIT_ID:
                                setDefaultRenderKitId(application, n);
                                break;
                            case ACTION_LISTENER:
                                addActionListener(servletContext, facesContext, application, n);
                                break;
                            case NAVIGATION_HANDLER:
                                setNavigationHandler(servletContext, facesContext, application, n);
                                break;
                            case VIEW_HANDLER:
                                String viewHandler = getNodeText(n);
                                if (viewHandler != null) {
                                    viewHandlers.put(viewHandler, n);
                                }
                                break;
                            case STATE_MANAGER:
                                setStateManager(servletContext, facesContext, application, n);
                                break;
                            case EL_RESOLVER:
                                addELResolver(servletContext, facesContext, associate, n);
                                break;
                            case DEFAULT_LOCALE:
                                setDefaultLocale(application, n);
                                break;
                            case SUPPORTED_LOCALE:
                                addSupportedLocale(application, n);
                                break;
                            case RESOURCE_BUNDLE:
                                addResouceBundle(associate, n);
                                break;
                            case RESOURCE_HANDLER:
                                setResourceHandler(servletContext, facesContext, application, n);
                                break;
                            case SYSTEM_EVENT_LISTENER:
                                addSystemEventListener(servletContext, facesContext, application, n);
                                break;
                            case DEFAULT_VALIDATORS:
                                if (defaultValidatorIds == null) {
                                    defaultValidatorIds = new LinkedHashSet<>();
                                } else {
                                    defaultValidatorIds.clear();
                                }
                                break;
                            case VALIDATOR_ID:
                                defaultValidatorIds.add(getNodeText(n));
                                break;
                            case SEARCH_EXPRESSION_HANDLER:
                                setSearchExpressionHandler(servletContext, facesContext, application, n);
                                break;
                            case SEARCH_KEYWORD_RESOLVER:
                                addSearchKeywordResolver(servletContext, facesContext, application, n);
                                break;
                        }
                    }
                }
            }
        }
    }
    registerDefaultValidatorIds(facesContext, application, defaultValidatorIds);
    // perform any special processing for ViewHandlers...
    processViewHandlers(servletContext, facesContext, application, viewHandlers);
    // process NamedEvent annotations, if any
    processAnnotations(facesContext, NamedEvent.class);
}
Also used : ApplicationAssociate(com.sun.faces.application.ApplicationAssociate) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Util.getLocaleFromString(com.sun.faces.util.Util.getLocaleFromString) Document(org.w3c.dom.Document) Application(jakarta.faces.application.Application) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with ApplicationAssociate

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

the class FacesResourceBundleELResolver method getFeatureDescriptors.

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
    if (base != null) {
        return null;
    }
    ArrayList<FeatureDescriptor> list = new ArrayList<>();
    FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
    ApplicationAssociate associate = ApplicationAssociate.getCurrentInstance();
    Map<String, ApplicationResourceBundle> rbMap = associate.getResourceBundles();
    if (rbMap == null) {
        return list.iterator();
    }
    // iterate over the list of managed beans
    for (Iterator<Map.Entry<String, ApplicationResourceBundle>> i = rbMap.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry<String, ApplicationResourceBundle> entry = i.next();
        String var = entry.getKey();
        ApplicationResourceBundle bundle = entry.getValue();
        if (bundle != null) {
            Locale curLocale = Util.getLocaleFromContextOrSystem(facesContext);
            String description = bundle.getDescription(curLocale);
            String displayName = bundle.getDisplayName(curLocale);
            list.add(Util.getFeatureDescriptor(var, displayName, description, false, false, true, ResourceBundle.class, Boolean.TRUE));
        }
    }
    return list.iterator();
}
Also used : Locale(java.util.Locale) FacesContext(jakarta.faces.context.FacesContext) ApplicationAssociate(com.sun.faces.application.ApplicationAssociate) ArrayList(java.util.ArrayList) ApplicationResourceBundle(com.sun.faces.application.ApplicationResourceBundle) FeatureDescriptor(java.beans.FeatureDescriptor) ResourceBundle(java.util.ResourceBundle) ApplicationResourceBundle(com.sun.faces.application.ApplicationResourceBundle) Map(java.util.Map)

Example 5 with ApplicationAssociate

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

the class ResourceLibraryContractsConfigProcessor method process.

/**
 * Process the configuration documents.
 *
 * @param servletContext the servlet context.
 * @param documentInfos the document info(s).
 * @throws Exception when an error occurs.
 */
@Override
public void process(ServletContext servletContext, FacesContext facesContext, DocumentInfo[] documentInfos) throws Exception {
    HashMap<String, List<String>> map = new HashMap<>();
    for (int i = 0; i < documentInfos.length; i++) {
        if (LOGGER.isLoggable(FINE)) {
            LOGGER.log(FINE, MessageFormat.format("Processing factory elements for document: ''{0}''", documentInfos[i].getSourceURI()));
        }
        Document document = documentInfos[i].getDocument();
        String namespace = document.getDocumentElement().getNamespaceURI();
        NodeList resourceLibraryContracts = document.getDocumentElement().getElementsByTagNameNS(namespace, RESOURCE_LIBRARY_CONTRACTS);
        if (resourceLibraryContracts != null && resourceLibraryContracts.getLength() > 0) {
            processResourceLibraryContracts(resourceLibraryContracts, map);
        }
    }
    if (!map.isEmpty()) {
        ApplicationAssociate associate = ApplicationAssociate.getCurrentInstance();
        associate.setResourceLibraryContracts(map);
    }
}
Also used : ApplicationAssociate(com.sun.faces.application.ApplicationAssociate) HashMap(java.util.HashMap) NodeList(org.w3c.dom.NodeList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) Document(org.w3c.dom.Document)

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