Merge lp:~zorba-coders/zorba/dataf-module-fix into lp:zorba/data-formatting-module

Proposed by Matthias Brantner
Status: Merged
Approved by: Matthias Brantner
Approved revision: 39
Merged at revision: 34
Proposed branch: lp:~zorba-coders/zorba/dataf-module-fix
Merge into: lp:zorba/data-formatting-module
Diff against target: 317 lines (+33/-192)
5 files modified
CMakeLists.txt (+2/-0)
src/com/zorba-xquery/www/modules/CMakeLists.txt (+27/-27)
src/com/zorba-xquery/www/modules/xsl-fo.xq.src/xslfo.cpp (+2/-162)
test/ExpQueryResults/data-formatting/xslfo.xml.res (+1/-1)
test/Queries/data-formatting/xslfo.xq (+1/-2)
To merge this branch: bzr merge lp:~zorba-coders/zorba/dataf-module-fix
Reviewer Review Type Date Requested Status
Cezar Andrei Approve
Matthias Brantner Approve
Review via email: mp+105267@code.launchpad.net

Commit message

- improved search of dependent jars
- removed dead code

Description of the change

- improved search of dependent jars
- removed dead code

To post a comment you must log in.
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Cezar Andrei (cezar-andrei) wrote :

Looks good.

