1 package org.jahia.taglibs.resourcebundle; 2 3 import java.util.Locale ; 4 import java.util.ResourceBundle ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.jsp.JspException ; 8 import javax.servlet.jsp.tagext.TagSupport ; 9 10 import org.jahia.data.JahiaData; 11 import org.jahia.resourcebundle.PagesEngineResourceBundle; 12 13 14 22 public class SetEngineResourceBundleTag extends TagSupport { 23 24 private static final String CLASS_NAME = 25 SetEngineResourceBundleTag.class.getName(); 26 27 private String resourceBundle = ""; 28 private String localeLangage = ""; 29 private String localeCountry = ""; 30 private String localeVariant = ""; 31 private Locale locale = null; 32 33 public void setResourceBundle(String resourceBundle) { 34 if ( resourceBundle == null ) 35 resourceBundle = ""; 36 this.resourceBundle = resourceBundle.trim(); 37 } 38 39 public void setLocaleLangage(String localeLangage) { 40 if ( localeLangage != null ) 41 this.localeLangage = localeLangage.trim(); 42 } 43 44 public void setLocaleCountry(String localeCountry) { 45 if ( localeCountry != null ) 46 this.localeCountry = localeCountry.trim(); 47 } 48 49 public void setLocaleVariant(String localeVariant) { 50 if ( localeVariant != null ) 51 this.localeVariant = localeVariant.trim(); 52 } 53 54 public int doStartTag() { 55 56 57 HttpServletRequest request = (HttpServletRequest )pageContext.getRequest(); 58 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 59 60 ResourceBundle res = null; 61 String resValue = null; 62 63 if ( localeLangage.equals("") ){ 64 locale = jData.params().getLocale(); 65 } else { 66 locale = new Locale (localeLangage,localeCountry,localeVariant); 67 } 68 69 res = ResourceBundle.getBundle(resourceBundle,locale); 70 71 if (res != null) { 72 try { 73 PagesEngineResourceBundle.getInstance().addResourceBundle( jData.params().getContentPage(), res , jData.params() ); 74 } catch (Throwable t){ 75 } 76 } 77 78 return SKIP_BODY; 79 80 } 81 82 public int doEndTag() throws JspException { 83 resourceBundle = ""; 86 localeLangage = ""; 87 localeCountry = ""; 88 localeVariant = ""; 89 locale = null; 90 return EVAL_PAGE; 91 } 92 93 } 94 | Popular Tags |