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