~zorba-coders/zorba/bug955040

« back to all changes in this revision

Viewing changes to src/com/zorba-xquery/www/modules/xsl-fo.xq.src/xslfo.cpp

  • Committer: Cezar Andrei
  • Date: 2012-03-06 08:11:49 UTC
  • Revision ID: cezar.lp@cezarandrei.com-20120306081149-ln2h00vpefiirezq
Integrate data-formating module into the same paradigm of java modules.
This fixes starting the JVM only once, and stating it right with the entire classpath of all the modules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 
43
43
namespace zorba { namespace xslfo {
44
44
 
45
 
class GeneratePDFFunction : public NonContextualExternalFunction {
 
45
class GeneratePDFFunction : public ContextualExternalFunction {
46
46
  private:
47
47
    const ExternalModule* theModule;
48
48
    ItemFactory* theFactory;
49
49
  public:
50
50
    GeneratePDFFunction(const ExternalModule* aModule) :
51
51
      theModule(aModule), theFactory(Zorba::getInstance(0)->getItemFactory()) {}
52
 
    ~GeneratePDFFunction() {
53
 
      JavaVMSingelton::destroyInstance();
54
 
    }
 
52
    ~GeneratePDFFunction() {}
55
53
 
56
54
  public:
57
55
    virtual String getURI() const { return theModule->getURI(); }
59
57
    virtual String getLocalName() const { return "generator-impl"; }
60
58
 
61
59
    virtual ItemSequence_t 
62
 
    evaluate(const ExternalFunction::Arguments_t& args) const;
 
60
    evaluate(const ExternalFunction::Arguments_t& args,
 
61
             const zorba::StaticContext*,
 
62
             const zorba::DynamicContext*) const;
63
63
};
64
64
 
65
65
class FindApacheFopFunction : public NonContextualExternalFunction {
249
249
  return ItemSequence_t(new VectorItemSequence(lClassPath));
250
250
}
251
251
 
252
 
ItemSequence_t GeneratePDFFunction::evaluate(const ExternalFunction::Arguments_t& args) const
 
252
ItemSequence_t
 
253
GeneratePDFFunction::evaluate(const ExternalFunction::Arguments_t& args,
 
254
                              const zorba::StaticContext* aStaticContext,
 
255
                              const zorba::DynamicContext* aDynamincContext) const
253
256
{
254
 
  Item classPathItem;
255
 
  // assemble classpath (list of path concatenated with ":" or ";")
256
 
  Iterator_t lIter = args[2]->getIterator();
257
 
  lIter->open();
258
 
  std::ostringstream lClassPath;
259
 
  while (lIter->next(classPathItem))
260
 
  {
261
 
    lClassPath << classPathItem.getStringValue() << File::getPathSeparator();
262
 
  }
263
 
  lIter->close();
264
 
 
265
 
  lIter = args[0]->getIterator();
 
257
  Iterator_t lIter = args[0]->getIterator();
266
258
  lIter->open();
267
259
  Item outputFormat;
268
260
  lIter->next(outputFormat);
270
262
  jthrowable lException = 0;
271
263
  static JNIEnv* env;
272
264
  try {
273
 
    env = JavaVMSingelton::getInstance(lClassPath.str().c_str())->getEnv();
 
265
    env = zorba::jvm::JavaVMSingelton::getInstance(aStaticContext)->getEnv();
274
266
    jstring outFotmatString = env->NewStringUTF(outputFormat.getStringValue().c_str());
275
267
    // Local variables
276
268
    std::ostringstream os;
402
394
    String base64S = encoding::Base64::encode(lStream);
403
395
    Item lRes = theFactory->createBase64Binary(base64S.c_str(), base64S.length());
404
396
    return ItemSequence_t(new SingletonItemSequence(lRes));
405
 
  } catch (VMOpenException&) {
 
397
  } catch (zorba::jvm::VMOpenException&) {
406
398
    Item lQName = theFactory->createQName("http://www.zorba-xquery.com/modules/xsl-fo",
407
399
        "VM001");
408
400
    throw USER_EXCEPTION(lQName, "Could not start the Java VM (is the classpath set?)");