/*  Copyright (c) 2001, 2003 Oracle Corporation. All Rights Reserved. */
package oracle.portal.provider.v2.http;

import java.util.Map;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import oracle.portal.provider.v2.ProviderContext;
import oracle.portal.utils.xml.v2.XMLUtil;

public class ServletProviderContext extends ProviderContext
{
    private static final String CONTEXT_PATH = "contextPath";
    private static final String SERVLET_PATH = "servletPath";
    private static final String SERVLET_CONFIG = "servletConfig";
    private static final String INVALIDATION_CACHING = "invalidationCaching";

    public ServletProviderContext(String repositoryPath, 
                                  int debugLevel,
                                  HttpServletRequest request, 
                                  ServletConfig config)
    {
        this(repositoryPath, debugLevel, request, config, true, null);
    }

    public ServletProviderContext(String repositoryPath, 
                                  int debugLevel,
                                  HttpServletRequest request, 
                                  ServletConfig config,
                                  boolean showTestPage)
    {

        this(repositoryPath, debugLevel, request, config, showTestPage, null);
    }

    public ServletProviderContext(String repositoryPath, 
                                  int debugLevel,
                                  HttpServletRequest request, 
                                  ServletConfig config,
                                  boolean showTestPage,
                                  String testPageURI)
    {
        this(repositoryPath, debugLevel, request, config, showTestPage, 
             testPageURI, null);
    }

    public ServletProviderContext(String repositoryPath, 
                                  int debugLevel,
                                  HttpServletRequest request, 
                                  ServletConfig config,
                                  boolean showTestPage,
                                  String testPageURI,
                                  Map attributes)
    {
        super(repositoryPath, debugLevel, showTestPage, testPageURI, attributes);
        String ic = 
            config.getInitParameter(HttpCommonConstants.INVALIDATION_CACHING);            
        if(ic != null)
        {
            setAttribute(INVALIDATION_CACHING, ic);
        }
        else
        {
            setAttribute(INVALIDATION_CACHING, "false");
        }
        setAttribute(CONTEXT_PATH, request.getContextPath());
        setAttribute(SERVLET_PATH, request.getServletPath());
        setAttribute(SERVLET_CONFIG, config);
    }

    public String getContextPath()
    {
        return (String)getAttribute(CONTEXT_PATH);
    }

    public String getServletPath()
    {
        return (String)getAttribute(SERVLET_PATH);
    }

    public ServletConfig getServletConfig()
    {
        return (ServletConfig)getAttribute(SERVLET_CONFIG);
    }

    public boolean isInvalidationCachingEnabled()
    {
        return XMLUtil.getBooleanValue((String)getAttribute(INVALIDATION_CACHING));
    }
}
        

