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 __author__ = """Ronaldo Amaral Santos <ronaldinho.as@gmail.com>"""
32 __docformat__ = 'plaintext'
33
34 from GranularUtils import Grain
35 from FileUtils import File
36 from GranulateOffice import GranulateOffice
37 from GranulatePDF import GranulatePDF
38
39
41 """
42 - Provides the content granularization delegating the responsability to the appropriate class.
43 - Keeps the oood server related information (host and port).
44
45 About the usage of the methods: getSummaryDocument, getThumbnailsDocument, getTableDocumentList,
46 getImageDocumentList and granulateDocument:
47 - The first parameter is the filename (without the path), like "test.odt"
48 - The second one is a string representing the file content.
49 Ex. >>> file = open(filepath,'r')
50 >>> file.read()
51 """
52 ooodServer = None
53 supportedOfficeDocument=('application/vnd.oasis.opendocument.text',
54 'application/vnd.sun.xml.writer',
55 'application/msword',
56 'application/rtf',
57 'application/vnd.stardivision.writer',
58 'application/x-starwriter',
59 'application/vnd.oasis.opendocument.spreadsheet',
60 'application/vnd.sun.xml.calc',
61 'application/vnd.ms-excel',
62 'application/vnd.stardivision.calc',
63 'application/x-starcalc',
64 'application/vnd.oasis.opendocument.presentation',
65 'application/vnd.sun.xml.impress',
66 'application/vnd.ms-powerpoint',
67 'application/vnd.stardivision.draw',
68 'application/vnd.stardivision.impress',
69 'application/x-starimpress',)
70
71
72 - def __init__(self, host=None, port=None):
73 """
74 Set the host and port of the oood daemon during the instance creation
75 """
76 if (host is not None) and (port is not None):
77 self.ooodServer = 'http://%s:%d' % (host, port)
78
79
80
81
82 - def __process(self, filename=None, data=None):
97
99 """
100 Set OpenOffice Daemon - oood host and port for conversion document
101 """
102 self.ooodServer = 'http://%s:%d' % (host, port)
103
105 """
106 Get OpenOffice Daemon - oood informations for conversion document
107 """
108 return self.ooodServer
109
111 """
112 Get Office Document's summary (odf, doc, ppt for instance)
113 """
114 GranulateObj = self.__process(filename=filename, data=data)
115 if hasattr(GranulateObj, 'getSummaryDocument'):
116 return GranulateObj.getSummaryDocument()
117 else:
118 return None
119
121 """
122 Get Office Document's Thumbnails (odf, doc, ppt for instance)
123 """
124 GranulateObj = self.__process(filename=filename, data=data)
125 if hasattr(GranulateObj, 'getThumbnailsDocument'):
126 return GranulateObj.getThumbnailsDocument()
127 else:
128 return None
129
131 """
132 Get a Table List from Office and PDF Documents
133 """
134 GranulateObj = self.__process(filename=filename, data=data)
135 if hasattr(GranulateObj, 'getTableDocumentList'):
136 return GranulateObj.getTableDocumentList()
137 else:
138 return None
139
141 """
142 Get a Image List from Office and PDF Documents
143 """
144 GranulateObj = self.__process(filename=filename, data=data)
145 if hasattr(GranulateObj, 'getImageDocumentList'):
146 return GranulateObj.getImageDocumentList()
147 else:
148 return None
149
151 """
152 Retrieve the grains of Documents. (tables and images, for example)
153 """
154 GranulateObj = self.__process(filename=filename, data=data)
155 if hasattr(GranulateObj, 'granulateDocument'):
156 return GranulateObj.granulateDocument()
157 else:
158 return None
159