2 # -*- coding: utf-8 -*-
3 ##############################################################################
5 # OpenERP, Open Source Management Solution
6 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 import sys, zipfile, xml.dom.minidom
26 class OpenDocumentTextFile :
27 def __init__ (self, filepath) :
28 zip = zipfile.ZipFile(filepath)
29 self.content = xml.dom.minidom.parseString(zip.read("content.xml"))
32 """ Converts the document to a string. """
34 for val in ["text:p", "text:h", "text:list"]:
35 for paragraph in self.content.getElementsByTagName(val) :
36 buffer += self.textToString(paragraph) + "\n"
39 def textToString(self, element) :
41 for node in element.childNodes :
42 if node.nodeType == xml.dom.Node.TEXT_NODE :
43 buffer += node.nodeValue
44 elif node.nodeType == xml.dom.Node.ELEMENT_NODE :
45 buffer += self.textToString(node)
48 if __name__ == "__main__" :
49 s =StringIO.StringIO(file(sys.argv[1]).read())
50 odt = OpenDocumentTextFile(s)
51 print odt.toString().encode('ascii','replace')
53 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: