FileDocCategorySizeDatePackage
LinkSubscriptionTag.javaAPI DocExample5296Thu Jul 08 09:27:04 BST 2004org.apache.struts.webapp.example

LinkSubscriptionTag

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

Fields Summary
protected String
page
The context-relative 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);
	Subscription subscription = null;
	try {
	    subscription = (Subscription) pageContext.findAttribute(name);
        } catch (ClassCastException e) {
	    subscription = null;
	}
	if (subscription == null)
	    throw new JspException
	        (messages.getMessage("linkSubscription.noSubscription", name));
	if (page.indexOf("?") < 0)
	    url.append("?");
	else
	    url.append("&");
	url.append("username=");
	url.append(TagUtils.getInstance().filter(subscription.getUser().getUsername()));
	url.append("&host=");
	url.append(TagUtils.getInstance().filter(subscription.getHost()));

	// 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("linkSubscription.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 context-relative URI.



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


             
       

	return (this.page);

    
public voidrelease()
Release any acquired resources.


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

    
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 context-relative URI.

param
page Set the context-relative URI


	this.page = page;