<%@page import = "oracle.portal.provider.v2.render.PortletRenderRequest,
                  oracle.portal.provider.v2.http.HttpCommonConstants,
                  oracle.portal.provider.v2.render.PortletRendererUtil,
                  oracle.portal.provider.v2.event.EventUtils,
                  oracle.portal.utils.xml.v2.XMLUtil,
                  oracle.portal.utils.v2.NameValuePair,
                  oracle.portal.sample.v2.devguide.eventform.EventFormCustomization,
                  oracle.portal.sample.v2.devguide.eventform.resource.EventFormBundle"

   contentType = "text/vnd.oracle.mobilexml"
%>

<%
try
{
    PortletRenderRequest portletRequest = (PortletRenderRequest)
        request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);

    EventFormCustomization defaultData = (EventFormCustomization) 
        PortletRendererUtil.getEditDefaultData(portletRequest);

    //
    // The portlet definition in provider.xml includes the following:
    //
    //    The event "submit" with the following event parameters:
    //        o param1
    //        o param2
    //
    //    The event "cancel" with the no event parameters.
    //

    String splashText     = defaultData.getSplashText();
    String parameter1Label   = defaultData.getParameter1Label();
    String parameter2Label   = defaultData.getParameter2Label();
    String submitButtonLabel = defaultData.getSubmitLabel();
    String cancelButtonLabel = defaultData.getCancelLabel();
    String parameter1Value   = defaultData.getParameter1ValueForMobile();
    String parameter2Value   = defaultData.getParameter2ValueForMobile();

    String eventSubmit       = EventUtils.eventName("submit");
    String eventSubmitParam1 = EventUtils.eventParameter("param1");
    String eventSubmitParam2 = EventUtils.eventParameter("param2");
    String eventCancel       = EventUtils.eventName("cancel");

    // Build up the list of parameters for the "submit" event
    NameValuePair[] eventSubmitParams = new NameValuePair[3];
    if (parameter1Value == null)
    {
        eventSubmitParams[0] = new NameValuePair(eventSubmitParam1, "");
    }
    else
    {
        eventSubmitParams[0] = 
            new NameValuePair(eventSubmitParam1, parameter1Value);
    }

    if (parameter2Value == null)
    {
        eventSubmitParams[1] = new NameValuePair(eventSubmitParam2, "");
    }
    else
    {
        eventSubmitParams[1] = 
            new NameValuePair(eventSubmitParam2, parameter2Value);
    }

    eventSubmitParams[2] = new NameValuePair(eventSubmit, "");

    // Build up an empty list of parameters for the "cancel" event
    NameValuePair[] eventCancelParams = new NameValuePair[1];
    eventCancelParams[0] = new NameValuePair(eventCancel, "");

    // Construct the hyperlinks for the two events
    String eventSubmitLink = PortletRendererUtil.constructLink(portletRequest, portletRequest.getRenderContext().getEventURL(), eventSubmitParams, true, true);
    String eventCancelLink = PortletRendererUtil.constructLink(portletRequest, portletRequest.getRenderContext().getEventURL(), eventCancelParams, true, true);
%>

<SimpleText>
    <SimpleTextItem>
        <%=splashText%>
    </SimpleTextItem>

    <SimpleTextItem>
        <SimpleHref target='<%=XMLUtil.escapeXMLAttribute(eventSubmitLink)%>'>
            <%=submitButtonLabel%>
        </SimpleHref>
    </SimpleTextItem>

    <SimpleTextItem>
        <SimpleHref target='<%=XMLUtil.escapeXMLAttribute(eventCancelLink)%>'>
            <%=cancelButtonLabel%>
        </SimpleHref>
    </SimpleTextItem>
</SimpleText>

<%
}
catch (IllegalStateException e)
{
    // This exception will be raised when calling 
    // PortletRendererUtil.constructLink from Oracle Portal 3.0.9
%>
    Error while displaying portlet: <%= e.getMessage() %>
    <br>(Attempted to use JPDK V2 functionality with Oracle Portal 3.0.9?)
<%
}
catch (Exception e)
{
%>
    <br>Exception occurred: <%= e.getMessage() %>
<%
}
%>