review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job dataf-module-fix-2012-05-09T20-55-39.218Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2012-04-30 09:55:44 +0000
3+++ CMakeLists.txt 2012-05-09 20:55:19 +0000
4@@ -25,6 +25,8 @@
5 FIND_PACKAGE (zorba_util-jvm_module QUIET)
6
7 IF (zorba_util-jvm_module_FOUND)
8+ INCLUDE ("${zorba_util-jvm_module_USE_FILE}")
9+
10 IF (JNI_FOUND)
11 INCLUDE_DIRECTORIES (${zorba_util-jvm_module_INCLUDE_DIRS})
12
13
14=== modified file 'src/com/zorba-xquery/www/modules/CMakeLists.txt'
15--- src/com/zorba-xquery/www/modules/CMakeLists.txt 2012-04-11 16:06:04 +0000
16+++ src/com/zorba-xquery/www/modules/CMakeLists.txt 2012-05-09 20:55:19 +0000
17@@ -12,9 +12,6 @@
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
20
21-
22-
23-
24 IF (NOT DEFINED XSL_FOP_HOME)
25 IF (DEFINED ENV{XSL_FOP_HOME})
26 SET(XSL_FOP_HOME $ENV{XSL_FOP_HOME})
27@@ -23,35 +20,35 @@
28
29 IF (NOT DEFINED XSL_FOP_HOME)
30 IF (WIN32)
31- MESSAGE (STATUS "Environment variable XSL_FOP_HOME not defined, trying default: C:\\dev\\libraries\\fop-1.0")
32- SET (XSL_FOP_HOME "C:\\dev\\libraries\\fop-1.0")
33+ SET (XSL_FOP_HOME "C:\\dev\\libraries\\fop-1.0 C:\\dev\\libraries\\fop-1.0\\lib C:\\dev\\libraries\\fop-1.0\\build")
34 ELSE (WIN32)
35- MESSAGE (STATUS "Environment variable XSL_FOP_HOME not defined, trying defaults: " ${Java_LIBRARIES} " /usr/share/java/ /usr/share/java/fop/")
36- SET (XSL_FOP_HOME "/usr/share/java/ /usr/share/java/fop/ ${Java_LIBRARIES}")
37+ 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})
38 ENDIF (WIN32)
39+ MESSAGE (STATUS "XSL_FOP_HOME not defined, trying defaults: ${XSL_FOP_HOME}")
40 ENDIF (NOT DEFINED XSL_FOP_HOME)
41
42 STRING(REGEX REPLACE "\\\\" "/" XSL_FOP_HOME "${XSL_FOP_HOME}")
43
44- MESSAGE (STATUS "XSL-FOP HOME: " ${XSL_FOP_HOME} )
45- FIND_FILE( FOP_JAR NAMES fop.jar
46- PATHS ${XSL_FOP_HOME} ${XSL_FOP_HOME}/build )
47- FIND_FILE( FOP_D1_JAR NAMES avalon-framework.jar
48- PATHS ${XSL_FOP_HOME} ${XSL_FOP_HOME}/lib )
49- FIND_FILE( FOP_D2_JAR NAMES batik-all.jar
50- PATHS ${XSL_FOP_HOME} ${XSL_FOP_HOME}/lib )
51- FIND_FILE( FOP_D3_JAR NAMES commons-io.jar
52- PATHS ${XSL_FOP_HOME} ${XSL_FOP_HOME}/lib )
53- FIND_FILE( FOP_D4_JAR NAMES commons-logging.jar
54- PATHS ${XSL_FOP_HOME} ${XSL_FOP_HOME}/lib )
55- FIND_FILE( FOP_D5_JAR NAMES serializer.jar
56- PATHS ${XSL_FOP_HOME} ${XSL_FOP_HOME}/lib )
57- FIND_FILE( FOP_D6_JAR NAMES xalan.jar xalan2.jar
58- PATHS ${XSL_FOP_HOME} ${XSL_FOP_HOME}/lib )
59- FIND_FILE( FOP_D7_JAR NAMES xmlgraphics-commons.jar
60- PATHS ${XSL_FOP_HOME} ${XSL_FOP_HOME}/lib )
61+ MESSAGE (STATUS "XSL-FOP HOME: ${XSL_FOP_HOME}")
62+ ZORBA_FIND_JAR ( FOP_JAR NAMES fop
63+ PATHS ${XSL_FOP_HOME} PATH_SUFFIXES build)
64+ ZORBA_FIND_JAR ( FOP_D1_JAR NAMES avalon-framework
65+ PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
66+ ZORBA_FIND_JAR ( FOP_D2_JAR NAMES batik-all
67+ PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
68+ ZORBA_FIND_JAR ( FOP_D3_JAR NAMES commons-io
69+ PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
70+ ZORBA_FIND_JAR ( FOP_D4_JAR NAMES commons-logging
71+ PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
72+ ZORBA_FIND_JAR ( FOP_D5_JAR NAMES serializer
73+ PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
74+ ZORBA_FIND_JAR ( FOP_D6_JAR NAMES xalan xalan2
75+ PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
76+ ZORBA_FIND_JAR ( FOP_D7_JAR NAMES xmlgraphics-commons
77+ PATHS ${XSL_FOP_HOME} PATH_SUFFIXES lib )
78
79- #MULTIPLE EXISTS CAN'T BE USED IN AN *IF* COMMAND, LOOKS LIKE A BUG ON CMAKE
80+ # Multiple "EXISTS" clauses can't be used in a single IF() command;
81+ # looks like a bug in cmake.
82 SET(ALL_FOP FALSE)
83 IF ( EXISTS ${FOP_JAR} )
84 IF ( EXISTS ${FOP_D1_JAR} )
85@@ -70,8 +67,7 @@
86 ENDIF ( EXISTS ${FOP_D2_JAR} )
87 ENDIF ( EXISTS ${FOP_D1_JAR} )
88 ENDIF ( EXISTS ${FOP_JAR} )
89- MESSAGE(STATUS "ALL_FOP:" ${ALL_FOP})
90-
91+
92 IF ( ALL_FOP )
93 MESSAGE(STATUS "FOP Libraries Found.")
94 INCLUDE (CMakeJavaInformation )
95@@ -101,5 +97,9 @@
96
97 ELSE ( ALL_FOP )
98 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")
99+ MESSAGE ( STATUS " fop: " ${FOP_JAR} "\n avalon: " ${FOP_D1_JAR}
100+ "\n batik: " ${FOP_D2_JAR} "\n io: " ${FOP_D3_JAR}
101+ "\n logging: " ${FOP_D4_JAR} "\n serializer: " ${FOP_D5_JAR} " "
102+ "\n xalan: " ${FOP_D6_JAR} "\n xmlgraphics: " ${FOP_D7_JAR} )
103 ENDIF ( ALL_FOP )
104
105
106=== modified file 'src/com/zorba-xquery/www/modules/xsl-fo.xq.src/xslfo.cpp'
107--- src/com/zorba-xquery/www/modules/xsl-fo.xq.src/xslfo.cpp 2012-04-11 13:45:56 +0000
108+++ src/com/zorba-xquery/www/modules/xsl-fo.xq.src/xslfo.cpp 2012-05-09 20:55:19 +0000
109@@ -62,36 +62,15 @@
110 const zorba::DynamicContext*) const;
111 };
112
113-class FindApacheFopFunction : public NonContextualExternalFunction {
114- private:
115- const ExternalModule* theModule;
116- ItemFactory* theFactory;
117- private:
118- void throwError(std::string aName) const;
119- public:
120- FindApacheFopFunction(const ExternalModule* aModule) :
121- theModule(aModule), theFactory(Zorba::getInstance(0)->getItemFactory()) {}
122-
123- virtual String getURI() const { return theModule->getURI(); }
124-
125- virtual String getLocalName() const { return "find-apache-fop"; }
126-
127- virtual ItemSequence_t
128- evaluate(const ExternalFunction::Arguments_t& args) const;
129-};
130-
131 class XSLFOModule : public ExternalModule {
132 private:
133 ExternalFunction* generatePDF;
134- ExternalFunction* findFop;
135 public:
136 XSLFOModule() :
137- generatePDF(new GeneratePDFFunction(this)),
138- findFop(new FindApacheFopFunction(this))
139+ generatePDF(new GeneratePDFFunction(this))
140 {}
141 ~XSLFOModule() {
142 delete generatePDF;
143- delete findFop;
144 }
145
146 virtual String getURI() const { return XSL_MODULE_NAMESPACE; }
147@@ -106,149 +85,10 @@
148 ExternalFunction* XSLFOModule::getExternalFunction(const String& localName) {
149 if (localName == "generator-impl") {
150 return generatePDF;
151- } else if (localName == "find-apache-fop") {
152- return findFop;
153- }
154+ }
155 return 0;
156 }
157
158-void FindApacheFopFunction::throwError(std::string aName) const {
159- Item lQName = theFactory->createQName("http://www.zorba-xquery.com/modules/xsl-fo",
160- "JAR-NOT-FOUND");
161- throw USER_EXCEPTION(lQName, aName);
162-}
163-
164-ItemSequence_t FindApacheFopFunction::evaluate(const ExternalFunction::Arguments_t& args) const
165-{
166- std::string lDirectorySeparator(File::getDirectorySeparator());
167- std::string lFopHome;
168- {
169- char* lFopHomeEnv = getenv("FOP_HOME");
170- if (lFopHomeEnv != 0) {
171- lFopHome = lFopHomeEnv;
172- }
173-#ifdef APPLE
174- else {
175- // If Apache FOP is installed with Mac Ports, FOP
176- // is typicaly installed in /opt/local/share/java/fop,
177- // so we check here, if the installation directory can
178- // be found in this directory.
179- std::string lFopPath("/opt/local/share/java/fop/");
180- File_t lRootDir = File::createFile(lFopPath);
181- if (lRootDir->exists() && lRootDir->isDirectory()) {
182- DirectoryIterator_t lFiles = lRootDir->files();
183- std::string lFileName;
184- // The FOP directory is in a subdirectory with the version
185- // number - so we check all subdirectories to get the final
186- // path.
187- while (lFiles->next(lFileName)) {
188- File_t lFile = File::createFile(lFopPath + lFileName);
189- if (lFile->isDirectory()) {
190- std::stringstream lStr(lFileName);
191- double lDirDouble = 0.0;
192- if (lStr >> lDirDouble) {
193- if (lDirDouble != 0.0) {
194- lFopHome = lFopPath + lFileName;
195- break;
196- }
197- }
198- }
199- }
200- }
201- }
202-#endif
203- }
204- std::string lFopLibDir;
205- {
206- char* lEnv = getenv("FOP_LIB_DIR");
207- if (lEnv != 0) {
208- lFopLibDir = lEnv;
209- }
210-#ifdef LINUX
211- // on a Ubuntu installation, all required
212- // jar files should be in /usr/share/java
213- // if Apache FOP is installed.
214- else {
215- lFopLibDir = "/usr/share/java";
216- }
217-#endif
218- }
219- // If neither a path to the fop install dir, nor a path
220- // to the jar files was found so far, we throw an exception.
221- if (lFopHome == "" && lFopLibDir == "") {
222- throwError("None of the environment variables FOP_HOME and FOP_LIB_DIR have been set.");
223- }
224- std::string lFopJarFile;
225- {
226- // Here we look for the fop.jar file, which should be either in $FOP_HOME/build or
227- // in the directory, where all jar files are.
228- lFopJarFile = lFopHome + lDirectorySeparator + "build" + lDirectorySeparator + "fop.jar";
229- std::string lFopJarFile1 = lFopJarFile;
230- File_t lJarFile = File::createFile(lFopJarFile);
231- if (!lJarFile->exists()) {
232- lFopJarFile = lFopLibDir + lDirectorySeparator + "fop.jar";
233- lJarFile = File::createFile(lFopJarFile);
234- if (!lJarFile->exists()) {
235- std::string errmsg = "Could not find fop.jar. If you are using Ubuntu or Mac OS X, please make sure, ";
236- errmsg += "that you have installed it, else make sure, that you have set the envroinment variable ";
237- errmsg += "FOP_HOME or FOP_LIB_DIR correctly. Tried '";
238- errmsg += lFopJarFile1;
239- errmsg += "' and '";
240- errmsg += lFopJarFile;
241- errmsg += "'.";
242- throwError(errmsg);
243- }
244- }
245- }
246- std::vector<Item> lClassPath;
247- lClassPath.push_back(theFactory->createString(lFopJarFile));
248- {
249- std::string lJarDir = lFopLibDir;
250- if (lFopHome != "")
251- lJarDir = lFopHome + lDirectorySeparator + "lib";
252- // This is a list of all jar files, Apache Fop depends on.
253- std::list<std::string> lDeps;
254- lDeps.push_back("avalon-framework");
255- lDeps.push_back("batik-all");
256- lDeps.push_back("commons-io");
257- lDeps.push_back("commons-logging");
258- lDeps.push_back("serializer");
259- lDeps.push_back("xalan");
260- lDeps.push_back("xmlgraphics-commons");
261-
262- File_t lJarDirF = File::createFile(lJarDir);
263- DirectoryIterator_t lFiles = lJarDirF->files();
264- std::string lFile; size_t count = 0;
265- // We check for all files, if it is a potential dependency and add it to
266- // the result
267- while (lFiles->next(lFile)) {
268- // If the file is not a jar file, we don't do anything
269- if (lFile.substr(lFile.size() - 4, std::string::npos) != ".jar")
270- continue;
271- for (std::list<std::string>::iterator i = lDeps.begin(); i != lDeps.end(); ++i) {
272- std::string lSub = lFile.substr(0, i->size());
273- if (lSub == *i) {
274- std::string lFull = lJarDir + lDirectorySeparator + lFile;
275- File_t f = File::createFile(lFull);
276- if (f->exists() && !f->isDirectory()) {
277- lClassPath.push_back(theFactory->createString(lFull));
278- // We count all jar files we add to the dependencies.
279- ++count;
280- break;
281- }
282- }
283- }
284- }
285- // Last, we check if all dependencies are found
286- if (count < lDeps.size()) {
287- std::string errmsg = "Could not find ";
288- errmsg += lDeps.front();
289- throwError(errmsg);
290- }
291- }
292- return ItemSequence_t(new VectorItemSequence(lClassPath));
293-}
294-
295 ItemSequence_t
296 GeneratePDFFunction::evaluate(const ExternalFunction::Arguments_t& args,
297 const zorba::StaticContext* aStaticContext,
298
299=== modified file 'test/ExpQueryResults/data-formatting/xslfo.xml.res'
300--- test/ExpQueryResults/data-formatting/xslfo.xml.res 2012-03-12 22:08:04 +0000
301+++ test/ExpQueryResults/data-formatting/xslfo.xml.res 2012-05-09 20:55:19 +0000
302@@ -1,1 +1,1 @@
303-<pdf><len>6484</len><start>JVBERi0xLj</start><end>AolJUVPRgo=</end></pdf>
304+<pdf><len>true</len><start>JVBERi0xLj</start></pdf>
305
306=== modified file 'test/Queries/data-formatting/xslfo.xq'
307--- test/Queries/data-formatting/xslfo.xq 2012-03-12 22:08:04 +0000
308+++ test/Queries/data-formatting/xslfo.xq 2012-05-09 20:55:19 +0000
309@@ -21,7 +21,6 @@
310 let $len := fn:string-length($pdf)
311 return
312 <pdf>
313- <len> { $len }</len>
314+ <len> { $len gt 6000 }</len>
315 <start>{ fn:substring($pdf, 1, 10)}</start>
316- <end> { fn:substring($pdf, $len -10, $len)}</end>
317 </pdf>

Subscribers

People subscribed via source and target branches

to all changes: