<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="Exception.jsp"
%>
<%@page import="com.fujitsu.iflow.common.wfapp.WFAppConstants"%>
<%@page import="com.fujitsu.iflow.common.wfapp.WFAppManifest"%>
<%@page import="com.fujitsu.iflow.common.wfapp.WFAppComponent"%>
<%@page import="com.fujitsu.iflow.model.workflow.WFSession"%>
<%@page import="com.fujitsu.iflow.model.workflow.WFObjectFactory"%>
<%@page import="com.fujitsu.iflow.model.util.URLEncoder"%>
<%@page import="java.util.Enumeration"%>
<%@page import="java.util.Hashtable"%>
<%@page import="java.util.Vector"%>
<%
    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 | Export Package</title></head>
<jsp:include page="StyleSheet.jsp" flush="true"/>
<script language="javascript" src="styles/clockscripts.js"></script>
<script language="javascript" src="styles/clockscripts.js"></script>

<script>
    function checkPackageName()
    {
        var namestr = document.packageForm.PackageName.value;
        var specialChars = "\\/:*\"?<>|\' ";
        var i = 0;
        for(i=0; i<specialChars.length; i++)
        {
           var specialChar = specialChars.charAt(i);
           if(namestr.indexOf(specialChar) >= 0)
           {
              alert("Following special characters are not allowed inside the package name: \\ / : * \" ? < > | ' and white spaces");
              return false;
           }    
        }

        return true;

    }
</script>

</head>
<body class="bodyClass" onLoad="goforit();">
<jsp:include page="Header.jsp" flush="true"/>
<br/><br/>

<form name="packageForm" method="post" action="ExportWFAppPackageAction.jsp" onSubmit="return checkPackageName();">
<center>


<TABLE bgcolor="#CCCCCC" border="0" cellpadding="4" cellspacing="1" class="tableClass" width="80%" align="center">
                  <tr align="center" class="headrow">
                    <td colspan="12" bgcolor="#EEEEEE" style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#FFFFFF', endColorStr='#6699CC', gradientType='1')"><font color="#000000" size="2">Package Workflow Application - Step 3</font></td>
                  </tr>

<%
   Hashtable clientFiles = (Hashtable)session.getAttribute("WFAppClientFiles");
   Hashtable serverFiles = (Hashtable)session.getAttribute("WFAppServerFiles");
   WFAppManifest manifest = (WFAppManifest)session.getAttribute("WFAppManifest");

%>

     <tr class="headrow">
      <th colspan="12">List of Client Side Files</th>
      </tr>
<%
  Hashtable componentHash = new Hashtable();
  WFAppComponent[] clientComponents = manifest.getClientComponents();
  if(clientComponents != null)
  {
     for(int i=0; i< clientComponents.length; i++)
        componentHash.put(clientComponents[i].getLocation(),clientComponents[i]);
  }
  manifest.removeClientComponents();

  if(clientFiles != null)
  {
     int k=0;
     Vector mfiles = insertionSort(clientFiles.elements());
     for(int kk=0; kk < mfiles.size(); kk++)
     {
        String location = (String)mfiles.elementAt(kk);

        if(componentHash.get(location) != null)
        {
           manifest.addClientComponent((WFAppComponent)componentHash.get(location));
        }
        else
        {
           WFAppComponent clientComponent = new WFAppComponent(location, WFAppConstants.SKIP_OPERATION);
           manifest.addClientComponent(clientComponent);
        }
        k = k + 1;
%>
      <tr bgcolor="#FFFFFF">
      <td><%= k %></td>
      <td><%= location %></td>
      </tr>
<%
    }
  }

%>

      <tr class="headrow">
      <th colspan="12">List of Server Side Files</th>
      </tr>
<%
  componentHash = new Hashtable();
  WFAppComponent[] serverComponents = manifest.getServerComponents();
  if(serverComponents != null)
  {
     for(int i=0; i< serverComponents.length; i++)
        componentHash.put(serverComponents[i].getLocation(),serverComponents[i]);
  }

  manifest.removeServerComponents();
  if(serverFiles != null)
  {
     int k=0;
     Vector mfiles = insertionSort(serverFiles.elements());
     for(int kk=0; kk < mfiles.size(); kk++)
     {
        String location = (String)mfiles.elementAt(kk);
        if(componentHash.get(location) != null)
        {
           manifest.addServerComponent((WFAppComponent)componentHash.get(location));
        }
        else
        {
           WFAppComponent serverComponent = new WFAppComponent(location, WFAppConstants.SKIP_OPERATION);
           manifest.addServerComponent(serverComponent);
        }
        k = k + 1;
%>
      <tr bgcolor="#FFFFFF">
      <td><%= k %></td>
      <td><%= location %></td>
      </tr>
<%
    }
  }

  session.setAttribute("WFAppManifest",manifest);
%>
</TABLE>


<p>


<table width="80%" cellpadding="4" cellspacing="0" class="tableclass">
<tr>
        <td valign="center" align="center" bgcolor="#FFFFFF">
        Enter Package Name <input type=text name=PackageName >&nbsp;
        <input type="submit" value="Submit" class="submitClass">
        </td>
    </tr>
</table>


</form>

<%!
    public Vector insertionSort(Enumeration sElements)
    {
       int i, j;
       String fileName;
       Vector mfiles = new Vector();
       for (; sElements.hasMoreElements() ;)
       {
          mfiles.addElement(sElements.nextElement());
       }
       
       for (i=1; i < mfiles.size(); i++)
       {
          fileName = (String)mfiles.elementAt(i);
          j = i;
          while ((j > 0) && (((String)mfiles.elementAt(j-1)).compareTo(fileName)>0))
          {
               mfiles.set(j,mfiles.elementAt(j-1));
               j = j - 1;
          }
          mfiles.set(j,fileName);
       }
       return mfiles;
   }

%>
</center>
</body>
</html>
