1 18 package org.apache.beehive.netui.tags.databinding.bundle; 19 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.tagext.TryCatchFinally ; 22 import javax.servlet.http.HttpServletRequest ; 23 import java.util.Locale ; 24 25 import org.apache.beehive.netui.tags.AbstractClassicTag; 26 import org.apache.beehive.netui.util.Bundle; 27 import org.apache.beehive.netui.script.common.BundleMap; 28 29 192 public class DeclareBundle 193 extends AbstractClassicTag 194 implements TryCatchFinally { 195 196 private String _name = null; 197 private String _bundlePath = null; 198 private String _language = null; 199 private String _country = null; 200 private String _variant = null; 201 202 208 public String getTagName() { 209 return "DeclareBundle"; 210 } 211 212 225 public void setLanguage(String language) { 226 _language = language; 227 } 228 229 242 public void setCountry(String country) { 243 _country = country; 244 } 245 246 255 public void setVariant(String variant) { 256 _variant = variant; 257 } 258 259 270 public void setName(String name) { 271 _name = name; 272 } 273 274 307 public void setBundlePath(String bundlePath) { 308 _bundlePath = bundlePath; 309 } 310 311 316 public int doStartTag() { 317 return SKIP_BODY; 318 } 319 320 329 public int doEndTag() 330 throws JspException { 331 332 if(_name.length() == 0) { 333 String msg = Bundle.getErrorString("Tags_DeclareBundle_invalidName", new Object []{_name}); 334 registerTagError(msg, null); 335 } 336 337 if(_name.equals(BundleMap.DEFAULT_STRUTS_BUNDLE_NAME)) { 338 String msg = Bundle.getErrorString("Tags_DeclareBundle_defaultIsReservedWord", null); 339 registerTagError(msg, null); 340 } 341 342 if(_bundlePath.length() == 0) { 343 String msg = Bundle.getErrorString("Tags_DeclareBundle_invalidResourcePath", new Object []{_bundlePath}); 344 registerTagError(msg, null); 345 } 346 347 Locale locale = getCurrentLocale(); 348 349 if(hasErrors()) { 350 reportErrors(); 351 return EVAL_PAGE; 352 } 353 354 BundleMap bundleMap = null; 355 Object obj = pageContext.getAttribute("bundle"); 356 if(obj == null) { 357 bundleMap = new BundleMap((HttpServletRequest )pageContext.getRequest(), pageContext.getServletContext()); 360 pageContext.setAttribute("bundle", bundleMap); 361 } 362 else if(!(obj instanceof BundleMap)) { 363 String msg = Bundle.getErrorString("Tags_DeclareBundle_wrongContextType", new Object []{obj.getClass().getName()}); 364 registerTagError(msg, null); 365 if(hasErrors()) 366 reportErrors(); 367 return EVAL_PAGE; 368 } 369 else 370 bundleMap = (BundleMap)obj; 371 372 bundleMap.registerResourceBundle(_name, _bundlePath, locale); 373 374 return EVAL_PAGE; 375 } 376 377 public void doFinally() { 378 localRelease(); 379 } 380 381 public void doCatch(Throwable t) 382 throws Throwable { 383 throw t; 384 } 385 386 389 protected void localRelease() { 390 super.localRelease(); 391 _name = null; 392 _bundlePath = null; 393 _language = null; 394 _country = null; 395 _variant = null; 396 } 397 398 private Locale getCurrentLocale() 399 throws JspException { 400 if(_language == null && _country == null && _variant == null) 401 return getUserLocale(); 402 403 if(hasErrors()) 404 return null; 405 406 if(_language != null && _country != null && _variant != null) 407 return new Locale (_language, _country, _variant); 408 else if(_language != null && _country != null) 409 return new Locale (_language, _country); 410 else if(_language != null) 411 return new Locale (_language); 412 else if(_country != null || _variant != null) { 413 String msg = Bundle.getErrorString("Tags_DeclareBundle_invalidLocaleOverride", new Object []{_language, _country, _variant}); 414 registerTagError(msg, null); 415 } 416 417 return getUserLocale(); 418 } 419 } 420 | Popular Tags |