<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="java.text.DateFormat, java.util.Date, java.util.List,
  java.util.Iterator, oracle.portal.provider.v2.render.PortletRenderRequest,
  oracle.portal.provider.v2.render.PortletRendererUtil,
  oracle.portal.provider.v2.render.http.HttpPortletRendererUtil,
  oracle.portal.provider.v2.url.UrlUtils,
  oracle.portal.provider.v2.preference.Preference,
  oracle.portal.provider.v2.preference.NameValuePreferenceDataObject,
  oracle.portal.provider.v2.http.HttpCommonConstants,
  oracle.portal.log.LogManager,
  oracle.portal.sample.v2.devguide.prefstore.GuestBookPortletDefinition" %>
<%!
private static final String SUBMIT_PARAM = "submit";
private static final String VISITOR_NAME_KEY = "name";
private static final String DATE_KEY = "date";
private static final String COMMENT_KEY = "comment";
%>
<%
PortletRenderRequest prr = (PortletRenderRequest)
    request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);

if(prr == null)
{%>
This JSP will not run outside of Oracle Portal.
<%
  return;
}

// This jsp recieves parameters from the guest book, stores the values
// and redirects back to  the page URl.
// Nothing gets rendered by this jsp

GuestBookPortletDefinition gbpd = 
    (GuestBookPortletDefinition)prr.getPortletDefinition();


// Handle a new submitted comment
if(prr.getQualifiedParameter(SUBMIT_PARAM) != null)
{
    NameValuePreferenceDataObject data = new NameValuePreferenceDataObject();
    DateFormat df = DateFormat.getDateTimeInstance();
    data.putString(VISITOR_NAME_KEY, prr.getUser().getName());
    data.putString(DATE_KEY, df.format(new Date()));
    data.putString(COMMENT_KEY, prr.getQualifiedParameter(COMMENT_KEY));

    gbpd.addGuestBookEntry(prr.getProviderInstance(), data);
}

// Feedback submit has completed. Redirect to show mode.
HttpPortletRendererUtil.sendRedirect(prr,prr.getRenderContext().getBackURL());
 
%>
