Merge lp:~zorba-coders/zorba/data-formatting-doc into lp:zorba/process-module

Proposed by William Candillon
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/data-formatting-doc
Merge into: lp:zorba/process-module
Diff against target: 1098 lines (+1023/-0) (has conflicts)
12 files modified
CMakeLists.txt (+56/-0)
cmake_modules/FindJNI.cmake (+286/-0)
cmake_modules/Windows/FindJNI.cmake (+37/-0)
src/CMakeLists.txt (+20/-0)
src/com/CMakeLists.txt (+17/-0)
src/com/zorba-xquery/CMakeLists.txt (+17/-0)
src/com/zorba-xquery/www/CMakeLists.txt (+17/-0)
src/com/zorba-xquery/www/modules/CMakeLists.txt (+105/-0)
src/com/zorba-xquery/www/modules/xsl-fo.xq (+161/-0)
src/com/zorba-xquery/www/modules/xsl-fo.xq.src/xslfo.cpp (+280/-0)
test/ExpQueryResults/data-formatting/xslfo.xml.res (+1/-0)
test/Queries/data-formatting/xslfo.xq (+26/-0)
Conflict adding file CMakeLists.txt.  Moved existing file to CMakeLists.txt.moved.
Conflict adding file src.  Moved existing file to src.moved.
Conflict adding file test.  Moved existing file to test.moved.
To merge this branch: bzr merge lp:~zorba-coders/zorba/data-formatting-doc
Reviewer Review Type Date Requested Status
Cezar Andrei Needs Fixing
William Candillon Approve
Review via email: mp+126953@code.launchpad.net

This proposal has been superseded by a proposal from 2012-10-03.

Commit message

Minor documentation improvements.

Description of the change

Minor documentation improvements.

To post a comment you must log in.
Revision history for this message
William Candillon (wcandillon) :
review: Approve
Revision history for this message
Cezar Andrei (cezar-andrei) wrote :

William, I think you chose the wrong branch to merge into. Pls check again.

review: Needs Fixing

Unmerged revisions

37. By William Candillon

Minor documentation improvement.

36. By Juan Zacarias

Changes to FindJNI.cmake to work with the Ubuntu Installer Approved: Juan Zacarias, Chris Hillery

35. By Chris Hillery

Don't depend on util-jvm to find Java for us; find it ourselves. Approved: Chris Hillery, Cezar Andrei

34. By Matthias Brantner

- improved search of dependent jars
- removed dead code Approved: Cezar Andrei, Matthias Brantner

33. By Chris Hillery

Report gracefully if util-jvm module is not found. Approved: Nicolae Brinza, Chris Hillery

32. By Chris Hillery

Add util-jvm link libraries.

31. By Cezar Andrei <email address hidden>

Integrated dependency on util-jvm module.

30. By Rodolfo Ochoa

Fixes on CMakeList to avoid submitting a test when module is not active.
Also added functionality to avoid testing for Java if module is not active. Approved: Matthias Brantner, Chris Hillery, Cezar Andrei

29. By Cezar Andrei <email address hidden>

Impl renaming getProperties to getPropertiesGlobal.

28. By Cezar Andrei <email address hidden>

