libis-format 1.2.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.travis.yml +19 -23
  4. data/Gemfile +0 -2
  5. data/README.md +2 -2
  6. data/base/Dockerfile +5 -3
  7. data/base/rework_path +5 -10
  8. data/data/PDFA_def.ps +3 -3
  9. data/data/eciRGB_v2.icc +0 -0
  10. data/data/types.yml +3 -16
  11. data/lib/libis/format/cli/convert.rb +4 -4
  12. data/lib/libis/format/config.rb +3 -3
  13. data/lib/libis/format/converter/audio_converter.rb +6 -38
  14. data/lib/libis/format/converter/base.rb +21 -8
  15. data/lib/libis/format/converter/chain.rb +6 -18
  16. data/lib/libis/format/converter/fop_pdf_converter.rb +2 -0
  17. data/lib/libis/format/converter/image_assembler.rb +82 -0
  18. data/lib/libis/format/converter/image_converter.rb +21 -141
  19. data/lib/libis/format/converter/image_splitter.rb +80 -0
  20. data/lib/libis/format/converter/image_watermarker.rb +261 -0
  21. data/lib/libis/format/converter/jp2_converter.rb +4 -4
  22. data/lib/libis/format/converter/office_converter.rb +5 -3
  23. data/lib/libis/format/converter/pdf_assembler.rb +66 -0
  24. data/lib/libis/format/converter/pdf_converter.rb +31 -98
  25. data/lib/libis/format/converter/pdf_optimizer.rb +70 -0
  26. data/lib/libis/format/converter/pdf_splitter.rb +65 -0
  27. data/lib/libis/format/converter/pdf_watermarker.rb +110 -0
  28. data/lib/libis/format/converter/spreadsheet_converter.rb +5 -3
  29. data/lib/libis/format/converter/video_converter.rb +3 -6
  30. data/lib/libis/format/converter/xslt_converter.rb +14 -15
  31. data/lib/libis/format/identifier.rb +3 -3
  32. data/lib/libis/format/info.rb +27 -0
  33. data/lib/libis/format/library.rb +147 -0
  34. data/lib/libis/format/tool/extension_identification.rb +4 -4
  35. data/lib/libis/format/tool/{ff_mpeg.rb → ffmpeg.rb} +1 -10
  36. data/lib/libis/format/tool/fop_pdf.rb +0 -12
  37. data/lib/libis/format/tool/identification_tool.rb +6 -6
  38. data/lib/libis/format/tool/office_to_pdf.rb +1 -10
  39. data/lib/libis/format/tool/pdf_copy.rb +1 -11
  40. data/lib/libis/format/tool/pdf_merge.rb +1 -11
  41. data/lib/libis/format/tool/pdf_optimizer.rb +2 -11
  42. data/lib/libis/format/tool/pdf_split.rb +1 -11
  43. data/lib/libis/format/tool/pdf_to_pdfa.rb +43 -59
  44. data/lib/libis/format/tool/pdfa_validator.rb +35 -28
  45. data/lib/libis/format/tool/spreadsheet_to_ods.rb +2 -10
  46. data/lib/libis/format/tool.rb +1 -1
  47. data/lib/libis/format/version.rb +1 -1
  48. data/lib/libis/format/yaml_loader.rb +71 -0
  49. data/lib/libis/format.rb +5 -2
  50. data/libis-format.gemspec +3 -5
  51. data/tools/fop/fop.bat +75 -75
  52. data/tools/fop/fop.cmd +31 -31
  53. data/tools/fop/fop.js +341 -341
  54. data/tools/fop/lib/avalon-framework.NOTICE.TXT +11 -11
  55. data/tools/fop/lib/xml-apis.LICENSE-SAX.html +17 -17
  56. data/tools/fop/lib/xml-apis.LICENSE.DOM-documentation.html +74 -74
  57. data/tools/fop/lib/xml-apis.LICENSE.DOM-software.html +66 -66
  58. metadata +19 -29
  59. data/data/AdobeRGB1998.icc +0 -0
  60. data/lib/libis/format/converter/email_converter.rb +0 -38
  61. data/lib/libis/format/tool/email_to_pdf.rb +0 -75
  62. data/lib/libis/format/type_database.rb +0 -133
  63. data/lib/libis/format/type_database_impl.rb +0 -120
  64. data/tools/emailconverter.jar +0 -0
  65. data/tools/pdf2pdfa +0 -395
  66. /data/bin/{droid_tool → droid} +0 -0
  67. /data/bin/{fido_tool → fido} +0 -0
