/* ====================================================================
* The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
*
* Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 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 end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by Jcorporate Ltd.
* (http://www.jcorporate.com/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. "Jcorporate" and product names such as "Expresso" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written permission,
* please contact info@jcorporate.com.
*
* 5. Products derived from this software may not be called "Expresso",
* or other Jcorporate product names; nor may "Expresso" or other
* Jcorporate product names appear in their name, without prior
* written permission of Jcorporate Ltd.
*
* 6. No product derived from this software may compete in the same
* market space, i.e. framework, without prior written permission
* of Jcorporate Ltd. For written permission, please contact
* partners@jcorporate.com.
*
* 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 JCORPORATE LTD 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.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Jcorporate Ltd. Contributions back
* to the project(s) are encouraged when you make modifications.
* Please send them to support@jcorporate.com. For more information
* on Jcorporate Ltd. and its products, please see
* <http://www.jcorporate.com/>.
*
* Portions of this software are based upon other open source
* products and are subject to their respective licenses.
*/
package com.jcorporate.expresso.ext.struts.taglib.html;
/*
* ExLayerTag.java
*
* Copyright 2002, 2002 Yves Henri AMAIZO.
* amy_amaizo@compuserve.com
*/
import com.jcorporate.expresso.core.misc.StringUtil;
import org.apache.struts.taglib.html.BaseFieldTag;
import org.apache.struts.util.ResponseUtils;
import javax.servlet.jsp.JspException;
/**
*
* Sample:
* <code>
* <%@taglib uri="/WEB-INF/tld/expresso.tld" prefix="expresso"%>
* <%@taglib uri="/WEB-INF/tld/expresso-html.tld" prefix="html"%>
* <html:html locale="true">
* <head>
* <TITLE>Sample TagLib Layer</TITLE>
* </head>
* <body>
* <html:form action="/expresso/Test.do">
* <table border="0" bgcolor="red">
* <tr>
* <TD width="10">Titre1</TD>
* <TD align="left" width="10"><html:radioLayer property="toto" id="titi" action="show" value="Yes"/>Yes</TD>
* <TD width="100%"align="left"><html:radioLayer property="toto" id="titi" action="hide" value="No"/>No</TD>
* </tr>
* <TR height="1">
* <TD colspan="3" height="1">
* <html:layer id="titi" state="hide">
* <table border="0" bgcolor="GREEN">
* <tr>
* <TD bgcolor="WHITE">Titre2</TD>
* <TD bgcolor="WHITE"><html:radioLayer property="toto" id="titi2" action="show" value="Yes"/>Yes</TD>
* <TD bgcolor="WHITE"><html:radioLayer property="toto" id="titi2" action="hide" value="No"/>No</TD>
* </tr>
* <tr height="1" bgcolor="WHITE">
* <TD height="1" colspan="3" bgcolor="WHITE"><html:layer id="titi2" state="hide"><expresso:InputTag name="toto"/></html:layer></TD>
* </tr>
* </table>
* </html:layer>
* </TD>
* </tr>
* </table>
* </html:form>
* </body>
* </html:html>
* </code>
*
*/
/**
* Tag for input fields of type "Layer".
*
* @author Yves Henri AMAIZO
*/
public class ExLayerTag extends BaseFieldTag {
private String id = "";
private String state = "SHOW";
private String tag = "SPAN";
private static String SPAN = "SPAN";
private static String DIV = "DIV";
private static String FONT = "FONT";
protected static String SHOW = "block";
protected static String HIDE = "none";
/**
* Constructor for LayerTag
*/
public ExLayerTag() {
super();
}
public int doStartTag() throws JspException {
StringBuffer results = new StringBuffer();
results.append("<");
results.append(tag);
results.append(" id=\"");
results.append(id);
results.append("\"");
results.append(prepareEventHandlers());
String style = StringUtil.notNull(getStyle());
setStyle("display:" + state + ";" + style);
results.append(prepareStyles());
results.append(">");
ResponseUtils.write(pageContext, results.toString());
//return EVAL_BODY_TAG;
return EVAL_BODY_BUFFERED;
}
public int doEndTag() throws JspException {
StringBuffer results = new StringBuffer();
results.append(getBodyContent().getString());
results.append("</");
results.append(tag);
results.append(">");
ResponseUtils.write(pageContext, results.toString());
return EVAL_PAGE;
}
/**
* Gets the id
*
* @return Returns a String
*/
public String getId() {
return id;
}
/**
* Sets the id
*
* @param id The id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* Gets the display
*
* @return Returns a String
*/
public String getState() {
return state;
}
/**
* Sets the display
*
* @param state The display to set
* @throws JspException for invalid parameters
*/
public void setState(String state) throws JspException {
if (state.equalsIgnoreCase("SHOW")) {
this.state = SHOW;
} else {
if (state.equalsIgnoreCase("HIDE")) {
this.state = HIDE;
} else {
throw new JspException("state must be hide or show");
}
}
}
/**
* Gets the tag
*
* @return Returns a String
*/
public String getTag() {
return tag;
}
/**
* Sets the tag
*
* @param tag The tag to set
* @throws JspException for invalid parameters
*/
public void setTag(String tag) throws JspException {
if (tag.equalsIgnoreCase(SPAN)) {
this.tag = SPAN;
} else {
if (tag.equalsIgnoreCase(DIV)) {
this.tag = DIV;
} else {
if (tag.equalsIgnoreCase(FONT)) {
this.tag = FONT;
} else {
throw new JspException("tag must be 'span' 'div' or 'font'");
}
}
}
}
}
|