Fix adding test only when XSL-FOP is built.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'CMakeLists.txt'
--- CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ CMakeLists.txt 2012-09-28 12:58:20 +0000
@@ -0,0 +1,56 @@
1# Copyright 2006-2010 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15MESSAGE (STATUS "******** BEGIN Configuring module Data-Formatting ********")
16
17CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
18
19PROJECT (zorba_data-formatting_module)
20
21FIND_PACKAGE (zorba_util-jvm_module QUIET)
22
23IF (zorba_util-jvm_module_FOUND)
24 INCLUDE ("${zorba_util-jvm_module_USE_FILE}")
25
26 FIND_PACKAGE(JNI)
27 FIND_PACKAGE(Java)
28 FIND_PACKAGE (Zorba REQUIRED HINTS "${ZORBA_BUILD_DIR}")
29 INCLUDE ("${Zorba_USE_FILE}")
30
31 IF (JNI_FOUND)
32 INCLUDE_DIRECTORIES (${zorba_util-jvm_module_INCLUDE_DIRS})
33
34 ENABLE_TESTING ()
35 INCLUDE (CTest)
36
37 SET_CMAKE_MODULE_PATH ()
38
39 FIND_PACKAGE (Zorba REQUIRED HINTS "${ZORBA_BUILD_DIR}")
40 INCLUDE ("${Zorba_USE_FILE}")
41
42 ADD_SUBDIRECTORY ("src")
43 #ADD_TEST_DIRECTORY ("${CMAKE_SOURCE_DIR}/test")
44
45 DONE_DECLARING_ZORBA_URIS ()
46
47 ELSE (JNI_FOUND)
48 MESSAGE ( STATUS "Java and/or JNI not found; skipping data-formating module.")
49 ENDIF(JNI_FOUND)
50
51ELSE (zorba_util-jvm_module_FOUND)
52 MESSAGE (STATUS "Zorba's util-jvm module not found; skipping data-formatting module.")
53ENDIF (zorba_util-jvm_module_FOUND)
54
55
56MESSAGE (STATUS "******** END Configuring module Data-Formatting ********")
057
=== renamed file 'CMakeLists.txt' => 'CMakeLists.txt.moved'
=== added directory 'cmake_modules'
=== added file 'cmake_modules/FindJNI.cmake'
--- cmake_modules/FindJNI.cmake 1970-01-01 00:00:00 +0000
+++ cmake_modules/FindJNI.cmake 2012-09-28 12:58:20 +0000
@@ -0,0 +1,286 @@
1# - Find JNI java libraries.
2# This module finds if Java is installed and determines where the
3# include files and libraries are. It also determines what the name of
4# the library is. This code sets the following variables:
5#
6# JNI_INCLUDE_DIRS = the include dirs to use
7# JNI_LIBRARIES = the libraries to use
8# JNI_FOUND = TRUE if JNI headers and libraries were found.
9# JAVA_AWT_LIBRARY = the path to the jawt library
10# JAVA_JVM_LIBRARY = the path to the jvm library
11# JAVA_INCLUDE_PATH = the include path to jni.h
12# JAVA_INCLUDE_PATH2 = the include path to jni_md.h
13# JAVA_AWT_INCLUDE_PATH = the include path to jawt.h
14#
15
16#=============================================================================
17# Copyright 2001-2009 Kitware, Inc.
18#
19# Distributed under the OSI-approved BSD License (the "License");
20# see accompanying file Copyright.txt for details.
21#
22# This software is distributed WITHOUT ANY WARRANTY; without even the
23# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24# See the License for more information.
25#=============================================================================
26# (To distribute this file outside of CMake, substitute the full
27# License text for the above reference.)
28
29# Expand {libarch} occurences to java_libarch subdirectory(-ies) and set ${_var}
30MACRO(java_append_library_directories _var)
31 # Determine java arch-specific library subdir
32 # Mostly based on openjdk/jdk/make/common/shared/Platform.gmk as of openjdk
33 # 1.6.0_18 + icedtea patches. However, it would be much better to base the
34 # guess on the first part of the GNU config.guess platform triplet.
35 IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
36 SET(_java_libarch "amd64")
37 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
38 SET(_java_libarch "i386")
39 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha")
40 SET(_java_libarch "alpha")
41 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
42 # Subdir is "arm" for both big-endian (arm) and little-endian (armel).
43 SET(_java_libarch "arm")
44 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
45 # mips* machines are bi-endian mostly so processor does not tell
46 # endianess of the underlying system.
47 SET(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "mips" "mipsel" "mipseb")
48 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
49 SET(_java_libarch "ppc64")
50 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
51 SET(_java_libarch "ppc")
52 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
53 # Both flavours can run on the same processor
54 SET(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9")
55 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(parisc|hppa)")
56 SET(_java_libarch "parisc" "parisc64")
57 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390")
58 # s390 binaries can run on s390x machines
59 SET(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "s390" "s390x")
60 ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^sh")
61 SET(_java_libarch "sh")
62 ELSE(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
63 SET(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}")
64 ENDIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
65
66 # Append default list architectures if CMAKE_SYSTEM_PROCESSOR was empty or
67 # system is non-Linux (where the code above has not been well tested)
68 IF(NOT _java_libarch OR NOT CMAKE_SYSTEM_NAME MATCHES "Linux")
69 LIST(APPEND _java_libarch "i386" "amd64" "ppc")
70 ENDIF(NOT _java_libarch OR NOT CMAKE_SYSTEM_NAME MATCHES "Linux")
71
72 # Sometimes ${CMAKE_SYSTEM_PROCESSOR} is added to the list to prefer
73 # current value to a hardcoded list. Remove possible duplicates.
74 LIST(REMOVE_DUPLICATES _java_libarch)
75
76 FOREACH(_path ${ARGN})
77 IF(_path MATCHES "{libarch}")
78 FOREACH(_libarch ${_java_libarch})
79 STRING(REPLACE "{libarch}" "${_libarch}" _newpath "${_path}")
80 LIST(APPEND ${_var} "${_newpath}")
81 ENDFOREACH(_libarch)
82 ELSE(_path MATCHES "{libarch}")
83 LIST(APPEND ${_var} "${_path}")
84 ENDIF(_path MATCHES "{libarch}")
85 ENDFOREACH(_path)
86ENDMACRO(java_append_library_directories)
87
88GET_FILENAME_COMPONENT(java_install_version
89 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit;CurrentVersion]" NAME)
90
91SET(JAVA_AWT_LIBRARY_DIRECTORIES
92 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/lib"
93 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/lib"
94 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/lib"
95 )
96
97FILE(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _JAVA_HOME)
98
99JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
100 ${_JAVA_HOME}/jre/lib/{libarch}
101 ${_JAVA_HOME}/jre/lib
102 ${_JAVA_HOME}/lib
103 ${_JAVA_HOME}
104 /usr/lib/jvm/java-6-openjdk/jre/lib
105 /usr/lib/jvm/java-6-openjdk-i386/jre/lib
106 /usr/lib/jvm/java-6-openjdk-amd64/jre/lib
107 /usr/lib/jvm/java-6-openjdk/jre/lib/{libarch}
108 /usr/lib/jvm/java-6-openjdk-i386/jre/lib/{libarch}
109 /usr/lib/jvm/java-6-openjdk-amd64/jre/lib/{libarch}
110 /usr/lib
111 /usr/local/lib
112 /usr/lib/jvm/java/lib
113 /usr/lib/java/jre/lib/{libarch}
114 /usr/local/lib/java/jre/lib/{libarch}
115 /usr/local/share/java/jre/lib/{libarch}
116 /usr/lib/j2sdk1.4-sun/jre/lib/{libarch}
117 /usr/lib/j2sdk1.5-sun/jre/lib/{libarch}
118 /opt/sun-jdk-1.5.0.04/jre/lib/{libarch}
119 /usr/lib/jvm/java-6-sun/jre/lib/{libarch}
120 /usr/lib/jvm/java-1.5.0-sun/jre/lib/{libarch}
121 /usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/{libarch} # can this one be removed according to #8821 ? Alex
122 /usr/lib/jvm/java-openjdk/jre/lib/{libarch}
123 # Debian specific paths for default JVM
124 /usr/lib/jvm/default-java/jre/lib/{libarch}
125 /usr/lib/jvm/default-java/jre/lib
126 /usr/lib/jvm/default-java/lib
127 )
128
129SET(JAVA_JVM_LIBRARY_DIRECTORIES)
130FOREACH(dir ${JAVA_AWT_LIBRARY_DIRECTORIES})
131 SET(JAVA_JVM_LIBRARY_DIRECTORIES
132 ${JAVA_JVM_LIBRARY_DIRECTORIES}
133 "${dir}"
134 "${dir}/client"
135 "${dir}/server"
136 )
137ENDFOREACH(dir)
138
139
140SET(JAVA_AWT_INCLUDE_DIRECTORIES
141 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
142 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
143 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
144 ${_JAVA_HOME}/include
145 /usr/lib/jvm/java-6-openjdk/include
146 /usr/lib/jvm/java-6-openjdk-amd64/include
147 /usr/lib/jvm/java-6-openjdk-i386/include
148 /usr/include
149 /usr/local/include
150 /usr/lib/java/include
151 /usr/local/lib/java/include
152 /usr/lib/jvm/java/include
153 /usr/lib/jvm/java-6-sun/include
154 /usr/lib/jvm/java-1.5.0-sun/include
155 /usr/lib/jvm/java-6-sun-1.6.0.00/include # can this one be removed according to #8821 ? Alex
156 /usr/lib/jvm/java-6-openjdk/include
157 /usr/local/share/java/include
158 /usr/lib/j2sdk1.4-sun/include
159 /usr/lib/j2sdk1.5-sun/include
160 /opt/sun-jdk-1.5.0.04/include
161 # Debian specific path for default JVM
162 /usr/lib/jvm/default-java/include
163 )
164
165FOREACH(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
166 GET_FILENAME_COMPONENT(jpath "${JAVA_PROG}" PATH)
167 FOREACH(JAVA_INC_PATH ../include ../java/include ../share/java/include)
168 IF(EXISTS ${jpath}/${JAVA_INC_PATH})
169 SET(JAVA_AWT_INCLUDE_DIRECTORIES ${JAVA_AWT_INCLUDE_DIRECTORIES} "${jpath}/${JAVA_INC_PATH}")
170 ENDIF(EXISTS ${jpath}/${JAVA_INC_PATH})
171 ENDFOREACH(JAVA_INC_PATH)
172 FOREACH(JAVA_LIB_PATH
173 ../lib ../jre/lib ../jre/lib/i386
174 ../java/lib ../java/jre/lib ../java/jre/lib/i386
175 ../share/java/lib ../share/java/jre/lib ../share/java/jre/lib/i386)
176 IF(EXISTS ${jpath}/${JAVA_LIB_PATH})
177 SET(JAVA_AWT_LIBRARY_DIRECTORIES ${JAVA_AWT_LIBRARY_DIRECTORIES} "${jpath}/${JAVA_LIB_PATH}")
178 ENDIF(EXISTS ${jpath}/${JAVA_LIB_PATH})
179 ENDFOREACH(JAVA_LIB_PATH)
180ENDFOREACH(JAVA_PROG)
181
182IF(APPLE)
183 IF(EXISTS ~/Library/Frameworks/JavaVM.framework)
184 SET(JAVA_HAVE_FRAMEWORK 1)
185 ENDIF(EXISTS ~/Library/Frameworks/JavaVM.framework)
186 IF(EXISTS /Library/Frameworks/JavaVM.framework)
187 SET(JAVA_HAVE_FRAMEWORK 1)
188 ENDIF(EXISTS /Library/Frameworks/JavaVM.framework)
189 IF(EXISTS /System/Library/Frameworks/JavaVM.framework)
190 SET(JAVA_HAVE_FRAMEWORK 1)
191 ENDIF(EXISTS /System/Library/Frameworks/JavaVM.framework)
192
193 IF(JAVA_HAVE_FRAMEWORK)
194 IF(NOT JAVA_AWT_LIBRARY)
195 SET (JAVA_AWT_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
196 ENDIF(NOT JAVA_AWT_LIBRARY)
197
198 IF(NOT JAVA_JVM_LIBRARY)
199 SET (JAVA_JVM_LIBRARY "-framework JavaVM" CACHE FILEPATH "Java Frameworks" FORCE)
200 ENDIF(NOT JAVA_JVM_LIBRARY)
201
202 IF(NOT JAVA_AWT_INCLUDE_PATH)
203 IF(EXISTS /System/Library/Frameworks/JavaVM.framework/Headers/jawt.h)
204 SET (JAVA_AWT_INCLUDE_PATH "/System/Library/Frameworks/JavaVM.framework/Headers" CACHE FILEPATH "jawt.h location" FORCE)
205 ENDIF(EXISTS /System/Library/Frameworks/JavaVM.framework/Headers/jawt.h)
206 ENDIF(NOT JAVA_AWT_INCLUDE_PATH)
207
208 # If using "-framework JavaVM", prefer its headers *before* the others in
209 # JAVA_AWT_INCLUDE_DIRECTORIES... (*prepend* to the list here)
210 #
211 SET(JAVA_AWT_INCLUDE_DIRECTORIES
212 ~/Library/Frameworks/JavaVM.framework/Headers
213 /Library/Frameworks/JavaVM.framework/Headers
214 /System/Library/Frameworks/JavaVM.framework/Headers
215 ${JAVA_AWT_INCLUDE_DIRECTORIES}
216 )
217 ENDIF(JAVA_HAVE_FRAMEWORK)
218ELSE(APPLE)
219 FIND_LIBRARY(JAVA_AWT_LIBRARY jawt
220 PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES}
221 )
222 FIND_LIBRARY(JAVA_JVM_LIBRARY NAMES jvm JavaVM java
223 PATHS ${JAVA_JVM_LIBRARY_DIRECTORIES}
224 )
225ENDIF(APPLE)
226
227# add in the include path
228FIND_PATH(JAVA_INCLUDE_PATH jni.h
229 ${JAVA_AWT_INCLUDE_DIRECTORIES}
230)
231
232FIND_PATH(JAVA_INCLUDE_PATH2 jni_md.h
233 ${JAVA_INCLUDE_PATH}
234 ${JAVA_INCLUDE_PATH}/win32
235 ${JAVA_INCLUDE_PATH}/linux
236 ${JAVA_INCLUDE_PATH}/freebsd
237 ${JAVA_INCLUDE_PATH}/solaris
238)
239
240FIND_PATH(JAVA_AWT_INCLUDE_PATH jawt.h
241 ${JAVA_INCLUDE_PATH}
242)
243
244
245IF (APPLE)
246 # On Mac, the java headers files are broken symlinks if the Apple Developer Tools for Java are not installed
247 EXECUTE_PROCESS(COMMAND cat ${JAVA_INCLUDE_PATH}/jni.h
248 OUTPUT_QUIET
249 ERROR_QUIET
250 RESULT_VARIABLE SYMLINK_CHECK_RESULT_VARIABLE)
251 IF (SYMLINK_CHECK_RESULT_VARIABLE GREATER 0)
252 SET (JAVA_INCLUDE_PATH "JAVA_INCLUDE_PATH-NOTFOUND")
253 SET (JAVA_INCLUDE_PATH2 "JAVA_INCLUDE_PATH2-NOTFOUND")
254 SET (JAVA_AWT_INCLUDE_PATH "JAVA_AWT_INCLUDE_PATH-NOTFOUND")
255 ENDIF()
256ENDIF (APPLE)
257
258
259#INCLUDE("${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake")
260#FIND_PACKAGE_HANDLE_STANDARD_ARGS(JNI DEFAULT_MSG JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
261# JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
262
263MARK_AS_ADVANCED(
264 JAVA_AWT_LIBRARY
265 JAVA_JVM_LIBRARY
266 JAVA_AWT_INCLUDE_PATH
267 JAVA_INCLUDE_PATH
268 JAVA_INCLUDE_PATH2
269)
270
271IF (JAVA_AWT_LIBRARY AND JAVA_JVM_LIBRARY AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2 AND JAVA_AWT_INCLUDE_PATH)
272 SET(JNI_FOUND 1)
273 SET(JNI_LIBRARIES
274 ${JAVA_AWT_LIBRARY}
275 ${JAVA_JVM_LIBRARY}
276 )
277 SET(JNI_INCLUDE_DIRS
278 ${JAVA_INCLUDE_PATH}
279 ${JAVA_INCLUDE_PATH2}
280 ${JAVA_AWT_INCLUDE_PATH}
281 )
282ELSE (JAVA_AWT_LIBRARY AND JAVA_JVM_LIBRARY AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2 AND JAVA_AWT_INCLUDE_PATH)
283 SET(JNI_FOUND 0)
284 SET(JNI_LIBRARIES "")
285 SET(JNI_INCLUDE_DIRS "")
286ENDIF (JAVA_AWT_LIBRARY AND JAVA_JVM_LIBRARY AND JAVA_INCLUDE_PATH AND JAVA_INCLUDE_PATH2 AND JAVA_AWT_INCLUDE_PATH)
0287
=== added directory 'cmake_modules/Windows'
=== added file 'cmake_modules/Windows/FindJNI.cmake'
--- cmake_modules/Windows/FindJNI.cmake 1970-01-01 00:00:00 +0000
+++ cmake_modules/Windows/FindJNI.cmake 2012-09-28 12:58:20 +0000
@@ -0,0 +1,37 @@
1# Copyright 2010 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# - Try to find the JNI libraries on Windows
16#
17# See the FindJNI.cmake module shipped with Zorba for more information.
18
19FIND_PACKAGE_WIN32_NO_PROXY (JNI JNI_FOUND)
20
21IF (JNI_FOUND)
22
23 STRING (REPLACE "/jvm.lib" "" JAVA_JVM_LIBRARY_PATH "${JAVA_JVM_LIBRARY}")
24
25 IF (EXISTS "${JAVA_JVM_LIBRARY_PATH}/../jre/bin/client")
26 SET (FOUND_LOCATION "${JAVA_JVM_LIBRARY_PATH}/../jre/bin/client")
27 # find the needed DLL's
28 FIND_PACKAGE_DLL_WIN32 (${FOUND_LOCATION} "jvm")
29 ELSEIF (EXISTS "${JAVA_JVM_LIBRARY_PATH}/../jre/bin/server")
30 SET (FOUND_LOCATION "${JAVA_JVM_LIBRARY_PATH}/../jre/bin/server")
31 # find the needed DLL's
32 FIND_PACKAGE_DLL_WIN32 (${FOUND_LOCATION} "jvm")
33 ELSE (EXISTS "${JAVA_JVM_LIBRARY_PATH}/../jre/bin/client")
34 MESSAGE (WARNING "Could not find the jvm.dll for the JVM library: ${JAVA_JVM_LIBRARY}. Please extend this module to find the jvm.dll somewhere in your JVM directory or make sure that jvm.dll is in the PATH.")
35 ENDIF (EXISTS "${JAVA_JVM_LIBRARY_PATH}/../jre/bin/client")
36
37ENDIF (JNI_FOUND)
038
=== added directory 'src'
=== renamed directory 'src' => 'src.moved'
=== added file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/CMakeLists.txt 2012-09-28 12:58:20 +0000
@@ -0,0 +1,20 @@
1# Copyright 2006-2008 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# all external module libraries are generated in the directory
16# of the corresponding .xq file
17MESSAGE(STATUS "Add com")
18ADD_SUBDIRECTORY(com)
19
20MESSAGE(STATUS "End modules")
021
=== added directory 'src/com'
=== added file 'src/com/CMakeLists.txt'
--- src/com/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/com/CMakeLists.txt 2012-09-28 12:58:20 +0000
@@ -0,0 +1,17 @@
1# Copyright 2006-2008 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# all external module libraries are generated in the directory
16# of the corresponding .xq file
17ADD_SUBDIRECTORY(zorba-xquery)
018
=== added directory 'src/com/zorba-xquery'
=== added file 'src/com/zorba-xquery/CMakeLists.txt'
--- src/com/zorba-xquery/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/com/zorba-xquery/CMakeLists.txt 2012-09-28 12:58:20 +0000
@@ -0,0 +1,17 @@
1# Copyright 2006-2008 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# all external module libraries are generated in the directory
16# of the corresponding .xq file
17ADD_SUBDIRECTORY(www)
018
=== added directory 'src/com/zorba-xquery/www'
=== added file 'src/com/zorba-xquery/www/CMakeLists.txt'
--- src/com/zorba-xquery/www/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/com/zorba-xquery/www/CMakeLists.txt 2012-09-28 12:58:20 +0000
@@ -0,0 +1,17 @@
1# Copyright 2006-2008 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# all external module libraries are generated in the directory
16# of the corresponding .xq file
17ADD_SUBDIRECTORY(modules)
018
=== added directory 'src/com/zorba-xquery/www/modules'
=== added file 'src/com/zorba-xquery/www/modules/CMakeLists.txt'
--- src/com/zorba-xquery/www/modules/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/com/zorba-xquery/www/modules/CMakeLists.txt 2012-09-28 12:58:20 +0000
@@ -0,0 +1,105 @@
1# Copyright 2006-2010 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15 IF (NOT DEFINED XSL_FOP_HOME)
16 IF (DEFINED ENV{XSL_FOP_HOME})
17 SET(XSL_FOP_HOME $ENV{XSL_FOP_HOME})
18 ENDIF (DEFINED ENV{XSL_FOP_HOME})
19 ENDIF (NOT DEFINED XSL_FOP_HOME)
20
21 IF (NOT DEFINED XSL_FOP_HOME)
22 IF (WIN32)
23 SET (XSL_FOP_HOME "C:\\dev\\libraries\\fop-1.0 C:\\dev\\libraries\\fop-1.0\\lib C:\\dev\\libraries\\fop-1.0\\build")
24 ELSE (WIN32)
25 SET (XSL_FOP_HOME /usr/share/java/ /usr/share/java/fop/ /opt/local/share/java/fop/1.0 /opt/local/share/java/fop/1.0 ${Java_LIBRARIES})
26 ENDIF (WIN32)
27 MESSAGE (STATUS "XSL_FOP_HOME not defined, trying defaults: ${XSL_FOP_HOME}")
28 ENDIF (NOT DEFINED XSL_FOP_HOME)
29
30 STRING(REGEX REPLACE "\\\\" "/" XSL_FOP_HOME "${XSL_FOP_HOME}")
31
32 MESSAGE (STATUS "XSL-FOP HOME: ${XSL_FOP_HOME}")
33 ZORBA_FIND_JAR ( FOP_JAR NAMES fop
34 PATHS ${XSL_FOP_HOME} PATH_SUFFIXES build)
35 ZORBA_FIND_JAR ( FOP_D1_JAR NAMES avalon-framework
36 PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
37 ZORBA_FIND_JAR ( FOP_D2_JAR NAMES batik-all
38 PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
39 ZORBA_FIND_JAR ( FOP_D3_JAR NAMES commons-io
40 PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
41 ZORBA_FIND_JAR ( FOP_D4_JAR NAMES commons-logging
42 PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
43 ZORBA_FIND_JAR ( FOP_D5_JAR NAMES serializer
44 PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
45 ZORBA_FIND_JAR ( FOP_D6_JAR NAMES xalan xalan2
46 PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
47 ZORBA_FIND_JAR ( FOP_D7_JAR NAMES xmlgraphics-commons
48 PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
49
50 # Multiple "EXISTS" clauses can't be used in a single IF() command;
51 # looks like a bug in cmake.
52 SET(ALL_FOP FALSE)
53 IF ( EXISTS ${FOP_JAR} )
54 IF ( EXISTS ${FOP_D1_JAR} )
55 IF ( EXISTS ${FOP_D2_JAR} )
56 IF ( EXISTS ${FOP_D3_JAR} )
57 IF ( EXISTS ${FOP_D4_JAR} )
58 IF ( EXISTS ${FOP_D5_JAR} )
59 IF ( EXISTS ${FOP_D6_JAR} )
60 IF ( EXISTS ${FOP_D7_JAR} )
61 SET(ALL_FOP TRUE)
62 ENDIF ( EXISTS ${FOP_D7_JAR} )
63 ENDIF ( EXISTS ${FOP_D6_JAR} )
64 ENDIF ( EXISTS ${FOP_D5_JAR} )
65 ENDIF ( EXISTS ${FOP_D4_JAR} )
66 ENDIF ( EXISTS ${FOP_D3_JAR} )
67 ENDIF ( EXISTS ${FOP_D2_JAR} )
68 ENDIF ( EXISTS ${FOP_D1_JAR} )
69 ENDIF ( EXISTS ${FOP_JAR} )
70
71 IF ( ALL_FOP )
72 MESSAGE(STATUS "FOP Libraries Found.")
73 INCLUDE (CMakeJavaInformation )
74 EXECUTE_PROCESS (
75 COMMAND ${JAVA_RUNTIME} -version
76 RESULT_VARIABLE JAVA_VERSION
77 OUTPUT_QUIET
78 ERROR_QUIET
79 )
80
81 INCLUDE_DIRECTORIES (${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PATH2})
82 INCLUDE_DIRECTORIES (${JAVA_INCLUDE_PATH})
83 DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/xsl-fo"
84 VERSION 1.0 FILE "xsl-fo.xq"
85 LINK_LIBRARIES "${JAVA_JVM_LIBRARY}" ${zorba_util-jvm_module_LIBRARIES})
86
87 DECLARE_ZORBA_JAR(FILE ${FOP_JAR} EXTERNAL)
88 DECLARE_ZORBA_JAR(FILE ${FOP_D1_JAR} EXTERNAL)
89 DECLARE_ZORBA_JAR(FILE ${FOP_D2_JAR} EXTERNAL)
90 DECLARE_ZORBA_JAR(FILE ${FOP_D3_JAR} EXTERNAL)
91 DECLARE_ZORBA_JAR(FILE ${FOP_D4_JAR} EXTERNAL)
92 DECLARE_ZORBA_JAR(FILE ${FOP_D5_JAR} EXTERNAL)
93 DECLARE_ZORBA_JAR(FILE ${FOP_D6_JAR} EXTERNAL)
94 DECLARE_ZORBA_JAR(FILE ${FOP_D7_JAR} EXTERNAL)
95
96 ADD_TEST_DIRECTORY("${PROJECT_SOURCE_DIR}/test")
97
98 ELSE ( ALL_FOP )
99 MESSAGE (STATUS "fop.jar and/or all its dependecies (avalon-framework.jar, batik-all.jar, commons-io.jar, commons-logging.jar, serializer.jar, xalan2.jar, xmlgraphics-commons.jar) not found skiping data-formating module")
100 MESSAGE ( STATUS " fop: " ${FOP_JAR} "\n avalon: " ${FOP_D1_JAR}
101 "\n batik: " ${FOP_D2_JAR} "\n io: " ${FOP_D3_JAR}
102 "\n logging: " ${FOP_D4_JAR} "\n serializer: " ${FOP_D5_JAR} " "
103 "\n xalan: " ${FOP_D6_JAR} "\n xmlgraphics: " ${FOP_D7_JAR} )
104 ENDIF ( ALL_FOP )
105
0106
=== added file 'src/com/zorba-xquery/www/modules/xsl-fo.xq'
--- src/com/zorba-xquery/www/modules/xsl-fo.xq 1970-01-01 00:00:00 +0000
+++ src/com/zorba-xquery/www/modules/xsl-fo.xq 2012-09-28 12:58:20 +0000
@@ -0,0 +1,161 @@
1xquery version "3.0";
2
3(:
4 : Copyright 2006-2009 The FLWOR Foundation.
5 :
6 : Licensed under the Apache License, Version 2.0 (the "License");
7 : you may not use this file except in compliance with the License.
8 : 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:)
18(:~
19 :
20 : This module converts <a href="http://www.w3schools.com/xslfo/default.asp">XSL-FO</a> documents
21 : to various formats such as PDF, EPS, PCL, AFP, Text, PNG, Postscript, RTF, and TIFF.
22 : For instance, the following example converts a simple XSL-FO document to PDF:
23 : <br />
24 : <pre class="ace-static" ace-mode="xquery"><![CDATA[import module namespace fop = "http://www.zorba-xquery.com/modules/xsl-fo";
25 : import module namespace file = "http://expath.org/ns/file";
26 :
27 : declare namespace fo = "http://www.w3.org/1999/XSL/Format";
28 :
29 : let $xsl-fo := <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
30 : <fo:layout-master-set>
31 : <fo:simple-page-master master-name="my-page">
32 : <fo:region-body margin="1in"/>
33 : </fo:simple-page-master>
34 : </fo:layout-master-set>
35 :
36 : <fo:page-sequence master-reference="my-page">
37 : <fo:flow flow-name="xsl-region-body">
38 : <fo:block>Hello, world!</fo:block>
39 : </fo:flow>
40 : </fo:page-sequence>
41 : </fo:root>
42 : let $pdf := fop:generator($fop:PDF, $xsl-fo)
43 : return file:write-binary("simple.pdf", $pdf)]]></pre>
44 : <br />
45 : This module uses Apache-FOP to generate content from an XSL-FO document.
46 : See <a href="http://xmlgraphics.apache.org/fop/">the Apache FOP documentation</a> for further information.
47 : <br />
48 : <br />
49 : <b>Note for Windows users</b>: On Windows, this module won't work out of the box, since
50 : this module uses Java. But the Java VM dll is not in the system path by default. To make
51 : this module work, you need to add the directory where the jvm.dll is located to the
52 : system path. This dll is located at JRE_DIR\bin\client. On a standard installation, this would
53 : be something a path like "C:\Program Files\Java\jre6\bin\client".
54 :
55 : @author Markus Pilman
56 : @see http://xmlgraphics.apache.org/fop/
57 : @library <a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">JDK - Java Development Kit</a>
58 : @project Zorba/Data Formatting/XSL-FO
59 :)
60module namespace xsl-fo = "http://www.zorba-xquery.com/modules/xsl-fo";
61
62import module namespace util-jvm = "http://www.zorba-xquery.com/modules/util-jvm";
63
64declare namespace err = "http://www.w3.org/2005/xqt-errors";
65
66declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
67declare option ver:module-version "1.0";
68
69(:~
70 : The mime type of IBMs AFP format (application/x-afp).
71 :)
72declare variable $xsl-fo:AFP as xs:string := "application/x-afp";
73(:~
74 : The mime type of the EPS format (application/postscript).
75 :)
76declare variable $xsl-fo:EPS as xs:string := "application/postscript";
77(:~
78 : The mime type of the PCL format (application/x-pcl).
79 :)
80declare variable $xsl-fo:PCL as xs:string := "application/x-pcl";
81(:~
82 : The mime type of the PDF format (application/pdf).
83 :)
84declare variable $xsl-fo:PDF as xs:string := "application/pdf";
85(:~
86 : The mime type for plain text files (text/plain).
87 :)
88declare variable $xsl-fo:PLAIN_TEXT as xs:string := "text/plain";
89(:~
90 : The mime type of the PNG format (image/png).
91 :)
92declare variable $xsl-fo:PNG as xs:string := "image/png";
93(:~
94 : The mime type of the postscript format (application/postscript).
95 :)
96declare variable $xsl-fo:POSTSCRIPT as xs:string := "application/postscript";
97(:~
98 : The mime type of the RTF format (application/rtf).
99 :)
100declare variable $xsl-fo:RTF as xs:string := "application/rtf";
101(:~
102 : The mime type of TIFF format (application/tiff).
103 :)
104declare variable $xsl-fo:TIFF as xs:string := "image/tiff";
105
106(:~
107 : Deprecated. This function has been deprecated, the JVM and it's classpath is handled diffrently.<br/>
108 : The generator function takes an XSL-FO document as input and generates output in the format given as input.
109 : The output format can be given as a MIME type - for example "application/pdf" - or one of the predefined
110 : variables can be used - like $xsl-fo:PDF. Please refer to the Apache FOP documentation for
111 : <a href="http://xmlgraphics.apache.org/fop/0.95/output.html">supported output formats</a>.
112 :
113 : Apache FOP does not support 100% of the XSL-FO standard.
114 : Please consult the <a href="http://xmlgraphics.apache.org/fop/">official documentation for further information</a>.
115 :
116 : @param $output-format The mime of the output format.
117 : @param $xsl-fo-document The XSL-FO document from which the output should be generated. <a href="http://www.w3schools.com/xslfo/xslfo_intro.asp">More information about XSL-FO documents.</a>.
118 : @param $classpath This parameter is not used, hence the deprecation of this function.
119 : @return The generated output document.
120 : @error xsl-fo:VM001 If zorba was unable to start the JVM.
121 : @error xsl-fo:JAVA-EXCEPTION If Apache FOP throws an exception - i.e. if the input format is not correct/supported.
122 : @deprecated
123 :)
124declare function xsl-fo:generator($output-format as xs:string, $xsl-fo-document as node(), $classpath as xs:string+) as xs:base64Binary {
125 xsl-fo:generator-impl($output-format, $xsl-fo-document)
126};
127
128(:~
129 : The function behaves like <a href="#generator#3">generator#3</a>, but tries to find the needed Java libraries itself.
130 : <br />
131 : On a Mac OS X computer, it should be sufficient to install Apache FOP via Mac Ports.<br />
132 : On Ubuntu it should be sufficient to install the fop packages via apt-get.<br />
133 : On Windows, the classpath needs to be set manually using <a href="#generator#3">generator#3</a>.
134 : <br />
135 : This function tries to find the jar files via environment variables. The user can set the
136 : variable FOP_HOME to the root directory of an Apache FOP distribution. If you have all
137 : JAR files in the same directory, you can set the environment variable FOP_LIB_DIR to this
138 : directory.
139 :
140 : @param $output-format The mime of the output format, to tell Apache FOP which kind of document it should
141 : create.
142 : @param $xsl-fo-document The XSL-FO document from which the output should be generated.
143 : @return The generated output document.
144 : @error xsl-fo:VM001 If zorba was unable to start the JVM.
145 : @error xsl-fo:JAVA-EXCEPTION If Apache FOP throws an exception - i.e. if the input format is not correct/supported.
146 : @error xsl-fo:JAR-NOT-FOUND If a needed Java library could not be found.
147 :)
148declare function xsl-fo:generator($output-format as xs:string, $xsl-fo-document as node()) as xs:base64Binary {
149 xsl-fo:generator-impl($output-format, $xsl-fo-document)
150};
151
152
153(:~
154 : Internal function used to format XSL-FO documents.
155 :
156 : @param $output-format The mime type of the output format.
157 : @param $xsl-fo-document The XSL-FO representation of the document.
158 : @return The base64Binary Representation of document.
159 :)
160declare %private function xsl-fo:generator-impl($output-format as xs:string, $xsl-fo-document as node()) as xs:base64Binary external;
161
0162
=== added directory 'src/com/zorba-xquery/www/modules/xsl-fo.xq.src'
=== added file 'src/com/zorba-xquery/www/modules/xsl-fo.xq.src/xslfo.cpp'
--- src/com/zorba-xquery/www/modules/xsl-fo.xq.src/xslfo.cpp 1970-01-01 00:00:00 +0000
+++ src/com/zorba-xquery/www/modules/xsl-fo.xq.src/xslfo.cpp 2012-09-28 12:58:20 +0000
@@ -0,0 +1,280 @@
1/*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * 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 */
16#include <sstream>
17#include <iostream>
18#include <cstdlib>
19#include <list>
20
21#include <zorba/base64.h>
22#include <zorba/empty_sequence.h>
23#include <zorba/diagnostic_list.h>
24#include <zorba/function.h>
25#include <zorba/external_module.h>
26#include <zorba/user_exception.h>
27#include <zorba/file.h>
28#include <zorba/item_factory.h>
29#include <zorba/serializer.h>
30#include <zorba/singleton_item_sequence.h>
31#include <zorba/vector_item_sequence.h>
32#include <zorba/zorba.h>
33
34#include "JavaVMSingleton.h"
35
36#define XSL_MODULE_NAMESPACE "http://www.zorba-xquery.com/modules/xsl-fo"
37
38class JavaException {
39};
40
41#define CHECK_EXCEPTION(env) if ((lException = env->ExceptionOccurred())) throw JavaException()
42
43namespace zorba { namespace xslfo {
44
45class GeneratePDFFunction : public ContextualExternalFunction {
46 private:
47 const ExternalModule* theModule;
48 ItemFactory* theFactory;
49 public:
50 GeneratePDFFunction(const ExternalModule* aModule) :
51 theModule(aModule), theFactory(Zorba::getInstance(0)->getItemFactory()) {}
52 ~GeneratePDFFunction() {}
53
54 public:
55 virtual String getURI() const { return theModule->getURI(); }
56
57 virtual String getLocalName() const { return "generator-impl"; }
58
59 virtual ItemSequence_t
60 evaluate(const ExternalFunction::Arguments_t& args,
61 const zorba::StaticContext*,
62 const zorba::DynamicContext*) const;
63};
64
65class XSLFOModule : public ExternalModule {
66 private:
67 ExternalFunction* generatePDF;
68 public:
69 XSLFOModule() :
70 generatePDF(new GeneratePDFFunction(this))
71 {}
72 ~XSLFOModule() {
73 delete generatePDF;
74 }
75
76 virtual String getURI() const { return XSL_MODULE_NAMESPACE; }
77
78 virtual ExternalFunction* getExternalFunction(const String& localName);
79
80 virtual void destroy() {
81 delete this;
82 }
83};
84
85ExternalFunction* XSLFOModule::getExternalFunction(const String& localName) {
86 if (localName == "generator-impl") {
87 return generatePDF;
88 }
89 return 0;
90}
91
92ItemSequence_t
93GeneratePDFFunction::evaluate(const ExternalFunction::Arguments_t& args,
94 const zorba::StaticContext* aStaticContext,
95 const zorba::DynamicContext* aDynamincContext) const
96{
97 Iterator_t lIter = args[0]->getIterator();
98 lIter->open();
99 Item outputFormat;
100 lIter->next(outputFormat);
101 lIter->close();
102 jthrowable lException = 0;
103 static JNIEnv* env;
104 try {
105 env = zorba::jvm::JavaVMSingleton::getInstance(aStaticContext)->getEnv();
106 jstring outFotmatString = env->NewStringUTF(outputFormat.getStringValue().c_str());
107 // Local variables
108 std::ostringstream os;
109 Zorba_SerializerOptions_t lOptions;
110 Serializer_t lSerializer = Serializer::createSerializer(lOptions);
111 jclass fopFactoryClass;
112 jobject fopFactory;
113 jmethodID fopFactoryNewInstance;
114 jclass byteArrayOutputStreamClass;
115 jobject byteArrayOutputStream;
116 jobject fop;
117 jmethodID newFop;
118 jclass transformerFactoryClass;
119 jobject transformerFactory;
120 jobject transormer;
121 jclass stringReaderClass;
122 jobject stringReader;
123 jstring xmlUTF;
124 const char* xml;
125 std::string xmlString;
126 jclass streamSourceClass;
127 jobject streamSource;
128 jobject defaultHandler;
129 jclass saxResultClass;
130 jobject saxResult;
131 jboolean isCopy;
132 jbyteArray res;
133 Item base64;
134 String resStore;
135 jsize dataSize;
136 jbyte* dataElements;
137
138 Item item;
139 lIter = args[1]->getIterator();
140 lIter->open();
141 lIter->next(item);
142 lIter->close();
143 // Searialize Item
144 SingletonItemSequence lSequence(item);
145 lSerializer->serialize(&lSequence, os);
146 xmlString = os.str();
147 xml = xmlString.c_str();
148
149 // Create an OutputStream
150 byteArrayOutputStreamClass = env->FindClass("java/io/ByteArrayOutputStream");
151 CHECK_EXCEPTION(env);
152 byteArrayOutputStream = env->NewObject(byteArrayOutputStreamClass,
153 env->GetMethodID(byteArrayOutputStreamClass, "<init>", "()V"));
154 CHECK_EXCEPTION(env);
155
156 // Create a FopFactory instance
157 fopFactoryClass = env->FindClass("org/apache/fop/apps/FopFactory");
158 CHECK_EXCEPTION(env);
159 fopFactoryNewInstance = env->GetStaticMethodID(fopFactoryClass, "newInstance", "()Lorg/apache/fop/apps/FopFactory;");
160 CHECK_EXCEPTION(env);
161 fopFactory = env->CallStaticObjectMethod(fopFactoryClass, fopFactoryNewInstance);
162 CHECK_EXCEPTION(env);
163
164 // Create the Fop
165 newFop = env->GetMethodID(fopFactoryClass, "newFop", "(Ljava/lang/String;Ljava/io/OutputStream;)Lorg/apache/fop/apps/Fop;");
166 CHECK_EXCEPTION(env);
167 fop = env->CallObjectMethod(fopFactory,
168 newFop,
169 outFotmatString, byteArrayOutputStream);
170 CHECK_EXCEPTION(env);
171
172 // Create the Transformer
173 transformerFactoryClass = env->FindClass("javax/xml/transform/TransformerFactory");
174 CHECK_EXCEPTION(env);
175 transformerFactory = env->CallStaticObjectMethod(transformerFactoryClass,
176 env->GetStaticMethodID(transformerFactoryClass, "newInstance", "()Ljavax/xml/transform/TransformerFactory;"));
177 CHECK_EXCEPTION(env);
178 transormer = env->CallObjectMethod(transformerFactory,
179 env->GetMethodID(transformerFactoryClass, "newTransformer", "()Ljavax/xml/transform/Transformer;"));
180 CHECK_EXCEPTION(env);
181
182 // Create Source
183 xmlUTF = env->NewStringUTF(xml);
184 stringReaderClass = env->FindClass("java/io/StringReader");
185 CHECK_EXCEPTION(env);
186 stringReader = env->NewObject(stringReaderClass,
187 env->GetMethodID(stringReaderClass, "<init>", "(Ljava/lang/String;)V"), xmlUTF);
188 CHECK_EXCEPTION(env);
189 streamSourceClass = env->FindClass("javax/xml/transform/stream/StreamSource");
190 CHECK_EXCEPTION(env);
191 streamSource = env->NewObject(streamSourceClass,
192 env->GetMethodID(streamSourceClass, "<init>", "(Ljava/io/Reader;)V"), stringReader);
193 CHECK_EXCEPTION(env);
194
195 // Create the SAXResult
196 defaultHandler = env->CallObjectMethod(fop,
197 env->GetMethodID(env->FindClass("org/apache/fop/apps/Fop"), "getDefaultHandler",
198 "()Lorg/xml/sax/helpers/DefaultHandler;"));
199 CHECK_EXCEPTION(env);
200 saxResultClass = env->FindClass("javax/xml/transform/sax/SAXResult");
201 CHECK_EXCEPTION(env);
202 saxResult = env->NewObject(saxResultClass,
203 env->GetMethodID(saxResultClass, "<init>", "(Lorg/xml/sax/ContentHandler;)V"),
204 defaultHandler);
205 CHECK_EXCEPTION(env);
206
207 // Transform
208 env->CallObjectMethod(transormer,
209 env->GetMethodID(env->FindClass("javax/xml/transform/Transformer"),
210 "transform",
211 "(Ljavax/xml/transform/Source;Ljavax/xml/transform/Result;)V"),
212 streamSource, saxResult);
213 CHECK_EXCEPTION(env);
214
215 // Close outputstream
216 env->CallObjectMethod(byteArrayOutputStream,
217 env->GetMethodID(env->FindClass("java/io/OutputStream"),
218 "close", "()V"));
219 CHECK_EXCEPTION(env);
220 saxResultClass = env->FindClass("javax/xml/transform/sax/SAXResult");
221 CHECK_EXCEPTION(env);
222
223 // Get the byte array
224 res = (jbyteArray) env->CallObjectMethod(byteArrayOutputStream,
225 env->GetMethodID(byteArrayOutputStreamClass, "toByteArray", "()[B"));
226 CHECK_EXCEPTION(env);
227
228 // Create the result
229 dataSize = env->GetArrayLength(res);
230 dataElements = env->GetByteArrayElements(res, &isCopy);
231
232 std::string lBinaryString((const char*) dataElements, dataSize);
233 std::stringstream lStream(lBinaryString);
234 String base64S = encoding::Base64::encode(lStream);
235 Item lRes = theFactory->createBase64Binary(base64S.c_str(), base64S.length());
236 return ItemSequence_t(new SingletonItemSequence(lRes));
237 } catch (zorba::jvm::VMOpenException&) {
238 Item lQName = theFactory->createQName("http://www.zorba-xquery.com/modules/xsl-fo",
239 "VM001");
240 throw USER_EXCEPTION(lQName, "Could not start the Java VM (is the classpath set?)");
241 } catch (JavaException&) {
242 jclass stringWriterClass = env->FindClass("java/io/StringWriter");
243 jclass printWriterClass = env->FindClass("java/io/PrintWriter");
244 jclass throwableClass = env->FindClass("java/lang/Throwable");
245 jobject stringWriter = env->NewObject(
246 stringWriterClass,
247 env->GetMethodID(stringWriterClass, "<init>", "()V"));
248 jobject printWriter = env->NewObject(
249 printWriterClass, env->GetMethodID(printWriterClass, "<init>", "(Ljava/io/Writer;)V"), stringWriter);
250 env->CallObjectMethod(lException, env->GetMethodID(throwableClass, "printStackTrace", "(Ljava/io/PrintWriter;)V"), printWriter);
251 //env->CallObjectMethod(printWriter, env->GetMethodID(printWriterClass, "flush", "()V"));
252 jmethodID toStringMethod = env->GetMethodID(stringWriterClass, "toString", "()Ljava/lang/String;");
253 jobject errorMessageObj = env->CallObjectMethod(
254 stringWriter, toStringMethod);
255 jstring errorMessage = (jstring) errorMessageObj;
256 const char *errMsg = env->GetStringUTFChars(errorMessage, 0);
257 std::stringstream s;
258 s << "A Java Exception was thrown:" << std::endl << errMsg;
259 env->ReleaseStringUTFChars(errorMessage, errMsg);
260 std::string err("");
261 err += s.str();
262 env->ExceptionClear();
263 Item lQName = theFactory->createQName("http://www.zorba-xquery.com/modules/xsl-fo",
264 "JAVA-EXCEPTION");
265 throw USER_EXCEPTION(lQName, err);
266 }
267 return ItemSequence_t(new EmptySequence());
268}
269
270}}; // namespace zorba, xslfo
271
272#ifdef WIN32
273# define DLL_EXPORT __declspec(dllexport)
274#else
275# define DLL_EXPORT __attribute__ ((visibility("default")))
276#endif
277
278extern "C" DLL_EXPORT zorba::ExternalModule* createModule() {
279 return new zorba::xslfo::XSLFOModule();
280}
0281
=== added directory 'test'
=== renamed directory 'test' => 'test.moved'
=== added directory 'test/ExpQueryResults'
=== added directory 'test/ExpQueryResults/data-formatting'
=== added file 'test/ExpQueryResults/data-formatting/xslfo.xml.res'
--- test/ExpQueryResults/data-formatting/xslfo.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/data-formatting/xslfo.xml.res 2012-09-28 12:58:20 +0000
@@ -0,0 +1,1 @@
1<pdf><len>true</len><start>JVBERi0xLj</start></pdf>
02
=== added directory 'test/Queries'
=== added directory 'test/Queries/data-formatting'
=== added file 'test/Queries/data-formatting/xslfo.xq'
--- test/Queries/data-formatting/xslfo.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/data-formatting/xslfo.xq 2012-09-28 12:58:20 +0000
@@ -0,0 +1,26 @@
1import module namespace fop = "http://www.zorba-xquery.com/modules/xsl-fo";
2import module namespace file = "http://expath.org/ns/file";
3
4declare namespace fo = "http://www.w3.org/1999/XSL/Format";
5
6let $xsl-fo := <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
7 <fo:layout-master-set>
8 <fo:simple-page-master master-name="my-page">
9 <fo:region-body margin="1in"/>
10 </fo:simple-page-master>
11 </fo:layout-master-set>
12
13 <fo:page-sequence master-reference="my-page">
14 <fo:flow flow-name="xsl-region-body">
15 <fo:block>Hello, world!</fo:block>
16 </fo:flow>
17 </fo:page-sequence>
18 </fo:root>
19let $pdfBase64Binary := fop:generator($fop:PDF, $xsl-fo)
20let $pdf := xs:string($pdfBase64Binary)
21let $len := fn:string-length($pdf)
22return
23 <pdf>
24 <len> { $len gt 6000 }</len>
25 <start>{ fn:substring($pdf, 1, 10)}</start>
26 </pdf>

Subscribers

People subscribed via source and target branches

to all changes: