001: /**
002: * $Id: CatMsgTag.java,v 1.7 2005/09/21 10:53:06 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.logging.Level;
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: * CatMsgTag - Retrieves a message from a message catalog as
026: * specified by the 'key ' attribute
027: *
028: * @author Bryan Hanks
029: * @author Robert O'Brien
030: * @version 1.0
031: */
032: public class CatMsgTag extends BaseTagSupport {
033:
034: private static Logger logger = PortalLogger
035: .getLogger(CatMsgTag.class);
036: /**
037: * Message key
038: */
039: String key;
040:
041: /**
042: * Default value.
043: */
044: String dfault = null;
045:
046: /**
047: * Find the message catalog to use and write the message to the page.
048: * If default provided, and no message found for key, return default (NMJ: CR 4972546)
049: *
050: * @return SKIP_BODY
051: */
052: public int doStartTag() throws JspException {
053:
054: Catalog catalog;
055:
056: if (name != null) {
057: catalog = (Catalog) pageContext.getAttribute(name);
058: } else {
059: CatalogTag catalogtag = (CatalogTag) findAncestorWithClass(
060: this , CatalogTag.class);
061: catalog = catalogtag.getCatalog();
062: }
063:
064: if (catalog == null) {
065: logger.warning("PSMA_CSPWTU0012");
066: throw new JspException("No catalog found");
067: }
068:
069: try {
070: String rslt = catalog.getMsg(key, dfault);
071: if (rslt == null) {
072: String s = "Can't find resource for catalog " + name
073: + ", with key " + key;
074: logger.warning("PSMA_CSPWTU0012");
075: throw new JspException(s);
076: }
077:
078: if (id == null) {
079: pageContext.getOut().print(rslt);
080: } else {
081: // handle indirect message display e.g. 'process' handling
082: pageContext.setAttribute(id, rslt);
083: }
084: } catch (java.io.IOException e) {
085: logger.log(Level.SEVERE, "", e);
086: throw new JspException("IOException: " + e.getMessage());
087: }
088:
089: return SKIP_BODY;
090: }
091:
092: /**
093: * Set the message key attribute
094: *
095: * @param key message key
096: */
097: public void setKey(String key) {
098: this .key = evalAttribute(key); // eval necessary for folderName substitution (NMJ: CR 4972546)
099: }
100:
101: /**
102: * Set the default value.
103: * @param dfault
104: */
105: public void setDefault(String dfault) {
106: this .dfault = evalAttribute(dfault);
107: }
108:
109: /**
110: * Cleanup
111: */
112: public void release() {
113: key = null;
114: }
115: }
|