TableColumnTag.java :  » J2EE » Jaffa » org » jaffa » presentation » portlet » widgets » taglib » Java Open Source

Java Open Source » J2EE » Jaffa 
Jaffa » org » jaffa » presentation » portlet » widgets » taglib » TableColumnTag.java
/*
 * ====================================================================
 * JAFFA - Java Application Framework For All
 *
 * Copyright (C) 2002 JAFFA Development Group
 *
 *     This library is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU Lesser General Public
 *     License as published by the Free Software Foundation; either
 *     version 2.1 of the License, or (at your option) any later version.
 *
 *     This library is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *     Lesser General Public License for more details.
 *
 *     You should have received a copy of the GNU Lesser General Public
 *     License along with this library; if not, write to the Free Software
 *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Redistribution and use of this software and associated documentation ("Software"),
 * with or without modification, are permitted provided that the following conditions are met:
 * 1.  Redistributions of source code must retain copyright statements and notices.
 *         Redistributions must also contain a copy of this document.
 * 2.  Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 * 3.  The name "JAFFA" must not be used to endorse or promote products derived from
 *   this Software without prior written permission. For written permission,
 *   please contact mail to: jaffagroup@yahoo.com.
 * 4.  Products derived from this Software may not be called "JAFFA" nor may "JAFFA"
 *   appear in their names without prior written permission.
 * 5.  Due credit should be given to the JAFFA Project (http://jaffa.sourceforge.net).
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 */

package org.jaffa.presentation.portlet.widgets.taglib;

import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.ServletRequest;
import java.io.PrintWriter;
import java.io.IOException;
import org.apache.log4j.Logger;
import org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterTableTagMissingRuntimeException;
import org.jaffa.util.MessageHelper;
import javax.servlet.jsp.tagext.TryCatchFinally;

/** Tag Handler for the TableColumn widget.*/
public class TableColumnTag extends TagSupport implements TryCatchFinally {

    private static Logger log = Logger.getLogger(TableColumnTag.class);
    private static final String TAG_NAME = "TableColumn";


    /** property declaration for tag attribute: column.
     */
    private String m_column;

    /** property declaration for tag attribute: title.
     */
    private String m_title;

    /** property declaration for tag attribute: width.
     */
    private String m_width;

    /** This variable contains the parent (enclosing) tag. */
    private TableTag m_tableTag = null;

    /** The value for this field will be computed based on m_title */
    private String m_labelEditorLink;
    
    /** Default constructor.
     */
    public TableColumnTag() {
        super();
        initTag();
    }

    private void initTag() {
        m_column = null;
        m_title = null;
        m_width = null;
        m_tableTag = null;
        m_labelEditorLink = "";
    }



    ////////////////////////////////////////////////////////////////
    ///                                                          ///
    ///   User methods.                                          ///
    ///                                                          ///
    ///   Modify these methods to customize your tag handler.    ///
    ///                                                          ///
    ////////////////////////////////////////////////////////////////


    //
    // methods called from doStartTag()
    //
    /** This adds a column to the outer TableTag.
     */
    public void otherDoStartTagOperations()  {

        //
        // TODO: code that performs other operations in doStartTag
        //       should be placed here.
        //       It will be called after initializing variables,
        //       finding the parent, setting IDREFs, etc, and
        //       before calling theBodyShouldBeEvaluated().
        //

        // TableTag should be present
        if (m_tableTag == null) {
            String str = "The " + TAG_NAME + " for column " + getColumn() + " should be inside a TableTag";
            log.error(str);
            throw new OuterTableTagMissingRuntimeException(str);
        }

        // just add the column to the TableTag
        m_tableTag.addColumn(m_column, m_title, m_width, m_labelEditorLink);
    }

    /** Returns a false.
     * @return a false.
     */
    public boolean theBodyShouldBeEvaluated()  {

        //
        // TODO: code that determines whether the body should be
        //       evaluated should be placed here.
        //       Called from the doStartTag() method.
        //
        //return true;
        return false;

    }


    //
    // methods called from doEndTag()
    //
    /** Does nothing.
     */
    public void otherDoEndTagOperations()  {

        //
        // TODO: code that performs other operations in doEndTag
        //       should be placed here.
        //       It will be called after initializing variables,
        //       finding the parent, setting IDREFs, etc, and
        //       before calling shouldEvaluateRestOfPageAfterEndTag().
        //


    }

