<%
/* Copyright (c) 2002, 2003 Oracle Corporation. All Rights Reserved. */
%>
<%@ taglib uri="http://xmlns.oracle.com/uix/ui" prefix="uix" %>

<%@ page import="java.util.Locale,
           oracle.cabo.share.config.Configuration,
           oracle.cabo.share.nls.LocaleContext,
           oracle.cabo.ui.ServletRenderingContext,
           oracle.webdb.utils.SimpleStringBuffer,
           oracle.webdb.reformlet.Utility,
           oracle.webdb.providerui.RequestContext,
           oracle.webdb.providerui.ResourceService,
           oracle.webdb.providerui.ProviderBuilderConstants,
           oracle.webdb.providerui.event.ProviderConstants,
           oracle.webdb.providerui.builder.BuilderFactory,
           oracle.webdb.providerui.resource.ProviderUIBundle,
           oracle.webdb.providerui.builder.base.ProviderBuilder"
           session="true" %>

<%
  RequestContext reqContext = 
                      BuilderFactory.getRequestContext();
  Locale locale = reqContext.getLocale();
%>

<%@ include file="ProviderBuilderCaboSetup.jsp" %>
<%
  ProviderBuilder providerBuilder = BuilderFactory.getProviderBuilder(
                    ProviderBuilderConstants.DATAVIEW_PROVIDER_BUILDER);
  String resourceBundleClass = providerBuilder.getResourceBundleClass();
  ResourceService rs =
    BuilderFactory.getResourceService(resourceBundleClass,locale);
 
  String strHeader1Text = rs.getMessage(ProviderUIBundle.EDIT_DATAVIEW_PROVIDER_STEP1_TITLE);
  
  String strHeader1Explanation = 
                  rs.getMessage(ProviderUIBundle.EDIT_DATAVIEW_PROVIDER_STEP1_DESCRIPTION);
  
  String strHeader2Text = rs.getMessage(ProviderUIBundle.PROXY_TITLE);
  String strHeader2Explanation = 
                  rs.getMessage(ProviderUIBundle.DATAVIEW_PROXY_DESCRIPTION);
  
  String strLocationLabel = rs.getMessage(ProviderUIBundle.PROVIDER_LOCATION);
  String strProxyHostLabel = rs.getMessage(ProviderUIBundle.PROXY_HOST);
  String strProxyPortLabel = rs.getMessage(ProviderUIBundle.PROXY_PORT);
  String strDontProxyForLabel = rs.getMessage(ProviderUIBundle.DONT_PROXY_FOR);

  String locationValue = 
   reqContext.getParameter(ProviderConstants.PROVIDER_URL) == null ? "" : 
    (String) reqContext.getParameter(ProviderConstants.PROVIDER_URL);
  
  String strProxyHostVal = 
    reqContext.getParameter(ProviderConstants.PROXY_HOST) == null ? "" : 
    (String) reqContext.getParameter(ProviderConstants.PROXY_HOST);
  
  String strProxyPortVal = 
    reqContext.getParameter(ProviderConstants.PROXY_PORT) == null ? "" : 
    (String) reqContext.getParameter(ProviderConstants.PROXY_PORT);

  String strDontProxyForVal = 
    reqContext.getParameter(ProviderConstants.DONT_PROXY_FOR) == null ? "" : 
    (String) reqContext.getParameter(ProviderConstants.DONT_PROXY_FOR);

  //The next set of instructions provide a hook to call additional processing URL (Intermediate servlet). 
  //This additional processing is required as WebClipping's provider.xml needs to be updated 
  //if HTTP Proxy config has changed for OmniPortlet. Both providers should have exact same
  //proxy config always.
  String contextURL = reqContext.getContextURL();
  
  SimpleStringBuffer additionalActionURLBuf = new SimpleStringBuffer(contextURL);
  additionalActionURLBuf.append("providerui/ProviderAdditionalSettingsServlet");
  reqContext.setParameter(ProviderConstants.ADDITIONAL_ACTION_URL,
                          additionalActionURLBuf.toString(), 
                          RequestContext.SESSION_SCOPE);
  
  SimpleStringBuffer currentURLBuf = new SimpleStringBuffer(contextURL);
  currentURLBuf.append("providerui/EditProvider?");
  //when the page is called from WizardStep.fetchSource, it's a dispatcher.include.
  //with this, the queryString param is lost. Hence store the queryStirng to be used later to
  // reconstruct the entire currentURL.
  if (request.getQueryString() != null)
  {
    currentURLBuf.append(request.getQueryString());
    reqContext.setParameter(ProviderConstants.QUERY_STRING_PARAM, request.getQueryString(), 
                            RequestContext.SESSION_SCOPE);
  }
  else 
  {
    currentURLBuf.append((String) reqContext.getParameter(ProviderConstants.QUERY_STRING_PARAM, 
                         RequestContext.SESSION_SCOPE));
  }
  
  reqContext.setParameter(ProviderConstants.CURRENT_URL, currentURLBuf.toString(), 
                          RequestContext.SESSION_SCOPE);

  // add a param in reqContext so that call differentiation may be made as to original 
  //introducer of the current request. 
  reqContext.setParameter(ProviderConstants.ORIGINATING_PROVIDER_PARAM, 
                          ProviderConstants.OP_ORIGINATING_PROVIDER, 
                          RequestContext.SESSION_SCOPE);
