You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #! /bin/sh
  2. #
  3. # Copyright 2005 The Apache Software Foundation
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # Shell script to run FOP, adapted from the Jakarta-Ant project.
  17. rpm_mode=true
  18. fop_exec_args=
  19. no_config=false
  20. fop_exec_debug=false
  21. show_help=false
  22. for arg in "$@" ; do
  23. if [ "$arg" = "--noconfig" ] ; then
  24. no_config=true
  25. elif [ "$arg" = "--execdebug" ] ; then
  26. fop_exec_debug=true
  27. elif [ my"$arg" = my"--h" -o my"$arg" = my"--help" ] ; then
  28. show_help=true
  29. fop_exec_args="$fop_exec_args -h"
  30. else
  31. if [ my"$arg" = my"-h" -o my"$arg" = my"-help" ] ; then
  32. show_help=true
  33. fi
  34. fop_exec_args="$fop_exec_args \"$arg\""
  35. fi
  36. done
  37. # Source/default fop configuration
  38. if $no_config ; then
  39. rpm_mode=false
  40. else
  41. # load system-wide fop configuration
  42. if [ -f "/etc/fop.conf" ] ; then
  43. . /etc/fop.conf
  44. fi
  45. # load user fop configuration
  46. if [ -f "$HOME/.fop/fop.conf" ] ; then
  47. . $HOME/.fop/fop.conf
  48. fi
  49. if [ -f "$HOME/.foprc" ] ; then
  50. . "$HOME/.foprc"
  51. fi
  52. # provide default configuration values
  53. if [ -z "$rpm_mode" ] ; then
  54. rpm_mode=false
  55. fi
  56. if [ -z "$usejikes" ] ; then
  57. usejikes=$use_jikes_default
  58. fi
  59. fi
  60. # Setup Java environment in rpm mode
  61. if $rpm_mode ; then
  62. if [ -f /usr/share/java-utils/java-functions ] ; then
  63. . /usr/share/java-utils/java-functions
  64. set_jvm
  65. set_javacmd
  66. fi
  67. fi
  68. # OS specific support. $var _must_ be set to either true or false.
  69. cygwin=false;
  70. darwin=false;
  71. case "`uname`" in
  72. CYGWIN*) cygwin=true ;;
  73. Darwin*) darwin=true
  74. if [ -z "$JAVA_HOME" ] ; then
  75. JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
  76. fi
  77. ;;
  78. esac
  79. if [ -z "$FOP_HOME" -o ! -d "$FOP_HOME" ] ; then
  80. ## resolve links - $0 may be a link to fop's home
  81. PRG="$0"
  82. progname=`basename "$0"`
  83. # need this for relative symlinks
  84. while [ -h "$PRG" ] ; do
  85. ls=`ls -ld "$PRG"`
  86. link=`expr "$ls" : '.*-> \(.*\)$'`
  87. if expr "$link" : '/.*' > /dev/null; then
  88. PRG="$link"
  89. else
  90. PRG=`dirname "$PRG"`"/$link"
  91. fi
  92. done
  93. FOP_HOME=`dirname "$PRG"`
  94. # make it fully qualified
  95. FOP_HOME=`cd "$FOP_HOME" && pwd`
  96. fi
  97. # For Cygwin, ensure paths are in UNIX format before anything is touched
  98. if $cygwin ; then
  99. [ -n "$FOP_HOME" ] &&
  100. FOP_HOME=`cygpath --unix "$FOP_HOME"`
  101. [ -n "$JAVA_HOME" ] &&
  102. JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
  103. fi
  104. if [ -z "$JAVACMD" ] ; then
  105. if [ -n "$JAVA_HOME" ] ; then
  106. if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
  107. # IBM's JDK on AIX uses strange locations for the executables
  108. JAVACMD="$JAVA_HOME/jre/sh/java"
  109. else
  110. JAVACMD="$JAVA_HOME/bin/java"
  111. fi
  112. else
  113. JAVACMD=`which java 2> /dev/null `
  114. if [ -z "$JAVACMD" ] ; then
  115. JAVACMD=java
  116. fi
  117. fi
  118. fi
  119. if [ ! -x "$JAVACMD" ] ; then
  120. echo "Error: JAVA_HOME is not defined correctly."
  121. echo " We cannot execute $JAVACMD"
  122. exit 1
  123. fi
  124. if [ -n "$CLASSPATH" ] ; then
  125. LOCALCLASSPATH=$CLASSPATH
  126. fi
  127. # add fop.jar, fop-sandbox and fop-hyph.jar, which reside in $FOP_HOME/build
  128. LOCALCLASSPATH=${FOP_HOME}/build/fop.jar:${FOP_HOME}/build/fop-sandbox.jar:${FOP_HOME}/build/fop-hyph.jar:$LOCALCLASSPATH
  129. # add in the dependency .jar files, which reside in $FOP_HOME/lib
  130. DIRLIBS=${FOP_HOME}/lib/*.jar
  131. for i in ${DIRLIBS}
  132. do
  133. # if the directory is empty, then it will return the input string
  134. # this is stupid, so case for it
  135. if [ "$i" != "${DIRLIBS}" ] ; then
  136. if [ -z "$LOCALCLASSPATH" ] ; then
  137. LOCALCLASSPATH=$i
  138. else
  139. LOCALCLASSPATH="$i":$LOCALCLASSPATH
  140. fi
  141. fi
  142. done
  143. # add in user-defined hyphenation JARs
  144. if [ -n "$FOP_HYPHENATION_PATH" ] ; then
  145. LOCALCLASSPATH=$LOCALCLASSPATH:$FOP_HYPHENATION_PATH
  146. fi
  147. # For Cygwin, switch paths to appropriate format before running java
  148. # For PATHs convert to unix format first, then to windows format to ensure
  149. # both formats are supported. Probably this will fail on directories with ;
  150. # in the name in the path. Let's assume that paths containing ; are more
  151. # rare than windows style paths on cygwin.
  152. if $cygwin; then
  153. if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
  154. format=mixed
  155. else
  156. format=windows
  157. fi
  158. FOP_HOME=`cygpath --$format "$FOP_HOME"`
  159. LCP_TEMP=`cygpath --path --unix "$LOCALCLASSPATH"`
  160. LOCALCLASSPATH=`cygpath --path --$format "$LCP_TEMP"`
  161. if [ -n "$CLASSPATH" ] ; then
  162. CP_TEMP=`cygpath --path --unix "$CLASSPATH"`
  163. CLASSPATH=`cygpath --path --$format "$CP_TEMP"`
  164. fi
  165. CYGHOME=`cygpath --$format "$HOME"`
  166. fi
  167. # Show script help if requested
  168. if $show_help ; then
  169. fop_exec_args=""
  170. echo $0 '[script options] [FOP options]'
  171. echo 'Script Options:'
  172. echo ' --help, -h print this message and FOP help'
  173. echo ' --noconfig suppress sourcing of /etc/fop.conf,'
  174. echo ' $HOME/.fop/fop.conf, and $HOME/.foprc'
  175. echo ' configuration files'
  176. echo ' --execdebug print FOP exec line generated by this'
  177. echo ' launch script'
  178. fi
  179. # add a second backslash to variables terminated by a backslash under cygwin
  180. if $cygwin; then
  181. case "$FOP_HOME" in
  182. *\\ )
  183. FOP_HOME="$FOP_HOME\\"
  184. ;;
  185. esac
  186. case "$CYGHOME" in
  187. *\\ )
  188. CYGHOME="$CYGHOME\\"
  189. ;;
  190. esac
  191. case "$LOCALCLASSPATH" in
  192. *\\ )
  193. LOCALCLASSPATH="$LOCALCLASSPATH\\"
  194. ;;
  195. esac
  196. case "$CLASSPATH" in
  197. *\\ )
  198. CLASSPATH="$CLASSPATH\\"
  199. ;;
  200. esac
  201. fi
  202. # The default commons logger for JDK1.4 is JDK1.4Logger.
  203. # To use a different logger, uncomment the one desired below
  204. # LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
  205. # LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
  206. # LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
  207. # Logging levels
  208. # Below option is only if you are using SimpleLog instead of the default JDK1.4 Logger.
  209. # To set logging levels for JDK 1.4 Logger, edit the %JAVA_HOME%/JRE/LIB/logging.properties
  210. # file instead.
  211. # Possible SimpleLog values: "trace", "debug", "info" (default), "warn", "error", or "fatal".
  212. # LOGLEVEL=-Dorg.apache.commons.logging.simplelog.defaultlog=INFO
  213. # Execute FOP using eval/exec to preserve spaces in paths,
  214. # java options, and FOP args
  215. fop_exec_command="exec \"$JAVACMD\" $LOGCHOICE $LOGLEVEL -classpath \"$LOCALCLASSPATH\" $FOP_OPTS org.apache.fop.cli.Main $fop_exec_args"
  216. if $fop_exec_debug ; then
  217. echo $fop_exec_command
  218. fi
  219. eval $fop_exec_command