#!/bin/sh
set +u

dist=`dirname $0`

jars=$dist/xp.jar:$dist/resolver.jar:$dist/relaxng.jar:$dist/xsc.jar:$dist/jh.jar:$dist/saxon.jar

if [ -f $dist/xxe.jar ]; then
    cp=$dist/xxe_app.jar:$dist/xxe.jar:$jars:$dist/xxe_help.jar
elif [ -d $dist/../class/com/xmlmind/xmledit ]; then
    cp=$dist/../class:$jars
else
    echo "xxe.jar not found"
    exit 2
fi

mem=
opt=

if [ `uname` = "Darwin" ]; then
    # On Mac, XXE is designed to run with the following settings.
    # (512Mb is needed to print large documents due to what's probably
    # a bug.)

    mem="-Xss1m -Xmx512m"

    opt="-Xdock:name=XMLEditor -Xdock:icon=$dist/icon/xxe.tiff"
    opt="$opt -Dcom.apple.mrj.application.apple.menu.about.name=XMLEditor"
    opt="$opt -Dapple.laf.useScreenMenuBar=true"
else
    # -Xss1m is needed to support *really* large XML-Schemas
    # -Xmx128m is needed from Java[tm] 1.4.2 which by default sets this to 64m

    mem="-Xss1m -Xmx128m"

    # About AWT Toolkits on Linux
    # ---------------------------
    # The default awt.toolkit for Java 1.4 is sun.awt.motif.MToolkit.
    # The default awt.toolkit for Java 1.5 is sun.awt.X11.XToolkit.
    #
    # Java Toolkit   Window managers       Drag&Drop
    #                other than            
    #                Gnome's and 
    #                KDE's standard
    # ---- --------  ----------------      ----------
    # 1.4  MToolkit  No problem with       Incompatible with XDND   
    #                mwm        
    #
    # 1.5  XToolkit  Minor problems with   No problem with XDND 
    #                mwm
    #
    #      MToolkit  No problem with mwm   Compatible with XDND
    #                                      but crashes after a
    #                                      dozen drops
    #
    # 1.6  XToolkit  Minor problems with
    #                mwm.
    #
    #      MToolkit  Almost no keyboard
    #                focus at all!
    #

    ###opt="-Dawt.toolkit=sun.awt.motif.MToolkit"
fi

java $mem $opt \
    -DXXE_GUI="$XXE_GUI" \
    -DXXE_ADDON_PATH="$XXE_ADDON_PATH" \
    -DXXE_USER_PREFERENCES="$XXE_USER_PREFERENCES" \
    -classpath "$cp" \
    com.xmlmind.xmleditapp.start.Start "$@"
