📄 setusrengineresourcebundletag.java
字号:
package org.jahia.taglibs.resourcebundle;import java.util.Locale;import java.util.ResourceBundle;import java.security.Principal;import java.io.*;import java.util.*;import javax.servlet.http.*;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;import org.jahia.data.JahiaData;import org.jahia.services.pages.JahiaPage;import org.jahia.exceptions.JahiaException;import org.jahia.utils.JahiaConsole;import org.jahia.resourcebundle.JahiaResourceBundle;import org.jahia.resourcebundle.GrpUsrEngineResourceBundle;import org.jahia.services.usermanager.*;import org.jahia.registries.ServicesRegistry;/** * This tag should be called on top of each template JSP file to associate a res bun. with a given grp. * It is used to allow template designer to provide a different engine resource bunlde * that Jahia will use to give different look to the engines * popup that are opened from pages using this template and for a given user. * * @author Khue Nguyen */public class SetUsrEngineResourceBundleTag extends TagSupport { private static final String CLASS_NAME = SetUsrEngineResourceBundleTag.class.getName(); private String resourceBundle = ""; private String localeLangage = ""; private String localeCountry = ""; private String localeVariant = ""; private Locale locale = null; private String userName = null; public void setResourceBundle(String resourceBundle) { if ( resourceBundle == null ) resourceBundle = ""; this.resourceBundle = resourceBundle.trim(); } public void setLocaleLangage(String localeLangage) { if ( localeLangage != null ) this.localeLangage = localeLangage.trim(); } public void setLocaleCountry(String localeCountry) { if ( localeCountry != null ) this.localeCountry = localeCountry.trim(); } public void setLocaleVariant(String localeCountry) { if ( localeVariant != null ) this.localeVariant = localeVariant.trim(); } public void setUserName(String userName) { if ( userName != null ) this.userName = userName.trim(); } public int doStartTag() { HttpServletRequest request = (HttpServletRequest)pageContext.getRequest(); JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); if (jData == null) { HashMap tempEngineMap = (HashMap) request.getAttribute("org.jahia.engines.EngineHashMap"); jData = (JahiaData) tempEngineMap.get("jData"); } ResourceBundle res = null; String resValue = null; if ( localeLangage.equals("") ){ locale = jData.params().getLocale(); } else { locale = new Locale(localeLangage,localeCountry,localeVariant); } res = ResourceBundle.getBundle(resourceBundle,locale); if (res != null) { try { JahiaUser usr = ServicesRegistry.getInstance().getJahiaUserManagerService().lookupUser(jData.params().getSiteID(),this.userName); if ( usr == null ){ // check if the user is the root admin. usr = ServicesRegistry.getInstance().getJahiaUserManagerService().lookupUser(0,this.userName); } if ( usr != null ){ GrpUsrEngineResourceBundle.getInstance().addResourceBundle( jData.params().getPage(), (Principal)usr, res ); } } catch (Throwable t){ } } return SKIP_BODY; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -