source: trunk/zoo-services/openoffice/cgi-env/Exporter.py @ 1

Last change on this file since 1 was 1, checked in by djay, 14 years ago

Initial ZOO SVN Repository Import.

File size: 3.7 KB
Line 
1#
2# Author : Gérald FENOY
3#
4# Copyright 2008-2009 GeoLabs SARL. All rights reserved.
5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal
8# in the Software without restriction, including without limitation the rights
9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.
23#
24
25import uno
26import getopt, sys
27
28from unohelper import Base, systemPathToFileUrl, absolutize
29
30from com.sun.star.beans import PropertyValue
31from com.sun.star.script import CannotConvertException
32from com.sun.star.lang import IllegalArgumentException
33from com.sun.star.task import ErrorCodeIOException
34from com.sun.star.io import IOException, XOutputStream
35
36class OutputStream( Base, XOutputStream ):
37    def __init__( self ):
38        self.closed = 0
39    def closeOutput(self):
40        self.closed = 1
41    def writeBytes( self, seq ):
42        sys.stdout.write( seq.value )
43    def flush( self ):
44        pass
45
46def OdtConverter(conf,inputs,outputs):
47        # get the uno component context from the PyUNO runtime 
48        localContext = uno.getComponentContext()
49
50        # create the UnoUrlResolver
51        # on a single line
52        resolver =      localContext.ServiceManager.createInstanceWithContext   ("com.sun.star.bridge.UnoUrlResolver", localContext )
53
54        # connect to the running office                                 
55        ctx = resolver.resolve( conf["oo"]["server"].replace("::","=")+";urp;StarOffice.ComponentContext" )
56        smgr = ctx.ServiceManager
57
58        # get the central desktop object
59        desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
60
61        # get the file name
62        adressDoc=systemPathToFileUrl(conf["main"]["dataPath"]+"/"+inputs["InputDoc"]["value"])
63
64        propFich=PropertyValue("Hidden", 0, True, 0),
65
66        myDocument=0
67        try:
68            myDocument = desktop.loadComponentFromURL(adressDoc,"_blank",0,propFich)
69        except CannotConvertException, e:
70            print >> sys.stderr,  'Impossible de convertir le fichier pour les raisons suivantes : \n'
71            print >> sys.stderr,  e
72            sys.exit(0)
73        except IllegalArgumentException, e:
74            print >> sys.stderr,  'Impossible de convertir le fichier pour les  raisons suivantes : \n'
75            print >> sys.stderr,  e
76            sys.exit(0)
77
78        outputDoc=systemPathToFileUrl(conf["main"]["tmpPath"]+"/"+inputs["OutputDoc"]["value"])
79
80        tmp=inputs["OutputDoc"]["value"].split('.');
81
82        outputFormat={"pdf": "writer_pdf_Export", "html": "HTML (StarWriter)","odt": "writer8","doc": "MS Word 97","rtf": "Rich Text Format"}
83
84        for i in range(len(outputFormat)) :
85            if tmp[1]==outputFormat.keys()[i] :
86                filterName=outputFormat[tmp[1]]
87                prop1Fich = (
88                    PropertyValue( "FilterName" , 0, filterName , 0 ),
89                        PropertyValue( "Overwrite" , 0, True , 0 )
90                )
91                break
92
93        myDocument.storeToURL(outputDoc,prop1Fich)
94        myDocument.close(True)
95        ctx.ServiceManager
96        outputs["OutputedDocument"]={"value": inputs["OutputDoc"]["value"],"dataType": "string"}
97        return 3
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png