⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiaresourcebundle.java

📁 java 写的一个新闻发布系统
💻 JAVA
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .//////// NK 18.02.2002 - added in Jahia//package org.jahia.resourcebundle;import java.util.Locale;import java.util.ResourceBundle;import java.security.Principal;import org.jahia.params.ParamBean;import org.jahia.exceptions.JahiaException;import org.jahia.services.pages.*;import org.jahia.services.sites.JahiaSite;import org.jahia.registries.ServicesRegistry;import org.jahia.services.usermanager.*;import org.jahia.utils.JahiaConsole;/** * Tools to handles resource bundle within Jahia. * * @author Khue Nguyen * @version 1.0 */public class JahiaResourceBundle{    private static final String CLASS_NAME = JahiaResourceBundle.class.getName();    public static final String ENGINE_DEFAULT_RESOURCE_BUNDLE 		= "JahiaEnginesResources";    //--------------------------------------------------------------------------    /**     * Returns the requested resource.     *     * If the requested resource bundle is missing and useDefault is true,     * Jahia will look for another engine resource bundle in that order :     *	 *     *		1. 	Look for the engine resource bundle of the current user.	 *         			This resource bundle can be set in the template used by the page	 *         			with the SetUsrEngineResourceBundleTag,SetGrpEngineResourceBundleTag.     *	 *     *		2. 	Look for the engine resource bundle of the page.	 *         			This resource bundle can be set in the template used by the page	 *         			with the SetEngineResourceBundleTag.     *	 *     *		3.  Look for the site's default engine resource bundle.	 *            Each site can have a default engine resource bundle. It's name	 *         			must be of this form : "JahiaEnginesResourcesMYJAHIASITE"	 *         			where MYJAHIASITE is the virtual site's sitekey in uppercase.     *	 *     *		4.  Finally if none of the previous resource bundle are available,	 *         			Jahia will return the internal engine's default resource bundle	 *         			named "JahiaEnginesResources".     *     *     * @param String resourceName, the resource name     * @param ParamBean jParams     * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()     *     * @return ResourceBundle, the requested resource bundle     *     * @see EngineResourceBundleTag     * @see SetEngineResourceBundleTag     * @see JahiaEnginesResources.properties     *     * @author Khue Nguyen     */    public static String getEngineResource(	String resourceName,                                            ParamBean jParams,                                            Locale locale ){        ResourceBundle res = null;        String resValue = null;        if ( resourceName == null || resourceName.trim().equals("") )            return null;        if ( locale == null )            locale = jParams.getLocale();                boolean adminMode = false;        try {            adminMode = jParams.isInAdminMode();        } catch ( Throwable t ){            t.printStackTrace();        }                    if ( !adminMode ) {            // first look for user's engine resource bundle            res = getGrpUsrEngineResourceBundle(jParams.getPageID(),jParams.getUser());            if ( res != null ){                try {                    resValue = res.getString(resourceName);                    return resValue;                } catch ( Throwable t ){                }            }                // second look for page's engine resource bundle            res = getPageEngineResourceBundle(jParams.getPageID(),jParams);            if ( res != null ){                try {                    resValue = res.getString(resourceName);                    return resValue;                } catch ( Throwable t ){                }            }                // third look for site's engine resource bundle            res = getSiteEngineResourceBundle(jParams.getSite(),jParams,locale);            if ( res != null ){                try {                    resValue = res.getString(resourceName);                    return resValue;                } catch ( Throwable t ){                }            }        }                    // fourth look for jahia's engine default resource bundle        res = getEngineDefaultResourceBundle(jParams,locale);        if ( res != null ){            try {                resValue = res.getString(resourceName);                return resValue;            } catch ( Throwable t ){            }        }        return null;    }    //--------------------------------------------------------------------------    /**     * Returns the requested resource bundle.     *     * If the requested resource bundle is missing and useDefault is true,     * Jahia will look for another engine resource bundle in that order :     *	 *     *		1. 	Look for the engine resource bundle of the current user.	 *         			This resource bundle can be set in the template used by the page	 *         			with the SetUsrEngineResourceBundleTag,SetGrpEngineResourceBundleTag.     *	 *     *		2. 	Look for the engine resource bundle of the page.	 *         			This resource bundle can be set in the template used by the page	 *         			with the SetEngineResourceBundleTag.     *	 *     *		3.  Look for the site's default engine resource bundle.	 *            Each site can have a default engine resource bundle. It's name	 *         			must be of this form : "JahiaEnginesResourcesMYJAHIASITE"	 *         			where MYJAHIASITE is the virtual site's sitekey in uppercase.     *	 *     *		4.  Finally if none of the previous resource bundle are available,	 *         			Jahia will return the internal engine's default resource bundle	 *         			named "JahiaEnginesResources".     *     *     * @param String resourceBundle, the resource bundle name     * @param ParamBean jParams     * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()     * @param boolean useDefault, when true , return Jahia engines' default resource bundle	 *                           	  if the requested resource bundle is missing.     *     * @return ResourceBundle, the requested resource bundle     * @author Khue Nguyen     */    public static ResourceBundle getEngineResourceBundle(                                                    String resourceBundle,                                                    ParamBean jParams,                                                    Locale locale,                                                    boolean useDefault ){        ResourceBundle res = null;        if ( locale == null )            locale = jParams.getLocale();        try {            res = ResourceBundle.getBundle(resourceBundle,locale);        } catch ( Throwable t ){            //JahiaConsole.println(CLASS_NAME+".getEngineResourceBundle",t.getMessage());        }        if ( ((res == null) && useDefault) && (jParams != null) ){            // first look for usr, grp's engine resource bundle            res = getGrpUsrEngineResourceBundle(jParams.getPageID(),jParams.getUser());                        if ( res == null ){                // second look for page's engine resource bundle                res = getPageEngineResourceBundle(jParams.getPageID(),jParams);            }            if ( res == null ){                // third look for site's engine resource bundle                res = getSiteEngineResourceBundle(jParams.getSite(),jParams,locale);            }            if ( res == null ){                // fourth look for jahia default engine resource bundle                res = getEngineDefaultResourceBundle(jParams,locale);            }        }        return res;    }    //--------------------------------------------------------------------------    /**     * Returns Jahia engines' default resource bundle     * This resource bundle's name is "JahiaEnginesResources"     *     * @param ParamBean jParams     * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()     *     * @return ResourceBundle, the Jahia engines' default resource bundle or null if not found     */    public static ResourceBundle getEngineDefaultResourceBundle(                                                    ParamBean jParams,                                                    Locale locale ){        if ( locale == null ){            if ( jParams != null ){                locale = jParams.getLocale();            } else {                locale = Locale.getDefault();            }        }        ResourceBundle res = null;        try {            res = ResourceBundle.getBundle(ENGINE_DEFAULT_RESOURCE_BUNDLE,locale);        } catch ( Throwable t ){            //JahiaConsole.println(	CLASS_NAME+".getEngineDefaultResourceBundle",            //						t.getMessage());        }        return res;    }    //--------------------------------------------------------------------------    /**     * Returns the current site engines' resource bundle     * Internally, Jahia look for a resource bundle whose name is :     *     * "JahiaEnginesResources" + jParams.getSite().getSiteKey().toUpperCase()     *     * like :	JahiaEnginesResourcesMYJAHIASITE     *     * @param JahiaSite site     * @param ParamBean jParams     * @param Locale locale, if null, uses the locale returned by ParamBean.getLocale()     *     * @return ResourceBundle, the site engines' default resource bundle or null if not found     */    public static ResourceBundle getSiteEngineResourceBundle( JahiaSite site,                                                              ParamBean jParams,                                                              Locale locale ){        if ( site == null )            return null;        if ( locale == null ){            if ( jParams != null ){                locale = jParams.getLocale();            } else {                locale = Locale.getDefault();            }        }        ResourceBundle res = null;        try {            res = ResourceBundle.getBundle( ENGINE_DEFAULT_RESOURCE_BUNDLE                                            +site.getSiteKey().toUpperCase(),locale);        } catch ( Throwable t ){            //JahiaConsole.println(	CLASS_NAME+".getSiteEngineResourceBundle",            //						t.getMessage());        }        return res;    }    //--------------------------------------------------------------------------    /**     * Returns the engine resource bundle associated with the page.     * With the SetEngineResourceBundleTag, you can associate an engine resource bundle     * with a template JSP.     *     * Jahia will use this resource bundle to give different look to the engines     * popup that are opened from pages using this template.     *     * @param int pageID, the page id     *     * @return ResourceBundle, the site engines' default resource bundle or null if not found     */    public static ResourceBundle getPageEngineResourceBundle( int pageID , ParamBean jParams){        if ( jParams == null )            return null;        if ( pageID == -1 )            return null;        JahiaPage page = null;        try {            page = ServicesRegistry.getInstance().getJahiaPageService().lookupPage(pageID,null);        } catch ( Throwable t) {            //JahiaConsole.println(	CLASS_NAME+".getPageEngineResourceBundle",            //						t.getMessage());        }        if ( (page == null) )            return null;        ResourceBundle res = null;        try {            res = PagesEngineResourceBundle.getInstance().getResourceBundle( page , jParams );        } catch ( Throwable t ){            //JahiaConsole.println(	CLASS_NAME+".getPageEngineResourceBundle",            //						t.getMessage());        }        return res;    }    //--------------------------------------------------------------------------    /**     * Returns the engine resource bundle associated with a page and a given Principal.     * With the SetUsrEngineResourceBundleTag and SetGrpEngineResourceBundleTag,      * you can associate an engine resource bundle with a template JSP for a given user or group.     *     * Jahia will use this resource bundle to give different look to the engines     * popup that are opened from pages using this template and for the current user.     *     * @param int pageID, the page id     *     * @return ResourceBundle, the grp or usr engines' default resource bundle or null if not found     */    public static ResourceBundle getGrpUsrEngineResourceBundle( int pageID , JahiaUser user){        if ( pageID == -1 || user==null )            return null;        JahiaPage page = null;        try {            page = ServicesRegistry.getInstance().getJahiaPageService().lookupPage(pageID,null);        } catch ( Throwable t) {            //JahiaConsole.println(	CLASS_NAME+".getPageEngineResourceBundle",            //						t.getMessage());        }        if ( (page == null) )            return null;        ResourceBundle res = null;        try {            res = GrpUsrEngineResourceBundle.getInstance().getResourceBundle( page , (Principal)user );        } catch ( Throwable t ){            //JahiaConsole.println(	CLASS_NAME+".getPageEngineResourceBundle",            //						t.getMessage());        }        return res;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -