001: /**
002: * $Id: CommandTag.java,v 1.5 2005/09/21 10:50:33 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.base;
014:
015: import com.sun.portal.log.common.PortalLogger;
016:
017: import javax.servlet.jsp.*;
018: import javax.servlet.jsp.tagext.*;
019: import java.util.logging.Logger;
020: import java.util.logging.Level;
021:
022: /**
023: * The CommandTag abstract class supports tags which execute
024: * a command or action. Subclasses must implement the
025: * abstract execute() method.
026: *
027: * @author Robert O'Brien
028: * @version 1.0
029: */
030: public abstract class CommandTag extends BaseTagSupport {
031:
032: // Create a logger for this class
033: private static Logger debugLogger = PortalLogger
034: .getLogger(CommandTag.class);
035:
036: /**
037: * Saves the status of command execution
038: */
039: protected boolean executeStatus = false;
040:
041: /**
042: * Execute the command action. Returns the command status.
043: * Subclasses must provide an implementation of this method.
044: * If the command fails then the tag body is included,
045: * Else if the command fails then the tag body is skipped.
046: *
047: * @return true if the command succeeds.
048: * false if the command fails.
049: * @exception JspException
050: */
051: public abstract boolean execute() throws JspException;
052:
053: /**
054: * Execute the command and include or skip the
055: * body depending on the command status. If the
056: * command succeeds then skip the tag body. If
057: * the command fails then include the tag body.
058: *
059: * @return SKIP_BODY if the command succeeds.
060: * EVAL_BODY_INCLUDE if the command fails.
061: * @exception JspException
062: */
063: public int doStartTag() throws JspException {
064: try {
065: executeStatus = execute();
066: } catch (Exception e) {
067: debugLogger.log(Level.FINE, "PSMA_CSPWTB0006", e);
068: throw new JspException(this .getClass().getName()
069: + ".doStartTag(): execute failed: "
070: + e.getMessage());
071: }
072: if (executeStatus) {
073: return SKIP_BODY;
074: } else {
075: return EVAL_BODY_INCLUDE;
076: }
077: }
078:
079: /**
080: * If command has succeeded then evaluate the rest
081: * of the page. If the command fails then skip the
082: * page.
083: *
084: * @return SKIP_PAGE if the command fails.
085: * EVAL_PAGE if the command suceeds.
086: * @exception JspException
087: */
088: public int doEndTag() throws JspException {
089: if (executeStatus) {
090: return EVAL_PAGE;
091: } else {
092: return SKIP_PAGE;
093: }
094: }
095:
096: /**
097: * Cleanup
098: */
099: public void release() {
100: super .release();
101: executeStatus = false;
102: }
103:
104: }
|