001: /**
002: * $Id: CatalogTag.java,v 1.5 2005/09/21 10:53:11 dg154973 Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wireless.taglibs.util;
014:
015: import java.util.Locale;
016: import java.util.logging.Logger;
017:
018: import javax.servlet.jsp.*;
019: import javax.servlet.jsp.tagext.*;
020:
021: import com.sun.portal.log.common.PortalLogger;
022: import com.sun.portal.wireless.taglibs.base.*;
023:
024: /**
025: * CatalogTag - make a message catalog available
026: *
027: * Attributes:
028: *
029: * id - name to save catalog on page context
030: * name - name to retrieve catalog from page context
031: * resource - name of resource to load
032: *
033: * @author Bryan Hanks
034: * @author Robert O'Brien
035: *
036: * @version 1.0
037: */
038: public class CatalogTag extends BaseTagSupport implements BeanHolder {
039:
040: private static Logger logger = PortalLogger
041: .getLogger(CatalogTag.class);
042: /**
043: * The message catalog
044: */
045: Catalog catalog;
046:
047: /**
048: * Name of the resource bundle
049: */
050: String resource;
051:
052: /**
053: * Return the message catalog
054: *
055: * @return the message catalog
056: */
057: public Catalog getCatalog() {
058: return catalog;
059: }
060:
061: /**
062: * Return the catalog as a bean
063: *
064: * @return the message catalog
065: */
066: public Object getBean() {
067: return catalog;
068: }
069:
070: /**
071: * Make the message catalog available
072: *
073: * @return EVAL_BODY_INCLUDE
074: * @exception JspException
075: */
076: public int doStartTag() throws JspException {
077:
078: if (name != null) {
079: catalog = (Catalog) pageContext.findAttribute(name);
080: if (catalog != null) {
081: return EVAL_BODY_INCLUDE;
082: }
083: }
084:
085: if (resource == null) {
086: logger.warning("PSMA_CSPWTU0006");
087: throw new JspException(
088: "CatalogTag: missing 'resource' attribute");
089: }
090:
091: catalog = new Catalog(resource, getLocale());
092:
093: if (id != null) {
094: pageContext.setAttribute(id, catalog);
095: }
096:
097: return EVAL_BODY_INCLUDE;
098: }
099:
100: /**
101: * Get the user's locale
102: *
103: * @return
104: */
105: private Locale getLocale() {
106: try {
107: UtilContext uc = UtilContext.getContext(pageContext);
108: return uc.getLocale();
109: } catch (Exception e) {
110: return Locale.getDefault();
111: }
112: }
113:
114: /**
115: * Set the resource attribute
116: *
117: * @param resource the resource
118: */
119: public void setResource(String resource) {
120: this .resource = resource;
121: }
122:
123: /**
124: * Cleanup
125: */
126: public void release() {
127: super.release();
128: resource = null;
129: catalog = null;
130: }
131: }
|