libis-format 1.0.7 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +32 -24
- data/README.md +2 -2
- data/base/Dockerfile +5 -3
- data/base/rework_path +5 -10
- data/bin/{droid → droid_tool} +0 -0
- data/bin/{fido → fido_tool} +0 -0
- data/lib/libis/format.rb +12 -3
- data/lib/libis/format/cli/convert.rb +4 -4
- data/lib/libis/format/config.rb +16 -12
- data/lib/libis/format/converter/audio_converter.rb +2 -36
- data/lib/libis/format/converter/base.rb +22 -8
- data/lib/libis/format/converter/chain.rb +3 -3
- data/lib/libis/format/converter/image_assembler.rb +82 -0
- data/lib/libis/format/converter/image_converter.rb +20 -138
- data/lib/libis/format/converter/image_splitter.rb +84 -0
- data/lib/libis/format/converter/image_watermarker.rb +261 -0
- data/lib/libis/format/converter/jp2_converter.rb +1 -1
- data/lib/libis/format/converter/office_converter.rb +2 -2
- data/lib/libis/format/converter/pdf_assembler.rb +66 -0
- data/lib/libis/format/converter/pdf_converter.rb +6 -132
- data/lib/libis/format/converter/pdf_metadata.rb +82 -0
- data/lib/libis/format/converter/pdf_optimizer.rb +67 -0
- data/lib/libis/format/converter/pdf_protecter.rb +147 -0
- data/lib/libis/format/converter/pdf_selecter.rb +83 -0
- data/lib/libis/format/converter/pdf_splitter.rb +70 -0
- data/lib/libis/format/converter/pdf_watermarker_header.rb +71 -0
- data/lib/libis/format/converter/pdf_watermarker_image.rb +76 -0
- data/lib/libis/format/converter/pdf_watermarker_text.rb +93 -0
- data/lib/libis/format/converter/spreadsheet_converter.rb +2 -2
- data/lib/libis/format/converter/video_converter.rb +1 -1
- data/lib/libis/format/identifier.rb +3 -3
- data/lib/libis/format/info.rb +27 -0
- data/lib/libis/format/library.rb +147 -0
- data/lib/libis/format/tool.rb +4 -1
- data/lib/libis/format/tool/extension_identification.rb +4 -4
- data/lib/libis/format/tool/identification_tool.rb +6 -6
- data/lib/libis/format/tool/pdf_merge.rb +3 -3
- data/lib/libis/format/tool/{pdf_copy.rb → pdf_metadata.rb} +5 -5
- data/lib/libis/format/tool/pdf_protect.rb +47 -0
- data/lib/libis/format/tool/pdf_select.rb +47 -0
- data/lib/libis/format/tool/pdf_split.rb +4 -4
- data/lib/libis/format/tool/pdf_watermark.rb +47 -0
- data/lib/libis/format/tool/spreadsheet_to_ods.rb +1 -0
- data/lib/libis/format/version.rb +1 -1
- data/lib/libis/format/yaml_loader.rb +71 -0
- data/libis-format.gemspec +3 -2
- data/tools/PdfTool.jar +0 -0
- data/tools/bcpkix-jdk15on-167.jar +0 -0
- data/tools/bcprov-jdk15on-167.jar +0 -0
- data/tools/fop/fop.bat +75 -75
- data/tools/fop/fop.cmd +31 -31
- data/tools/fop/fop.js +341 -341
- data/tools/fop/lib/avalon-framework.NOTICE.TXT +11 -11
- data/tools/fop/lib/xml-apis.LICENSE-SAX.html +17 -17
- data/tools/fop/lib/xml-apis.LICENSE.DOM-documentation.html +74 -74
- data/tools/fop/lib/xml-apis.LICENSE.DOM-software.html +66 -66
- metadata +32 -19
- data/bin/pdf_copy +0 -13
- data/lib/libis/format/type_database.rb +0 -133
- data/lib/libis/format/type_database_impl.rb +0 -120
- data/tools/bcpkix-jdk15on-1.49.jar +0 -0
- data/tools/bcprov-jdk15on-1.49.jar +0 -0
data/lib/libis/format/version.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'yaml'
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
module Libis
|
6
|
+
module Format
|
7
|
+
class YamlLoader
|
8
|
+
# noinspection RubyResolve
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
def query(key, value)
|
12
|
+
case key.to_s.downcase.to_sym
|
13
|
+
when :name
|
14
|
+
return [database[value.to_s.upcase.to_sym]]
|
15
|
+
when :category
|
16
|
+
database.find_all { |_, info| info.category == value.to_s.upcase.to_sym }
|
17
|
+
when :puid
|
18
|
+
database.find_all { |_, info| info.puids.include?(value) }
|
19
|
+
when :mimetype
|
20
|
+
database.find_all { |_, info| info.mimetypes.include?(value) }
|
21
|
+
when :extension
|
22
|
+
database.find_all { |_, info| info.extensions.include?(value) }
|
23
|
+
else
|
24
|
+
return []
|
25
|
+
end.map(&:last)
|
26
|
+
end
|
27
|
+
|
28
|
+
def load_formats(file_or_hash)
|
29
|
+
hash = file_or_hash.is_a?(Hash) ? file_or_hash : YAML::load_file(file_or_hash)
|
30
|
+
hash.each do |category, format_list|
|
31
|
+
format_list.each do |format_name, format_info|
|
32
|
+
format_info.symbolize_keys!
|
33
|
+
format_name = format_name.to_sym
|
34
|
+
new_info = Libis::Format::Info.new(
|
35
|
+
name: format_name,
|
36
|
+
category: category.to_sym,
|
37
|
+
description: format_info[:NAME],
|
38
|
+
puids: format_info[:PUID]&.strip&.split(/[\s,]+/)&.map { |v| v.strip } || [],
|
39
|
+
mimetypes: format_info[:MIME]&.strip&.split(/[\s,]+/)&.map(&:strip) || [],
|
40
|
+
extensions: format_info[:EXTENSIONS]&.strip&.split(/[\s,]+/)&.map { |v| v.strip } || []
|
41
|
+
)
|
42
|
+
if (old_info = database[format_name])
|
43
|
+
new_info = Libis::Format::Info.new(
|
44
|
+
name: format_name,
|
45
|
+
category: category.to_sym,
|
46
|
+
description: new_info.description.blank? ? old_info.description : new_info.description,
|
47
|
+
puids: (old_info.puids + new_info.puids).uniq,
|
48
|
+
mimetypes: (old_info.mimetypes + new_info.mimetypes).uniq,
|
49
|
+
extensions: (old_info.extensions + new_info.extensions).uniq
|
50
|
+
)
|
51
|
+
end
|
52
|
+
database[format_name] = new_info
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
attr_reader :database
|
61
|
+
|
62
|
+
def initialize
|
63
|
+
@database = {}
|
64
|
+
format_database = Libis::Format::Config[:format_library_database]
|
65
|
+
load_formats(format_database)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/libis-format.gemspec
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
lib = File.expand_path('../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
|
6
|
+
require 'bundler'
|
6
7
|
require 'libis/format/version'
|
7
8
|
|
8
9
|
Gem::Specification.new do |spec|
|
@@ -32,10 +33,10 @@ Gem::Specification.new do |spec|
|
|
32
33
|
spec.add_development_dependency 'nokogiri'
|
33
34
|
end
|
34
35
|
|
35
|
-
spec.add_runtime_dependency 'libis-tools', '
|
36
|
+
spec.add_runtime_dependency 'libis-tools', '>= 1.0.9'
|
36
37
|
spec.add_runtime_dependency 'os', '= 0.9.6'
|
37
38
|
spec.add_runtime_dependency 'mini_magick', '~> 4.3'
|
38
39
|
spec.add_runtime_dependency 'deep_dive', '~> 0.3'
|
39
40
|
spec.add_runtime_dependency 'chromaprint', '~> 0.0.2'
|
40
41
|
spec.add_runtime_dependency 'naturally', '~> 2.1'
|
41
|
-
end
|
42
|
+
end
|
data/tools/PdfTool.jar
CHANGED
Binary file
|
Binary file
|
Binary file
|
data/tools/fop/fop.bat
CHANGED
@@ -1,75 +1,75 @@
|
|
1
|
-
@ECHO OFF
|
2
|
-
REM Licensed to the Apache Software Foundation (ASF) under one or more
|
3
|
-
REM contributor license agreements. See the NOTICE file distributed with
|
4
|
-
REM this work for additional information regarding copyright ownership.
|
5
|
-
REM The ASF licenses this file to You under the Apache License, Version 2.0
|
6
|
-
REM (the "License"); you may not use this file except in compliance with
|
7
|
-
REM the License. You may obtain a copy of the License at
|
8
|
-
REM
|
9
|
-
REM http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
REM
|
11
|
-
REM Unless required by applicable law or agreed to in writing, software
|
12
|
-
REM distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
REM See the License for the specific language governing permissions and
|
15
|
-
REM limitations under the License.
|
16
|
-
REM $Id: fop.bat 1736993 2016-03-29 09:19:30Z ssteiner $
|
17
|
-
|
18
|
-
SETLOCAL ENABLEDELAYEDEXPANSION
|
19
|
-
|
20
|
-
rem %~dp0 is the expanded pathname of the current script under NT
|
21
|
-
set LOCAL_FOP_HOME=
|
22
|
-
if "%OS%"=="Windows_NT" set LOCAL_FOP_HOME="%~dp0"
|
23
|
-
|
24
|
-
rem Code from Apache Ant project
|
25
|
-
rem Slurp the command line arguments. This loop allows for an unlimited number
|
26
|
-
rem of arguments (up to the command line limit, anyway).
|
27
|
-
rem Could also do a "shift" and "%*" for all params, but apparently doesn't work
|
28
|
-
rem with Win9x.
|
29
|
-
set FOP_CMD_LINE_ARGS=%1
|
30
|
-
if ""%1""=="""" goto doneStart
|
31
|
-
shift
|
32
|
-
:setupArgs
|
33
|
-
if ""%1""=="""" goto doneStart
|
34
|
-
set FOP_CMD_LINE_ARGS=%FOP_CMD_LINE_ARGS% %1
|
35
|
-
shift
|
36
|
-
goto setupArgs
|
37
|
-
rem This label provides a place for the argument list loop to break out
|
38
|
-
rem and for NT handling to skip to.
|
39
|
-
:doneStart
|
40
|
-
|
41
|
-
set LOGCHOICE=
|
42
|
-
rem The default commons logger for JDK1.4 is JDK1.4Logger.
|
43
|
-
rem To use a different logger, uncomment the one desired below
|
44
|
-
rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
|
45
|
-
rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
|
46
|
-
rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
|
47
|
-
|
48
|
-
set LOGLEVEL=
|
49
|
-
rem Logging levels
|
50
|
-
rem Below option is only if you are using SimpleLog instead of the default JDK1.4 Logger.
|
51
|
-
rem To set logging levels for JDK 1.4 Logger, edit the %JAVA_HOME%\JRE\LIB\logging.properties
|
52
|
-
rem file instead.
|
53
|
-
rem Possible SimpleLog values: "trace", "debug", "info" (default), "warn", "error", or "fatal".
|
54
|
-
rem set LOGLEVEL=-Dorg.apache.commons.logging.simplelog.defaultlog=INFO
|
55
|
-
|
56
|
-
set LIBDIR=%LOCAL_FOP_HOME%lib
|
57
|
-
|
58
|
-
set LOCALCLASSPATH=%FOP_HYPHENATION_PATH%
|
59
|
-
for %%l in (%LOCAL_FOP_HOME%build\*.jar %LIBDIR%\*.jar %LOCAL_FOP_HOME%target\*.jar) do set LOCALCLASSPATH=!LOCALCLASSPATH!;%%l
|
60
|
-
|
61
|
-
set JAVAOPTS=-Denv.windir=%WINDIR%
|
62
|
-
|
63
|
-
if "%JAVA_HOME%" == "" goto noJavaHome
|
64
|
-
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
|
65
|
-
if "%JAVACMD%" == "" set JAVACMD=%JAVA_HOME%\bin\java
|
66
|
-
goto runFop
|
67
|
-
|
68
|
-
:noJavaHome
|
69
|
-
if "%JAVACMD%" == "" set JAVACMD=java
|
70
|
-
|
71
|
-
:runFop
|
72
|
-
rem echo "%JAVACMD%" %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
|
73
|
-
"%JAVACMD%" %JAVAOPTS% %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" %FOP_OPTS% org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
|
74
|
-
|
75
|
-
ENDLOCAL
|
1
|
+
@ECHO OFF
|
2
|
+
REM Licensed to the Apache Software Foundation (ASF) under one or more
|
3
|
+
REM contributor license agreements. See the NOTICE file distributed with
|
4
|
+
REM this work for additional information regarding copyright ownership.
|
5
|
+
REM The ASF licenses this file to You under the Apache License, Version 2.0
|
6
|
+
REM (the "License"); you may not use this file except in compliance with
|
7
|
+
REM the License. You may obtain a copy of the License at
|
8
|
+
REM
|
9
|
+
REM http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
REM
|
11
|
+
REM Unless required by applicable law or agreed to in writing, software
|
12
|
+
REM distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
REM See the License for the specific language governing permissions and
|
15
|
+
REM limitations under the License.
|
16
|
+
REM $Id: fop.bat 1736993 2016-03-29 09:19:30Z ssteiner $
|
17
|
+
|
18
|
+
SETLOCAL ENABLEDELAYEDEXPANSION
|
19
|
+
|
20
|
+
rem %~dp0 is the expanded pathname of the current script under NT
|
21
|
+
set LOCAL_FOP_HOME=
|
22
|
+
if "%OS%"=="Windows_NT" set LOCAL_FOP_HOME="%~dp0"
|
23
|
+
|
24
|
+
rem Code from Apache Ant project
|
25
|
+
rem Slurp the command line arguments. This loop allows for an unlimited number
|
26
|
+
rem of arguments (up to the command line limit, anyway).
|
27
|
+
rem Could also do a "shift" and "%*" for all params, but apparently doesn't work
|
28
|
+
rem with Win9x.
|
29
|
+
set FOP_CMD_LINE_ARGS=%1
|
30
|
+
if ""%1""=="""" goto doneStart
|
31
|
+
shift
|
32
|
+
:setupArgs
|
33
|
+
if ""%1""=="""" goto doneStart
|
34
|
+
set FOP_CMD_LINE_ARGS=%FOP_CMD_LINE_ARGS% %1
|
35
|
+
shift
|
36
|
+
goto setupArgs
|
37
|
+
rem This label provides a place for the argument list loop to break out
|
38
|
+
rem and for NT handling to skip to.
|
39
|
+
:doneStart
|
40
|
+
|
41
|
+
set LOGCHOICE=
|
42
|
+
rem The default commons logger for JDK1.4 is JDK1.4Logger.
|
43
|
+
rem To use a different logger, uncomment the one desired below
|
44
|
+
rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog
|
45
|
+
rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
|
46
|
+
rem set LOGCHOICE=-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
|
47
|
+
|
48
|
+
set LOGLEVEL=
|
49
|
+
rem Logging levels
|
50
|
+
rem Below option is only if you are using SimpleLog instead of the default JDK1.4 Logger.
|
51
|
+
rem To set logging levels for JDK 1.4 Logger, edit the %JAVA_HOME%\JRE\LIB\logging.properties
|
52
|
+
rem file instead.
|
53
|
+
rem Possible SimpleLog values: "trace", "debug", "info" (default), "warn", "error", or "fatal".
|
54
|
+
rem set LOGLEVEL=-Dorg.apache.commons.logging.simplelog.defaultlog=INFO
|
55
|
+
|
56
|
+
set LIBDIR=%LOCAL_FOP_HOME%lib
|
57
|
+
|
58
|
+
set LOCALCLASSPATH=%FOP_HYPHENATION_PATH%
|
59
|
+
for %%l in (%LOCAL_FOP_HOME%build\*.jar %LIBDIR%\*.jar %LOCAL_FOP_HOME%target\*.jar) do set LOCALCLASSPATH=!LOCALCLASSPATH!;%%l
|
60
|
+
|
61
|
+
set JAVAOPTS=-Denv.windir=%WINDIR%
|
62
|
+
|
63
|
+
if "%JAVA_HOME%" == "" goto noJavaHome
|
64
|
+
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
|
65
|
+
if "%JAVACMD%" == "" set JAVACMD=%JAVA_HOME%\bin\java
|
66
|
+
goto runFop
|
67
|
+
|
68
|
+
:noJavaHome
|
69
|
+
if "%JAVACMD%" == "" set JAVACMD=java
|
70
|
+
|
71
|
+
:runFop
|
72
|
+
rem echo "%JAVACMD%" %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
|
73
|
+
"%JAVACMD%" %JAVAOPTS% %LOGCHOICE% %LOGLEVEL% -cp "%LOCALCLASSPATH%" %FOP_OPTS% org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
|
74
|
+
|
75
|
+
ENDLOCAL
|
data/tools/fop/fop.cmd
CHANGED
@@ -1,31 +1,31 @@
|
|
1
|
-
@ECHO OFF
|
2
|
-
REM Licensed to the Apache Software Foundation (ASF) under one or more
|
3
|
-
REM contributor license agreements. See the NOTICE file distributed with
|
4
|
-
REM this work for additional information regarding copyright ownership.
|
5
|
-
REM The ASF licenses this file to You under the Apache License, Version 2.0
|
6
|
-
REM (the "License"); you may not use this file except in compliance with
|
7
|
-
REM the License. You may obtain a copy of the License at
|
8
|
-
REM
|
9
|
-
REM http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
REM
|
11
|
-
REM Unless required by applicable law or agreed to in writing, software
|
12
|
-
REM distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
REM See the License for the specific language governing permissions and
|
15
|
-
REM limitations under the License.
|
16
|
-
REM $Id: fop.cmd 1734671 2016-03-12 05:39:53Z gadams $
|
17
|
-
|
18
|
-
set LOCAL_FOP_HOME=%~dp0
|
19
|
-
set FOP_CMD_LINE_ARGS=%1
|
20
|
-
if ""%1""=="""" goto doneStart
|
21
|
-
shift
|
22
|
-
:setupArgs
|
23
|
-
if ""%1""=="""" goto doneStart
|
24
|
-
set FOP_CMD_LINE_ARGS=%FOP_CMD_LINE_ARGS% %1
|
25
|
-
shift
|
26
|
-
goto setupArgs
|
27
|
-
rem This label provides a place for the argument list loop to break out
|
28
|
-
:doneStart
|
29
|
-
|
30
|
-
call "%LOCAL_FOP_HOME%\fop.bat" %FOP_CMD_LINE_ARGS%
|
31
|
-
|
1
|
+
@ECHO OFF
|
2
|
+
REM Licensed to the Apache Software Foundation (ASF) under one or more
|
3
|
+
REM contributor license agreements. See the NOTICE file distributed with
|
4
|
+
REM this work for additional information regarding copyright ownership.
|
5
|
+
REM The ASF licenses this file to You under the Apache License, Version 2.0
|
6
|
+
REM (the "License"); you may not use this file except in compliance with
|
7
|
+
REM the License. You may obtain a copy of the License at
|
8
|
+
REM
|
9
|
+
REM http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
REM
|
11
|
+
REM Unless required by applicable law or agreed to in writing, software
|
12
|
+
REM distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
REM See the License for the specific language governing permissions and
|
15
|
+
REM limitations under the License.
|
16
|
+
REM $Id: fop.cmd 1734671 2016-03-12 05:39:53Z gadams $
|
17
|
+
|
18
|
+
set LOCAL_FOP_HOME=%~dp0
|
19
|
+
set FOP_CMD_LINE_ARGS=%1
|
20
|
+
if ""%1""=="""" goto doneStart
|
21
|
+
shift
|
22
|
+
:setupArgs
|
23
|
+
if ""%1""=="""" goto doneStart
|
24
|
+
set FOP_CMD_LINE_ARGS=%FOP_CMD_LINE_ARGS% %1
|
25
|
+
shift
|
26
|
+
goto setupArgs
|
27
|
+
rem This label provides a place for the argument list loop to break out
|
28
|
+
:doneStart
|
29
|
+
|
30
|
+
call "%LOCAL_FOP_HOME%\fop.bat" %FOP_CMD_LINE_ARGS%
|
31
|
+
|
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();
|