Hi there,

I've sent a zip file a few days ago, but it seems it
is in difficult to download format. Can you download
it? Now I re-send it in plain text format.


Cheers,
Kelvin Yap
[EMAIL PROTECTED]








__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

Attachment: struts-menu.tld
Description: struts-menu.tld

/*
 * MenuBase.java
 *
 * Created on January 28, 2001, 7:28 PM
 */

package com.fgm.web.menu;

/**
 * This revised version contains one additional property - 'action', 
 * as well as it's getter & setter method. The 'action' property is
 * used in the new <CODE>DisplayActionMenuTag</CODE>.
 * <p>Revision done by <a href="mailto:[EMAIL PROTECTED]">Kelvin Yap</a>
 * @author  ssayles
 * @version $Revision date: July 25, 2003, 3:00 PM $
 */
public abstract class MenuBase {

    /** Holds value of property name. */
    protected String name;
    /** Holds value of property title. */
    protected String title;
    /** Holds value of property location. */
    protected String location;
    /** Holds value of property target. */
    protected String target;
    /** Holds value of property description. */
    protected String description;
    /** Holds value of property onClick. */
    protected String onClick;
    /** Holds value of property onMouseOver. */
    protected String onMouseOver;
    /** Holds value of property onMouseOut. */
    protected String onMouseOut;
    /** Holds value of property image. */
    private String image;
    /** Holds value of property altImage. */
    private String altImage;
    /** Holds value of property toolTip. */
    private String toolTip;
    /** Holds value of property roles. */
    private String roles;
    
    /** Holds value of property page. */
    private String page;

    /** Holds value of property action, that is, Struts Logical Action Name. */
    private String action;
    
    /** Creates new MenuBase */
    public MenuBase() {}
    
    /** Getter for property name.
     * @return Value of property name.
     */
    public String getName() {
        return name;
    }
    /** Setter for property name.
     * @param name New value of property name.
     */
    public void setName(String name) {
        this.name = name;
    }
    /** Getter for property title.
     * @return Value of property title.
     */
    public String getTitle() {
        return title;
    }
    /** Setter for property title.
     * @param title New value of property title.
     */
    public void setTitle(String title) {
        this.title = title;
    }
    /** Getter for property location.
     * @return Value of property location.
     */
    public String getLocation() {
        return location;
    }
    /** Setter for property location.
     * @param location New value of property location.
     */
    public void setLocation(String location) {
        this.location = location;
    }
    /** Getter for property target.
     * @return Value of property target.
     */
    public String getTarget() {
        return target;
    }
    /** Setter for property target.
     * @param target New value of property target.
     */
    public void setTarget(String target) {
        this.target = target;
    }
    /** Getter for property description.
     * @return Value of property description.
     */
    public String getDescription() {
        return description;
    }
    /** Setter for property description.
     * @param description New value of property description.
     */
    public void setDescription(String description) {
        this.description = description;
    }
    /** Getter for property onClick.
     * @return Value of property onClick.
     */
    public String getOnClick() {
        return onClick;
    }
    /** Setter for property onClick.
     * @param onClick New value of property onClick.
     */
    public void setOnClick(String onClick) {
        this.onClick = onClick;
    }
    /** Getter for property onMouseOver.
     * @return Value of property onMouseOver.
     */
    public String getOnMouseOver() {
        return onMouseOver;
    }
    /** Setter for property onMouseOver.
     * @param onMouseOver New value of property onMouseOver.
     */
    public void setOnMouseOver(String onMouseOver) {
        this.onMouseOver = onMouseOver;
    }
    
    /** Getter for property onMouseOut.
     * @return Value of property onMouseOut.
     */
    public String getOnMouseOut() {
        return onMouseOut;
    }
    /** Setter for property onMouseOut.
     * @param onMouseOut New value of property onMouseOut.
     */
    public void setOnMouseOut(String onMouseOut) {
        this.onMouseOut = onMouseOut;
    }
    
    /** Getter for property image.
     * @return Value of property image.
     */
    public String getImage() {
        return image;
    }
    /** Setter for property image.
     * @param image New value of property image.
     */
    public void setImage(String image) {
        this.image = image;
    }
    /** Getter for property altImage.
     * @return Value of property altImage.
     */
    public String getAltImage() {
        return altImage;
    }
    /** Setter for property altImage.
     * @param altImage New value of property altImage.
     */
    public void setAltImage(String altImage) {
        this.altImage = altImage;
    }
    /** Getter for property toolTip.
     * @return Value of property toolTip.
     */
    public String getToolTip() {
        return toolTip;
    }
    /** Setter for property toolTip.
     * @param toolTip New value of property toolTip.
     */
    public void setToolTip(String toolTip) {
        this.toolTip = toolTip;
    }
    /**
     * Returns the roles.
     * @return String
     */
    public String getRoles() {
        return roles;
    }

    /**
     * Sets the roles.
     * @param roles The roles to set
     */
    public void setRoles(String roles) {
        this.roles = roles;
    }

    /** 
     * Returns the value for page.
     * @return Value of property page.
     */
    public String getPage() {
        return this.page;
    }
    
    /** 
     * Sets the value for page.
     * @param page New value of property page.
     */
    public void setPage(String page) {
        this.page = page;
    }

