<HTML>
<HEAD>
  <TITLE>XMLDB Demonstation Installation</TITLE>
    <HTA:APPLICATION ID="XDBi"
     APPLICATIONNAME="XDB Demonstration Installer"
     BORDER="thin"
     BORDERSTYLE="normal"
     CAPTION="yes"
     ICON=""
     MAXIMIZEBUTTON="no"
     MINIMIZEBUTTON="no"
     SHOWINTASKBAR="yes"
     SINGLEINSTANCE="yes"
     SYSMENU="yes"
     VERSION="1.0"
   />

  <SCRIPT LANGUAGE="VBScript">

  Option Explicit
  Const FILE_SEPERATOR    = "\" 
  Const CONFIG_LOAD_FAILED = 1
  
  dim WSHELL
  dim FSO
  dim SQLPLUS
  dim HTTP
  dim FILEMANAGER 
  dim INSTALLATION
  dim CONFIGURATION
  dim DEMONSTRATION
  dim LOGWINDOW
  dim LOGBUFFER
  dim XMLHELPER
     
  Sub init()
    
    dim filename, result

    window.resizeTo 580,400
     
    filename = "installParameters.xml"
    Set INSTALLATION = CreateObject("Msxml2.FreeThreadedDOMDocument.6.0")
    INSTALLATION.async = false
    result = INSTALLATION.load(filename)
    
    If (result = False) Then 
      MsgBox "Error while loading or parsing file : " & filename,vbCritical
      self.close()
    End If
    
    showInputForm(INSTALLATION)
    
    set LOGWINDOW = Document.getElementById("installationLog")
     
    Set WSHELL         = CreateObject("WScript.Shell")
    Set FSO            = CreateObject("Scripting.FileSystemObject")

    set FILEMANAGER     = new fileSystemControl
    FILEMANAGER.initialize WSHELL,FSO 

    set CONFIGURATION  = new configurationControl
    CONFIGURATION.initialize WSHELL, FSO
      
    SET SQLPLUS        = new sqlPlusControl
    SQLPLUS.initialize CONFIGURATION 
    
    SET HTTP           = new httpControl
    HTTP.initialize CONFIGURATION, WSHELL
    
    SET XMLHELPER = new xmlHelperControl
    XMLHELPER.initialize CONFIGURATION
    
    filename = CONFIGURATION.getInstallFolderPath() & FILE_SEPERATOR & CONFIGURATION.getDemoName() + ".xml"
    Set DEMONSTRATION = CreateObject("Msxml2.FreeThreadedDOMDocument.6.0")
    DEMONSTRATION.async = false
    result = DEMONSTRATION.load(filename)
    
    If (result = False) Then 
      MsgBox "Error while loading or parsing file : " & filename,vbCritical
      self.close()
    End If
    
  End Sub

  Sub writeLogMessage(logMessage)
  
    LOGBUFFER = LOGBUFFER + logMessage + chr(10) + chr(13) 
    LOGWINDOW.innerText = LOGBUFFER
    LOGWINDOW.scrolltop = LOGWINDOW.scrolltop + 16 
    
  end sub
 
  Sub showInputForm(INSTALLATION)

    dim filename, inputStylesheet, result, xslProcessor, html, target
    
    filename = "install.xsl"
    Set inputStylesheet = CreateObject("Msxml2.FreeThreadedDOMDocument.6.0")
    inputStylesheet.async = false
    result = inputStylesheet.load(filename)

    If (result = False) Then 
      MsgBox "Error while loading or parsing file : " & filename,vbCritical
      self.close()
    End If
    
    dim xslt
    set xslt = CreateObject("Msxml2.XSLTemplate.6.0")
    set xslt.stylesheet = inputStylesheet 
    set xslProcessor = xslt.createProcessor()
    xslProcessor.input = INSTALLATION
    xslProcessor.transform()
    html = xslProcessor.output

    Set target = Document.getElementById("inputForm")
    target.innerHTML = html
    
  End Sub

  Sub cancelInstall()
     self.close()
  End Sub
  
  Sub doInstall()

    dim result
    
    result = validateOracleHome(CONFIGURATION)
    if (not result) then
      exit Sub
    end if

    result = validateDBA(CONFIGURATION,SQLPLUS)
    if (not result) then
      exit Sub
    end if

    result = validateUsername(CONFIGURATION,SQLPLUS)
    if (not result) then
      exit Sub
    end if
  
    result = validateHTTP(CONFIGURATION,HTTP)
    if (not result) then
      exit Sub
    end if
    
    CONFIGURATION.addMacros DEMONSTRATION, INSTALLATION
    LOGBUFFER = ""

    createFolders CONFIGURATION,DEMONSTRATION,FILEMANAGER
    copyFolders CONFIGURATION,DEMONSTRATION,FILEMANAGER
    copyFiles CONFIGURATION,DEMONSTRATION,FILEMANAGER
    cloneFolders CONFIGURATION,DEMONSTRATION,FILEMANAGER
    cloneFiles CONFIGURATION,DEMONSTRATION,FILEMANAGER
    
    doInstallActions CONFIGURATION,DEMONSTRATION,SQLPLUS,HTTP
     
    makeWebFolders DEMONSTRATION, HTTP    
    makeFtpScripts CONFIGURATION,DEMONSTRATION,FILEMANAGER

    makeSQLShortCuts CONFIGURATION,DEMONSTRATION,FILEMANAGER
    makeHttpShortCuts DEMONSTRATION,FILEMANAGER
    makeGeneralShortCuts  CONFIGURATION,DEMONSTRATION,FILEMANAGER
    makeFavorites CONFIGURATION,DEMONSTRATION,FILEMANAGER
    
    installationSuccessful CONFIGURATION,DEMONSTRATION
    
    writeLogMessage "Installation Successful"
     
  end sub
  
  function validateOracleHome(CONFIGURATION)
  
    validateOracleHome = true
    Exit Function
    
  end function

  function validateDBA(CONFIGURATION,SQLPLUS)
  
    dim returnCode, connectionString, button

    connectionString = CONFIGURATION.getDBAUsername & "/********@" & CONFIGURATION.getTNSAlias()   
    
    returnCode = SQLPLUS.testConnection(CONFIGURATION.getDBAUsername, CONFIGURATION.getDBAPassword, "")
 
    If returnCode = 2 Then
      validateDBA = true
      Exit Function
    End If
          
    button = MsgBox ("Failed to connect as " & connectionString & ". Check TNS Alias, DBA User and Password.",vbOKOnly + vbCritical)
    validateDBA = false
    
  end function

  function validateUsername(CONFIGURATION,SQLPLUS)
  
    dim returnCode, connectionString, button

    connectionString = CONFIGURATION.getUsername & "/********@" & CONFIGURATION.getTNSAlias()   
    
    returnCode = SQLPLUS.testConnection(CONFIGURATION.getUsername, CONFIGURATION.getPassword, "")
 
    If returnCode = 2 Then
      validateUsername = true
      Exit Function
    End If

    button = MsgBox ("Failed to connect as " & connectionString & ". Check TNS Alias, DBA User and Password.",vbOKOnly + vbCritical)
    validateUsername = false
    
  end Function
    
  function validateHTTP(CONFIGURATION,HTTP)
  
    Dim returnCode, button
  
    returnCode = HTTP.doHead("/public", CONFIGURATION.getUsername(), CONFIGURATION.getPassword())
  
    If returnCode = 200 Then
      validateHTTP = true
      Exit Function
    End If

    button = MsgBox ("Unable to access " & CONFIGURATION.getServerURL() & "/public. Please Check hostname and HTTP port number",vbOKOnly + vbCritical)
    validateHTTP = false
    
  end Function

  </SCRIPT>
  <SCRIPT LANGUAGE="VBScript" SRC="install.vbs"></SCRIPT> 
</HEAD>
<BODY style="background-color:#ECE9D8;" onload="init()" SCROLL="no">
  <PRE id="inputForm"/>
</BODY>
</HTML>