Generating OO documents
In order to call LibreOffice document templates from a context action, a few option variables have to be set before calling the function. Generating LibreOffice documents requires the OpenOffice library, which is provided as dynamic link library with the ODABA installation.
The document generator is called via the SystemClass::CreateDocument() interface function by using an OSI expression. In order to be executed correctly, the function has to be executed with a property handle as calling object. In order to call the function properly, the complete document path and the complete template path have to be provided in internal option variables __DocumentPath and __TemplatePath. It is up to the application to provide proper location and file names.
Beside these mandatory option variables, usually a number of additional option variables has to be set, which are referenced in the document template. Since document templates are global functions, root object instance for the document are usually passed as instance identifier (LOID or key value) or as access path.
The main entry point for starting the document generation is the template function with the same name as the document (after replacing spaces in the document name by underscores). In order to use a different starting point, the proper entry point may be passed as parameter to the executable or might be set in the Options.Documentation.DocumentExchange.TemplateEntryPoint option variable.
The example below shows two fragments for an implementation of a context action for executing LibreOffice document generation.
// generate document in current process
bool ...fragment(Property &ph) {
// root object instance is selected in ph
// the following options are required by the document generatoin interface
Option("__DocumentPath") = GetDocumentPath(); // complete document path
Option("__TemplatePath") = GetTemplatePath(); // complete template path
// set other option variables requested by the template
// ...
// running in current process
ph.executeExpression("SystenClass::CreateDocument()");
}
// generate document in separate process
bool ...fragment(Property &ph) {
// root object instance is selected in ph
// create ini-file for CreateDocument
fstream ini_file;
ini_file.open ("test.ini", fstream::out | fstream::app);
ini_file << "[SYSTEM]" << std::endl;
ini_file << "DICTIONARY=" << Option("SYSDB").toString().data() << endl;
ini_file << "[CreateDocument]" << std::endl;
ini_file << "DICTIONARY=" << Option("SYSDB").toString().data() << endl;
ini_file << "RESOURCES=" << Option("RESDB").toString().data() << endl;
ini_file << "DATABASE=" << Option("DATDB").toString().data() << endl;
ini_file << "ONLINE_VERSION=YES" << endl;
ini_file << "ACCESS_MODE=Write" << endl;
ini_file << "NET=YES" << endl;
ini_file << "ODABA_ROOT=" << Option("ODABA_ROOT").toString().data() << endl;
ini_file << "CTXI_DLL=" << Option("CTXI_DLL").toString().data()<< endl;
ini_file << "TRACE=" << Option("TRACE").toString().data() << endl;
ini_file << "DSC_Language=" << Option("DSC_Language").toString().data() endl;
// create option variables for template options
ini_file.close();
odaba::String path(Option("ODABA_ROOT"));
path += "/CreateDocument.exe";
// depending on template reqirements additional optione might be set
ph.instanceContext().executeProgram(path,"test.ini",GetTemplatePath(),GetDocumentPath());
return true;
}