OOTextExtractor.inc.php
1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
class OOTextExtractor extends ExternalDocumentExtractor
{
private $converter;
private $javaPath;
private $ooHost;
private $ooPort;
private $targetMimeType;
public function __construct($targetMimeType='plain/text')
{
parent::__construct();
$config =& KTConfig::getSingleton();
$this->converter = KTUtil::findCommand('extractors/jodconverter', 'jodconverter');
$this->javaPath = KTUtil::findCommand('extractors/java', 'java');
$this->ooHost = $config->get('openoffice/host', 'localhost');
$this->ooPort = $config->get('openoffice/port', 8100);
$this->targetMimeType = $targetMimeType;
}
public function getDisplayName()
{
return _kt('OpenOffice Text Extractor');
}
public function getSupportedMimeTypes()
{
return array(
'text/rtf',
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.text-template',
'application/vnd.oasis.opendocument.text-web',
'application/vnd.oasis.opendocument.text-master',
'application/vnd.sun.xml.writer',
'application/vnd.sun.xml.writer.template',
'application/vnd.sun.xml.writer.global',
);
}
public function needsIntermediateSourceFile()
{
// we need the intermediate file because it
// has the correct extension. jodconverter uses the extension to determine mimetype
return true;
}
protected function getCommandLine()
{
$cmdline = "$this->javaPath -jar $this->converter $this->sourcefile $this->mimetype $this->targetfile $this->targetMimeType $this->ooHost $this->ooPort";
return $cmdline;
}
public function diagnose()
{
if (false === $this->converter)
{
return _kt('Cannot locate jodconverter');
}
if (false === $this->javaPath)
{
return _kt('Cannot locate java');
}
$connection = @fsockopen($this->ooHost, $this->ooPort,$errno, $errstr,5 );
if (false === $connection)
{
return _kt('Cannot connect to openoffice host');
}
fclose($connection);
return null;
}
}
?>