From ffc1cd2d80b53b351d2b3584a1bbf5c0e025e37e Mon Sep 17 00:00:00 2001 From: Megan Watson Date: Fri, 8 May 2009 22:10:00 +0200 Subject: [PATCH] KTS-4282 Updated JODConverter to the latest version. Modified xmlrpc function to send the OOo host and port through. "PDF Conversion should support more document formats" Fixed. --- bin/luceneserver/ktlucene.jar | Bin 23635 -> 0 bytes bin/luceneserver/lib/jodconverter-2.2.2.jar | Bin 0 -> 32054 bytes bin/luceneserver/lib/jodconverter.jar | Bin 56056 -> 0 bytes bin/luceneserver/lib/juh-3.0.1.jar | Bin 0 -> 55622 bytes bin/luceneserver/lib/juh.jar | Bin 55519 -> 0 bytes bin/luceneserver/lib/jurt-3.0.1.jar | Bin 0 -> 108330 bytes bin/luceneserver/lib/jurt.jar | Bin 108114 -> 0 bytes bin/luceneserver/lib/ridl-3.0.1.jar | Bin 0 -> 253610 bytes bin/luceneserver/lib/ridl.jar | Bin 253589 -> 0 bytes bin/luceneserver/lib/slf4j-api-1.5.6.jar | Bin 0 -> 22338 bytes bin/luceneserver/lib/slf4j-jdk14-1.5.6.jar | Bin 0 -> 8815 bytes bin/luceneserver/lib/unoil-3.0.1.jar | Bin 0 -> 1360160 bytes bin/luceneserver/lib/unoil.jar | Bin 1356784 -> 0 bytes bin/luceneserver/lib/xstream-1.3.1.jar | Bin 0 -> 431406 bytes plugins/ktstandard/PDFGeneratorAction.php | 2 +- plugins/pdfConverter/pdfConverter.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- search2/indexing/lib/XmlRpcLucene.inc.php | 31 ++++++++++++++++++++++++++++++- 17 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 bin/luceneserver/lib/jodconverter-2.2.2.jar delete mode 100644 bin/luceneserver/lib/jodconverter.jar create mode 100644 bin/luceneserver/lib/juh-3.0.1.jar delete mode 100644 bin/luceneserver/lib/juh.jar create mode 100644 bin/luceneserver/lib/jurt-3.0.1.jar delete mode 100644 bin/luceneserver/lib/jurt.jar create mode 100644 bin/luceneserver/lib/ridl-3.0.1.jar delete mode 100644 bin/luceneserver/lib/ridl.jar create mode 100644 bin/luceneserver/lib/slf4j-api-1.5.6.jar create mode 100644 bin/luceneserver/lib/slf4j-jdk14-1.5.6.jar create mode 100644 bin/luceneserver/lib/unoil-3.0.1.jar delete mode 100644 bin/luceneserver/lib/unoil.jar create mode 100644 bin/luceneserver/lib/xstream-1.3.1.jar diff --git a/bin/luceneserver/ktlucene.jar b/bin/luceneserver/ktlucene.jar index 95e16c7..9ebabda 100644 Binary files a/bin/luceneserver/ktlucene.jar and b/bin/luceneserver/ktlucene.jar differ diff --git a/bin/luceneserver/lib/jodconverter-2.2.2.jar b/bin/luceneserver/lib/jodconverter-2.2.2.jar new file mode 100644 index 0000000..d033256 Binary files /dev/null and b/bin/luceneserver/lib/jodconverter-2.2.2.jar differ diff --git a/bin/luceneserver/lib/jodconverter.jar b/bin/luceneserver/lib/jodconverter.jar deleted file mode 100644 index 0cdc94f..0000000 Binary files a/bin/luceneserver/lib/jodconverter.jar and /dev/null differ diff --git a/bin/luceneserver/lib/juh-3.0.1.jar b/bin/luceneserver/lib/juh-3.0.1.jar new file mode 100644 index 0000000..1e38c5c Binary files /dev/null and b/bin/luceneserver/lib/juh-3.0.1.jar differ diff --git a/bin/luceneserver/lib/juh.jar b/bin/luceneserver/lib/juh.jar deleted file mode 100644 index 27e1b19..0000000 Binary files a/bin/luceneserver/lib/juh.jar and /dev/null differ diff --git a/bin/luceneserver/lib/jurt-3.0.1.jar b/bin/luceneserver/lib/jurt-3.0.1.jar new file mode 100644 index 0000000..3e2b117 Binary files /dev/null and b/bin/luceneserver/lib/jurt-3.0.1.jar differ diff --git a/bin/luceneserver/lib/jurt.jar b/bin/luceneserver/lib/jurt.jar deleted file mode 100644 index a6fdcd5..0000000 Binary files a/bin/luceneserver/lib/jurt.jar and /dev/null differ diff --git a/bin/luceneserver/lib/ridl-3.0.1.jar b/bin/luceneserver/lib/ridl-3.0.1.jar new file mode 100644 index 0000000..5976c18 Binary files /dev/null and b/bin/luceneserver/lib/ridl-3.0.1.jar differ diff --git a/bin/luceneserver/lib/ridl.jar b/bin/luceneserver/lib/ridl.jar deleted file mode 100644 index bb03341..0000000 Binary files a/bin/luceneserver/lib/ridl.jar and /dev/null differ diff --git a/bin/luceneserver/lib/slf4j-api-1.5.6.jar b/bin/luceneserver/lib/slf4j-api-1.5.6.jar new file mode 100644 index 0000000..d794252 Binary files /dev/null and b/bin/luceneserver/lib/slf4j-api-1.5.6.jar differ diff --git a/bin/luceneserver/lib/slf4j-jdk14-1.5.6.jar b/bin/luceneserver/lib/slf4j-jdk14-1.5.6.jar new file mode 100644 index 0000000..1ce0a28 Binary files /dev/null and b/bin/luceneserver/lib/slf4j-jdk14-1.5.6.jar differ diff --git a/bin/luceneserver/lib/unoil-3.0.1.jar b/bin/luceneserver/lib/unoil-3.0.1.jar new file mode 100644 index 0000000..5dfd090 Binary files /dev/null and b/bin/luceneserver/lib/unoil-3.0.1.jar differ diff --git a/bin/luceneserver/lib/unoil.jar b/bin/luceneserver/lib/unoil.jar deleted file mode 100644 index bc8d498..0000000 Binary files a/bin/luceneserver/lib/unoil.jar and /dev/null differ diff --git a/bin/luceneserver/lib/xstream-1.3.1.jar b/bin/luceneserver/lib/xstream-1.3.1.jar new file mode 100644 index 0000000..4ef4219 Binary files /dev/null and b/bin/luceneserver/lib/xstream-1.3.1.jar differ diff --git a/plugins/ktstandard/PDFGeneratorAction.php b/plugins/ktstandard/PDFGeneratorAction.php index b5422f0..76d081b 100644 --- a/plugins/ktstandard/PDFGeneratorAction.php +++ b/plugins/ktstandard/PDFGeneratorAction.php @@ -257,7 +257,7 @@ class PDFGeneratorAction extends KTDocumentAction { if(!$res){ $default->log->error('PDF Generator: PDF file could not be generated'); - $this->errorRedirectToMain(_kt('PDF file could not be generated, the file may be of an unsupported mime type.')); + $this->errorRedirectToMain(_kt('PDF file could not be generated, the file may be of an unsupported mime type or the PDF Generator could not connect.')); exit(); } diff --git a/plugins/pdfConverter/pdfConverter.php b/plugins/pdfConverter/pdfConverter.php index 20c8097..ec2f1a5 100644 --- a/plugins/pdfConverter/pdfConverter.php +++ b/plugins/pdfConverter/pdfConverter.php @@ -32,19 +32,34 @@ class pdfConverter extends BaseProcessor { public $order = 2; protected $namespace = 'pdf.converter.processor'; + private $ooHost = '127.0.0.1'; + private $ooPort = 8100; + /** + * Constructor gets the connection to the java server + * + * @return pdfConverter + */ public function pdfConverter() { $config =& KTConfig::getSingleton(); $javaServerUrl = $config->get('indexer/javaLuceneURL'); + $this->ooHost = $config->get('openoffice/host','127.0.0.1'); + $this->ooPort = $config->get('openoffice/port','8100'); $this->xmlrpc = XmlRpcLucene::get($javaServerUrl); } + /** + * Gets the document path and calls the conversion function + * + * @return boolean + */ public function processDocument() { $oStorage = KTStorageManagerUtil::getSingleton(); $path = $oStorage->temporaryFile($this->document); + $ext = KTMime::getFileType($this->document->getMimeTypeID()); if(!file_exists($path)){ global $default; @@ -53,7 +68,7 @@ class pdfConverter extends BaseProcessor } // do pdf conversion - $res = $this->convertFile($path); + $res = $this->convertFile($path, $ext); if($res === false){ global $default; @@ -80,14 +95,17 @@ class pdfConverter extends BaseProcessor // taken from the original list of accepted types in the pdf generator action $mime_types = array(); - //$mime_types[] = 'text/plain'; - //$mime_types[] = 'text/xml'; - //$mime_types[] = 'chemical/x-pdb'; - //$mime_types[] = 'text/csv'; + $mime_types[] = 'text/plain'; + $mime_types[] = 'text/html'; + $mime_types[] = 'text/csv'; $mime_types[] = 'text/rtf'; + + // Office OLE2 - 2003, XP, etc $mime_types[] = 'application/msword'; $mime_types[] = 'application/vnd.ms-powerpoint'; $mime_types[] = 'application/vnd.ms-excel'; + + // Star Office $mime_types[] = 'application/vnd.sun.xml.writer'; $mime_types[] = 'application/vnd.sun.xml.writer.template'; $mime_types[] = 'application/vnd.sun.xml.calc'; @@ -96,6 +114,8 @@ class pdfConverter extends BaseProcessor $mime_types[] = 'application/vnd.sun.xml.draw.template'; $mime_types[] = 'application/vnd.sun.xml.impress'; $mime_types[] = 'application/vnd.sun.xml.impress.template'; + + // Open Office $mime_types[] = 'application/vnd.oasis.opendocument.text'; $mime_types[] = 'application/vnd.oasis.opendocument.text-template'; $mime_types[] = 'application/vnd.oasis.opendocument.graphics'; @@ -105,39 +125,65 @@ class pdfConverter extends BaseProcessor $mime_types[] = 'application/vnd.oasis.opendocument.spreadsheet'; $mime_types[] = 'application/vnd.oasis.opendocument.spreadsheet-template'; + // Office 2007 + $mime_types[] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; + $mime_types[] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.template'; + $mime_types[] = 'application/vnd.openxmlformats-officedocument.presentationml.template'; + $mime_types[] = 'application/vnd.openxmlformats-officedocument.presentationml.slideshow'; + $mime_types[] = 'application/vnd.openxmlformats-officedocument.presentationml.presentation'; + $mime_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + $mime_types[] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.template'; + return $mime_types; } - function convertFile($filename) + /** + * Converts the given file to a pdf + * + * @param string $filename The full path to the file + * @param string $ext The extension of the file + * @return boolean + */ + function convertFile($filename, $ext) { global $default; + $tempDir = $default->tmpDirectory; + + // Create temporary copy of document + $sourceFile = tempnam($tempDir, 'pdfconverter') . '.' .$ext; + $res = @copy($filename, $sourceFile); + + // Create a temporary file to store the converted document + $targetFile = tempnam($tempDir, 'pdfconverter') . '.pdf'; // Get contents and send to converter - $buffer = file_get_contents($filename); - $buffer = $this->xmlrpc->convertDocument($buffer, 'pdf'); + $result = $this->xmlrpc->convertDocument($sourceFile, $targetFile, $this->ooHost, $this->ooPort); - if($buffer === false){ + if($result === false){ $default->log->error('PDF Converter Plugin: Conversion to PDF Failed'); + @unlink($sourceFile); + @unlink($targetFile); return false; } - $dir = $default->pdfDirectory; + $pdfDir = $default->pdfDirectory; // Ensure the PDF directory exists - if(!file_exists($dir)){ - mkdir($dir, 0755); + if(!file_exists($pdfDir)){ + mkdir($pdfDir, 0755); } - $pdfFile = $dir .'/'. $this->document->iId.'.pdf'; + $pdfFile = $pdfDir .'/'. $this->document->iId.'.pdf'; // if a previous version of the pdf exists - delete it if(file_exists($pdfFile)){ @unlink($pdfFile); } - file_put_contents($pdfFile, $buffer); - unset($buffer); - + // Copy the generated pdf into the pdf directory + $res = @copy($targetFile, $pdfFile); + @unlink($sourceFile); + @unlink($targetFile); return $pdfFile; } diff --git a/search2/indexing/lib/XmlRpcLucene.inc.php b/search2/indexing/lib/XmlRpcLucene.inc.php index 7b09b2a..9959874 100755 --- a/search2/indexing/lib/XmlRpcLucene.inc.php +++ b/search2/indexing/lib/XmlRpcLucene.inc.php @@ -400,15 +400,44 @@ class XmlRpcLucene return $obj['metadata']; } + /** + * Converts a document to the format of the given target file based on the extension of both files. + * + * @param string $sourceFile The full path of the document to be converted, with extension. + * @param string $targetFile The full path of the file to save the converted document with the desired extension. + * @param string $ooHost The host domain or IP address on which OpenOffice is running + * @param string $ooPort The port on which OpenOffice is listening. + * @return boolean + */ + function convertDocument($sourceFile, $targetFile, $ooHost, $ooPort) + { + $function = new xmlrpcmsg('openoffice.convertDocument', + array( + php_xmlrpc_encode((string) $sourceFile), + php_xmlrpc_encode((string) $targetFile), + php_xmlrpc_encode((string) $ooHost), + php_xmlrpc_encode((int) $ooPort) + ) + ); + + $result=&$this->client->send($function, 120); + + if($result->faultCode()) { + $this->error($result, 'convertDocument'); + return false; + } + return php_xmlrpc_decode($result->value()) == 0; + } /** * Convert document to given format. Defaults to pdf * + * @deprecated * @param $content * @param $toExtension * @return unknown_type */ - function convertDocument($content, $toExtension = 'pdf') + function convertDocumentStreamed($content, $toExtension = 'pdf') { $function = new xmlrpcmsg('openoffice.convertDocument', array( -- libgit2 0.21.4