#!/bin/sh
set +u

dist=`dirname $0`

jars=$dist/xp.jar:$dist/resolver.jar:$dist/relaxng.jar:$dist/xsc.jar:$dist/jh.jar:$dist/ftp.jar:$dist/http.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

# ----------------------------------------------------------------------------
# Supported Java properties not documented elsewhere
# ==================================================
#
# XXE_JAVA_IMAGE_TOOLKIT_EXCLUDE
# ------------------------------
# Value: list of file extensions separated by semi-colons
#
# Example: -DXXE_JAVA_IMAGE_TOOLKIT_EXCLUDE="bmp;wbmp"
# This would prevent the built-in Java[tm] 1.5 image toolkit 
# from handing BMP images.
# This is useful in case you find an external image toolkit 
# which handles specified image extensions better than the built-in 
# Java image toolkit.
# ----------------------------------------------------------------------------

mem=
opt=

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

    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"

    # The Kunststoff Look&Feel is used by default with Java 1.4, 
    # but not with 1.5 (because Ocean looks great).
    # (This is configurable using the Options dialog box, General tab.)

    if [ -f $dist/kunststoff.jar ]; then
        cp=$cp:$dist/kunststoff.jar
    fi

    # 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.
    #
    # MToolkit seems to have a better behavior with older Window Managers
    # such as mwm.

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

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