Re: Source updated for JDK1.5

Keats Kirsch <[email protected]>
Newsgroups gmane.comp.java.webmacro.user
Message-ID <[email protected]>
One more bit of code ... I extended your JSPAttributes class a bit.  
Attached for your review.

Keats

Marc Palmer wrote:

> Lane Sharman wrote:
>
>> Hi Keats,
>>
>> this is good news.
>>
>> I will take into account some of the other posts; clean up the 
>> contrib; and post an rc2 shortly.
>
>
> Hold off that RC2 at the moment, I need to get the JSP + Tablig stuff 
> done, hopefully tomorrow.
>
> Cheers
>
JSPAttributes.java (text/plain, 2 KB)
package org.webmacro.jsp;

import java.util.Enumeration;

import javax.servlet.jsp.PageContext;

/**
 * User: mpalmer
 * <p/>
 * Class that provides access to the JSP pageContext attributes
 */
public class JSPAttributes
{

   private PageContext pc;

   private PageAttributes pageAttributes;

   private RequestAttributes requestAttributes;

	private SessionAttributes sessionAttributes;

	private ApplicationAttributes applicationAttributes;

	public JSPAttributes(PageContext pc)
	{
		this.pc = pc;
	}

	public PageContext getPageContext()
	{
		return pc;
	}

	abstract class ScopedAttributes {
		protected int scope;

		public int getScope()
		{
			return scope;		
		}
		
		public Object get(Object name)
		{
			return pc.getAttribute(name.toString(), scope);
		}		

		public void set(Object name, Object value)
		{
			pc.setAttribute(name.toString(), value, scope);
		}
		
		public Enumeration getKeys()
		{
			return pc.getAttributeNamesInScope(scope);
		}
	}
	
   public final class PageAttributes extends ScopedAttributes
   {
		final private int scope = PageContext.PAGE_SCOPE;
   }

   public final class RequestAttributes
   {
		final private int scope = PageContext.REQUEST_SCOPE;
   }

	public final class SessionAttributes
	{
		final private int scope = PageContext.SESSION_SCOPE;
	}

	public final class ApplicationAttributes
	{
		final private int scope = PageContext.APPLICATION_SCOPE;
	}
	
   public PageAttributes getPage()
   {
      if (pageAttributes == null)
      	pageAttributes = new PageAttributes();
		return pageAttributes;
   }

	public RequestAttributes getRequest()
	{
		if (requestAttributes == null)
			requestAttributes = new RequestAttributes();
		return requestAttributes;
	}

	public SessionAttributes getSession()
	{
		if (sessionAttributes == null)
			sessionAttributes = new SessionAttributes();
		return sessionAttributes;
	}

   public ApplicationAttributes getApplication()
   {
   	if (applicationAttributes == null) 
   		applicationAttributes = new ApplicationAttributes();
   	return applicationAttributes; 
   }
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.