Re: MIME type of current document
Hi, we think that we found a solution for this problem. So far, it works with the documents we tested. Let textDocument be the current document that has been obtained from the model. String getFileFormat(XTextDocument textDocument) { try { final Object objTypeDetection = context.getServiceManager().createInstanceWithContext( com.sun.star.document.TypeDetection, context); final XTypeDetection typeDetection = UnoRuntime.queryInterface(XTypeDetection.class, objTypeDetection); final XNameAccess typeNameAccess = UnoRuntime.queryInterface(XNameAccess.class,objTypeDetection); final String typeByURL = typeDetection.queryTypeByURL(textDocument.getURL()); final PropertyValue[] typeProperties = (PropertyValue[]) typeNameAccess.getByName(typeByURL); for (final PropertyValue property : typeProperties) { if (property.Name.equals(MediaType)) { return (String) property.Value; } } return ; } catch (final Exception e) { return ; } } Regards, Kai Labusch
Re: MIME type of current document
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. Juergen
Re: MIME type of current document
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
Re: MIME type of current document
On Wed, Jan 09, 2013 at 11:59:09AM -0300, 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 Things are more complicated, that documentation should direct to the FilterFactory server, not the TypeDetection. 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 Use the FilterName found in getArgs() to get the filter by name in the FilterFactory service. From the filter, get the Type property, and use it to get the type by name in the TypeDetection service. From the type, get the MediaType property. The previous version of the marco didn't work with a .doc, the following should: REM * BASIC * Option Explicit Sub Main Dim oDoc as Object oDoc = ThisComponent Dim aArgs() aArgs = oDoc.getArgs() Dim sFilterName$ SearchPropArray( aArgs, FilterName, sFilterName) Dim sMime$ GetMimeFromFilterName( sFilterName, sMime) End Sub Sub GetMimeFromFilterName(ByVal sFilterName$, sMime$) Dim oTypeDetection as Object Dim oFilterFactory as Object Dim aFilter(), aType() Dim sType$ Dim i% oTypeDetection = CreateUnoService(_ com.sun.star.document.TypeDetection) oFilterFactory = CreateUnoService(_ com.sun.star.document.FilterFactory) If NOT oFilterFactory.hasByName(sFilterName) Then Exit Sub End If aFilter = oFilterFactory.getByName(sFilterName) SearchPropArray(aFilter, Type, sType) If NOT oTypeDetection.hasByName(sType) Then Exit Sub End If aType = oTypeDetection.getByName(sType) SearchPropArray(aType, MediaType, sMime) MsgBox sMime End Sub Sub SearchPropArray(aArray, sName$, aValue) Dim i% For i = 0 To UBound(aArray) If aArray(i).Name = sName Then aValue = aArray(i).Value Exit For End If Next End Sub -- Ariel Constenla-Haile La Plata, Argentina pgphWvk6xcr05.pgp Description: PGP signature
Re: MIME type of current document
On Wed, Dec 19, 2012 at 8:04 AM, Robert Barbey robert.bar...@acrolinx.comwrote: 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. Thank you very much! Best, Robert Do you mean to say what kind of document is it open in OpenOffice? like if its writer or calc or impress? Or do you mean the metadata of the document. Here is a basic code for each: This is to verify is a text document: Dim s As String s = com.sun.star.text.TextDocument If ThisComponent.supportsService(s) Then Print The document is a text document Else Print The document is not a text document End If A more complete can be seen here: http://ooo.pastebin.ca/2300890 Here is for the user fields ' Access the user fields for the information regarding the document. vInfo = vDoc.getDocumentInfo() vVal = oData.ElementNames s = ===User Fields=== For i = 0 to vInfo.GetUserFieldCount() - 1 sKey = vInfo.GetUserFieldName(i) sVal = vInfo.GetUserFieldValue(i) s = s Chr$(13) ( sKey , sVal ) Next i '(Info 1,) '(Info 2,) '(Info 3,) '(Info 4,) MsgBox s, 0, User Fields -- Alexandro Colorado Apache OpenOffice Contributor http://es.openoffice.org
MIME type of current document
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. Thank you very much! Best, Robert