%>
  
  <uix:tableLayout width="100%">
    <uix:contents>

     <%-- header1 starts here --%>
     <uix:rowLayout>
        <uix:contents>
          <uix:header text="<%=strHeader1Text %>">
            <uix:contents>
              <uix:rowLayout>
                <uix:contents>
                  <uix:styledText styleClass="OraInstructionText"
                        text="<%=strHeader1Explanation %>"/>
                </uix:contents>
              </uix:rowLayout>
            </uix:contents>
          </uix:header>
        </uix:contents>
      </uix:rowLayout>

      <uix:rowLayout>
        <uix:contents>
          <uix:tableLayout hAlign="center" cellPadding="10" cellSpacing="5" width="70%">
            <uix:contents>

            <uix:rowLayout>
              <uix:cellFormat height="8"/>
            </uix:rowLayout>

             <uix:rowLayout>
              <uix:contents>
                <uix:cellFormat wrappingDisabled="true">
                 <contents>
                   <uix:styledText styleClass="OraFieldText"
                     text="<%=strLocationLabel %>"/>
                 </contents>      
                </uix:cellFormat>
                <uix:cellFormat>
                 <contents>
                     <uix:styledText styleClass="OraFieldText"
                        text="<%=locationValue %>"/>
                 </contents>      
                </uix:cellFormat>
              </uix:contents>
             </uix:rowLayout>

             <input type="hidden" name="<%= ProviderConstants.PROVIDER_URL %>" :
                          value="<%=locationValue %>"/>

            </uix:contents>
          </uix:tableLayout>
        </uix:contents>
      </uix:rowLayout>
      <%-- header1 ends here --%>

      <%-- header2 starts here --%>
      <uix:rowLayout>
        <uix:contents>
          <uix:header text="<%=strHeader2Text %>">
            <uix:contents>
              <uix:rowLayout>
                <uix:contents>
                  <uix:styledText styleClass="OraInstructionText"
                        text="<%=strHeader2Explanation %>"/>
                </uix:contents>
              </uix:rowLayout>
            </uix:contents>
          </uix:header>
        </uix:contents>
      </uix:rowLayout>

      <uix:rowLayout>
        <uix:contents>
          <uix:tableLayout hAlign="center" cellSpacing="5" width="70%">
            <uix:contents>

            <uix:rowLayout>
              <uix:cellFormat height="8"/>
            </uix:rowLayout>

             <uix:rowLayout hAlign="left" >
              <uix:contents>
               <uix:cellFormat width="40%">
                 <uix:styledText styleClass="OraFieldText"
                    text="<%=strProxyHostLabel %>"/>
               </uix:cellFormat>
               <uix:cellFormat hAlign="left">
                 <uix:textInput name="<%= ProviderConstants.PROXY_HOST %>"
                    text="<%=strProxyHostVal %>" columns="50"/>
               </uix:cellFormat>
              </uix:contents>
             </uix:rowLayout>

             <uix:rowLayout hAlign="left">
               <uix:contents>
               <uix:cellFormat>
                 <uix:styledText styleClass="OraFieldText"
                    text="<%=strProxyPortLabel %>"/>
               </uix:cellFormat>
               <uix:cellFormat hAlign="left">
                 <uix:textInput name="<%= ProviderConstants.PROXY_PORT %>"
                    text="<%=strProxyPortVal %>" columns="50"/>
               </uix:cellFormat>
              </uix:contents>
             </uix:rowLayout>

             <uix:rowLayout hAlign="left">
              <uix:contents>
               <uix:cellFormat>
                 <uix:styledText styleClass="OraFieldText"
                    text="<%=strDontProxyForLabel %>"/>
               </uix:cellFormat>
               <uix:cellFormat hAlign="left">
                 <uix:textInput name="<%= ProviderConstants.DONT_PROXY_FOR %>"
                    text="<%=strDontProxyForVal %>" columns="50"/>
               </uix:cellFormat>
              </uix:contents>
             </uix:rowLayout>

            </uix:contents>
          </uix:tableLayout>
        </uix:contents>
      </uix:rowLayout>

    </uix:contents>
  </uix:tableLayout>
 
