alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

package tadm;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import tadm.AntTag;

/**
 * Child tag to pass ant properties to Ant tag
 * 
 */
public class AntProperty extends TagSupport {
    
    public AntProperty() {}

    public int doStartTag() throws JspException {
	Tag parent=getParent();
	if( parent == null  )
	    throw new JspException( "AntProperty used as top-level tag,"+
				    "must be inside ");
	if( ! (parent instanceof AntTag))
	    throw new JspException( "AntProperty must be child of ");

	AntTag antTag=(AntTag)parent;

	if( value==null && location!= null ) {
	    // the property will be set with the absolute path
	    // of the "location", relative to this or another
	    // (accessible) web application
	    HttpServletRequest req=(HttpServletRequest)pageContext.
		getRequest();
	    ServletContext thisCtx=pageContext.getServletConfig().
		getServletContext();
	    ServletContext targetCtx=(webapp==null) ? thisCtx:
		thisCtx.getContext( webapp );
	    value=targetCtx.getRealPath(location);
	}

	
	if( value == null ) {
	    // if param is used, try it first ( param!= name )
	    if( param != null ) {
		value=pageContext.getRequest().getParameter( param );
	    } else {
		value=pageContext.getRequest().getParameter( name );
	    }
	}

	if( value != null )
	    antTag.setProperty( name, value );

	return SKIP_BODY;
    }

    //-------------------- Properties --------------------
    String name;
    String value;
    String param;

    public void setName( String s ) {
	name=s;
    }

    public void setParam( String s ) {
	param=s;
    }

    public void setValue( String s ) {
	value=s;
    }

    // -------------------- Special properties --------------------
    String location;
    String webapp;

    public void setLocation( String s ) {
	location=s;
    }

    /** Set the property with the "base" of the web application
     */
    public void setWebApp( String s ) {
	webapp=s;
    }


    // -------------------- From ant --------------------
    
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.