    /** Returns a true.
     * @return a true.
     */
    public boolean shouldEvaluateRestOfPageAfterEndTag()  {

        //
        // TODO: code that determines whether the rest of the page
        //       should be evaluated after the tag is processed
        //       should be placed here.
        //       Called from the doEndTag() method.
        //
        return true;

    }


    //
    // methods called from doAfterBody()
    //
    /** Returns a false.
     * @return a false.
     */
    public boolean theBodyShouldBeEvaluatedAgain()  {

        //
        // TODO: code that determines whether the tag body should be
        //       evaluated again after processing the tag
        //       should be placed here.
        //       You can use this method to create iterating tags.
        //       Called from the doAfterBody() method.
        //
        return false;

    }


    ////////////////////////////////////////////////////////////////
    ///                                                          ///
    ///   Tag Handler interface methods.                         ///
    ///                                                          ///
    ///   Do not modify these methods; instead, modify the       ///
    ///   methods that they call.                                ///
    ///                                                          ///
    ////////////////////////////////////////////////////////////////


    /** .//GEN-BEGIN:doStartTag
     *
     * This method is called when the JSP engine encounters the start tag,
     * after the attributes are processed.
     * Scripting variables (if any) have their values set here.
     * @return EVAL_BODY_TAG if the JSP engine should evaluate the tag body, otherwise return SKIP_BODY.
     * This method is automatically generated. Do not modify this method.
     * Instead, modify the methods that this method calls.
     *
     */
    public int doStartTag() throws JspException {
        //
        // Then we find the parent (enclosing tag)
        //
        if (m_tableTag == null) {
            m_tableTag = (TableTag)findAncestorWithClass(this, TableTag.class);
        }

        otherDoStartTagOperations();

        if (theBodyShouldBeEvaluated()) {
            return EVAL_BODY_INCLUDE;
        } else {
            return SKIP_BODY;
        }
    }//GEN-END:doStartTag

    /** .//GEN-BEGIN:doEndTag
     *
     *
     * This method is called after the JSP engine finished processing the tag.
     * @return EVAL_PAGE if the JSP engine should continue evaluating the JSP page, otherwise return SKIP_PAGE.
     * This method is automatically generated. Do not modify this method.
     * Instead, modify the methods that this method calls.
     *
     */
    public int doEndTag() throws JspException {
        otherDoEndTagOperations();

        if (shouldEvaluateRestOfPageAfterEndTag()) {
            return EVAL_PAGE;
        } else {
            return SKIP_PAGE;
        }
    }//GEN-END:doEndTag

    /** Getter for the attribute column.
     * @return Value of attribute column.
     */
    public String getColumn() {
        return m_column;
    }

    /** Setter for the attribute column.
     * @param value New value of attribute column.
     */
    public void setColumn(String value) {
        m_column = value;
    }

    /** Getter for the attribute title.
     * @return Value of attribute title.
     */
    public String getTitle() {
        return m_title;
    }

    /** Setter for the attribute title.
     * @param value New value of attribute title.
     */
    public void setTitle(String value) {
        if (value != null) {
            m_title = MessageHelper.replaceTokens(pageContext, value);
            if (MessageHelper.hasTokens(value))
                m_labelEditorLink = TagHelper.getLabelEditorLink(pageContext, value);
        } else
            m_title = value;
    }

    /** Getter for the attribute width.
     * @return Value of attribute width.
     */
    public String getWidth() {
        return m_width;
    }

    /** Setter for the attribute width.
     * @param value New value of attribute width.
     */
    public void setWidth(String value) {
        m_width = value;
    }

    /** Invoked if a Throwable occurs while evaluating the BODY inside a tag or in any of the following methods: Tag.doStartTag(), Tag.doEndTag(), IterationTag.doAfterBody() and BodyTag.doInitBody().
     * This method is not invoked if the Throwable occurs during one of the setter methods.
     * This method will merely re-throw the input Throwable.
     * @param t The throwable exception navigating through this tag
     * @throws Throwable The throwable exception navigating through this tag.
     */
    public void doCatch(Throwable t) throws Throwable {
        throw t;
    }

    /** Invoked in all cases after doEndTag() for any class implementing Tag, IterationTag or BodyTag. This method is invoked even if an exception has occurred in the BODY of the tag, or in any of the following methods: Tag.doStartTag(), Tag.doEndTag(), IterationTag.doAfterBody() and BodyTag.doInitBody().
     * This method is not invoked if the Throwable occurs during one of the setter methods.
     * This will reset the internal fields, so that the Tag can be re-used.
     */
    public void doFinally() {
        initTag();
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.