<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"%>
<%@page errorPage="Exception.jsp"%>
<%@page import="com.fujitsu.iflow.common.wfapp.WFAppComponent"%>
<%@page import="com.fujitsu.iflow.common.wfapp.WFAppConstants"%>
<%@page import="com.fujitsu.iflow.common.wfapp.WFAppManifest"%>
<%@page import="com.fujitsu.iflow.model.util.WFAppInstaller"%>
<%@page import="com.fujitsu.iflow.model.workflow.WFSession"%>
<%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"%>
<%@page import="java.io.File"%>
<%@page import="java.util.Enumeration"%>
<%@page import="java.util.Properties"%>
<%@page import="java.util.Hashtable"%>

<%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    WFSession wfSession = (WFSession)session.getAttribute("ModelsessionID");
    if (wfSession == null) {
        %><jsp:include page="PasswordPanel.jsp" flush="true"/><%
        return;
    }
    String[] bcolor = {"evenrow","oddrow"};
    int nextColor = 0;
    session.setAttribute("TabIndex","2");
%>
<html>
<head><title>Interstage Business Process Manager | Import Package</title></head>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="javascript" src="styles/clockscripts.js"></script>
<script>
function checkValues()
{
   if(document.myForm.DisableTriggersFlag.checked==true)
      document.myForm.DisableTriggers.value="true";
   else
      document.myForm.DisableTriggers.value="false";
   document.myForm.submit();
   return true;
}
</script>
</head>
<body class="bodyClass" onLoad="goforit();">
<jsp:include page="Header.jsp" flush="true"/>
<br/><br/>
<!--
<b>The package I-BPM_TEST1_V20_iflow_PKG.jar has been imported into the I-BPM system successfully.</b> 
-->
<br/>

<%
    WFAppInstaller installer = new WFAppInstaller();
    Hashtable patternMappings = new Hashtable();
    String currentFolderPath = new File(".").getAbsolutePath();
    String packagePath = (String)session.getAttribute("PackagePath");

    String rootFolderPath = null;
    Properties sysprops = System.getProperties();
    if(sysprops.getProperty("user.home") != null)
    {
       rootFolderPath = (new File(sysprops.getProperty("user.home"))).getAbsolutePath();
       if(rootFolderPath.charAt(rootFolderPath.length()-1) != File.separatorChar)
          rootFolderPath = rootFolderPath + File.separatorChar;
          
    }
    else
       rootFolderPath = currentFolderPath.substring(0,currentFolderPath.indexOf(File.separator)+1);


    session.removeAttribute("PackagePath");
    patternMappings.put(WFAppConstants.CLIENT_ROOT_PATTERN, rootFolderPath);
    patternMappings.put(WFAppConstants.IBPM_PORTAL_ROOT_PATTERN, application.getRealPath("/").trim());
    WFAppManifest manifest = installer.checkManifest(wfSession,packagePath, patternMappings);
    manifest.setClientVirtualToRealMapping(patternMappings);
    session.setAttribute("WFAppManifest", manifest);
    session.setAttribute("WFAppPackagePath",packagePath);
    String componentOptions = "";
    
%>

<form method="post" action="ImportWFAppPackageAction.jsp" name="myForm">
<center>
<TABLE bgcolor="#CCCCCC" border="0" cellpadding="4" cellspacing="1" class="tableClass" width="650" align="center">
                  <tr align="center" class="headrow">
                    <td bgcolor="#EEEEEE" style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FFFFFF', endColorStr='#6699CC', gradientType='1')"><font color="#000000" size="2">Import Workflow Application Package</font></td>
                  </tr>
                  <tr>
                  <td>Disable Triggers: <input type="checkbox" name="DisableTriggersFlag" value="" checked>
                      <input type="hidden" name="DisableTriggers" value="">
                  </td>
                  </tr>
