Search in sources :

Example 1 with ApplicationResourceBundle

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

the class ApplicationConfigProcessor method addResouceBundle.

private void addResouceBundle(ApplicationAssociate associate, Node resourceBundle) {
    if (resourceBundle != null) {
        NodeList children = resourceBundle.getChildNodes();
        if (children != null) {
            String baseName = null;
            String var = null;
            List<Node> descriptions = null;
            List<Node> displayNames = null;
            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 BASE_NAME:
                            baseName = getNodeText(n);
                            break;
                        case VAR:
                            var = getNodeText(n);
                            break;
                        case RES_DESCRIPTIONS:
                            if (descriptions == null) {
                                descriptions = new ArrayList<>(2);
                            }
                            descriptions.add(n);
                            break;
                        case RES_DISPLAY_NAMES:
                            if (displayNames == null) {
                                displayNames = new ArrayList<>(2);
                            }
                            displayNames.add(n);
                            break;
                    }
                }
            }
            if (baseName != null && var != null) {
                associate.addResourceBundle(var, new ApplicationResourceBundle(baseName, getTextMap(displayNames), getTextMap(descriptions)));
            }
        }
    }
}
Also used : NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ApplicationResourceBundle(com.sun.faces.application.ApplicationResourceBundle) Util.getLocaleFromString(com.sun.faces.util.Util.getLocaleFromString)

Example 2 with ApplicationResourceBundle

use of com.sun.faces.application.ApplicationResourceBundle 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 3 with ApplicationResourceBundle

use of com.sun.faces.application.ApplicationResourceBundle in project ctsms by phoenixctms.

the class WebUtil method clearResourceBundleCache.

public static void clearResourceBundleCache() throws Exception {
    getServiceLocator().getToolsService().clearResourceBundleCache();
    // https://stackoverflow.com/questions/4325164/how-to-reload-resource-bundle-in-web-application
    ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader());
    Iterator<ApplicationResourceBundle> it = ApplicationAssociate.getCurrentInstance().getResourceBundles().values().iterator();
    while (it.hasNext()) {
        ApplicationResourceBundle appBundle = it.next();
        Map<Locale, ResourceBundle> resources = CommonUtil.getDeclaredFieldValue(appBundle, "resources");
        resources.clear();
    }
}
Also used : Locale(java.util.Locale) ApplicationResourceBundle(com.sun.faces.application.ApplicationResourceBundle) ResourceBundle(java.util.ResourceBundle) ApplicationResourceBundle(com.sun.faces.application.ApplicationResourceBundle)

Aggregations

ApplicationResourceBundle (com.sun.faces.application.ApplicationResourceBundle)3 Locale (java.util.Locale)2 ResourceBundle (java.util.ResourceBundle)2 ApplicationAssociate (com.sun.faces.application.ApplicationAssociate)1 Util.getLocaleFromString (com.sun.faces.util.Util.getLocaleFromString)1 FacesContext (jakarta.faces.context.FacesContext)1 FeatureDescriptor (java.beans.FeatureDescriptor)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1