<%@page contentType="text/html;charset=UTF-8" pageEncoding="ISO-8859-1" session="true"
%><%@page errorPage="Exception.jsp"
%><%@page import="com.fujitsu.iflow.common.UdaNameSanitizer"
%><%@page import="com.fujitsu.iflow.common.DataSourceConfParser"
%><%@page import="com.fujitsu.iflow.common.ErrorMessage"
%><%@page import="com.fujitsu.iflow.model.bpm.BPMSession"
%><%@page import="com.fujitsu.iflow.model.bpmcore.BPMSessionImpl"
%><%@page import="com.fujitsu.iflow.model.util.ModelException"
%><%@page import="com.fujitsu.iflow.model.util.QuickForm"
%><%@page import="com.fujitsu.iflow.model.util.QuickFormOperation"
%><%@page import="com.fujitsu.iflow.model.util.URLEncoder"
%><%@page import="com.fujitsu.iflow.model.workflow.AttachmentRef"
%><%@page import="com.fujitsu.iflow.model.workflow.AttachmentRef"
%><%@page import="com.fujitsu.iflow.model.workflow.DataItem"
%><%@page import="com.fujitsu.iflow.model.workflow.DataItemRef"
%><%@page import="com.fujitsu.iflow.model.workflow.Plan"
%><%@page import="com.fujitsu.iflow.model.workflow.ProcessInstantiator"
%><%@page import="com.fujitsu.iflow.model.workflow.FormRef"
%><%@page import="com.fujitsu.iflow.model.workflow.Node"
%><%@page import="java.io.File"
%><%@page import="java.io.Writer"
%><%@page import="java.util.Hashtable"
%><%@page import="java.text.DateFormat"
%><%@page import="java.util.Date"
%><%@page import="java.util.Properties"
%><%@page import="java.util.Enumeration"
%><%@page import="java.util.Locale"
%><%@page import="java.io.FileInputStream"
%><%@page import="java.util.StringTokenizer" 
%><%@page import="javax.xml.parsers.DocumentBuilder"
%><%@page import="javax.xml.parsers.DocumentBuilderFactory"
%><%@page import="org.w3c.dom.Document"
%><%@page import="org.w3c.dom.Element"
%><%@page import="org.w3c.dom.*"
%><%@page import="org.w3c.dom.NodeList"
%><%@page import="org.xml.sax.SAXException"
%><%@page import="org.xml.sax.SAXParseException"
%><%
    request.setCharacterEncoding("UTF-8");request.getParameterNames(); //Need dummy call for WL9.1
    BPMSession bps = (BPMSession) session.getAttribute("BPMSession");
    if(bps == null) 
    {
%>     <jsp:include page="PasswordPanel.jsp" flush="true"/>
<%
        return;
    }
    String webServerURL = bps.getServerOption("TWFServerBaseURL");
    String planID = request.getParameter("planToProcess");
    String selectedForm = request.getParameter("Forms");
    String uploadPressed = request.getParameter("Upload");
    if(uploadPressed != null) 
    {
        session.setAttribute("PlanIdToUpload", planID);
        response.sendRedirect("Upload.jsp");
        return;
    }
%>

<%

    //addtion regarding QFE done
    String fileName = application.getRealPath("/").trim();
    if (fileName.endsWith(File.separator))
        fileName = fileName + "Config"+File.separator+"QuickFormCSSDef.xml";
    else
        fileName = fileName + File.separator + "Config"+File.separator+"QuickFormCSSDef.xml";
    //End of Addition
    Enumeration paramNames = (Enumeration)request.getParameterNames();
    while(paramNames.hasMoreElements())
    {
    String pName = (String)paramNames.nextElement();
    }
    String[] bcolor = {"evenrow","oddrow"};
    int nextColor = 0;

    if(planID == null)
    { 
       %><jsp:include page="TemplateList.jsp" flush="true"/><%
       return;
    }

    Plan plan = bps.getPlan(Long.parseLong(planID));
    String desc = plan.getDesc();
    desc = (desc == null || desc.length() <=0)?"":desc;
    session.setAttribute("plan", plan);
    session.setAttribute("planID", planID);
    ProcessInstantiator processInstantiator = null;
    Boolean bResuseInstantiator = (Boolean)session.getAttribute("reuseProcInstantiator");
    if (bResuseInstantiator == null || !bResuseInstantiator.booleanValue()) 
    {
        processInstantiator = bps.getProcessInstantiator(plan.getId());
        processInstantiator.setName("");
        processInstantiator.setDescription("");
    }
    else 
    {
        processInstantiator = (ProcessInstantiator)session.getAttribute("processInstantiator");
        if (!processInstantiator.getPlan().getName().equals(plan.getName())) 
        {
            processInstantiator = bps.getProcessInstantiator(plan.getId());
            processInstantiator.setName("");
            processInstantiator.setDescription("");
        }
    }
    session.setAttribute("reuseProcInstantiator", new Boolean(false));
    session.setAttribute("processInstantiator", processInstantiator);

    FormRef [] startForms = {};
    Node [] definitionNodes = plan.getNodes();
    if (definitionNodes.length > 0) 
    {
        for (int i = 0; i < definitionNodes.length; i++) 
        {
            if (definitionNodes[i].getType() == Node.TYPE_START) 
            {
                startForms = definitionNodes[i].getForms();
                break;
            }
        }
    }

%>

