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

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

import oracle.portal.provider.v1.*;

import java.io.*;

/**
 * A Class class.

 */
public class SubscriberRenderer implements PortletRenderer {

    /**
     * Constructor
     */
    public SubscriberRenderer() {
    }

    /** Renders this portlet.
     * Portlet's are responsible for ensuring the request's user has sufficient
     * rights to receive this rendering.
     *
     * @param pr ProviderRequest for this rendering.
     */

    public void render(PortletRenderRequest pr) throws PortletException, AccessControlException {
        try {
            String user = pr.getUser().getName();
            
            Provider provider = pr.getProvider();
            ProviderSubscriber providerSubscriber = provider.getSubscriber();
            String subID = null;

            if (providerSubscriber != null)
            {
              subID = providerSubscriber.getId();
            }

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

            // Writes container -- handles rendering the border if necessary
            PortletRendererUtil.renderPortletHeader(pr, out, null);

            if (user != null) {
                out.println("<b> Hello " + user + " </b>");
            } else {
                out.println("<b> Hello World! </b>");
            }
            if (subID != null) {
                out.println("<b> your Subscriber id is " + subID + " </b>");
            } else {
                out.println("<b> your Subscriber id is NOT AVAILABLE </b>");
            }
            // Ends the container
            PortletRendererUtil.renderPortletFooter(pr, out);
        } catch (IllegalArgumentException ie) {
            throw new PortletException(ie);
        } catch (java.io.IOException ioe) {
            throw new PortletException(ioe);
        }
    }
}
