FileDocCategorySizeDatePackage
UrlSupport.javaAPI DocGlassfish v2 API6200Sat May 05 19:17:52 BST 2007org.apache.taglibs.standard.tag.common.core

UrlSupport

public abstract class UrlSupport extends javax.servlet.jsp.tagext.BodyTagSupport implements ParamParent

Support for tag handlers for <url>, the URL creation and rewriting tag in JSTL 1.0.

author
Shawn Bayern

Fields Summary
protected String
value
protected String
context
private String
var
private int
scope
private ParamSupport.ParamManager
params
Constructors Summary
public UrlSupport()

	super();
	init();
    
Methods Summary
public voidaddParameter(java.lang.String name, java.lang.String value)

	params.addParameter(name, value);
    
public intdoEndTag()

	String result;				// the eventual result

	// add (already encoded) parameters
	String baseUrl = resolveUrl(value, context, pageContext);
	result = params.aggregateParams(baseUrl);

	// if the URL is relative, rewrite it
	if (!ImportSupport.isAbsoluteUrl(result)) {
	    HttpServletResponse response =
                ((HttpServletResponse) pageContext.getResponse());
            result = response.encodeURL(result);
	}

	// store or print the output
	if (var != null)
	    pageContext.setAttribute(var, result, scope);
	else {
	    try {
	        pageContext.getOut().print(result);
	    } catch (java.io.IOException ex) {
		throw new JspTagException(ex.toString(), ex);
	    }
	}

	return EVAL_PAGE;
    
public intdoStartTag()

	params = new ParamSupport.ParamManager();
	return EVAL_BODY_BUFFERED;
    
private voidinit()

	value = var = null;
	params = null;
	context = null;
	scope = PageContext.PAGE_SCOPE;
    
public voidrelease()

	init();
    
public static java.lang.StringresolveUrl(java.lang.String url, java.lang.String context, javax.servlet.jsp.PageContext pageContext)

	// don't touch absolute URLs
	if (ImportSupport.isAbsoluteUrl(url))
	    return url;

	// normalize relative URLs against a context root
	HttpServletRequest request =
	    (HttpServletRequest) pageContext.getRequest();
	if (context == null) {
	    if (url.startsWith("/"))
		return (request.getContextPath() + url);
	    else
		return url;
	} else {
            if (!context.startsWith("/") || !url.startsWith("/")) {
                throw new JspTagException(
                    Resources.getMessage("IMPORT_BAD_RELATIVE"));
            }
            if (context.equals("/")) {
                // Don't produce string starting with '//', many
                // browsers interpret this as host name, not as
                // path on same host.
                return url;
            } else {
                return (context + url);
            }
        }
    
public voidsetScope(java.lang.String scope)

	this.scope = Util.getScope(scope);
    
public voidsetVar(java.lang.String var)

        this.var = var;