// Copyright (c) 1999, 2000 Oracle Corporation
package oracle.jbo.html.jsp.datatags;

import javax.servlet.jsp.tagext.TagSupport;

import javax.servlet.jsp.JspException;

import oracle.jbo.http.HttpContainer;

import java.util.Properties;

import oracle.jbo.html.jsp.JSPApplicationRegistry;

import oracle.jbo.http.ApplicationBindingListener;

/**
 * A custom data tag that may be used to clear the JBO HTTP page cache.
 */
public class ReleasePageResourcesTag extends TagSupport
{
   private String mReleaseMode = JSPApplicationRegistry.STATELESS;
   private String mAppId = null;

   public ReleasePageResourcesTag()
   {
   }

   public String getReleasemode()
   {
      return mReleaseMode;
   }

   public void setReleasemode(String releaseMode)
   {
      mReleaseMode = releaseMode;
   }

   public void setreleasemode(String releaseMode)
   {
      mReleaseMode = releaseMode;
   }
   
   public String getAppid()
   {
      return mAppId;
   }

   public void setAppid(String appId)
   {
      mAppId = appId;
   }

   /**
    * Perform clean up tasks related to the end of a page request.
    */
   public int doEndTag() throws JspException
   {
      try
      {
         HttpContainer container = (HttpContainer)pageContext
            .getAttribute(HttpContainer.PAGE_CONTEXT_CONTAINER_NAME);

         if (container != null)
         {
            Properties props = new Properties();
            props.put(
               ApplicationBindingListener.RELEASE_MODE
               , mReleaseMode);

            if (mAppId != null)
            {
               container.removeValue(
                  HttpContainer.APPLICATION_BINDING_LISTENER_PREFIX + mAppId
                  , props);
            }
            else
            {
               // Clear the BC4J page context.
               container.clear(props);
            }
         }
      }
      catch(Exception ex)
      {
         throw new JspException(ex.getMessage());
      }

      return SKIP_BODY;
   }
}

