// Copyright (c) 2001 Oracle Corporation
package oracle.portal.provider.v1.http;

import javax.servlet.*;
import javax.servlet.http.*;
import oracle.portal.provider.v1.*;

/**
 * The <code>ServletPageRenderer</code> allows a web provder whose Servlet
 * container is servlet 2.0 compliant (e.g. JServ 1.1) to use servlets to
 * render portlets. Because Portal's communication with the provider adapter
 * is made via the post method, the servlet rendering class must override
 * either the <code>service()</code> method or the <code>doPost()</code>
 * method.  To use the ServletPageRenderer, set the portlet's renderer tag
 * to:<P><code> &ltrenderer
 * class="oracle.portal.provider.v1.http.ServletPageRenderer"&gt<br>.<br>.<br>
 * &lt/renderer&gt</code><p> The tags to set the render modes are
 * &ltshowServlet&gt, &lthelpServlet&gt, &ltaboutServlet&gt,
 * &ltpreviewServlet&gt, &ltdetailsServlet&gt, &lteditServlet&gt and
 * &lteditDetailsServlet&gt. Included within these tags should be the fully
 * qualified class name of the rendering servlet.
 *
 * If you are not using {@link DefaultProvider} (or a subclass of {@link
 * DefaultProvider}) you can still use ServletPageRenderer.  To initialize the
 * renderer, use the accessor methods that correspond to the above tags.  For
 * example, to set the servlet for the SHOW mode, call
 * <code>setShowServlet()</code>.
 *
 * <p>Since this class extends {@link PageRenderer}, you can also use the
 * rendering methods it supports (JSP, static html)
 *
 * @deprecated <code>PageRenderer</code> and its subclasses have been replaced by
 * the more flexible {@link RenderManager}.
 */
public class ServletPageRenderer extends PageRenderer
{
    /**
     * Null Constructor
     */
    public ServletPageRenderer()
    {
        super();
    }

    /**
     * Sets the servlet class used for rendering the portlet's show mode. 
     * If not set, rendering will be handed back up to the 
     * <code>PageRenderer</code>.
     *
     * @param servletName the fully qualified class name of the rendering
     * servlet that renders this portlet in the show mode.
     */
    public void setShowServlet(String servletName) throws PortletException
    {
        setShowPage(new Servlet20Renderer(this, servletName));
    }

    /**
     * Gets the servlet used for rendering the portlet's show mode. 
     *     
     * @return fully qualified class name of the rendering
     * servlet that renders this portlet in the show mode.
     */
    public String getShowServlet()
    {
        ManagedRenderer mr = getShowPage(getContentType());
        if (mr != null && mr instanceof Servlet20Renderer)
        {
            return ((Servlet20Renderer)mr).getServletClass();
        }
        return null;
    }

    /**
     * Sets the servlet used for rendering the portlet's show mode. 
     * If not set, rendering will be handed back up to the 
     * <code>PageRenderer</code>.
     *
     * @param servletName the fully qualified class name of the rendering
     * servlet that renders this portlet in the show mode.
     */
    public void setHelpServlet(String servletName) throws PortletException
    {
        setHelpPage(new Servlet20Renderer(this, servletName));
    }

    /**
     * Gets the servlet used for rendering the portlet's help mode. 
     *     
     * @return fully qualified class name of the rendering
     * servlet that renders this portlet in the help mode.
     */
    public String getHelpServlet()
    {
        ManagedRenderer mr = getHelpPage(getContentType());
        if (mr != null && mr instanceof Servlet20Renderer)
        {
            return ((Servlet20Renderer)mr).getServletClass();
        }
        return null;
    }

    /**
     * Sets the servlet used for rendering the portlet's about mode. 
     * If not set, rendering will be handed back up to the 
     * <code>PageRenderer</code>.
     *
     * @param servletName the fully qualified class name of the rendering
     * servlet that renders this portlet in the about mode.
     */
    public void setAboutServlet(String servletName) throws PortletException
    {
        setAboutPage(new Servlet20Renderer(this, servletName));
    }

    /**
     * Gets the servlet used for rendering the portlet's about mode. 
     *     
     * @return fully qualified class name of the rendering
     * servlet that renders this portlet in the about mode.
     */
    public String getAboutServlet()
    {
        ManagedRenderer mr = getAboutPage(getContentType());
        if (mr != null && mr instanceof Servlet20Renderer)
        {
            return ((Servlet20Renderer)mr).getServletClass();
        }
        return null;
    }

