--- /dev/null
+@ECHO OFF\r
+REM Licensed to the Apache Software Foundation (ASF) under one or more\r
+REM contributor license agreements. See the NOTICE file distributed with\r
+REM this work for additional information regarding copyright ownership.\r
+REM The ASF licenses this file to You under the Apache License, Version 2.0\r
+REM (the "License"); you may not use this file except in compliance with\r
+REM the License. You may obtain a copy of the License at\r
+REM\r
+REM http://www.apache.org/licenses/LICENSE-2.0\r
+REM\r
+REM Unless required by applicable law or agreed to in writing, software\r
+REM distributed under the License is distributed on an "AS IS" BASIS,\r
+REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+REM See the License for the specific language governing permissions and\r
+REM limitations under the License.\r
+REM $Id$\r
+\r
+SETLOCAL ENABLEDELAYEDEXPANSION\r
+\r
+rem %~dp0 is the expanded pathname of the current script under NT\r
+set LOCAL_FOP_HOME=\r
+if "%OS%"=="Windows_NT" set LOCAL_FOP_HOME=%~dp0\r
+\r
+rem Code from Apache Ant project\r
+rem Slurp the command line arguments. This loop allows for an unlimited number\r
+rem of arguments (up to the command line limit, anyway).\r
+rem Could also do a "shift" and "%*" for all params, but apparently doesn't work \r
+rem with Win9x.\r
+set FOP_CMD_LINE_ARGS=%1\r
+if ""%1""=="""" goto doneStart\r
+shift\r
+:setupArgs\r
+if ""%1""=="""" goto doneStart\r
+set FOP_CMD_LINE_ARGS=%FOP_CMD_LINE_ARGS% %1\r
+shift\r
+goto setupArgs\r
+rem This label provides a place for the argument list loop to break out \r
+rem and for NT handling to skip to.\r
+:doneStart\r
+\r
+set LOGCHOICE=\r
+rem The default commons logger for JDK1.4 is JDK1.4Logger.\r
+rem To use a different logger, uncomment the one desired below\r
+rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog\r
+rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog\r
+rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger\r
+\r
+set LOGLEVEL=\r
+rem Logging levels\r
+rem Below option is only if you are using SimpleLog instead of the default JDK1.4 Logger.\r
+rem To set logging levels for JDK 1.4 Logger, edit the %JAVA_HOME%\JRE\LIB\logging.properties \r
+rem file instead.\r
+rem Possible SimpleLog values: "trace", "debug", "info" (default), "warn", "error", or "fatal".\r
+rem set LOGLEVEL=-Dorg.apache.commons.logging.simplelog.defaultlog=INFO\r
+\r
+set LIBDIR=%LOCAL_FOP_HOME%lib\r
+\r
+set LOCALCLASSPATH=%FOP_HYPHENATION_PATH%\r
+for %%l in (%LOCAL_FOP_HOME%build\*.jar %LIBDIR%\*.jar) do set LOCALCLASSPATH=!LOCALCLASSPATH!;%%l\r
+\r
+if "%JAVA_HOME%" == "" goto noJavaHome\r
+if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome\r
+if "%JAVACMD%" == "" set JAVACMD=%JAVA_HOME%\bin\java\r
+goto runFop\r
+\r
+:noJavaHome\r
+if "%JAVACMD%" == "" set JAVACMD=java\r
+\r
+:runFop\r
+rem echo "%JAVACMD%" %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%\r
+"%JAVACMD%" %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%\r
+\r
+ENDLOCAL\r
--- /dev/null
+// Licensed to the Apache Software Foundation (ASF) under one or more\r
+// contributor license agreements. See the NOTICE file distributed with\r
+// this work for additional information regarding copyright ownership.\r
+// The ASF licenses this file to You under the Apache License, Version 2.0\r
+// (the "License"); you may not use this file except in compliance with\r
+// the License. You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+// $Id$ -->\r
+\r
+// jscript to run FOP, adapted from the Jakarta-Ant project.\r
+\r
+// rpm_mode is irrelevant on Windows\r
+// var rpm_mode=true;\r
+var fop_exec_args = "";\r
+var no_config=false;\r
+var fop_exec_debug=false;\r
+var debug=false;\r
+var keep_open=false;\r
+var show_help=false;\r
+\r
+var config_wanted = new Array("FOP_HOME", "CLASSPATH", "FOP_HYPHENATION_PATH", "FOP_OPTS", "JAVA_OPTS", "LOGCHOICE", "LOGLEVEL");\r
+\r
+// parse command-line arguments\r
+function read_args() {\r
+ var args = WScript.Arguments;\r
+ var named = new ActiveXObject("Scripting.Dictionary");\r
+ for (i = 0; i < args.length; i++) {\r
+ switch(args(i)) {\r
+ case "--debug":\r
+ debug=true;\r
+ break;\r
+ case "--execdebug":\r
+ fop_exec_debug=true;\r
+ break;\r
+ case "--keepopen":\r
+ keep_open=true;\r
+ break;\r
+ case "--noconfig":\r
+ no_config=true;\r
+ break;\r
+ case "-h":\r
+ case "--help":\r
+ case "--h":\r
+ case "-help":\r
+ show_help=true;\r
+ // fop_exec_args=fop_exec_args + " -h";\r
+ break;\r
+ default:\r
+ fop_exec_args=fop_exec_args + " " + args(i);\r
+ }\r
+ }\r
+ if (debug) {\r
+ WScript.Echo("debug: " + debug);\r
+ WScript.Echo("execdebug: " + fop_exec_debug);\r
+ WScript.Echo("keepopen: " + keep_open);\r
+ WScript.Echo("noconfig: " + no_config);\r
+ WScript.Echo("help: " + show_help);\r
+ WScript.Echo("fop arguments: " + fop_exec_args);\r
+ }\r
+}\r
+\r
+var help_text="Usage:\n"\r
+ + WScript.ScriptFullName + " [script options] [FOP options]\n"\r
+ + "Script Options:\n"\r
+ + " --help, -h print this message and FOP help\n"\r
+ + " --debug print debugging information for this launch script\n"\r
+ + " --execdebug print FOP exec line generated by this launch script\n"\r
+ + " --keepopen keep FOP's command window open\n"\r
+ + " --noconfig suppress reading of configuration file and registry";\r
+\r
+function read_environment() {\r
+ for (i in config_wanted) {\r
+ if (!config.Exists(config_wanted[i])) {\r
+ var env_var_string = "%" + config_wanted[i] + "%";\r
+ var env_var = shell.ExpandEnvironmentStrings(env_var_string);\r
+ if (env_var != "" && env_var != env_var_string) {\r
+ config.Add(config_wanted[i], env_var);\r
+ if (debug) {\r
+ WScript.Echo(config_wanted[i] + " env: "\r
+ + config.Item(config_wanted[i]));\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+function read_desktop(dtname) {\r
+ if (fs.FolderExists(dtname)) {\r
+ var fopname = fs.GetFolder(dtname).ParentFolder.Path\r
+ + "\\Application Data\\Fop";\r
+ if (fs.FolderExists(fopname)) {\r
+ var fop_conf_name = fs.GetFolder(fopname).Path + "\\fop.conf";\r
+ if (fs.FileExists(fop_conf_name)) {\r
+ // source fop_conf_file\r
+ var conf_file = fs.openTextFile(fs.GetFile(fop_conf_name));\r
+ var conf_lines = new ActiveXObject("Scripting.Dictionary");\r
+ while (!conf_file.AtEndOfStream) {\r
+ var line = conf_file.ReadLine();\r
+ var m = line.match(/(.+?)=(.+)/);\r
+ if (m != null) {\r
+ conf_lines.Add(m[1], m[2]);\r
+ }\r
+ }\r
+ for (j in config_wanted) {\r
+ if (!config.Exists(config_wanted[j])\r
+ && conf_lines.Exists(config_wanted[j])) {\r
+ config.Add(config_wanted[j], conf_lines.Item(config_wanted[j]));\r
+ if (debug) {\r
+ WScript.Echo(config_wanted[j] + " " + dts[i] + ": "\r
+ + config.Item(config_wanted[i]));\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
+\r
+function read_registry(section) {\r
+ for (j in config_wanted) {\r
+ if (!config.Exists(config_wanted[j])) {\r
+ var reg_var;\r
+ try {\r
+ reg_var = shell.RegRead(section + "\\Software\\Fop\\"\r
+ + config_wanted[j]);\r
+ config.Add(config_wanted[j], reg_var);\r
+ if (debug) {\r
+ WScript.Echo(config_wanted[j] + " " + rks[i] + ": "\r
+ + config.Item(config_wanted[j]));\r
+ }\r
+ } catch(e) {}\r
+ }\r
+ }\r
+}\r
+\r
+// construct FOP_HOME from the script folder\r
+function get_fop_home() {\r
+ if (!config.Exists("FOP_HOME")\r
+ || !fs.FolderExists(config.Item("FOP_HOME"))) {\r
+ var fop_home = WScript.ScriptFullName;\r
+ fop_home = fop_home.substring(0, fop_home.length\r
+ - WScript.ScriptName.length - 1);\r
+ if (config.Exists("FOP_HOME")) {\r
+ config.Remove("FOP_HOME");\r
+ }\r
+ config.Add("FOP_HOME", fop_home);\r
+ if (debug) {\r
+ WScript.Echo("FOP_HOME dyn: " + config.Item("FOP_HOME"));\r
+ }\r
+ }\r
+}\r
+\r
+function get_java_cmd() {\r
+ var java_home = shell.ExpandEnvironmentStrings("%JAVA_HOME%");\r
+ javacmd = "java";\r
+ if (java_home != "" && typeof(java_home) != "undefined"\r
+ && fs.FolderExists(java_home)) {\r
+ var javacmd_candidate = java_home + "\\bin\\java.exe";\r
+ if (fs.FileExists(javacmd_candidate)) {\r
+ javacmd = javacmd_candidate;\r
+ }\r
+ }\r
+ if (debug) {\r
+ WScript.Echo("java command: " + javacmd);\r
+ }\r
+}\r
+\r
+function get_local_classpath() {\r
+ if (config.Exists("CLASSPATH")) {\r
+ local_classpath = config.Item("CLASSPATH");\r
+ if (debug) {\r
+ WScript.Echo("local classpath: " + local_classpath);\r
+ }\r
+ }\r
+\r
+ // add fop.jar, fop-sandbox and fop-hyph.jar, which reside in $FOP_HOME/build\r
+ var lcp = local_classpath;\r
+ local_classpath = config.Item("FOP_HOME") + "\\build\\fop.jar;"\r
+ + config.Item("FOP_HOME") + "\\build\\fop-sandbox.jar;"\r
+ + config.Item("FOP_HOME") + "\\build\\fop-hyph.jar";\r
+ if (lcp != "") {\r
+ local_classpath += ";" + lcp;\r
+ }\r
+ if (debug) {\r
+ WScript.Echo("local classpath: " + local_classpath);\r
+ }\r
+\r
+ // add in the dependency .jar files, which reside in $FOP_HOME/lib\r
+ var libdir_name = config.Item("FOP_HOME") + "\\lib";\r
+ var dirlibs;\r
+ if (fs.FolderExists(libdir_name)) {\r
+ dirlibs = fs.GetFolder(libdir_name).Files;\r
+ var e = new Enumerator(dirlibs);\r
+ for (; !e.atEnd(); e.moveNext()) {\r
+ if (e.item().Name.match("\.jar$")) {\r
+ local_classpath = libdir_name + "\\" + e.item().Name + ";" + local_classpath;\r
+ }\r
+ }\r
+ if (debug) {\r
+ WScript.Echo("local classpath: " + local_classpath);\r
+ }\r
+ }\r
+\r
+ // add in user-defined hyphenation JARs\r
+ if (config.Exists("FOP_HYPHENATION_PATH")) {\r
+ local_classpath += ";" + config.Item("FOP_HYPHENATION_PATH");\r
+ if (debug) {\r
+ WScript.Echo("local classpath: " + local_classpath);\r
+ }\r
+ }\r
+}\r
+\r
+// Execute fop via shell.Exec\r
+function fop_exec() {\r
+ var fop_exec_command = "\"" + javacmd + "\" "\r
+ + (config.Exists("JAVA_OPTS")?config.Item("JAVA_OPTS") + " ":"")\r
+ + (config.Exists("LOGCHOICE")?config.Item("LOGCHOICE") + " ":"")\r
+ + (config.Exists("LOGLEVEL")?config.Item("LOGLEVEL") + " ":"")\r
+ "-classpath \"" + local_classpath + "\" "\r
+ + (config.Exists("FOP_OPTS")?config.Item("FOP_OPTS"):"")\r
+ + "org.apache.fop.cli.Main " + fop_exec_args;\r
+ if (debug || fop_exec_debug) {\r
+ WScript.Echo(fop_exec_command);\r
+ }\r
+\r
+ var fop_run = shell.Exec(fop_exec_command);\r
+ while (true) {\r
+ while (!fop_run.StdOut.AtEndOfStream) {\r
+ WScript.Echo(fop_run.StdOut.ReadLine());\r
+ }\r
+ while (!fop_run.StdErr.AtEndOfStream) {\r
+ WScript.Echo(fop_run.StdErr.ReadLine());\r
+ }\r
+ if (fop_run.Status == 1) {\r
+ break;\r
+ }\r
+ WScript.Sleep(100);\r
+ }\r
+ if (debug) {\r
+ WScript.Echo("exit status: " + fop_run.ExitCode);\r
+ }\r
+}\r
+\r
+// Execute fop via shell.Run\r
+function fop_run() {\r
+ var fop_exec_command = "cmd /" + (keep_open?"K":"C") + " \""\r
+ + "\"" + javacmd + "\" " \r
+ + (config.Exists("JAVA_OPTS")?config.Item("JAVA_OPTS") + " ":"")\r
+ + (config.Exists("LOGCHOICE")?config.Item("LOGCHOICE") + " ":"")\r
+ + (config.Exists("LOGLEVEL")?config.Item("LOGLEVEL") + " ":"")\r
+ + "-classpath \"" + local_classpath + "\" "\r
+ + (config.Exists("FOP_OPTS")?config.Item("FOP_OPTS") + " ":"")\r
+ + "org.apache.fop.cli.Main " + fop_exec_args + "\"";\r
+ if (debug || fop_exec_debug) {\r
+ WScript.Echo(fop_exec_command);\r
+ }\r
+ var exit_code = shell.Run(fop_exec_command, 1, 1);\r
+ if (debug) {\r
+ WScript.Echo("exit status: " + exit_code);\r
+ } else {\r
+ if (exit_code != 0) {\r
+ WScript.Echo("A FOP error occurred (FOP exit status: " + exit_code + ")\n"\r
+ + "Use option --keepopen to see FOP's output\n"\r
+ + "(that is two dashes)");\r
+ }\r
+ }\r
+}\r
+\r
+function get_log_choice() {\r
+ // The default commons logger for JDK1.4 is JDK1.4Logger.\r
+ // To use a different logger, uncomment the one desired below\r
+ if (!config.Exists("LOGCHOICE")) {\r
+ // config.Add("LOGCHOICE","\"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog\"");\r
+ // config.Add("LOGCHOICE","\"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog\"");\r
+ // config.Add("LOGCHOICE","\"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger\"");\r
+ if (debug && config.Exists("LOGCHOICE")) {\r
+ WScript.Echo("LOGCHOICE script: " + config.Item("LOGCHOICE"));\r
+ }\r
+ }\r
+}\r
+\r
+function get_log_level() {\r
+ // Logging levels\r
+ // Below option is only if you are using SimpleLog instead of the default JDK1.4 Logger.\r
+ // To set logging levels for JDK 1.4 Logger, edit the %JAVA_HOME%/JRE/LIB/logging.properties \r
+ // file instead.\r
+ // Possible SimpleLog values: "trace", "debug", "info" (default), "warn", "error", or "fatal".\r
+ if (!config.Exists("LOGLEVEL")) {\r
+ // config.Add("LOGLEVEL","\"-Dorg.apache.commons.logging.simplelog.defaultlog=INFO\"");\r
+ if (debug && config.Exists("LOGLEVEL")) {\r
+ WScript.Echo("LOGLEVEL script: " + config.Item("LOGLEVEL"));\r
+ }\r
+ }\r
+}\r
+\r
+var shell = WScript.CreateObject("WScript.Shell");\r
+var fs = WScript.CreateObject("Scripting.FileSystemObject");\r
+\r
+// configuration\r
+var config = new ActiveXObject("Scripting.Dictionary");\r
+\r
+read_args();\r
+read_environment();\r
+if (!no_config) {\r
+ // read user and system-wide fop configurations\r
+ var spec = shell.SpecialFolders;\r
+ var dts = new Array("Desktop", "AllUsersDesktop");\r
+ for (i in dts) {\r
+ read_desktop(spec(dts[i]));\r
+ }\r
+ // read user and system-wide registry\r
+ var rks = new Array("HKCU", "HKLM");\r
+ for (i in rks) {\r
+ read_registry(rks[i]);\r
+ }\r
+}\r
+\r
+get_fop_home();\r
+get_log_choice();\r
+get_log_level();\r
+var javacmd = "";\r
+get_java_cmd();\r
+var local_classpath = "";\r
+get_local_classpath();\r
+\r
+// Show script help if requested\r
+if (show_help) {\r
+ // fop_exec_args = "";\r
+ keep_open = true;\r
+ WScript.Echo(help_text);\r
+}\r
+\r
+// fop_exec();\r
+fop_run();\r