<%@ page import="oracle.portal.provider.v2.cache.esi.ESIUtils" %>
<%@ page import="oracle.portal.utils.NameValue" %>
<%@ page import="oracle.portal.provider.v2.render.PortletRenderRequest" %>
<%@ page import="oracle.portal.provider.v2.render.PortletRenderer" %>
<%@ page import="oracle.portal.provider.v2.render.PortletRendererUtil" %>
<%@ page import="oracle.portal.provider.v2.render.http.HttpPortletRendererUtil" %>
<%@ page import="oracle.portal.provider.v2.http.HttpCommonConstants" %>
<%@ page import="oracle.portal.sample.v2.devguide.esi.ESICustomization" %>
<%@ page import="oracle.portal.sample.v2.devguide.esi.resource.ESIBundle" %>
<%@ page import="oracle.webdb.utils.SimpleStringBuffer" %>
<%@ page import="java.util.ResourceBundle" %>
<%@ page import="java.util.Locale" %>

<%
  PortletRenderRequest prr = (PortletRenderRequest) 
      request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);

  // Get customized strings.
  ESICustomization data = (ESICustomization)
      PortletRendererUtil.getEditData(prr);

  // Get non-customizable resource strings.
  Locale locale = prr.getPortletReference().getLocale();
  ResourceBundle bundle =
      prr.getPortletDefinition().getResourceBundle(locale);

  // Get customized fragment URL.
  String fragmentURL = data.getFragmentURL(request);

  // Invalidation is performed by overloading edit mode.
  // Edit mode handles customization if accessed via the Customize link 
  // on the portlet header.
  // If accessed by clicking on the rendered invalidation link then 
  // a URL parameter, _invalidate_cache, is used to indicate 
  // to the edit mode renderer that invalidation is being 
  // performed and not customization.
  SimpleStringBuffer invalQueryString = new SimpleStringBuffer("_mode=");
  invalQueryString.append(Integer.toString(PortletRenderer.MODE_EDIT));
  invalQueryString.append("&_invalidate_cache=true");
  String invalidationLink = HttpPortletRendererUtil.parameterizeLink(
             request, PortletRendererUtil.DESIGN_LINK, 
             invalQueryString.toString());

  String invalidationLinkText = bundle.getString(ESIBundle.INVALIDATELINK_TEXT_KEY);
  String preamble = bundle.getString(ESIBundle.PREAMBLE_KEY);

  int expiryTime = 0;
  int removalTime = 0;
  String method = null;
  boolean onErrorContinue = false;
  int timeoutInSeconds = 0;
  String timeoutMessage = bundle.getString(ESIBundle.TIMEOUTMESSAGE_KEY);
  String queryString = null;

  // This ESI include directive uses custom headers for caching.
  NameValue[] esiCustomHeaders = new NameValue[2];
  esiCustomHeaders[0] = new NameValue("ACCOUNTNUMBER", "5577");
  esiCustomHeaders[1] = new NameValue("STOCK", "ORCL");

  String esiInclude = ESIUtils.generateESIInclude(
        fragmentURL, expiryTime, removalTime, method, queryString,
        onErrorContinue, timeoutInSeconds, timeoutMessage,  
        esiCustomHeaders);
%>

<%=preamble%>

<br>
<br>

<table border="1">
  <tr>
    <td>
      <%=esiInclude%>
    </td>
  </tr>
</table>

<br>

<a href=<%=invalidationLink%>><%=invalidationLinkText%></a>
 