    /**
     * Sets the servlet used for rendering the portlet's preview mode. 
     * If not set, rendering will be handed back up to the 
     * <code>PageRenderer</code>.
     *
     * @param servletName the fully qualified class name of the rendering
     * servlet that renders this portlet in the preview mode.
     */
    public void setPreviewServlet(String servletName) throws PortletException
    {
        setPreviewPage(new Servlet20Renderer(this, servletName));
    }

    /**
     * Gets the servlet used for rendering the portlet's preview mode. 
     *     
     * @return fully qualified class name of the rendering
     * servlet that renders this portlet in the preview mode.
     */
    public String getPreviewServlet()
    {
        ManagedRenderer mr = getPreviewPage(getContentType());
        if (mr != null && mr instanceof Servlet20Renderer)
        {
            return ((Servlet20Renderer)mr).getServletClass();
        }
        return null;
    }

    /**
     * Sets the servlet used for rendering the portlet's show details mode. 
     * If not set, rendering will be handed back up to the 
     * <code>PageRenderer</code>.
     *
     * @param servletName the fully qualified class name of the rendering
     * servlet that renders this portlet in the show details mode.
     */
    public void setDetailsServlet(String servletName) throws PortletException
    {
        setShowDetailsPage(new Servlet20Renderer(this, servletName));
    }

    /**
     * Gets the servlet used for rendering the portlet's show detials mode. 
     *     
     * @return fully qualified class name of the rendering
     * servlet that renders this portlet in the show details mode.
     */
    public String getDetailsServlet()
    {
        ManagedRenderer mr = getShowDetailsPage(getContentType());
        if (mr != null && mr instanceof Servlet20Renderer)
        {
            return ((Servlet20Renderer)mr).getServletClass();
        }
        return null;
    }

    /**
     * Sets the servlet used for rendering the portlet's edit mode. 
     * If not set, rendering will be handed back up to the 
     * <code>PageRenderer</code>.
     *
     * @param servletName the fully qualified class name of the rendering
     * servlet that renders this portlet in the edit mode.
     */
    public void setEditServlet(String servletName) throws PortletException
    {
        setEditPage(new Servlet20Renderer(this, servletName));
    }

    /**
     * Gets the servlet used for rendering the portlet's edit mode. 
     *     
     * @return fully qualified class name of the rendering
     * servlet that renders this portlet in the edit mode.
     */
    public String getEditServlet()
    {
        ManagedRenderer mr = getEditPage(getContentType());
        if (mr != null && mr instanceof Servlet20Renderer)
        {
            return ((Servlet20Renderer)mr).getServletClass();
        }
        return null;
    }

    /**
     * Sets the servlet used for rendering the portlet's edit defaults mode.
     * If not set, rendering will be handed back up to the
     * <code>PageRenderer</code>.
     *
     * @param servletName the fully qualified class name of the rendering
     * servlet that renders this portlet in the edit defaults mode.
     */
    public void setEditDefaultsServlet(String servletName) throws PortletException
    {
        setEditDefaultsPage(new Servlet20Renderer(this, servletName));
    }

    /**
     * Gets the servlet used for rendering the portlet's edit defaults mode.
     *
     * @return fully qualified class name of the rendering
     * servlet that renders this portlet in the edit defaults mode.
     */
    public String getEditDefaultsServlet()
    {
        ManagedRenderer mr = getEditDefaultsPage(getContentType());
        if (mr != null && mr instanceof Servlet20Renderer)
        {
            return ((Servlet20Renderer)mr).getServletClass();
        }
        return null;
    }

    /**
     * Sets the servlet used for rendering the portlet's link mode.
     * If not set, rendering will be handed back up to the
     * <code>PageRenderer</code>.
     *
     * @param servletName the fully qualified class name of the rendering
     * servlet that renders this portlet in the link mode.
     */
    public void setLinkServlet(String servletName) throws PortletException
    {
        setLinkPage(new Servlet20Renderer(this, servletName));
    }

    /**
     * Gets the servlet used for rendering the portlet's link mode.
     *
     * @return fully qualified class name of the rendering
     * servlet that renders this portlet in the link mode.
     */
    public String getLinkServlet()
    {
        ManagedRenderer mr = getLinkPage(getContentType());
        if (mr != null && mr instanceof Servlet20Renderer)
        {
            return ((Servlet20Renderer)mr).getServletClass();
        }
        return null;
    }
}
