def getModelFromDocUrl(ctx, url): """Get document model from document url.""" doc = None args = ("Local", "Office") ucb = ctx.getServiceManager().createInstanceWithArgumentsAndContext( "com.sun.star.ucb.UniversalContentBroker", args, ctx ) identifier = ucb.createContentIdentifier(url) content = ucb.queryContent(identifier) p = Property() p.Name = "DocumentModel" p.Handle = -1 c = Command("getPropertyValues", -1, uno.Any("[]com.sun.star.beans.Property", (p,))) env = CommandEnvironment() try: ret = content.execute(c, 0, env) doc = ret.getObject(1, None) except: log.error("getModelFromDocUrl: {}", url) return doc
def getModelFromDocUrl(ctx, url): """Get document model from document url.""" doc = None args = ("Local", "Office") ucb = ctx.getServiceManager().createInstanceWithArgumentsAndContext( "com.sun.star.ucb.UniversalContentBroker", args, ctx) identifier = ucb.createContentIdentifier(url) content = ucb.queryContent(identifier) p = Property() p.Name = "DocumentModel" p.Handle = -1 c = Command() c.Handle = -1 c.Name = "getPropertyValues" c.Argument = uno.Any("[]com.sun.star.beans.Property", (p, )) env = CommandEnvironment() try: ret = content.execute(c, 0, env) doc = ret.getObject(1, None) except Exception as e: log.isErrorLevel() and log.error("getModelFromDocUrl: %s" % url) return doc
def getContentProperty(self, content, propName, classType): pv = [Property()] pv[0].Name = propName pv[0].Handle = -1 row = self.executeCommand(content, "getPropertyValues", uno.Any("[]com.sun.star.beans.Property", tuple(pv))) if (isinstance(classType, str)): return row.getString(1) elif (isinstance(classType, bool)): return True if (row.getBoolean(1)) else False elif (isinstance(classType, int)): return row.getInt(1) elif (isinstance(classType, int)): return row.getShort(1) else: return None
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
def getPropertyByName(self, name): i = self.get_index(name) if i is None: raise UnknownPropertyException(name, self) p = self.props[i] return Property(*p)
def getProperties(self): _props = [] for prop in self.props: _props.append(Property(*prop)) return tuple(_props)