<%
    if((startForms == null) || (startForms.length <= 0)) 
    {
%> 
      <html>
      <head>
      <title>Interstage Business Process Manager | Process Instance Instantiator</title>
      <jsp:include page="StyleSheet.jsp" flush="true"/>
      <script language="javascript">
        function deleteAttachment(name)
        {
           window.location.reload()
        }

        function validateInputFields()
        {
           var pName = document.wiForm.procName.value;
           var pDesc = document.wiForm.procDesc.value;
    
           if(pName.length > 30) 
           {
              alert("Process Instance name cannot be more than 30 characters.");
              document.wiForm.procName.focus();
              document.wiForm.procName.select();
              return false;
           }
           if(pDesc.length > 256) 
           {
              alert("Process Instance description cannot be more than 256 characters.");
              document.wiForm.procDesc.focus();
              document.wiForm.procDesc.select();
              return false;
           }       
        }
      </script>
      <script language="javascript" src="styles/timerScripts.js"></script>
      <script language="javascript" src="styles/clockscripts.js"></script>

      <style type="text/css">@import url(calendar/calendar-win2k-1.css);</style>
      <script type="text/javascript" src="calendar/calendar.js"></script>
      <script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
      <script type="text/javascript" src="calendar/calendar-setup.js"></script>
      </head>

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

     <center>
     <form name="wiForm" method="post" action="ProcessInstantiatorAction.jsp" onSubmit="return validateInputFields()">
<%
     String rowColor = bcolor[nextColor];
     nextColor = (nextColor + 1)%2;
%>
     <br/>
     <TABLE  class="tableClass" border="0" cellspacing="1" cellpadding ="4" bgcolor="#CCCCCC" width="90%">
       <COL WIDTH="20%"><COL WIDTH="80%">
       <tr colspan="2" class="<%=rowColor%>">
        <input name="operation" type="submit" value="Start" class="submitClass">
       </tr>
       <tr>
          <td class="headrow" colspan="2">
            <table width="100%">
                <tr>
                    <td class="headrow">
                        Create new instance of &nbsp; <b><% QuickForm.writeHtml(out, plan.getName()); %></b>
                        </td>
                    <td align="right" class="headrow">
                        (Id : <%= planID %>, Version : <%= plan.getVersion() %>)
                        </td>
                    </tr>
                <tr>
                    <td colspan="2" class="headrow">
                        <small>Process Definition Description : <% QuickForm.writeHtml(out, desc); %></small>
                        </td>
                </tr>
            </table>
          </td>
      </tr>
<%
      rowColor = bcolor[nextColor];
      nextColor = (nextColor + 1)%2;
%>
        <tr class="<%=rowColor%>">
          <td colspan="2">
            <table  class="tableClass" width="100%">
                <COL WIDTH="20%"><COL WIDTH="80%">
                <tr>
                    <td class="prompt"valign="top"> Name </td>
                    <td> <input name="procName" type="text" value="<% QuickForm.writeHtml(out, processInstantiator.getName()); %>" size="80"> </td>
                </tr>
                <tr>
                    <td class="prompt" valign="top"> Description </td>
                    <td>
                        <textarea name="procDesc" cols="62" rows="5"><% QuickForm.writeHtml(out, processInstantiator.getDescription()); %></textarea>
                    </td>
                </tr>
              </table>
            </td>
        </tr>

<%      
      DataItemRef[] dataInOrder = plan.getDataItemRefs();
      DataItem data[] = processInstantiator.getDataItems();
      int dataCount = 0;
      if (dataInOrder != null && dataInOrder.length > 0)
      {
        dataCount = dataInOrder.length;
        rowColor = bcolor[nextColor];
        nextColor = (nextColor + 1)%2;
%>
        <tr class="<%=rowColor%>">
            <td colspan="2">
                <table class="tableClass" width="100%" border="0">
                    <COL WIDTH="20%"><COL WIDTH="80%">
<%
        for (int i=0; i<dataCount; i++)
        {
            String name = dataInOrder[i].getName();
            if (name.trim().startsWith("_")) 
            {
                continue;
            }
            DataItem di=null;
            for (int j=0; j<data.length; j++) 
            {
                if (name.equals(data[j].getName())) 
                {
                    di = data[j];
                    break;
                }
            }
            if (di == null) 
            {
                throw new Exception("Inconsistency between Process Definition and ProcessInstanciator about data item '"+name+"'");
            }
            String value = di.getValue();
            String udaType = di.getType();
%>
            <tr>
               <td class="prompt"><% QuickForm.writeHtmlWithNBSPs(out, name); %></td>
               <td>
                   <% showInputBox(out, name, value, udaType); %>                 
               </td>
            </tr>
<%
        }   //for (int i=0; i<dataCount; i++)
%>
          </table>
        </td>
      </tr>
<%
      }   //if (data != null && data.length > 0)
      
      
      rowColor = bcolor[nextColor];
      nextColor = (nextColor + 1)%2;
%>
      </table><br/>
      <!-- New Table for attachments -->
      <TABLE  class="tableClass" border="0" cellspacing="1" cellpadding ="4" bgcolor="#CCCCCC" width="90%">
      <COL WIDTH="20%"><COL WIDTH="80%">
      <tr>
        <td colspan="3" class="headrow"> 
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="2%"><img src="images/icons/attachment.gif" border="0"></td>
              <td class="headrow">&nbsp;Attachments </td>
            </tr>
          </table>
        </td>
      </tr>
<%
      AttachmentRef attachments[] = processInstantiator.getAttachments();
      int attachCount = 0;
      if(attachments != null && attachments.length > 0) 
      {
         attachCount = attachments.length;
%>
         <tr class="oddrow">
         <th align="left">Attachment Title</th>
         <th align="left">Attachment</th>
         <th align="center">Delete</th>
         </tr>
<%
      }
      for (int i=0; i<attachCount; i++)
      {
         String name = attachments[i].getName();
         String attPath = attachments[i].getPath();
%>
         <tr class="<%= rowColor %>">
            <td> <% QuickForm.writeHtml(out, name); %> </td>
            <td> <input name="<% QuickForm.writeHtml(out, attPath); %>" type="hidden" 
                  value="<% QuickForm.writeHtml(out, attPath); %>" size="30">
                 <font class="arialfonts"><% QuickForm.writeHtml(out, attPath); %></font> </td>
            <td align="center"> <input name="attach1" type="checkbox" value="<% QuickForm.writeHtml(out, name); %>"> </td>
         </tr>
<%
         rowColor = bcolor[nextColor];
         nextColor = (nextColor + 1)%2;
      }   //for (int i=0; i<attachCount; i++)
%>
            </td>
        </tr>
        <tr class="<%= rowColor%>">
            <td colspan="3" align="right">
            <%
                if (attachments != null && attachments.length > 0)
                {
            %>
                    <input name="operation" type="submit" value="Delete Selected" class="submitClass">&nbsp;
            <%
                }
            %>

                <input name="operation" type="submit" value="Add" class="submitClass">
            </td>
        </tr>
   </TABLE>
   </form>
   </center>
   </body>
   </html>
<%
    } // End if Forms not there
    else 
    {
        QuickForm qf = null;       
        String formPath = "", formName = "";
        for (int i=0; i < startForms.length; i++) 
        {
            formPath = startForms[i].getPath();
            formName = startForms[i].getName();
            if(formPath.indexOf("FormsRepository") >= 0)
            {
                String formRep = formPath.substring(formPath.lastIndexOf("FormsRepository")+16);
                int pos = formRep.indexOf("\\");
                webServerURL = webServerURL.trim();
                if (!webServerURL.endsWith("/")) 
                {
                    webServerURL += "/";
                }
                StringBuffer encodedFormPath = new StringBuffer(webServerURL);
                encodedFormPath.append("QuickForms/");
                while (pos >= 0) 
                {
                    urlEncode(encodedFormPath, formRep.substring(0, pos));
                    encodedFormPath.append("/");
                    formRep = formRep.substring(pos+1);
                    pos = formRep.indexOf("\\");
                }
          
                urlEncode(encodedFormPath, formRep);
                qf = QuickForm.getQuickForm(formName, encodedFormPath.toString());
            }
            else
            {
                qf = QuickForm.getQuickForm(formName, formPath);
            }
            if(selectedForm == null || selectedForm.equals(formName) == true)
               break;
        }
        
        try
        {
            int size = qf.opList.length;
        //System.out.println("Size of Opcode in QF---"+size);
            DataItem udaData[] = processInstantiator.getDataItems();
            int ulen = udaData.length;
            /*if(udaData.length ==0)
            throw new Exception("User Defined Attributes required for this form does not exist in this Process. Please contact your System Administrator.");
        else
        {*/
             String udaNames[] = new String[ulen];
             for(int i=0; i<ulen; i++) 
            {
               udaNames[i] = udaData[i].getName();
            }
            Hashtable udaLookup = UdaNameSanitizer.getReverseLookup(udaNames);
            String rowColor = bcolor[nextColor];
            boolean insertFlag = false;

            for(int i=0; i<size; i++) 
            {
               QuickFormOperation op = qf.opList[i];
               String param = op.paramValue.trim();
               switch(op.opCode) 
               {
                case QuickFormOperation.WORKITEMHEADER:
    %>
                    <jsp:include page="ProcessHeader.jsp" flush="true"/><br>
    <%
                    continue;
                case QuickFormOperation.PROCESSPANEL:
    %>
    <!--------------------------beginning of process panel----------------------------->
                    <br/>
                    <TABLE  class="tableClass" border="0" cellspacing="1" cellpadding ="4" bgcolor="#CCCCCC" width="90%">
                      <COL WIDTH="20%"><COL WIDTH="80%">
                      <tr colspan="2" class="<%=rowColor%>">
                         <input name="operation" type="submit" value="Start" class="submitClass">
                      </tr>
                      <tr>
                         <td class="headrow" colspan="2">
                           <table width="100%">
                             <tr>
                               <td class="headrow">
                                  Create new instance of &nbsp; <b><% QuickForm.writeHtml(out, plan.getName()); %></b>
                               </td>
                               <td align="right" class="headrow">
                                  (Id : <%= planID %>, Version : <%= plan.getVersion() %>)
                               </td>
                            </tr>
                            <tr>
                               <td colspan="2" class="headrow">
                               <small>Process Definition Description : <% QuickForm.writeHtml(out, desc); %></small>
                               </td>
                           </tr>
                        </table>
                      </td>
                    </tr>
   <%
                    rowColor = bcolor[nextColor];
                    nextColor = (nextColor + 1)%2;
   %>
                   <tr class="<%=rowColor%>">
                     <td colspan="2">
                        <table  class="tableClass" width="100%">
                          <COL WIDTH="20%"><COL WIDTH="80%">
                            <tr>
                              <td class="prompt"valign="top"> Name </td>
                              <td> <input name="procName" type="text" 
                                   value="<% QuickForm.writeHtml(out, processInstantiator.getName()); %>" size="80"> </td>
                            </tr>
                            <tr>
                              <td class="prompt" valign="top"> Description </td>
                              <td>
                                 <textarea name="procDesc" cols="62" rows="5">
                                 <% QuickForm.writeHtml(out, processInstantiator.getDescription()); %></textarea>
                              </td>
                           </tr>
                       </table>
                   </td>
                 </tr>

                 <tr>
                   <td class="prompt" valign="top"> Forms </td>
                   <td>
    <%
                   boolean mflag = (selectedForm == null);
          
                   for(int kk=0; kk < startForms.length; kk++) 
                   {
                      String myForm = startForms[kk].getName();
                      if(mflag == true || (selectedForm != null && myForm.equals(selectedForm))) 
                      {
                         if(mflag == true)
                         {
                           selectedForm = myForm;
                           mflag = false;
                         }
    %>                   <b><% QuickForm.writeHtml(out, selectedForm); %>
                         </b> <input type="hidden" name="Forms" value="<%= selectedForm %>">
    <%
                     }
                     else 
                     {
    %>                   <b>[</b>&nbsp;
                         <a href="ProcessInstantiator.jsp?planToProcess=<%=planID%>&Forms=<%=URLEncoder.encode(myForm, "UTF-8")%>">
                         <% QuickForm.writeHtml(out, myForm); %></a>&nbsp;<b>]</b>
    <%
                     }

                   }
    %>
                  </td>
                 </tr>
                </TABLE>

    <!--------------------------end of process panel----------------------------------->
                
    <%
                   continue;
                case QuickFormOperation.ATTACHMENTPANEL: 
    %>
    <!--------------------------beginning of attachment panel----------------------------->
                  <br/>
                  <!-- New Table for attachments -->
                  <TABLE  class="tableClass" border="0" cellspacing="1" cellpadding ="4" bgcolor="#CCCCCC" width="90%">
      
                   <tr>
                     <td colspan="3" class="headrow" width="628"> 
                      <table width="100%" border="0" cellspacing="0" cellpadding="0">
                       <tr>
                         <td width="2%"><img src="images/icons/attachment.gif" border="0"></td>
                         <td class="headrow">&nbsp;Attachments </td>
                       </tr>
                      </table>
                     </td>
                   </tr>
   <%
                       AttachmentRef attachments[] = processInstantiator.getAttachments();
                       int attachCount = 0;
                       if(attachments != null && attachments.length > 0) 
                       {
                          attachCount = attachments.length;
   %>
                          <tr class="oddrow">
                            <th align="left">Attachment Title</th>
                            <th align="left">Attachment</th>
                            <th align="center">Delete</th>
                          </tr>
   <%
                      }
      
                      for (int ki=0; ki<attachCount; ki++)
                      {
                         String name = attachments[ki].getName();
                         String attPath = attachments[ki].getPath(); 
   %>
                         <tr class="<%= rowColor %>">
                           <td> <% QuickForm.writeHtml(out, name); %> </td>
                           <td> <input name="<% QuickForm.writeHtml(out, attPath); %>" type="hidden" 
                                 value="<% QuickForm.writeHtml(out, attPath); %>" size="30">
                                 <font class="arialfonts"><% QuickForm.writeHtml(out, attPath); %></font> </td>
                           <td align="center"> <input name="attach1" type="checkbox" value="<% QuickForm.writeHtml(out, name); %>"> </td>
                         </tr>
   <%
                         rowColor = bcolor[nextColor];
                         nextColor = (nextColor + 1)%2;
                     }   
   %>
                     <tr class="<%= rowColor%>">
                        <td colspan="3" align="right">
                     <%
                     if(attachments != null && attachments.length > 0)
                     {
            %>
                          <input name="operation" type="submit" value="Delete Selected" class="submitClass">&nbsp;
            <%
                     }
            %>

                         <input name="operation" type="submit" value="Add" class="submitClass">
                       </td>
                     </tr>
                    </TABLE>
                   
              
    <!--------------------------end of attachment panel----------------------------------->
    <%
                    continue;
                case QuickFormOperation.DEFAULTUDAS: 
                   {
    %>
                        <jsp:include page="DefaultUDAs.jsp" flush="true"/>
    <%
                   }
                   continue;
                 // This has been added to handle the new functionality provided in IBPM ver 8 server.
                case QuickFormOperation.HTMLCONTROL: {
                                                                      //try
                                      //{				
                                                        Properties prop = op.parseAttributes();            	  
                                                        handleControls(fileName,out,param,processInstantiator,bps,prop);
                                                        continue;
                                                       /* }catch(Exception nd)
                            {
                             out.write("This Process Instance Variable does not exist in the Process.");
                            }*/
                }
                case QuickFormOperation.TEMPLATESTART :{
                                                        continue;
                }
                case QuickFormOperation.TEMPLATEEND :{
                                                        continue;
                                                }   
                
                case QuickFormOperation.HTMLSTRING:
                  
                   if(insertFlag == false)
                   {
                     insertFlag = true;
    %>
                     <script language="javascript">
                       function deleteAttachment(name)
                       {
                          window.location.reload()
                       }

                       function validateInputFields()
                       {
                          var pName = document.wiForm.procName.value;
                          var pDesc = document.wiForm.procDesc.value;
    
                          if(pName.length > 30) 
                          {
                             alert("Process Instance name cannot be more than 30 characters.");
                             document.wiForm.procName.focus();
                             document.wiForm.procName.select();
                             return false;
                          }
                          if(pDesc.length > 256) 
                          {
                             alert("Process Instance description cannot be more than 256 characters.");
                             document.wiForm.procDesc.focus();
                             document.wiForm.procDesc.select();
                             return false;
                          }       
                       }
                       </script>
                     
                       <script language="javascript" src="styles/timerScripts.js"></script>
                       <script language="javascript" src="styles/clockscripts.js"></script>

                       <style type="text/css">@import url(calendar/calendar-win2k-1.css);</style>
                       <script type="text/javascript" src="calendar/calendar.js"></script>
                       <script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
                       <script type="text/javascript" src="calendar/calendar-setup.js"></script>
                       
    <%
                  }
                  String xmlString = 
                      op.paramValue.replaceAll("action=\"WorkItemAction.jsp\"",
                                              "action=\"ProcessInstantiatorAction.jsp\"" + 
                                              " onSubmit=\"return validateInputFields()\"");
                  xmlString = xmlString.replaceAll("resetWorkTimer\\(\\)","");
                  xmlString = xmlString.replaceAll("stopWorkTimer\\(\\)","");
                  //xmlString = xmlString.replaceAll("class=\"bodyClass\"","");
                  out.write(xmlString);
                  continue;
              }

              String value="";
              String attributeName = (String)udaLookup.get(param);
              String attrType = "STRING";
              if(attributeName != null) 
              {
                 value = processInstantiator.getDataItemValue(attributeName);

                 attrType = processInstantiator.getDataItemType(attributeName);
                
              }

              switch(op.opCode) 
              {
                 case QuickFormOperation.FIELD:
                    QuickForm.writeHtmlWithLineBreaks(out, value);
                    break;
                 case QuickFormOperation.INPUT:
                    showInputBox(out, attributeName, value, attrType);
                    break;
                 case QuickFormOperation.HIDDEN:
                    out.write("<input type=\"hidden\" name=\"uda_");
                    QuickForm.writeHtml(out, param);
                    out.write("\" value=\"");
                    QuickForm.writeHtml(out, value);
                    out.write("\" />");
                    break;
                 case QuickFormOperation.CALENDAR:
                    showInputBox(out, attributeName, value, attrType);
                    break;
                default:
                    throw new Exception("Invalid opcode {{?" + op.opCode + " " + param + "}}");
            }
         } //for
     // }
      }catch (Exception e) 
      {
        throw new Exception ("Unable to render form '"+formName+"' file '"+formPath
               +"' for start node because: "+e.toString());
      }

   } // End Forms exist
