1 64 65 package com.jcorporate.expresso.ext.struts.taglib.html; 66 67 import com.jcorporate.expresso.core.controller.ControllerException; 68 import com.jcorporate.expresso.core.controller.ControllerResponse; 69 import com.jcorporate.expresso.core.i18n.Messages; 70 import com.jcorporate.expresso.core.misc.StringUtil; 71 import com.jcorporate.expresso.ext.struts.taglib.ControllerUtils; 72 import org.apache.struts.taglib.html.HtmlTag; 73 import org.apache.struts.util.ResponseUtils; 74 75 import javax.servlet.ServletResponse ; 76 import javax.servlet.jsp.JspException ; 77 import javax.servlet.jsp.PageContext ; 78 import java.util.Locale ; 79 80 81 86 public class ExHtmlTag 87 extends HtmlTag { 88 95 public int doStartTag() 96 throws JspException { 97 ControllerResponse myResponse = ControllerUtils.getResponse(pageContext); 98 String charset = ""; 99 Locale l = null; 100 101 if (myResponse != null) { 102 try { 103 charset = StringUtil.notNull(myResponse.getString("charset")); 104 l = myResponse.getLocale(); 105 } catch (ControllerException ce) { 106 ce.printStackTrace(System.out); 107 throw new JspException (ce.getMessage()); 108 } 109 } else { 110 l = (Locale ) pageContext.getAttribute(Messages.LOCALE_KEY, 111 PageContext.SESSION_SCOPE); 112 113 if (l == null) { 114 l = Locale.getDefault(); 115 } 116 charset = Messages.getString(l, "charset"); 117 } 118 if (charset.equals("")) { 119 charset = "ISO-8859-1"; 120 } 121 122 ServletResponse res = pageContext.getResponse(); 123 res.setContentType("text/html;charset=" + charset); 124 125 StringBuffer sb = new StringBuffer ("<html"); 126 127 Locale currentLocale = l; 129 130 if (currentLocale != null) { 131 String lang = currentLocale.getLanguage(); 132 133 if ((lang != null) && (lang.length() > 0)) { 134 sb.append(" lang=\""); 135 sb.append(lang); 136 sb.append("\""); 137 138 if (xhtml) { 139 sb.append(" xml:lang=\""); 140 sb.append(lang); 141 sb.append("\""); 142 } 143 } 144 } 145 146 sb.append(">"); 147 sb.append("\n<meta http-equiv=\"Content-Type\" content=\"text/" + 148 "html;charset=" + charset + "\">"); 149 150 ResponseUtils.write(pageContext, sb.toString()); 152 153 return (EVAL_BODY_INCLUDE); 155 } 156 } | Popular Tags |