コード例 #1
0
    def connect1(self, acountUrl):
        content = self.ucb.getContent(self.getAccountUrl())

        # open the content
        aArg = OpenCommandArgument2()
        aArg.Mode = FOLDERS # FOLDER, DOCUMENTS -> simple filter
        aArg.Priority = 32768 # Ignored by most implementations

        self.ucb.executeCommand(content, "open", aArg)
コード例 #2
0
    def connect1(self, acountUrl):
        content = self.ucb.getContent(self.getAccountUrl())

        # list files in the content.
        l = self.ucb.listFiles(self.getAccountUrl(), None)

        # open the content
        aArg = OpenCommandArgument2()
        aArg.Mode = FOLDERS # FOLDER, DOCUMENTS -> simple filter
        aArg.Priority = 32768 # Ignored by most implementations

        self.ucb.executeCommand(content, "open", aArg)

        # get the title property of the content.
        obj = self.ucb.getContentProperty(content, "Title", str)
コード例 #3
0
    def listFiles(self, path, verifier):
        xContent = self.getContent(path)

        aArg = OpenCommandArgument2()
        aArg.Mode = ALL
        aArg.Priority = 32768

        # Fill info for the properties wanted.
        aArg.Properties = (Property(),)

        aArg.Properties[0].Name = "Title"
        aArg.Properties[0].Handle = -1

        xSet = self.executeCommand(xContent, "open", aArg)

        xResultSet = xSet.getStaticResultSet()

        files = []

        if (xResultSet.first()):
            # obtain XContentAccess interface for child content access and XRow for properties
            while (True):
                # Obtain URL of child.
                if (hasattr(xResultSet, "queryContentIdentifierString")):
                    aId = xResultSet.queryContentIdentifierString()
                    aTitle = FileAccess.getFilename(aId)
                elif (hasattr(xResultSet, "getString")):
                    # First column: Title (column numbers are 1-based!)
                    aTitle = xResultSet.getString(1)
                else:
                    aTitle = ""
                #if (len(aTitle) == 0 and xResultSet.wasNull()):
                if (len(aTitle) == 0):
                    # ignore
                    pass
                else:
                    files.append(aTitle)
                if (not xResultSet.next()):
                    break
                # next child
        if (verifier is not None):
            for i in range(len(files)):
                if (not verifier.verify(files[i])):
                    files.pop(i) # FIXME !!! dangerous
        return files
コード例 #4
0
def open_url(context, url):
    ''' open InputStream from a URL.

    :param url: a URL to open an InputStream.
    :returns: an instance of InputStream
    '''

    # see http://wiki.openoffice.org
    #     /wiki/Documentation/DevGuide/UCB/Using_the_UCB_API

    from hwp5.plat._uno.services import css
    css = css.bind(context)
    ucb = css.ucb.UniversalContentBroker('Local', 'Office')
    content_id = ucb.createContentIdentifier(url)
    content = ucb.queryContent(content_id)

    import unohelper
    from com.sun.star.io import XActiveDataSink

    class DataSink(unohelper.Base, XActiveDataSink):
        def setInputStream(self, stream):
            self.stream = stream

        def getInputStream(self):
            return self.stream

    datasink = DataSink()

    from com.sun.star.ucb import Command, OpenCommandArgument2
    openargs = OpenCommandArgument2()
    openargs.Mode = 2  # OpenMode.DOCUMENT
    openargs.Priority = 32768
    openargs.Sink = datasink

    command = Command()
    command.Name = 'open'
    command.Handle = -1
    command.Argument = openargs

    content.execute(command, 0, None)
    return datasink.stream