Load files into Writer only?

Jens Tröger jens.troeger at light-speed.de
Wed Mar 4 20:53:35 PST 2015

One way of approaching the problem below is by checking the file type of
the document, before handing it off to the soffice instance.  Checking
the extension only might be too flimsy, perhaps libmagic can help?

There is a list of supported file formats here:


but it seems rather tedious to me to check manually for Writer document
files.  Is there a better way?


On Thu, Feb 26, 2015 at 05:36:18PM +0100, Jens Tröger wrote:
> Hi,
> Is there a way to load Writer supported documents only, and dismiss
> (fail) on others?  For example, I connect to an office server like so
>   local = uno.getComponentContext()                                       
>   resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)
>   context = resolver.resolve("uno:pipe,name=foopipe;urp;StarOffice.ComponentContext")
>   desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
> Now I'd like to 
>   desktop.loadComponentFromURL()
> and if that file is e.g. and image that Writer can not open, then fail.
> Same for any other file which is not a Writer supported file.  I've
> looked at this call
>   http://www.openoffice.org/api/docs/common/ref/com/sun/star/lang/XMultiComponentFactory.html#createInstanceWithArgumentsAndContext
> but can't figure out if that's the right way to go.  Or should I check
> if the file is of a certain type before I pass it on to office?  In that
> case though, I might reject some funky format which Writer supports,
> just because I didn't know about it.
> Thanks!
> Jens

Jens Tröger

More information about the LibreOffice mailing list