@echo off
setlocal enabledelayedexpansion

rem binDir ends with '\'
set binDir=%~dp0
set libDir=%binDir%..\lib
set webappDir=%binDir%..\webapp
set etcDir=%binDir%..\etc
set varDir=%binDir%..\var

set xxeBinDir=%binDir%..\..\bin

rem XXE class path ---

set jars1=%xxeBinDir%\xerces.jar;%xxeBinDir%\xmlresolver.jar;%xxeBinDir%\relaxng.jar;%xxeBinDir%\saxon.jar;%xxeBinDir%\saxon12.jar

if exist "%xxeBinDir%\xxe.jar" goto xxejar
set cp1=%xxeBinDir%\..\class;%jars1%
goto xxefi
:xxejar
set cp1=%xxeBinDir%\xxe.jar;%jars1%
:xxefi

rem XXE server class path ---

set jars2=
for %%j in (%libDir%\*.jar) do set jars2=!jars2!;%%j

if exist "%binDir%xxeserver.jar" goto srvjar
set cp2=%binDir%..\server\class;%jars2%
goto srvfi
:srvjar
set cp2=%binDir%xxeserver.jar;%jars2%
:srvfi

rem Private JRE if any ---

if defined PROGRAMFILES(X86) if exist "%xxeBinDir%\jre64\bin\java.exe" goto privatejre
set java=java
goto javafi
:privatejre
set java=%xxeBinDir%\jre64\bin\java.exe
:javafi

rem Specify default index.html. May be overridden in actual arguments.
rem
rem Example of useful options to be inserted before "%*":
rem -loglevel INFO -logserver "%varDir%\srv"
rem -selfsign "CN=192.168.1.26" "%etcDir%\selfsign192_168_1_26.cert"
rem -faccess "%etcDir%\remote_files_conf.json"
rem where remote_files_conf.json contains valid JSON looking like:
rem [ { "label": "Work", "uri": "file:/C:/work" } ]
rem

"%java%" -Xss4m -Xmx2048m -Djava.awt.headless=true -DXXE_ADDON_PATH="%XXE_ADDON_PATH%" -DXXE_PREFS_DIR="%XXE_PREFS_DIR%" -classpath "%cp1%;%cp2%" com.xmlmind.xmleditsrv.server.StartServer -index "%webappDir%\index.html" %*
