#!/bin/sh

# JHOVE - JSTOR/Harvard Object Validation Environment
#
# Copyright 2003-2005 by JSTOR and the President and Fellows of Harvard College
# JHOVE is made available under the GNU General Public License (see the
# file LICENSE for details)
#
# Usage: jhove [-c config] [-m module] [-h handler] [-e encoding]
#              [-H handler] [-o output] [-x saxclass] [-t tempdir]
#              [-b bufsize] [-l loglevel] [[-krs] dir-file-or-uri [...]]
#
# Where -c config   Configuration file pathname
#       -m module   Module name
#       -h handler  Output handler name (defaults to TEXT)
#       -e encoding Character encoding of output handler (defaults to UTF-8)
#       -H handler  About handler name
#       -o output   Output file pathname (defaults to standard output)
#       -x saxclass SAX parser class (defaults to J2SE 1.4 default)
#       -t tempdir  Temporary directory in which to create temporary files
#       -b bufsize  Buffer size for buffered I/O (defaults to J2SE 1.4 default)
#       -l loglevel Logging level
#       -k          Calculate CRC32, MD5, SHA-1 and SHA-256 checksums
#       -r          Display raw data flags, not textual equivalents
#       -s          Format identification based on internal signatures only
#       dir-file-or-uri Directory, file pathname or URI of formatted content

# ***************************************************************************
# Configuration options:
# EXTRA_JARS  Extra JAR files to add to the Java class path
# ***************************************************************************
EXTRA_JARS=""

# NOTE: Nothing below this line should be edited
#############################################################################

# Infer JHOVE_HOME from script location
SCRIPT="${0}"

# Resolve absolute and relative symlinks
while [ -h "${SCRIPT}" ]; do
    LS=$( ls -ld "${SCRIPT}" )
    LINK=$( expr "${LS}" : '.*-> \(.*\)$' )
    if expr "${LINK}" : '/.*' > /dev/null; then
        SCRIPT="${LINK}"
    else
        SCRIPT="$( dirname "${SCRIPT}" )/${LINK}"
    fi
done

# Store absolute location
CWD="$( pwd )"
JHOVE_HOME="$( cd "$(dirname "${SCRIPT}" )" && pwd )"
cd "${CWD}" || exit

# Create Java class path
CP="${JHOVE_HOME}/bin/*"
if [ -n "${EXTRA_JARS}" ]; then
    CP="${CP}:${EXTRA_JARS}"
fi

# Set default configuration location
CONFIG="${JHOVE_HOME}/conf/jhove.conf"

# Set class path and invoke Java
java -Xss1024k -classpath "${CP}" edu.harvard.hul.ois.jhove.viewer.JhoveView -c "${CONFIG}" "${@}"