<%
      WFAppComponent[] tmpComponents = manifest.getServerComponents();
      Hashtable packagedDMSRoots = new Hashtable();
      if(tmpComponents != null)
      {
         for(int i=0; i < tmpComponents.length; i++)
         {
             String tmpPath = tmpComponents[i].getLocation();
             if(tmpPath.indexOf("%IBPM_DMS_ROOT") == 0)
             {
                String tmpStr = tmpPath.substring("%IBPM_DMS_ROOT".length());
                tmpStr = tmpStr.substring(0,tmpStr.indexOf("%"));
                packagedDMSRoots.put(tmpStr,tmpStr);
             }
         }
      }
      Hashtable virtualToRealMappings = manifest.getVirtualToRealMapping();

      
      for(Enumeration tenum = packagedDMSRoots.elements() ; tenum.hasMoreElements() ;) 
      {
         String packagedDMSRoot = "%IBPM_DMS_ROOT" + tenum.nextElement() + "%";
%>
          <tr>
          <td> <%= packagedDMSRoot %> &nbsp; &nbsp;
               <select NAME="R_<%= packagedDMSRoot %>">
<%
               
               for(Enumeration enum2 = virtualToRealMappings.keys() ; enum2.hasMoreElements() ;) 
               {
                  String mkey = (String)enum2.nextElement();
                  if(mkey.indexOf("%IBPM_DMS_ROOT") != 0)
                     continue;
%>
                  <option VALUE="<%= mkey %>" <%= packagedDMSRoot.equals(mkey) ? "selected" : "" %> ><%= virtualToRealMappings.get(mkey) %>
<%
               }
%>
               </select>
          </td>
          </tr>
<%          
      }

%>

                </table>

<TABLE border="0" cellpadding=4 cellspacing=1 class="tableClass" width="650" bgcolor="#CCCCCC"  align="center">
      <COL WIDTH="30%"><COL WIDTH="70%">
      <tr class="headrow">
      <th></th>
      <th>List of Server Side Files</th>
      </tr>
<%
    WFAppComponent[] serverComponents = manifest.getServerComponents();
    if(serverComponents != null)
    {
       for(int i=0; i < serverComponents.length; i++)
       {
          WFAppComponent serverComponent = serverComponents[i];
%>
            <TR>
             <TD>
             <%
                if(serverComponent.getOperation() == WFAppConstants.OVERWRITE_OPERATION)
                {
                   componentOptions = componentOptions + ",optionsc_" + i;
             %>
                   Overwrite<input type="radio" name="optionsc_<%= i %>" value="<%= WFAppConstants.OVERWRITE_OPERATION %>" checked> &nbsp; 
                   Skip <input type="radio" name="optionsc_<%=i%>" value="<%= WFAppConstants.SKIP_OPERATION %>">
             <%
                }
             %>
             </TD>
             <TD><%= serverComponent.getLocation() %></TD>
            </TR>
<%
       }
            
    }
%>
            
</TABLE>

<TABLE border="0" cellpadding=4 cellspacing=1 class="tableClass" width="650" bgcolor="#CCCCCC"  align="center">
      <COL WIDTH="30%"><COL WIDTH="70%">
      <tr class="headrow">
      <th></th>
      <th>List of Client Side Files</th>
      </tr>
<%
    WFAppComponent[] clientComponents = manifest.getClientComponents();
    if(clientComponents != null)
    {
       for(int i=0; i < clientComponents.length; i++)
       {
          WFAppComponent clientComponent = clientComponents[i];
%>       
             <TR>
             <TD>
             <%
                if(clientComponent.getOperation() == WFAppConstants.OVERWRITE_OPERATION)
                {
                   componentOptions = componentOptions + ",optioncc_" + i;
             %>
                   Overwrite<input type="radio" name="optioncc_<%= i %>" value="<%= WFAppConstants.OVERWRITE_OPERATION %>" checked> &nbsp; 
                   Skip <input type="radio" name="optioncc_<%=i%>" value="<%= WFAppConstants.SKIP_OPERATION %>">
             <%
                }
             %>
             </TD>
             <TD><%= clientComponent.getLocation() %></TD>
            </TR>
<%
       }
    }
%>
</TABLE>


<p>

<table>
<tr>
        <td valign="center" align="center" bgcolor="#EEEEEE">
        <input type="hidden" name="ComponentOptions" value="<%= componentOptions %>">
        <input type="button" value="Submit" class="submitClass" onClick="return checkValues()">
        </td>
    </tr>
</table>



</form>
</center>
</body>
</html>