%>


<%!
    private void urlEncode(StringBuffer dest, String source)
    {
        for(int i=0; i<source.length(); i++) {
            char ch = source.charAt(i);
            if ( (ch >= '0' && ch <= '9') ||
                 (ch >= 'a' && ch <= 'z') ||
                 (ch >= 'A' && ch <= 'Z') ||
                 (ch == '_') || (ch == '.')||
                 (ch == '/')) {
                dest.append(ch);
            }
            else {
                dest.append('%');
                int j = (int) ch;
                if (j<128) {
                    dest.append(Integer.toString((int)ch, 16));
                }
                // above 128 need to encode in UTF8 first!
                else if (j<2048) {
                    dest.append(Integer.toString(192 + ((j >> 6) % 32), 16));
                    dest.append('%');
                    dest.append(Integer.toString(128 + (j % 64), 16));
                }
                else if (j<2048) {
                    dest.append(Integer.toString(224 + ((j >> 12) % 16), 16));
                    dest.append('%');
                    dest.append(Integer.toString(128 + ((j>>6) % 64), 16));
                    dest.append('%');
                    dest.append(Integer.toString(128 + (j % 64), 16));
                }
            }
        }
    }

//new Additions
public void handleControls(String fileName,Writer out,String param, ProcessInstantiator task,BPMSession bps,java.util.Properties prop) 
//throws Exception
        {
         //String s = null;
         String type=null;
         String uda = null;
         String value = null;
         String maxchar = null;
         String maxwidth ="";
         String cols = "";
         String rows = "";
         String property1 = "";
         String size = "";
         String style_name="";
         boolean valid = false;

         type = prop.getProperty("type");
         uda = prop.getProperty("uda");
         
         if(prop.getProperty("value")!=null){
         	 value = prop.getProperty("value");
         }
         if(prop.getProperty("maxchar")!=null){
         	 maxchar = prop.getProperty("maxchar");
         }
         if (prop.getProperty("maxwidth") != null) {
             maxwidth = prop.getProperty("maxwidth");
         }
         if (prop.getProperty("rows") != null) {
             rows = prop.getProperty("rows");
         }
         if (prop.getProperty("cols") != null) {
             cols = prop.getProperty("cols");
         }
         if (prop.getProperty("multiselection") != null) {
             property1 = prop.getProperty("multiselection");
         }
         if (prop.getProperty("size") != null) {
             size = prop.getProperty("size");
         }
         if (prop.getProperty("name") != null) {
             style_name = prop.getProperty("name");
         }
         if (type != null) {
             valid = true;
         }
         
         // after reading all the tokens
           
          try
              {
                if (valid)
                        {
                        String input_value = null;
                        String attrType = "STRING";
                        String uda_type = "STRING";
                        if (uda != null) 
                        {
                               if(task != null)
                                { 
                                try{
                                    if(task.getDataItem(uda).getType() != null)
                                    {
                                    input_value = (String)task.getDataItemValue(uda);
                                    uda_type = (String)task.getDataItemType(uda);   
                                    }
                                    }catch(Exception ne)
                                    {
                                       
                                    }                       
                                } 
                                else 
                                        input_value =null;
                          
                         }
                        if(uda_type == null)
                            uda_type = type; 

                        if(input_value == null)
                            input_value = "";
                          //System.out.println("type----"+type);
                          if (type.equalsIgnoreCase("TEXT"))
                                          showTextBox(out,uda,value,input_value,maxchar,maxwidth,"TEXT");
                          else if ( type.equalsIgnoreCase("PASSWORD") )
                                          showTextBox(out,uda,value,input_value,maxchar,maxwidth,"PASSWORD");   
                          else if ( type.equalsIgnoreCase("HIDDEN") )
                                        showTextBox(out,uda,value,input_value,maxchar,maxwidth,"HIDDEN");
                          else if ( type.equalsIgnoreCase("READONLY") )
                                        showTextBox(out,uda,value,input_value,maxchar,maxwidth,"READONLY");
                          else if ( type.equalsIgnoreCase("TEXTAREA") )
                                        showTextArea(out,uda,value,input_value,rows,cols);
                          else if ( type.equalsIgnoreCase("RADIO") )
                                        showRadioBox(out,uda,value,input_value);
                          else if ( type.equalsIgnoreCase("CHECK") )
                                        showCheckBox(out,uda,value,input_value);
                          else if ( type.equalsIgnoreCase("COMBO") )
                                        showListBox(out,uda,value,input_value,"Single",size);
                          else if ( type.equalsIgnoreCase("LIST") )
                                        showListBox(out,uda,value,input_value,property1,size);
                         else if ( type.equalsIgnoreCase("CALENDAR") )
                                        showCalendar(out,uda,input_value);
                         else if ( type.equalsIgnoreCase("DEFAULT") )
                                        showCustomInputBox(out,uda,input_value,uda_type);
                         else if ( type.equalsIgnoreCase("STYLE") )
                                        putStyle(fileName,out,style_name,bps);
            }
        }catch(Exception e)
        {
            //throw new Exception("Excedption occurred while parsing the HTMLCONTROL type Data");
            System.out.println("Excedption occurred while parsing the HTMLCONTROL type Data" + e.toString());
        }
    }
  

    private Document getQuickFormCssDoc(BPMSession bps) throws ModelException
    {
        Document doc = null;
        try{            
            doc = DataSourceConfParser.getXmlConfigFileDocument(((BPMSessionImpl)bps)._wfs, "QuickFormCSSDef.xml");
        }catch(Exception ex){
            //ErrorMessage Could not complete the XML parsing. = 10017 = XML_PARSING_FAILED
            //Log.println(Log.LEVEL0,"getQuickFormCssDoc: "+ex);
            throw new ModelException(ErrorMessage.XML_PARSING_FAILED,ex);
        }
        return doc;
    }
   
   private String getStyleSheetsPath(String fileName,Writer out, String style_name,BPMSession bps)
        {
         String path = null;
         try
         {
          Document doc = getQuickFormCssDoc(bps);
          NodeList listOfStyles = doc.getElementsByTagName("style");
          int totalStyles = listOfStyles.getLength();
          //styleSheetName = new String[totalStyles];
          for(int s=0; s<listOfStyles.getLength() ; s++)
                {
                    org.w3c.dom.Node firstStyleNode = listOfStyles.item(s);
                    if(firstStyleNode.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE)
                    {
                        Element styleElement = (Element)firstStyleNode;
                        NodeList styleNameList = styleElement.getElementsByTagName("name");
                        Element styleNameElement = (Element)styleNameList.item(0);
                        NodeList textSNList = styleNameElement.getChildNodes();
                        String name = ((org.w3c.dom.Node)textSNList.item(0)).getNodeValue().trim();
                                        if(name.equals(style_name))
                                          {
                                            NodeList pathList = styleElement.getElementsByTagName("path");
                        Element pathVal = (Element)pathList.item(0);
                        NodeList pathNameList = pathVal.getChildNodes();
                        path= ((org.w3c.dom.Node)pathNameList.item(0)).getNodeValue().trim();
                                                return path;
                      }
                                 }//end of if clause
                }//end of for loop with s var
                //return path;
                }catch (Exception e)
            {
            e.printStackTrace();
            }catch (Throwable t)
            {
            t.printStackTrace ();
            }
            return null;
        }

    public void putStyle(String fileName,Writer out, String style_name,BPMSession bps)
        throws Exception
        {
          Properties props = new Properties();
          try
                {
                        String style = null;
                        if(style_name == null || style_name.length() == 0)
                            style = "default";
                        else
                            style = style_name;
                        String path = null;
                        //if(style_name != null && style_name.length() != 0)         
                                path = getStyleSheetsPath(fileName,out,style,bps);
                        //else         
                         //       path = getStyleSheetsPath(fileName,out,"default");
                        out.write("<LINK rel=\"stylesheet\" href=\""+path+"\" type=\"text/css\">\n");
                }catch(Exception e){
                        QuickForm.writeHtml(out, style_name);
            out.write("' ");
            
            out.write(" ");
            
                QuickForm.writeHtml(out, e.toString());
               
        }
                
    }

    public String getContolType(String type)
        {
        if ( type.equalsIgnoreCase("\"TEXT\""))
                        return "TEXT";
                else if ( type.equalsIgnoreCase("\"PASSWORD\"") )
                        return "PASSWORD";
                else if ( type.equalsIgnoreCase("\"HIDDEN\"") )
                        return "HIDDEN";
                else if ( type.equalsIgnoreCase("\"READONLY\"") )
                        return "READONLY";
                else if ( type.equalsIgnoreCase("\"TEXTAREA\"") )
                        return "TEXTAREA";
                else if ( type.equalsIgnoreCase("\"RADIO\"") )
                        return "RADIO";
                else if ( type.equalsIgnoreCase("\"CHECK\"") )
                        return "CHECK";
                else if ( type.equalsIgnoreCase("\"COMBO\"") )
                        return "COMBO";
                else if ( type.equalsIgnoreCase("\"LIST\"") )
                        return "LIST";
                else if ( type.equalsIgnoreCase("\"Calendar\"") )
                        return "CALENDAR";
                else if ( type.equalsIgnoreCase("\"Default\"") )
                        return "DEFAULT";
                else if ( type.equalsIgnoreCase("\"style\"") )
                        return "STYLE";
                return null;
    }

    public void showTextArea(Writer out,String uda,String value,String input_value,String rows,String cols)
        throws Exception
        {
       try
                {
                  value = input_value;
                out.write("<textarea name=\"uda_"+uda+"\" cols=\" "+cols+ " \" rows=\" "+rows+" \" value=\"\" >");
                out.write(input_value);
                out.write("</textarea>");
        } catch(Exception e)
                {  
               QuickForm.writeHtml(out, e.toString());
           
                }   
        }

    public void showRadioBox(Writer out,String uda,String value,String input_value)
        throws Exception
        {
                try
                {
         String[] tokens = null;
                 if(value!=null)
                        tokens = value.split("&sep;");
                 String name = "";
                 String val = "";
                 String select[]=null;
                 boolean flag = false;
                 if(input_value!=null )
                          select = input_value.split("&sep;");
                 
                 if(tokens!= null && tokens.length!=0)
                        {
                         for(int i_token=0;i_token<tokens.length;i_token++)
                         {
                         out.write("\n");
                         name = "";
                         val = "";
                         name = tokens[i_token];
                         val = name.substring(name.indexOf("=")+1);
                         name = name.substring(0,name.indexOf("=")); 
                         if(select != null && select.length !=0)
                                 {
                                         for(int index=0;index<select.length;index++)
                                                 {
                                                        if ( val.trim().equals(select[index].trim()))
                                                        {
                                                        flag = true;
                                                        }
                                                 }
                                }
                        if(flag)
                                 {
                                        out.write("<input type=\"radio\" name=\"uda_" + uda + "\" value=\""+val+"\" checked>");
                                        out.write(name);
                                        out.write("<br>");
                                 }
                        else    {
                                        out.write("<input type=\"radio\" name=\"uda_" + uda + "\" value=\""+val+"\">");
                                        out.write(name);
                                        out.write("<br>");
                                }
                                                   flag = false;
                        }
                   }
                } catch(Exception e)
                { 
                 QuickForm.writeHtml(out, e.toString());
             
        }
        }


    public void showCheckBox(Writer out,String uda,String value,String input_value)
        throws Exception
        {
                try
                {
                String name="";
                String val ="";

                String[] tokens= null;
                if(value != null)
                        tokens= value.split("&sep;");
                String select[] = null;
                if(input_value!=null )
                                select = input_value.split("&sep;");
                boolean flag = false;
                if(tokens != null  && tokens.length!=0)
                        {
                                for(int i_token=0;i_token<tokens.length;i_token++)
                                {
                                 out.write("\n");
                                 name = "";
                                 val = "";
                                 name = tokens[i_token];
                                 val = name.substring(name.indexOf("=")+1);
                                 name = name.substring(0,name.indexOf("="));
                                 String option = "option";
                                 if(select !=null && select.length!=0)
                                        {
                                                 for(int index=0;index<select.length;index++)
                                                                 {
                                                                        if ( val.trim().equals(select[index].trim()))
                                                                        {
                                                                          flag = true;  
                                                                        }
                                                                 }
                    }
                                                  if(flag)
                                                          out.write("<input type=\"checkbox\" name=\"uda_" + uda + "\" value=\""+val+"\" checked>");
                                                  else
                                                          out.write("<input type=\"checkbox\" name=\"uda_" + uda + "\" value=\""+val+"\">");
                                   flag = false;                        
                                   out.write(name);
                                }
            }
                } catch(Exception e)
                {   
                QuickForm.writeHtml(out, e.toString());
            
        }
        }


        public void showListBox(Writer out,String uda,String value,String input_value,String property1,String size)
        throws Exception
        {
                try
                {
        String[] tokens=null;
        String prop = property1;
                if(value !=null)
                                tokens = value.split("&sep;");
                String name = "";
                String val = "";
                boolean flag = false;
        String[] select = null;
        if(input_value != null )
           input_value.split("&sep;");
                out.write("\n");
                if(prop == null) 
                    prop = "Single";
                out.write("<select " + prop + " name=\"uda_"+uda+"\" size=\""+size+"\">");
                if(tokens!=null && tokens.length!=0)
                        {
                                        for(int i_token=0;i_token<tokens.length;i_token++)
                                                {
                                                 out.write("\n");
                                                 name = "";
                                                 val = "";
                                                 name = tokens[i_token];
                                                 val = name.substring(name.indexOf("=")+1);
                                                 name = name.substring(0,name.indexOf("="));
                                                 if(select !=null && select.length!=0)
                                                        {
                                                                 for(int index=0;index<select.length;index++)
                                                                        {
                                                                         if( val.trim().equals(select[index].trim()))
                                                                                {
                                                                                     flag = true;
                                                                                }
                                                                        }
                            }
                                                 if(flag)
                                                                 out.write("<option value=\""+val+"\" selected>" +name+"</option>");
                                                 else
                                                                 out.write("<option value=\""+val+"\" >" +name+"</option>");
                                                                   flag = false;
                                        }
                                  
                                         out.write("</select");
            }
                } catch(Exception e)
                {   
                    
                QuickForm.writeHtml(out, e.toString());
            
       }

    }

   public void showTextBox(Writer out,String uda, String value,String input_value,String maxchar,String maxwidth,String type) throws Exception 
    {
     try
                {
                 value = input_value;
                 if(type.equals("TEXT"))
                        {
             out.write("<input type=\"text\" name=\"uda_" + uda + "\" size=\""+maxwidth + "\" value=\"" + value + "\" maxlength=\"" + maxchar + "\"/>");
                        }else if(type.equals("HIDDEN"))
                        {
             out.write("<input type=\"HIDDEN\" name=\"uda_" + uda + "\" size=\""+maxwidth + "\" value=\"" + value + "\" maxlength=\"" + maxchar + "\"/>");
                        }else if(type.equals("PASSWORD"))
                        {
             out.write("<input type=\"PASSWORD\" name=\"uda_" + uda + "\" size=\""+maxwidth + "\" value=\"" + value + "\" maxlength=\"" + maxchar + "\"/>");
                        }else if(type.equals("READONLY"))
                        {
             out.write("<input type=\"TEXT\" name=\"uda_" + uda + "\" size=\""+maxwidth + "\"  READONLY value=\"" + value + "\" maxlength=\"" + maxchar + "\"/>");
                        }
                        out.write("\n");
                } catch(Exception e)
                {   
                 QuickForm.writeHtml(out, e.toString());
                }
    }

        public void showCalendar(Writer out,String uda, String udaValue)
        throws Exception
        {
                        // first rationalize the date into a long value
                // because apparently people do it different ways.
                                try{
                                 String udaIdentifier = UdaNameSanitizer.getSanitizedString(uda);
                long lval = 0;
                try {
                    lval = Long.parseLong(udaValue);
                }
                catch (Exception e2) {
                    // parse the date
                    // assign lval
                }
                //add hidden uda for value
                out.write("\n<input type=\"hidden\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"14\" value=\"");
                QuickForm.writeHtml(out, Long.toString(lval));
                out.write("\" />");
                //add input box
                out.write("\n<input type=\"text\" name=\"xxx_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"40\" onChange=\"validateDate(wiForm.uda_"+udaIdentifier+",wiForm.xxx_"+udaIdentifier+");\"/>");
                //Add image button
                out.write("\n<input type=\"image\" name=\"button_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" src=\"calendar/cal.gif\" width=\"16\" height=\"15\"/>");
                //Add Script
                out.write("\n<script type=\"text/javascript\">");
                out.write("\nwiForm.xxx_"+udaIdentifier+".value = formatDate(wiForm.uda_"+udaIdentifier+".value); ");
                out.write("\nCalendar.setup({inputField  : \"xxx_"+udaIdentifier+"\", button      : \"button_"+udaIdentifier+"\"});");
                out.write("\nshowTimeZone();");
                out.write("\n</script>");
                                }   catch (Exception e) {
                                    QuickForm.writeHtml(out, e.toString());
                        }

    }


 public void showCustomInputBox(Writer out, String udaName, String udaValue, String udaType)
 throws Exception
    {
    try {
            String udaIdentifier = UdaNameSanitizer.getSanitizedString(udaName);
            
              if(udaType.equals(DataItem.TYPE_DATE)) {
                // first rationalize the date into a long value
                // because apparently people do it different ways.
                long lval = 0;
                try {
                    lval = Long.parseLong(udaValue);
                }
                catch (Exception e2) {
                    // parse the date
                    // assign lval
                }
                //add hidden uda for value
                out.write("\n<input type=\"hidden\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"14\" value=\"");
                QuickForm.writeHtml(out, Long.toString(lval));
                out.write("\" />");
                //add input box
                out.write("\n<input type=\"text\" name=\"xxx_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"40\" onChange=\"validateDate(wiForm.uda_"+udaIdentifier+",wiForm.xxx_"+udaIdentifier+");\"/>");
                //Add image button
                out.write("\n<input type=\"image\" name=\"button_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" src=\"calendar/cal.gif\" width=\"16\" height=\"15\"/>");
                //Add Script
                out.write("\n<script type=\"text/javascript\">");
                out.write("\nwiForm.xxx_"+udaIdentifier+".value = formatDate(wiForm.uda_"+udaIdentifier+".value); ");
                out.write("\nCalendar.setup({inputField  : \"xxx_"+udaIdentifier+"\", button      : \"button_"+udaIdentifier+"\"});");
                out.write("\nshowTimeZone();");
                out.write("\n</script>");
            } else if (udaType.equals(DataItem.TYPE_STRING)) {
                //add input box
                if(udaValue == null)
                   udaValue = "";
                out.write("<textarea name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" cols=\"68\" rows=\"2\">");
                QuickForm.writeHtml(out, udaValue);
                out.write("</textarea>");
            } else if (udaType.equals(DataItem.TYPE_INTEGER)) {
                //add input box
                if(udaValue == null)
                   udaValue = "0";
                out.write("<input type=\"text\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"30\" value=\"");
                QuickForm.writeHtml(out, udaValue);
                out.write("\" onChange=\"validateInt(wiForm.uda_"+udaIdentifier+");\"/>");
            } else if (udaType.equals(DataItem.TYPE_LONG)) {
                if(udaValue == null)
                   udaValue = "0";
                //add input box
                out.write("<input type=\"text\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"30\" value=\"");
                QuickForm.writeHtml(out, udaValue);
                out.write("\" onChange=\"validateLong(wiForm.uda_"+udaIdentifier+");\"/>");
            } else if (udaType.equals(DataItem.TYPE_FLOAT)) {
                 if(udaValue == null)
                   udaValue = "0.0";
                //add input box
                out.write("<input type=\"text\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"30\" value=\"");
                QuickForm.writeHtml(out, udaValue);
                out.write("\" onChange=\"validateFloat(wiForm.uda_"+udaIdentifier+");\"/>");
            } else if (udaType.equals(DataItem.TYPE_BIGDECIMAL)) {
                //add input box
                if(udaValue == null)
                   udaValue = "0";
                out.write("<input type=\"text\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"30\" value=\"");
                QuickForm.writeHtml(out, udaValue);
                out.write("\" onChange=\"validateBig(wiForm.uda_"+udaIdentifier+");\"/>");
            } else if (udaType.equals(DataItem.TYPE_BOOLEAN)) {
                //add input box
                if(udaValue == null)
                   udaValue = "false";
                boolean isTrue = udaValue.equals("true");
                out.write("<input type=\"radio\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" ");
                if (isTrue) {
                    out.write("checked ");
                }
                out.write("value=\"true\" /> true ");
                out.write("<input type=\"radio\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" ");
                if (!isTrue) {
                    out.write("checked ");
                }
                out.write("value=\"false\" /> false ");
            } else {
                //add input box
                out.write("<input type=\"text\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"30\" value=\"");
                QuickForm.writeHtml(out, udaValue);
                out.write("\"/>");
            }
        }catch (Exception e) {
            out.write("Unable to understand '");
            QuickForm.writeHtml(out, udaValue);
            out.write("' because: ");
            QuickForm.writeHtml(out, e.toString());
        }
    
    }

//end of Additions

    private void showInputBox(Writer out, String udaName, String udaValue, String udaType)
        throws Exception
    {
        try {
            String udaIdentifier = UdaNameSanitizer.getSanitizedString(udaName);
            if(udaType.equals(DataItem.TYPE_DATE)) {
                // first rationalize the date into a long value
                // because apparently people do it different ways.
                long lval = 0;
                try {
                    lval = Long.parseLong(udaValue);
                }
                catch (Exception e2) {
                    // parse the date
                    // assign lval

                }
                //add hidden uda for value
                out.write("\n<input type=\"hidden\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"14\" value=\"");
                QuickForm.writeHtml(out, Long.toString(lval));
                out.write("\" />");
                //add input box
                out.write("\n<input type=\"text\" name=\"xxx_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"40\" onChange=\"validateDate(wiForm.uda_"+udaIdentifier+",wiForm.xxx_"+udaIdentifier+");\"/>");
                //Add image button
                out.write("\n<input type=\"image\" name=\"button_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" src=\"calendar/cal.gif\" width=\"16\" height=\"15\"/>");
                //Add Script
                out.write("\n<script type=\"text/javascript\">");
                out.write("\nwiForm.xxx_"+udaIdentifier+".value = formatDate(wiForm.uda_"+udaIdentifier+".value); ");
                out.write("\nCalendar.setup({inputField  : \"xxx_"+udaIdentifier+"\", button      : \"button_"+udaIdentifier+"\"});");
                out.write("\nshowTimeZone();");
                out.write("\n</script>");
            } else if (udaType.equals(DataItem.TYPE_STRING)) {
                //add input box
                out.write("<textarea name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" cols=\"68\" rows=\"2\"/>");
                QuickForm.writeHtml(out, udaValue);
                out.write("</textarea>");
            } else if (udaType.equals(DataItem.TYPE_INTEGER)) {
                //add input box
                out.write("<input type=\"text\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"30\" value=\"");
                QuickForm.writeHtml(out, udaValue);
                out.write("\" onChange=\"validateInt(wiForm.uda_"+udaIdentifier+");\"/>");
            } else if (udaType.equals(DataItem.TYPE_LONG)) {
                //add input box
                out.write("<input type=\"text\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"30\" value=\"");
                QuickForm.writeHtml(out, udaValue);
                out.write("\" onChange=\"validateLong(wiForm.uda_"+udaIdentifier+");\"/>");
            } else if (udaType.equals(DataItem.TYPE_FLOAT)) {
                //add input box
                out.write("<input type=\"text\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"30\" value=\"");
                QuickForm.writeHtml(out, udaValue);
                out.write("\" onChange=\"validateFloat(wiForm.uda_"+udaIdentifier+");\"/>");
            } else if (udaType.equals(DataItem.TYPE_BIGDECIMAL)) {
                //add input box
                out.write("<input type=\"text\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"30\" value=\"");
                QuickForm.writeHtml(out, udaValue);
                out.write("\" onChange=\"validateBig(wiForm.uda_"+udaIdentifier+");\"/>");
            } else if (udaType.equals(DataItem.TYPE_BOOLEAN)) {
                //add input box
                boolean isTrue = udaValue.equals("true");
                out.write("<input type=\"radio\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" ");
                if (isTrue) {
                    out.write("checked ");
                }
                out.write("value=\"true\" /> true ");
                out.write("<input type=\"radio\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" ");
                if (!isTrue) {
                    out.write("checked ");
                }
                out.write("value=\"false\" /> false ");
            } else {
                //add input box
                out.write("<input type=\"text\" name=\"uda_");
                QuickForm.writeHtml(out, udaIdentifier);
                out.write("\" size=\"30\" value=\"");
                QuickForm.writeHtml(out, udaValue);
                out.write("\"/>");
            }
        }
        catch (Exception e) {
            out.write("Unable to understand '");
            QuickForm.writeHtml(out, udaValue);
            out.write("' because: ");
            QuickForm.writeHtml(out, e.toString());
        }
    }

%>
