On 1/9/13 3:59 PM, Ariel Constenla-Haile wrote:
> Hi *
> 
> On Wed, Jan 9, 2013 at 11:40 AM, Jürgen Schmidt <jogischm...@gmail.com> wrote:
>> On 12/19/12 3:04 PM, Robert Barbey wrote:
>>> Hi everyone,
>>>
>>> is it possible to get the kind of document currently opened in Writer via 
>>> the API? Ideally, this would be a MIME type kind of thing.
>>>
>>
>> sorry for answering so late but I forget it and stumbled over this now
>> again. But the bad news is that I don't know it for sure but it seems
>> that it not possible.
> 
> The model has a getArgs() method
> http://www.openoffice.org/api/docs/common/ref/com/sun/star/document/TypeDetection.html
> 
> that returns a MediaDescriptor, look for "FilterName" in that array
> http://www.openoffice.org/api/docs/common/ref/com/sun/star/document/MediaDescriptor.html#FilterName
> 
> then use the TypeDetection to get the filter information by name, and
> search for "MediaType"
> http://www.openoffice.org/api/docs/common/ref/com/sun/star/document/TypeDetection.html
> 
> Sample Basic code:
> 
> REM  *****  BASIC  *****
> Option Explicit
> 
> Sub Main
>       Dim oDoc as Object
>       oDoc = ThisComponent
>       
>       Dim aArgs()
>       aArgs = oDoc.getArgs()
>       
>       Dim sFilterName$
>       Dim i%
>       For i = 0 To UBound(aArgs)
>               If aArgs(i).Name = "FilterName" Then
>                       sFilterName = aArgs(i).Value
>                       Exit For
>               End If
>       Next
>       
>       Dim sMime$
>       Dim oTypeDetection as Object
>       oTypeDetection = CreateUnoService("com.sun.star.document.TypeDetection")
>       If oTypeDetection.hasByName(sFilterName) Then
>               Dim aFilter()
>               aFilter = oTypeDetection.getByName(sFilterName)
>               For i = 0 To UBound(aFilter)
>                       If aFilter(i).Name = "MediaType" Then
>                               sMime = aFilter(i).Value
>                               Exit For
>                       End If
>               Next
>       End If
>       
>       MsgBox "Mime " & sMime
> End Sub
> 

thanks Ariel, I was looking for DociumentProperties and the deprecated
DocumentInfo. I've thought about the MediaDescriptor as well but of
course did not looked in the code in detail but only the API.

getArgs() a self explaining method for accessing these media
properties/args , why did I not noticed this ;-)

Why are these things so complicate? I would have expected that all
documents have a media type (mime type) by default. New documents would
get the mime type of the used default format as long as they are not
saved in a different format.

Going via the TypeDetection looks not really straight forward. The
question come into my mind why DocumentInfo is deprecated where a
MIMEType property is defined?

Juergen

Reply via email to