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.

fop 7.5KB

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