FileDocCategorySizeDatePackage
LinkUserTag.javaAPI DocExample5050Thu Jul 08 09:27:54 BST 2004org.apache.struts.webapp.example

LinkUserTag

public class LinkUserTag extends javax.servlet.jsp.tagext.TagSupport
Generate a URL-encoded hyperlink to the specified URI, with associated query parameters selecting a specified User.
version
$Revision: 1.10 $ $Date: 2004/03/14 06:23:44 $

Fields Summary
protected String
page
The hyperlink URI.
protected static org.apache.struts.util.MessageResources
messages
The message resources for this package.
private String
name
The attribute name.
Constructors Summary
Methods Summary
public intdoEndTag()
Render the end of the hyperlink.

exception
JspException if a JSP exception has occurred



	// Print the ending element to our output writer
	JspWriter writer = pageContext.getOut();
	try {
	    writer.print("</a>");
	} catch (IOException e) {
	    throw new JspException
	        (messages.getMessage("link.io", e.toString()));
	}

	return (EVAL_PAGE);

    
public intdoStartTag()
Render the beginning of the hyperlink.

exception
JspException if a JSP exception has occurred


	// Generate the URL to be encoded
        ModuleConfig config = (ModuleConfig) pageContext.getRequest()
            .getAttribute(org.apache.struts.Globals.MODULE_KEY);
        HttpServletRequest request =
            (HttpServletRequest) pageContext.getRequest();
        StringBuffer url = new StringBuffer(request.getContextPath());
	url.append(config.getPrefix());
        url.append(page);
	User user = null;
	try {
	    user = (User) pageContext.findAttribute(name);
        } catch (ClassCastException e) {
	    user = null;
	}
	if (user == null)
	    throw new JspException
	        (messages.getMessage("linkUser.noUser", name));
	if (page.indexOf("?") < 0)
	    url.append("?");
	else
	    url.append("&");
	url.append("username=");
	url.append(TagUtils.getInstance().filter(user.getUsername()));

	// Generate the hyperlink start element
	HttpServletResponse response =
	  (HttpServletResponse) pageContext.getResponse();
	StringBuffer results = new StringBuffer("<a href=\"");
	results.append(response.encodeURL(url.toString()));
	results.append("\">");

	// Print this element to our output writer
	JspWriter writer = pageContext.getOut();
	try {
	    writer.print(results.toString());
	} catch (IOException e) {
	    throw new JspException
		(messages.getMessage("linkUser.io", e.toString()));
	}

	// Evaluate the body of this tag
	return (EVAL_BODY_INCLUDE);

    
public java.lang.StringgetName()
Return the attribute name.


	return (this.name);

    
public java.lang.StringgetPage()
Return the hyperlink URI.



    // ------------------------------------------------------------- Properties


             
       

	return (this.page);

    
public voidrelease()
Release any acquired resources.


        super.release();
        this.page = null;
        this.name = "user";

    
public voidsetName(java.lang.String name)
Set the attribute name.

param
name The new attribute name


	this.name = name;

    
public voidsetPage(java.lang.String page)
Set the hyperlink URI.

param
page Set the hyperlink URI


	this.page = page;