data/tools/fop/fop.js CHANGED
@@ -1,341 +1,341 @@
1
- // Licensed to the Apache Software Foundation (ASF) under one or more
2
- // contributor license agreements. See the NOTICE file distributed with
3
- // this work for additional information regarding copyright ownership.
4
- // The ASF licenses this file to You under the Apache License, Version 2.0
5
- // (the "License"); you may not use this file except in compliance with
6
- // the License. You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- // $Id: fop.js 1734671 2016-03-12 05:39:53Z gadams $ -->
16
-
17
- // jscript to run FOP, adapted from the Jakarta-Ant project.
18
-
19
- // rpm_mode is irrelevant on Windows
20
- // var rpm_mode=true;
21
- var fop_exec_args = "";
22
- var no_config=false;
23
- var fop_exec_debug=false;
24
- var debug=false;
25
- var keep_open=false;
26
- var show_help=false;
27
-
28
- var config_wanted = new Array("FOP_HOME", "CLASSPATH", "FOP_HYPHENATION_PATH", "FOP_OPTS", "JAVA_OPTS", "LOGCHOICE", "LOGLEVEL");
29
-
30
- // parse command-line arguments
31
- function read_args() {
32
- var args = WScript.Arguments;
33
- var named = new ActiveXObject("Scripting.Dictionary");
34
- for (i = 0; i < args.length; i++) {
35
- switch(args(i)) {
36
- case "--debug":
37
- debug=true;
38
- break;
39
- case "--execdebug":
40
- fop_exec_debug=true;
41
- break;
42
- case "--keepopen":
43
- keep_open=true;
44
- break;
45
- case "--noconfig":
46
- no_config=true;
47
- break;
48
- case "-h":
49
- case "--help":
50
- case "--h":
51
- case "-help":
52
- show_help=true;
53
- // fop_exec_args=fop_exec_args + " -h";
54
- break;
55
- default:
56
- fop_exec_args=fop_exec_args + " " + args(i);
57
- }
58
- }
59
- if (debug) {
60
- WScript.Echo("debug: " + debug);
61
- WScript.Echo("execdebug: " + fop_exec_debug);
62
- WScript.Echo("keepopen: " + keep_open);
63
- WScript.Echo("noconfig: " + no_config);
64
- WScript.Echo("help: " + show_help);
65
- WScript.Echo("fop arguments: " + fop_exec_args);
66
- }
67
- }
68
-
69
- var help_text="Usage:\n"
70
- + WScript.ScriptFullName + " [script options] [FOP options]\n"
71
- + "Script Options:\n"
72
- + " --help, -h print this message and FOP help\n"
73
- + " --debug print debugging information for this launch script\n"
74
- + " --execdebug print FOP exec line generated by this launch script\n"
75
- + " --keepopen keep FOP's command window open\n"
76
- + " --noconfig suppress reading of configuration file and registry";
77
-
78
- function read_environment() {
79
- for (i in config_wanted) {
80
- if (!config.Exists(config_wanted[i])) {
81
- var env_var_string = "%" + config_wanted[i] + "%";
82
- var env_var = shell.ExpandEnvironmentStrings(env_var_string);
83
- if (env_var != "" && env_var != env_var_string) {
84
- config.Add(config_wanted[i], env_var);
85
- if (debug) {
86
- WScript.Echo(config_wanted[i] + " env: "
87
- + config.Item(config_wanted[i]));
88
- }
89
- }
90
- }
91
- }
92
- }
93
-
94
- function read_desktop(dtname) {
95
- if (fs.FolderExists(dtname)) {
96
- var fopname = fs.GetFolder(dtname).ParentFolder.Path
97
- + "\\Application Data\\Fop";
98
- if (fs.FolderExists(fopname)) {
99
- var fop_conf_name = fs.GetFolder(fopname).Path + "\\fop.conf";
100
- if (fs.FileExists(fop_conf_name)) {
101
- // source fop_conf_file
102
- var conf_file = fs.openTextFile(fs.GetFile(fop_conf_name));
103
- var conf_lines = new ActiveXObject("Scripting.Dictionary");
104
- while (!conf_file.AtEndOfStream) {
105
- var line = conf_file.ReadLine();
106
- var m = line.match(/(.+?)=(.+)/);
107
- if (m != null) {
108
- conf_lines.Add(m[1], m[2]);
109
- }
110
- }
111
- for (j in config_wanted) {
112
- if (!config.Exists(config_wanted[j])
113
- && conf_lines.Exists(config_wanted[j])) {
114
- config.Add(config_wanted[j], conf_lines.Item(config_wanted[j]));
115
- if (debug) {
116
- WScript.Echo(config_wanted[j] + " " + dts[i] + ": "
117
- + config.Item(config_wanted[i]));
118
- }
119
- }
120
- }
121
- }
122
- }
123
- }
124
- }
125
-
126
- function read_registry(section) {
127
- for (j in config_wanted) {
128
- if (!config.Exists(config_wanted[j])) {
129
- var reg_var;
130
- try {
131
- reg_var = shell.RegRead(section + "\\Software\\Fop\\"
132
- + config_wanted[j]);
133
- config.Add(config_wanted[j], reg_var);
134
- if (debug) {
135
- WScript.Echo(config_wanted[j] + " " + rks[i] + ": "
136
- + config.Item(config_wanted[j]));
137
- }
138
- } catch(e) {}
139
- }
140
- }
141
- }
142
-
143
- // construct FOP_HOME from the script folder
144
- function get_fop_home() {
145
- if (!config.Exists("FOP_HOME")
146
- || !fs.FolderExists(config.Item("FOP_HOME"))) {
147
- var fop_home = WScript.ScriptFullName;
148
- fop_home = fop_home.substring(0, fop_home.length
149
- - WScript.ScriptName.length - 1);
150
- if (config.Exists("FOP_HOME")) {
151
- config.Remove("FOP_HOME");
152
- }
153
- config.Add("FOP_HOME", fop_home);
154
- if (debug) {
155
- WScript.Echo("FOP_HOME dyn: " + config.Item("FOP_HOME"));
156
- }
157
- }
158
- }
159
-
160
- function get_java_cmd() {
161
- var java_home = shell.ExpandEnvironmentStrings("%JAVA_HOME%");
162
- javacmd = "java";
163
- if (java_home != "" && typeof(java_home) != "undefined"
164
- && fs.FolderExists(java_home)) {
165
- var javacmd_candidate = java_home + "\\bin\\java.exe";
166
- if (fs.FileExists(javacmd_candidate)) {
167
- javacmd = javacmd_candidate;
168
- }
169
- }
170
- if (debug) {
171
- WScript.Echo("java command: " + javacmd);
172
- }
173
- }
174
-
175
- function get_local_classpath() {
176
- if (config.Exists("CLASSPATH")) {
177
- local_classpath = config.Item("CLASSPATH");
178
- if (debug) {
179
- WScript.Echo("local classpath: " + local_classpath);
180
- }
181
- }
182
-
183
- // add fop.jar, fop-sandbox and fop-hyph.jar, which reside in $FOP_HOME/build
184
- var lcp = local_classpath;
185
- local_classpath = config.Item("FOP_HOME") + "\\build\\fop.jar;"
186
- + config.Item("FOP_HOME") + "\\build\\fop-sandbox.jar;"
187
- + config.Item("FOP_HOME") + "\\build\\fop-hyph.jar";
188
- if (lcp != "") {
189
- local_classpath += ";" + lcp;
190
- }
191
- if (debug) {
192
- WScript.Echo("local classpath: " + local_classpath);
193
- }
194
-
195
- // add in the dependency .jar files, which reside in $FOP_HOME/lib
196
- var libdir_name = config.Item("FOP_HOME") + "\\lib";
197
- var dirlibs;
198
- if (fs.FolderExists(libdir_name)) {
199
- dirlibs = fs.GetFolder(libdir_name).Files;
200
- var e = new Enumerator(dirlibs);
201
- for (; !e.atEnd(); e.moveNext()) {
202
- if (e.item().Name.match("\.jar$")) {
203
- local_classpath = libdir_name + "\\" + e.item().Name + ";" + local_classpath;
204
- }
205
- }
206
- if (debug) {
207
- WScript.Echo("local classpath: " + local_classpath);
208
- }
209
- }
210
-
211
- // add in user-defined hyphenation JARs
212
- if (config.Exists("FOP_HYPHENATION_PATH")) {
213
- local_classpath += ";" + config.Item("FOP_HYPHENATION_PATH");
214
- if (debug) {
215
- WScript.Echo("local classpath: " + local_classpath);
216
- }
217
- }
218
- }
219
-
220
- // Execute fop via shell.Exec
221
- function fop_exec() {
222
- var fop_exec_command = "\"" + javacmd + "\" "
223
- + (config.Exists("JAVA_OPTS")?config.Item("JAVA_OPTS") + " ":"")
224
- + (config.Exists("LOGCHOICE")?config.Item("LOGCHOICE") + " ":"")
225
- + (config.Exists("LOGLEVEL")?config.Item("LOGLEVEL") + " ":"")
226
- + "-classpath \"" + local_classpath + "\" "
227
- + (config.Exists("FOP_OPTS")?config.Item("FOP_OPTS"):"")
228
- + "org.apache.fop.cli.Main " + fop_exec_args;
229
- if (debug || fop_exec_debug) {
230
- WScript.Echo(fop_exec_command);
231
- }
232
-
233
- var fop_run = shell.Exec(fop_exec_command);
234
- while (true) {
235
- while (!fop_run.StdOut.AtEndOfStream) {
236
- WScript.Echo(fop_run.StdOut.ReadLine());
237
- }
238
- while (!fop_run.StdErr.AtEndOfStream) {
239
- WScript.Echo(fop_run.StdErr.ReadLine());
240
- }
241
- if (fop_run.Status == 1) {
242
- break;
243
- }
244
- WScript.Sleep(100);
245
- }
246
- if (debug) {
247
- WScript.Echo("exit status: " + fop_run.ExitCode);
248
- }
249
- }
250
-
251
- // Execute fop via shell.Run
252
- function fop_run() {
253
- var fop_exec_command = "cmd /" + (keep_open?"K":"C") + " \""
254
- + "\"" + javacmd + "\" "
255
- + (config.Exists("JAVA_OPTS")?config.Item("JAVA_OPTS") + " ":"")
256
- + (config.Exists("LOGCHOICE")?config.Item("LOGCHOICE") + " ":"")
257
- + (config.Exists("LOGLEVEL")?config.Item("LOGLEVEL") + " ":"")
258
- + "-classpath \"" + local_classpath + "\" "
259
- + (config.Exists("FOP_OPTS")?config.Item("FOP_OPTS") + " ":"")
260
- + "org.apache.fop.cli.Main " + fop_exec_args + "\"";
261
- if (debug || fop_exec_debug) {
262
- WScript.Echo(fop_exec_command);
263
- }
264
- var exit_code = shell.Run(fop_exec_command, 1, 1);
265
- if (debug) {
266
- WScript.Echo("exit status: " + exit_code);
267
- } else {
268
- if (exit_code != 0) {
269
- WScript.Echo("A FOP error occurred (FOP exit status: " + exit_code + ")\n"
270
- + "Use option --keepopen to see FOP's output\n"
271
- + "(that is two dashes)");
272
- }
273
- }
274
- }
275
-
276
- function get_log_choice() {
277
- // The default commons logger for JDK1.4 is JDK1.4Logger.
278
- // To use a different logger, uncomment the one desired below
279
- if (!config.Exists("LOGCHOICE")) {
280
- // config.Add("LOGCHOICE","\"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog\"");
281
- // config.Add("LOGCHOICE","\"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog\"");
282
- // config.Add("LOGCHOICE","\"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger\"");
283
- if (debug && config.Exists("LOGCHOICE")) {
284
- WScript.Echo("LOGCHOICE script: " + config.Item("LOGCHOICE"));
285
- }
286
- }
287
- }
288
-
289
- function get_log_level() {
290
- // Logging levels
291
- // Below option is only if you are using SimpleLog instead of the default JDK1.4 Logger.
292
- // To set logging levels for JDK 1.4 Logger, edit the %JAVA_HOME%/JRE/LIB/logging.properties
293
- // file instead.
294
- // Possible SimpleLog values: "trace", "debug", "info" (default), "warn", "error", or "fatal".
295
- if (!config.Exists("LOGLEVEL")) {
296
- // config.Add("LOGLEVEL","\"-Dorg.apache.commons.logging.simplelog.defaultlog=INFO\"");
297
- if (debug && config.Exists("LOGLEVEL")) {
298
- WScript.Echo("LOGLEVEL script: " + config.Item("LOGLEVEL"));
299
- }
300
- }
301
- }
302
-
303
- var shell = WScript.CreateObject("WScript.Shell");
304
- var fs = WScript.CreateObject("Scripting.FileSystemObject");
305
-
306
- // configuration
307
- var config = new ActiveXObject("Scripting.Dictionary");
308
-
309
- read_args();
310
- read_environment();
311
- if (!no_config) {
312
- // read user and system-wide fop configurations
313
- var spec = shell.SpecialFolders;
314
- var dts = new Array("Desktop", "AllUsersDesktop");
315
- for (i in dts) {
316
- read_desktop(spec(dts[i]));
317
- }
318
- // read user and system-wide registry
319
- var rks = new Array("HKCU", "HKLM");
320
- for (i in rks) {
321
- read_registry(rks[i]);
322
- }
323
- }
324
-
325
- get_fop_home();
326
- get_log_choice();
327
- get_log_level();
328
- var javacmd = "";
329
- get_java_cmd();
330
- var local_classpath = "";
331
- get_local_classpath();
332
-
333
- // Show script help if requested
334
- if (show_help) {
335
- // fop_exec_args = "";
336
- keep_open = true;
337
- WScript.Echo(help_text);
338
- }
339
-
340
- // fop_exec();
341
- fop_run();
1
+ // Licensed to the Apache Software Foundation (ASF) under one or more
2
+ // contributor license agreements. See the NOTICE file distributed with
3
+ // this work for additional information regarding copyright ownership.
4
+ // The ASF licenses this file to You under the Apache License, Version 2.0
5
+ // (the "License"); you may not use this file except in compliance with
6
+ // the License. You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ // $Id: fop.js 1734671 2016-03-12 05:39:53Z gadams $ -->
16
+
17
+ // jscript to run FOP, adapted from the Jakarta-Ant project.
18
+
19
+ // rpm_mode is irrelevant on Windows
20
+ // var rpm_mode=true;
21
+ var fop_exec_args = "";
22
+ var no_config=false;
23
+ var fop_exec_debug=false;
24
+ var debug=false;
25
+ var keep_open=false;
26
+ var show_help=false;
27
+
28
+ var config_wanted = new Array("FOP_HOME", "CLASSPATH", "FOP_HYPHENATION_PATH", "FOP_OPTS", "JAVA_OPTS", "LOGCHOICE", "LOGLEVEL");
29
+
30
+ // parse command-line arguments
31
+ function read_args() {
32
+ var args = WScript.Arguments;
33
+ var named = new ActiveXObject("Scripting.Dictionary");
34
+ for (i = 0; i < args.length; i++) {
35
+ switch(args(i)) {
36
+ case "--debug":
37
+ debug=true;
38
+ break;
39
+ case "--execdebug":
40
+ fop_exec_debug=true;
41
+ break;
42
+ case "--keepopen":
43
+ keep_open=true;
44
+ break;
45
+ case "--noconfig":
46
+ no_config=true;
47
+ break;
48
+ case "-h":
49
+ case "--help":
50
+ case "--h":
51
+ case "-help":
52
+ show_help=true;
53
+ // fop_exec_args=fop_exec_args + " -h";
54
+ break;
55
+ default:
56
+ fop_exec_args=fop_exec_args + " " + args(i);
57
+ }
58
+ }
59
+ if (debug) {
60
+ WScript.Echo("debug: " + debug);
61
+ WScript.Echo("execdebug: " + fop_exec_debug);
62
+ WScript.Echo("keepopen: " + keep_open);
63
+ WScript.Echo("noconfig: " + no_config);
64
+ WScript.Echo("help: " + show_help);
65
+ WScript.Echo("fop arguments: " + fop_exec_args);
66
+ }
67
+ }
68
+
69
+ var help_text="Usage:\n"
70
+ + WScript.ScriptFullName + " [script options] [FOP options]\n"
71
+ + "Script Options:\n"
72
+ + " --help, -h print this message and FOP help\n"
73
+ + " --debug print debugging information for this launch script\n"
74
+ + " --execdebug print FOP exec line generated by this launch script\n"
75
+ + " --keepopen keep FOP's command window open\n"
76
+ + " --noconfig suppress reading of configuration file and registry";
77
+
78
+ function read_environment() {
79
+ for (i in config_wanted) {
80
+ if (!config.Exists(config_wanted[i])) {
81
+ var env_var_string = "%" + config_wanted[i] + "%";
82
+ var env_var = shell.ExpandEnvironmentStrings(env_var_string);
83
+ if (env_var != "" && env_var != env_var_string) {
84
+ config.Add(config_wanted[i], env_var);
85
+ if (debug) {
86
+ WScript.Echo(config_wanted[i] + " env: "
87
+ + config.Item(config_wanted[i]));
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ function read_desktop(dtname) {
95
+ if (fs.FolderExists(dtname)) {
96
+ var fopname = fs.GetFolder(dtname).ParentFolder.Path
97
+ + "\\Application Data\\Fop";
98
+ if (fs.FolderExists(fopname)) {
99
+ var fop_conf_name = fs.GetFolder(fopname).Path + "\\fop.conf";
100
+ if (fs.FileExists(fop_conf_name)) {
101
+ // source fop_conf_file
102
+ var conf_file = fs.openTextFile(fs.GetFile(fop_conf_name));
103
+ var conf_lines = new ActiveXObject("Scripting.Dictionary");
104
+ while (!conf_file.AtEndOfStream) {
105
+ var line = conf_file.ReadLine();
106
+ var m = line.match(/(.+?)=(.+)/);
107
+ if (m != null) {
108
+ conf_lines.Add(m[1], m[2]);
109
+ }
110
+ }
111
+ for (j in config_wanted) {
112
+ if (!config.Exists(config_wanted[j])
113
+ && conf_lines.Exists(config_wanted[j])) {
114
+ config.Add(config_wanted[j], conf_lines.Item(config_wanted[j]));
115
+ if (debug) {
116
+ WScript.Echo(config_wanted[j] + " " + dts[i] + ": "
117
+ + config.Item(config_wanted[i]));
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+
126
+ function read_registry(section) {
127
+ for (j in config_wanted) {
128
+ if (!config.Exists(config_wanted[j])) {
129
+ var reg_var;
130
+ try {
131
+ reg_var = shell.RegRead(section + "\\Software\\Fop\\"
132
+ + config_wanted[j]);
133
+ config.Add(config_wanted[j], reg_var);
134
+ if (debug) {
135
+ WScript.Echo(config_wanted[j] + " " + rks[i] + ": "
136
+ + config.Item(config_wanted[j]));
137
+ }
138
+ } catch(e) {}
139
+ }
140
+ }
141
+ }
142
+
143
+ // construct FOP_HOME from the script folder
144
+ function get_fop_home() {
145
+ if (!config.Exists("FOP_HOME")
146
+ || !fs.FolderExists(config.Item("FOP_HOME"))) {
147
+ var fop_home = WScript.ScriptFullName;
148
+ fop_home = fop_home.substring(0, fop_home.length
149
+ - WScript.ScriptName.length - 1);
150
+ if (config.Exists("FOP_HOME")) {
151
+ config.Remove("FOP_HOME");
152
+ }
153
+ config.Add("FOP_HOME", fop_home);
154
+ if (debug) {
155
+ WScript.Echo("FOP_HOME dyn: " + config.Item("FOP_HOME"));
156
+ }
157
+ }
158
+ }
159
+
160
+ function get_java_cmd() {
161
+ var java_home = shell.ExpandEnvironmentStrings("%JAVA_HOME%");
162
+ javacmd = "java";
163
+ if (java_home != "" && typeof(java_home) != "undefined"
164
+ && fs.FolderExists(java_home)) {
165
+ var javacmd_candidate = java_home + "\\bin\\java.exe";
166
+ if (fs.FileExists(javacmd_candidate)) {
167
+ javacmd = javacmd_candidate;
168
+ }
169
+ }
170
+ if (debug) {
171
+ WScript.Echo("java command: " + javacmd);
172
+ }
173
+ }
174
+
175
+ function get_local_classpath() {
176
+ if (config.Exists("CLASSPATH")) {
177
+ local_classpath = config.Item("CLASSPATH");
178
+ if (debug) {
179
+ WScript.Echo("local classpath: " + local_classpath);
180
+ }
181
+ }
182
+
183
+ // add fop.jar, fop-sandbox and fop-hyph.jar, which reside in $FOP_HOME/build
184
+ var lcp = local_classpath;
185
+ local_classpath = config.Item("FOP_HOME") + "\\build\\fop.jar;"
186
+ + config.Item("FOP_HOME") + "\\build\\fop-sandbox.jar;"
187
+ + config.Item("FOP_HOME") + "\\build\\fop-hyph.jar";
188
+ if (lcp != "") {
189
+ local_classpath += ";" + lcp;
190
+ }
191
+ if (debug) {
192
+ WScript.Echo("local classpath: " + local_classpath);
193
+ }
194
+
195
+ // add in the dependency .jar files, which reside in $FOP_HOME/lib
196
+ var libdir_name = config.Item("FOP_HOME") + "\\lib";
197
+ var dirlibs;
198
+ if (fs.FolderExists(libdir_name)) {
199
+ dirlibs = fs.GetFolder(libdir_name).Files;
200
+ var e = new Enumerator(dirlibs);
201
+ for (; !e.atEnd(); e.moveNext()) {
202
+ if (e.item().Name.match("\.jar$")) {
203
+ local_classpath = libdir_name + "\\" + e.item().Name + ";" + local_classpath;
204
+ }
205
+ }
206
+ if (debug) {
207
+ WScript.Echo("local classpath: " + local_classpath);
208
+ }
209
+ }
210
+
211
+ // add in user-defined hyphenation JARs
212
+ if (config.Exists("FOP_HYPHENATION_PATH")) {
213
+ local_classpath += ";" + config.Item("FOP_HYPHENATION_PATH");
214
+ if (debug) {
215
+ WScript.Echo("local classpath: " + local_classpath);
216
+ }
217
+ }
218
+ }
219
+
220
+ // Execute fop via shell.Exec
221
+ function fop_exec() {
222
+ var fop_exec_command = "\"" + javacmd + "\" "
223
+ + (config.Exists("JAVA_OPTS")?config.Item("JAVA_OPTS") + " ":"")
224
+ + (config.Exists("LOGCHOICE")?config.Item("LOGCHOICE") + " ":"")
225
+ + (config.Exists("LOGLEVEL")?config.Item("LOGLEVEL") + " ":"")
226
+ + "-classpath \"" + local_classpath + "\" "
227
+ + (config.Exists("FOP_OPTS")?config.Item("FOP_OPTS"):"")
228
+ + "org.apache.fop.cli.Main " + fop_exec_args;
229
+ if (debug || fop_exec_debug) {
230
+ WScript.Echo(fop_exec_command);
231
+ }
232
+
233
+ var fop_run = shell.Exec(fop_exec_command);
234
+ while (true) {
235
+ while (!fop_run.StdOut.AtEndOfStream) {
236
+ WScript.Echo(fop_run.StdOut.ReadLine());
237
+ }
238
+ while (!fop_run.StdErr.AtEndOfStream) {
239
+ WScript.Echo(fop_run.StdErr.ReadLine());
240
+ }
241
+ if (fop_run.Status == 1) {
242
+ break;
243
+ }
244
+ WScript.Sleep(100);
245
+ }
246
+ if (debug) {
247
+ WScript.Echo("exit status: " + fop_run.ExitCode);
248
+ }
249
+ }
250
+
251
+ // Execute fop via shell.Run
252
+ function fop_run() {
253
+ var fop_exec_command = "cmd /" + (keep_open?"K":"C") + " \""
254
+ + "\"" + javacmd + "\" "
255
+ + (config.Exists("JAVA_OPTS")?config.Item("JAVA_OPTS") + " ":"")
256
+ + (config.Exists("LOGCHOICE")?config.Item("LOGCHOICE") + " ":"")
257
+ + (config.Exists("LOGLEVEL")?config.Item("LOGLEVEL") + " ":"")
258
+ + "-classpath \"" + local_classpath + "\" "
259
+ + (config.Exists("FOP_OPTS")?config.Item("FOP_OPTS") + " ":"")
260
+ + "org.apache.fop.cli.Main " + fop_exec_args + "\"";
261
+ if (debug || fop_exec_debug) {
262
+ WScript.Echo(fop_exec_command);
263
+ }
264
+ var exit_code = shell.Run(fop_exec_command, 1, 1);
265
+ if (debug) {
266
+ WScript.Echo("exit status: " + exit_code);
267
+ } else {
268
+ if (exit_code != 0) {
269
+ WScript.Echo("A FOP error occurred (FOP exit status: " + exit_code + ")\n"
270
+ + "Use option --keepopen to see FOP's output\n"
271
+ + "(that is two dashes)");
272
+ }
273
+ }
274
+ }
275
+
276
+ function get_log_choice() {
277
+ // The default commons logger for JDK1.4 is JDK1.4Logger.
278
+ // To use a different logger, uncomment the one desired below
279
+ if (!config.Exists("LOGCHOICE")) {
280
+ // config.Add("LOGCHOICE","\"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog\"");
281
+ // config.Add("LOGCHOICE","\"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog\"");
282
+ // config.Add("LOGCHOICE","\"-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger\"");
283
+ if (debug && config.Exists("LOGCHOICE")) {
284
+ WScript.Echo("LOGCHOICE script: " + config.Item("LOGCHOICE"));
285
+ }
286
+ }
287
+ }
288
+
289
+ function get_log_level() {
290
+ // Logging levels
291
+ // Below option is only if you are using SimpleLog instead of the default JDK1.4 Logger.
292
+ // To set logging levels for JDK 1.4 Logger, edit the %JAVA_HOME%/JRE/LIB/logging.properties
293
+ // file instead.
294
+ // Possible SimpleLog values: "trace", "debug", "info" (default), "warn", "error", or "fatal".
295
+ if (!config.Exists("LOGLEVEL")) {
296
+ // config.Add("LOGLEVEL","\"-Dorg.apache.commons.logging.simplelog.defaultlog=INFO\"");
297
+ if (debug && config.Exists("LOGLEVEL")) {
298
+ WScript.Echo("LOGLEVEL script: " + config.Item("LOGLEVEL"));
299
+ }
300
+ }
301
+ }
302
+
303
+ var shell = WScript.CreateObject("WScript.Shell");
304
+ var fs = WScript.CreateObject("Scripting.FileSystemObject");
305
+
306
+ // configuration
307
+ var config = new ActiveXObject("Scripting.Dictionary");
308
+
309
+ read_args();
310
+ read_environment();
311
+ if (!no_config) {
312
+ // read user and system-wide fop configurations
313
+ var spec = shell.SpecialFolders;
314
+ var dts = new Array("Desktop", "AllUsersDesktop");
315
+ for (i in dts) {
316
+ read_desktop(spec(dts[i]));
317
+ }
318
+ // read user and system-wide registry
319
+ var rks = new Array("HKCU", "HKLM");
320
+ for (i in rks) {
321
+ read_registry(rks[i]);
322
+ }
323
+ }
324
+
325
+ get_fop_home();
326
+ get_log_choice();
327
+ get_log_level();
328
+ var javacmd = "";
329
+ get_java_cmd();
330
+ var local_classpath = "";
331
+ get_local_classpath();
332
+
333
+ // Show script help if requested
334
+ if (show_help) {
335
+ // fop_exec_args = "";
336
+ keep_open = true;
337
+ WScript.Echo(help_text);
338
+ }
339
+
340
+ // fop_exec();
341
+ fop_run();