Beispiel #1
0
def expandUri(uri):
    if uri.startswith("vnd.sun.star.expand:"):
        uri = uri.replace("vnd.sun.star.expand:", "", 1)
        uri = uno.getComponentContext().getByName("/singletons/com.sun.star.util.theMacroExpander").expandMacros(uri)
    if uri.startswith("file:"):
        uri = uno.absolutize("", uri)  # necessary to get rid of .. in uri
    return uri
Beispiel #2
0
    def createAddress(self, id):
        # get the central desktop object
        desktop = self.smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",self.ctx)
        path = os.environ['CUON_OO_DOC']
        inProps = PropertyValue( "Hidden" , 0 , True, 0 ),
        fileUrl = uno.absolutize('test.sxc' , systemPathToFileUrl(path) )
        model = desktop.loadComponentFromURL( fileUrl , "_blank", 0, inProps)


        # access the current writer document
        #model = desktop.getCurrentComponent()

        # access the document's text property
        text = model.Text

        # create a cursor
        cursor = text.createTextCursor()

        liAddress = self.unpickleObject(id)
        for i in range(0,len(liAddress)):
            # insert the text into the document
            text.insertString( cursor, `liAddress[i]`, 0 )


        # Do a nasty thing before exiting the python process. In case the
        # last call is a oneway call (e.g. see idl-spec of insertString),
        # it must be forced out of the remote-bridge caches before python
        # exits the process. Otherwise, the oneway call may or may not reach
        # the target object.
        # I do this here by calling a cheap synchronous call (getPropertyValue).
        self.ctx.ServiceManager
Beispiel #3
0
def main():
    retVal = 0
    doc = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "hc:",["help", "connection-string=" , "html"])
        format = None
        url = "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
        filterName = "Text (Encoded)"
        for o, a in opts:
            if o in ("-h", "--help"):
                usage()
                sys.exit()
            if o in ("-c", "--connection-string" ):
                url = "uno:" + a + ";urp;StarOffice.ComponentContext"
            if o == "--html":
                filterName = "HTML (StarWriter)"
            
        print filterName
        if not len( args ):
              usage()
              sys.exit()
              
        ctxLocal = uno.getComponentContext()
        smgrLocal = ctxLocal.ServiceManager

        resolver = smgrLocal.createInstanceWithContext(
                 "com.sun.star.bridge.UnoUrlResolver", ctxLocal )
        ctx = resolver.resolve( url )
        smgr = ctx.ServiceManager

        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx )

        cwd = systemPathToFileUrl( getcwd() )
        outProps = (
            PropertyValue( "FilterName" , 0, filterName , 0 ),
            PropertyValue( "OutputStream",0, OutputStream(),0))
        inProps = PropertyValue( "Hidden" , 0 , True, 0 ),
        for path in args:
            try:
                fileUrl = uno.absolutize( cwd, systemPathToFileUrl(path) )
                doc = desktop.loadComponentFromURL( fileUrl , "_blank", 0,inProps)

                if not doc:
                    raise UnoException( "Couldn't open stream for unknown reason", None )

                doc.storeToURL("private:stream",outProps)
            except IOException, e:
                sys.stderr.write( "Error during conversion: " + e.Message + "\n" )
                retVal = 1
            except UnoException, e:
                sys.stderr.write( "Error ("+repr(e.__class__)+") during conversion:" + e.Message + "\n" )
                retVal = 1
Beispiel #4
0
def main(host, port, path, pagecountlimit):
    retVal = 0
    pagecountlimit = '50'
    doc = None

    url = "uno:socket,host=%s,port=%d;urp;StarOffice.ComponentContext" % (host, port)

    ctxLocal = uno.getComponentContext()
    smgrLocal = ctxLocal.ServiceManager

    resolver = smgrLocal.createInstanceWithContext(
             "com.sun.star.bridge.UnoUrlResolver", ctxLocal )
    ctx = resolver.resolve( url )
    smgr = ctx.ServiceManager

    desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx )

    cwd = systemPathToFileUrl( getcwd() )

    outProps = (
        #PropertyValue( "FilterName" , 0, "StarOffice XML (Writer)" , 0 ),
        PropertyValue( "OutputStream",0, OutputStream(),0),)
    inProps = (PropertyValue( "Hidden" , 0 , True, 0 ),)
    try:
        fileUrl = uno.absolutize( cwd, systemPathToFileUrl(path) )
        doc = desktop.loadComponentFromURL( fileUrl, "_blank", 0, inProps)

        if not doc:
            raise UnoException( "Couldn't open stream for unknown reason", None )

        # pdb.set_trace()

        try:
            cursor = doc.getCurrentController().getViewCursor()
            cursor.jumpToLastPage()
            pagecount = cursor.getPage()
            if pagecount > int(pagecountlimit):
                raise UnoException( "Input document has %d pages which exceeeds the page count limit of %d." % (pagecount, int(pagecountlimit)), None )
        except  AttributeError:
             # opened picture files will not behave, but do not need to have their page counted
             pass

        doc.storeToURL("private:stream",outProps)
    except IOException, e:
        sys.stderr.write( "Error during conversion: " + e.Message + "\n" )
        retVal = 1
for dir in dirs:
#dir = dirs[0]
#if True: 
    os.chdir(dir)
    files = os.listdir(dir)
    cwd = systemPathToFileUrl( os.getcwd() )

    print "for directory '" + dir + "' we found " + str(len(files)) + " files."

    for file in files:
        if file.endswith('.xml'):
            print 'skipping: ' + file
            continue

        try:
            inProps = (PropertyValue( "Hidden" , 0 , True, 0 ),)
            fileUrl = uno.absolutize( cwd, systemPathToFileUrl(file) )
            doc = desktop.loadComponentFromURL( fileUrl, "_blank", 0, inProps)

            cursor = doc.getCurrentController().getViewCursor()
            cursor.jumpToLastPage()
            page_count = cursor.getPage()
            print file + ',' + str(page_count)
            result.write(str(page_count) + '\n')
            result.flush()
            doc.dispose()
        except:
            pass

result.close()
Beispiel #6
0
        resolver = smgrLocal.createInstanceWithContext(
                 "com.sun.star.bridge.UnoUrlResolver", ctxLocal )
        ctx = resolver.resolve( url )
        smgr = ctx.ServiceManager

        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx )

        cwd = systemPathToFileUrl( getcwd() )
        outProps = (
            PropertyValue( "FilterName" , 0, filterName , 0 ),
            )
        inProps = PropertyValue( "Hidden" , 0 , True, 0 ),
        for path in args:
		try:
			fileUrl = uno.absolutize( cwd, systemPathToFileUrl(path + ".sxw") )
			doc = desktop.loadComponentFromURL( fileUrl , "_blank", 0,inProps)

			if not doc:
				raise UnoException( "Couldn't open " + fileUrl, None )

			saveUrl = uno.absolutize( cwd, systemPathToFileUrl(path) )
			doc.storeToURL(saveUrl + "." + extension ,outProps)
        
		except IOException, e:
			sys.stderr.write( "Error during conversion: " + e.Message + "\n" )
			retVal = 1
		except UnoException, e:
			sys.stderr.write( "Error ("+repr(e.__class__)+") during conversion:" + e.Message + "\n" )
			retVal = 1
	if doc:
Beispiel #7
0
 def test_absolutize(self):
     relative_path = "../.."
     url = "file:///home/foo/bar/hoge/123.ods"
     desired = "file:///home/foo/bar/"
     result = uno.absolutize(url, relative_path)
     self.assertEqual(result, desired)