1 package org.jahia.deprecated.taglibs.resourcebundle; 2 3 import java.io.IOException ; 4 import java.util.Locale ; 5 import java.util.MissingResourceException ; 6 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpSession ; 9 import javax.servlet.jsp.JspException ; 10 import javax.servlet.jsp.JspWriter ; 11 import javax.servlet.jsp.tagext.TagSupport ; 12 13 import org.jahia.params.ParamBean; 14 import org.jahia.resourcebundle.JahiaResourceBundle; 15 import org.jahia.utils.JahiaConsole; 16 17 18 29 public class MessageTag extends TagSupport { 30 31 private static final String CLASS_NAME = MessageTag.class.getName(); 32 33 private String key = ""; 34 35 public void setKey(String key) { 36 if ( key == null ) 37 key = ""; 38 this.key = key; 39 } 40 41 public int doStartTag() { 42 43 HttpServletRequest request = (HttpServletRequest )pageContext.getRequest(); 44 String resValue = null; 45 46 Locale currentLocale = request.getLocale(); 47 HttpSession session = pageContext.getSession(); 48 if (session != null) { 49 if (session.getAttribute(ParamBean.SESSION_LOCALE) != null) { 50 currentLocale = (Locale ) session.getAttribute(ParamBean. 51 SESSION_LOCALE); 52 } 53 } 54 55 try { 56 resValue = JahiaResourceBundle 57 .getMessageResource( key, 58 currentLocale ); 59 60 } catch ( MissingResourceException mre ) { 61 JahiaConsole.println(CLASS_NAME+"doStartTag", mre.toString()); 62 } 63 64 if (resValue == null) { 65 resValue = ""; 66 } 67 68 try { 69 JspWriter out = pageContext.getOut(); 70 out.print( resValue ); 71 out.flush(); 72 } catch (IOException ioe) { 73 JahiaConsole.println(CLASS_NAME+"doStartTag", ioe.toString()); 74 } 75 76 return SKIP_BODY; 77 78 } 79 80 public int doEndTag() throws JspException { 81 key = ""; 84 return EVAL_PAGE; 85 } 86 87 88 } 89 | Popular Tags |