    /**
     * Returns the value for action.
     * @return Value of property action.
     */
    public String getAction() {
        return this.action;
    }

    /**
     * Sets the value for action.
     * @param action New value of property action.
     */
    public void setAction(String action) {
        this.action = action;
    }
    
}
/*
 * DisplayActionMenuTag.java
 *
 * Created on July 25, 2003, 4:06 PM
 */

package com.fgm.web.menu.displayer.taglib;

import java.net.MalformedURLException;
import javax.servlet.jsp.JspException;
import org.apache.struts.util.RequestUtils;
import com.fgm.web.menu.MenuComponent;

/**
 * <p>This JSP Custom Tag pays special care to the Struts Action URI.
 *
 * <p>The major behavior of this tag is to set the value for the usage in the
 * HTML hyperlink 'href' attribute. The value is determined by the following
 * attributes defined in menu-config.xml, in this prioritize order:
 * 'action', 'page', 'location'.
 *
 * <p>You can now define an 'action' attribute in the &lt;Item&gt; element
 * in your menu-config.xml. The 'action' attribute takes the value
 * of a Logical Struts Action name for which to look up the
 * context-relative URI. The resultant URI will carry the
 * Context Path (if any), Module Prefix (if any), Session ID (if any),
 * and Servlet Mapping (path mapping or extension mapping). Here is
 * an example:
 * <PRE>
 * &lt;Menu name="indexMenuMore" title="More Examples"&gt;
 *   &lt;Item name="actionExample"  title="Example - 'action' attribute" 
 *         <B>action="/menu/bullet"</B>/&gt;
 *   &lt;Item name="pageExample" title="Example - 'page' attribute" 
 *         <B>page="/bulletmenu.jsp"</B>/&gt;
 * &lt;/Menu&gt;
 * </PRE>
 * <p>If you omit 'action' attribute but have defined 'page' attribute,
 * the resultant URI will carry the Context Path (if any),
 * Module Prefix (if any) and Session ID (if any).
 *
 * <p>If you omit both 'action' and 'page' attibutes but have defined
 * 'location' attribute, then the resultant URI will be exactly
 * the same as the 'location' value you provided.
 *
 * <p>You have to make sure that you are using the revised version
 * of com.fgm.web.menu.MenuBase.class file and struts-menu.tld
 * tag library descriptor file. The revised MenuBase class have the 'action'
 * property and the corresponding setter and getter methods added. Whereas
 * the revised struts-menu.tld file contains a new 'dislayActionMenu' tag:
 *<PRE> 
 *     &lt;tag&gt;
 *       &lt;name&gt;displayActionMenu&lt;/name&gt;
 *       
&lt;tagclass&gt;com.fgm.web.menu.displayer.taglib.DisplayActionMenuTag&lt;/tagclass&gt;
 *       &lt;attribute&gt;
 *           &lt;name&gt;name&lt;/name&gt;
 *           &lt;required&gt;true&lt;/required&gt;
 *           &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;  
 *       &lt;/attribute&gt;
 *       &lt;attribute&gt;
 *           &lt;name&gt;target&lt;/name&gt;
 *           &lt;required&gt;false&lt;/required&gt;
 *           &lt;rtexprvalue&gt;false&lt;/rtexprvalue&gt;  
 *       &lt;/attribute&gt;
 *     &lt;/tag&gt;
 *</PRE>
 * @author  <a href="mailto:[EMAIL PROTECTED]">Kelvin Yap</a>
 * @version $Revision: 1.0 $ $Date: July 25, 2003, 4:06 PM $
 */
public class DisplayActionMenuTag extends DisplayMenuTag {

    /**
     * This will set the value for the usage in the HTML hyperlink
     * 'href' attribute. The value is determined by the following
     * attributes defined in menu-config, in this prioritize order:
     * 'action', 'page', 'location'.
     *
     * @param menu The menu component to set the location for.
     */
    protected void setPageLocation(MenuComponent menu) {

        try {
            if (menu.getAction() != null) {
                // generate Struts Action URL,
                // this will append Context Path (if any),
                // Servlet Mapping (path mapping or extension mapping)
                // Module Prefix (if any) & Session ID (if any)
                String action = RequestUtils.computeURL(
                    pageContext, null, null, null, menu.getAction(),
                    null, null, true
                );
                menu.setLocation(action);
            } else if (menu.getPage() != null) {
                // generate Page URL,
                // this will append Context Path (if any),
                // Module Prefix (if any) & Session ID (if any)
                String page = RequestUtils.computeURL(
                    pageContext, null, null, appendSlash(menu.getPage()),
                    null, null, null, true
                );
                menu.setLocation(page);
            }
        } catch (MalformedURLException e) {
            // URL cannot be formed, let's use
            // the default 'location' property value
        }
        
        // do all contained menus
        MenuComponent[] subMenus = menu.getMenuComponents();
        if (subMenus.length > 0) {
            for (int i = 0; i < subMenus.length; i++) {
                setPageLocation(subMenus[i]);
            }
        }
    }
    
    /**
     * Returns the value with page prepended with a "/"
     * if it is not already.
     *
     * @param page The value for the page.
     */
    private String appendSlash(String page) {
        if (page.startsWith("/")) {
            return page;
        } else {
            page = "/" + page;
        }
        return page;
    }
}

Reply via email to