Beispiel #1
0
    def save(self, fileUrl):
        if not self.doc:
            raise "Failed to save cause there is no document"
        if fileUrl.startswith("file://"):
            fileUrl = fileUrl[7:]
        if not fileUrl:
            raise "Failed to save cause invalid file \"%s\" defined." % fileUrl

        try:
            import unohelper
            outUrl = unohelper.systemPathToFileUrl(fileUrl)
            outProps = []

            fileExt = os.path.splitext(fileUrl)[1].lower()
            if fileExt == '.txt' or fileExt == '.text':
                outProps.append( UnoPropertyValue('FilterName', 0, 'Text (encoded)', 0) )
            elif fileExt == '.htm' or fileExt == '.html':
                outProps.append( UnoPropertyValue('FilterName', 0, 'HTML (StarWriter)', 0) )
            elif fileExt == '.pdf':
                outProps.append( UnoPropertyValue('FilterName', 0, 'writer_pdf_Export', 0) )
            #else: opendocument...

            print "Save to: %s" % outUrl
            self.doc.storeToURL(outUrl, tuple(outProps))
        except:
            traceback.print_exc()
Beispiel #2
0
    def read(self, outputstream = OutputStream()):
        outProps = []
        outProps.append( UnoPropertyValue("FilterName" , 0, outputstream.filterName, 0) )
        outProps.append( UnoPropertyValue("Overwrite" , 0, True , 0) )
        outProps.append( UnoPropertyValue("OutputStream", 0, outputstream, 0) )

        try:
            self.doc.storeToURL("private:stream", tuple(outProps))
        except UnoErrorCodeIOException, e:
            self.unoConfig._logger.write("ErrorCodeIOException: %s" % e.ErrCode)
Beispiel #3
0
    def load(self, fileUrl):
        if not fileUrl.startswith("file://"):
            raise "Invalid file url \"%s\"" % fileUrl

        fileName = fileUrl[7:]
        if not os.path.isfile(fileName):
            raise "There exist no such file \"%s\"" % fileName

        self.close()

        fileBaseName = os.path.basename(fileName)
        self.unoConfig._logger.write("Loading document %s ...\n" %
                                     fileBaseName)

        inProps = []
        if self.unoConfig.hideClient:
            inProps.append(UnoPropertyValue("Hidden", 0, True, 0))

        self.doc = self.desktop.loadComponentFromURL(fileUrl, "_blank", 0,
                                                     tuple(inProps))
        if not self.doc:
            raise "Failed to load document %s" % fileName

        self.unoConfig._logger.write("Done loading document %s\n" %
                                     fileBaseName)