1 package org.jahia.deprecated.taglibs.resourcebundle; 2 3 import java.io.IOException ; 4 import java.util.Locale ; 5 import java.util.MissingResourceException ; 6 import java.util.ResourceBundle ; 7 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpSession ; 10 import javax.servlet.jsp.JspException ; 11 import javax.servlet.jsp.JspWriter ; 12 import javax.servlet.jsp.tagext.TagSupport ; 13 14 import org.jahia.data.JahiaData; 15 import org.jahia.params.ParamBean; 16 import org.jahia.resourcebundle.JahiaResourceBundle; 17 import org.jahia.utils.JahiaConsole; 18 import org.jahia.utils.JahiaTools; 19 20 21 49 public class EngineResourceBundleTag extends TagSupport { 50 51 private static final String CLASS_NAME = EngineResourceBundleTag.class.getName(); 52 53 public static final String JAHIA_ENGINE_TAG = "<jahiaEngine>"; 54 public static final String SITE_TEMPLATE_TAG = "<siteTemplate>"; 55 56 private String resourceName = ""; 57 private String defaultValue = ""; 58 59 public void setDefaultValue(String value) { 60 this.defaultValue = value; 61 } 62 63 public void setResourceName(String resourceName) { 64 if ( resourceName == null ) 65 resourceName = ""; 66 this.resourceName = resourceName; 67 } 68 69 public void displayError(String message) { 70 try { 71 JspWriter out = pageContext.getOut(); 72 out.print( "<!--" + CLASS_NAME + ":" + message + "-->" ); 73 } catch (IOException ioe) { 74 JahiaConsole.println(CLASS_NAME+"doStartTag", ioe.toString()); 75 } 76 } 77 78 public int doStartTag() { 79 80 HttpServletRequest request = (HttpServletRequest )pageContext.getRequest(); 81 JahiaData jData = (JahiaData) request.getAttribute("org.jahia.data.JahiaData"); 82 83 Locale currentLocale = request.getLocale(); 84 HttpSession session = pageContext.getSession(); 85 if (session != null) { 86 if (session.getAttribute(ParamBean.SESSION_LOCALE) != null) { 87 currentLocale = (Locale ) session.getAttribute(ParamBean. 88 SESSION_LOCALE); 89 } 90 } 91 92 String resValue = null; 93 94 try { 95 if ( jData != null ){ 96 resValue = JahiaResourceBundle 97 .getEngineResource( resourceName, 98 jData.params(), 99 jData.params().getLocale() ); 100 } else { 101 ResourceBundle resBundle = JahiaResourceBundle 103 .getEngineDefaultResourceBundle(null,currentLocale); 104 resValue = resBundle.getString(resourceName); 105 } 106 } catch ( MissingResourceException mre ) { 107 JahiaConsole.println(CLASS_NAME+"doStartTag", mre.toString()); 108 } 109 110 if (resValue == null) { 111 resValue = this.defaultValue; 112 } 113 114 try { 115 JspWriter out = pageContext.getOut(); 116 if ( jData != null ){ 117 out.print( parseResourceValue(resValue,jData.params()) ); 118 } else { 119 out.print(parseResourceValue(resValue,null)); 120 } 121 } catch (IOException ioe) { 122 JahiaConsole.println(CLASS_NAME+"doStartTag", ioe.toString()); 123 } 124 125 return SKIP_BODY; 126 127 } 128 129 140 public static String parseResourceValue(String val,ParamBean jParams){ 141 142 if ( (val == null) || (jParams == null) || (jParams.getSite()== null) ) 143 return val; 144 val = JahiaTools.replacePattern(val,JAHIA_ENGINE_TAG, 145 "/jsp/jahia/engines/"); 146 147 val = JahiaTools.replacePattern(val,SITE_TEMPLATE_TAG, 148 "/jsp/jahia/templates/" + jParams.getSite().getSiteKey() + "/"); 149 150 return val; 151 152 } 153 154 public int doEndTag() throws JspException { 155 resourceName = ""; 158 return EVAL_PAGE; 159 } 160 161 162 } 163 | Popular Tags |