/*  Copyright (c) 2000, 2001, Oracle Corporation. All Rights Reserved. */

package oracle.portal.sample.v2.devguide.subscriber;

import java.io.*;

import oracle.portal.provider.v2.*;
import oracle.portal.provider.v2.render.*;
import oracle.portal.provider.v2.render.http.BaseManagedRenderer;
import oracle.portal.provider.v2.security.AccessControlException;


public class SubscriberRenderer extends BaseManagedRenderer
{

    public void renderBody(PortletRenderRequest pr) throws PortletException
    {
        try
        {
            String user = pr.getUser().getName();
            ProviderInstance provider = pr.getProviderInstance();
            ProviderSubscription providerSubscription = provider.getSubscription();
            String subID = null;

            if (providerSubscription != null)
            {
                subID = providerSubscription.getSubscriptionKey();
            }

            PrintWriter out = pr.getWriter("text/html");

            if (user != null)
            {
                out.println("<b> Hello " + user + " </b>");
            }
            else
            {
                out.println("<b> Hello World! </b>");
            }
            if (subID != null)
            {
                out.println("<b> your Subscription key is " + subID + " </b>");
            }
            else
            {
                out.println("<b> your Subscription key is NOT AVAILABLE </b>");
            }
        }
        catch (IllegalArgumentException ie)
        {
            throw new PortletException(ie);
        }
        catch (java.io.IOException ioe)
        {
            throw new PortletException(ioe);
        }
    }
}
