source: branches/branch-1.3/zoo-project/zoo-services/openoffice/cgi-env/Exporter.py @ 732

Last change on this file since 732 was 420, checked in by djay, 11 years ago

Update header of some Python files.

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

Search

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