WOPI discovery: change action name to 'view' when we can import the format
Also add a script that can detect if discovery.xml is no longer in sync with the core.git filter configuration. richdocuments.git d6b65b79835bc499f720d15bb6c00441079b2fd6 (Respect WOPI action names, 2016-10-04) can launch a read-only loleaflet based on this info. Change-Id: I09232bb53844d0737dfdc66cd0e87342b9dd0fb6libreoffice-5-3
parent
c453f2626a
commit
d8daaff1e9
|
@ -2,10 +2,10 @@
|
|||
<wopi-discovery>
|
||||
<net-zone name="external-http">
|
||||
<app name="application/vnd.lotus-wordpro">
|
||||
<action name="edit" ext="lwp"/>
|
||||
<action name="view" ext="lwp"/>
|
||||
</app>
|
||||
<app name="image/svg+xml">
|
||||
<action name="edit" ext="svg"/>
|
||||
<action name="view" ext="svg"/>
|
||||
</app>
|
||||
<app name="application/vnd.ms-powerpoint">
|
||||
<action name="edit" ext="pot"/>
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
<!-- Writer documents -->
|
||||
<app name="application/vnd.sun.xml.writer">
|
||||
<action name="edit" ext="sxw"/>
|
||||
<action name="view" ext="sxw"/>
|
||||
</app>
|
||||
<app name="application/vnd.oasis.opendocument.text">
|
||||
<action name="edit" ext="odt"/>
|
||||
|
@ -27,7 +27,7 @@
|
|||
|
||||
<!-- Calc documents -->
|
||||
<app name="application/vnd.sun.xml.calc">
|
||||
<action name="edit" ext="sxc"/>
|
||||
<action name="view" ext="sxc"/>
|
||||
</app>
|
||||
<app name="application/vnd.oasis.opendocument.spreadsheet">
|
||||
<action name="edit" ext="ods"/>
|
||||
|
@ -38,7 +38,7 @@
|
|||
|
||||
<!-- Impress documents -->
|
||||
<app name="application/vnd.sun.xml.impress">
|
||||
<action name="edit" ext="sxi"/>
|
||||
<action name="view" ext="sxi"/>
|
||||
</app>
|
||||
<app name="application/vnd.oasis.opendocument.presentation">
|
||||
<action name="edit" ext="odp"/>
|
||||
|
@ -49,9 +49,9 @@
|
|||
|
||||
<!-- Draw documents -->
|
||||
<app name="application/vnd.sun.xml.draw">
|
||||
<action name="edit" ext="sxd"/>
|
||||
<action name="view" ext="sxd"/>
|
||||
</app>
|
||||
<app name="iapplication/vnd.oasis.opendocument.graphics">
|
||||
<app name="application/vnd.oasis.opendocument.graphics">
|
||||
<action name="edit" ext="odg"/>
|
||||
</app>
|
||||
<app name="application/vnd.oasis.opendocument.graphics-flat-xml">
|
||||
|
@ -65,7 +65,7 @@
|
|||
|
||||
<!-- Text master documents -->
|
||||
<app name="application/vnd.sun.xml.writer.global">
|
||||
<action name="edit" ext="sxg"/>
|
||||
<action name="view" ext="sxg"/>
|
||||
</app>
|
||||
<app name="application/vnd.oasis.opendocument.text-master">
|
||||
<action name="edit" ext="odm"/>
|
||||
|
@ -73,7 +73,7 @@
|
|||
|
||||
<!-- Math documents -->
|
||||
<app name="application/vnd.sun.xml.math">
|
||||
<action name="edit" ext="sxm"/>
|
||||
<action name="view" ext="sxm"/>
|
||||
</app>
|
||||
<app name="application/vnd.oasis.opendocument.formula">
|
||||
<action name="edit" ext="odf"/>
|
||||
|
@ -81,7 +81,7 @@
|
|||
|
||||
<!-- Text template documents -->
|
||||
<app name="application/vnd.sun.xml.writer.template">
|
||||
<action name="edit" ext="stw"/>
|
||||
<action name="view" ext="stw"/>
|
||||
</app>
|
||||
<app name="application/vnd.oasis.opendocument.text-template">
|
||||
<action name="edit" ext="ott"/>
|
||||
|
@ -94,7 +94,7 @@
|
|||
|
||||
<!-- Spreadsheet template documents -->
|
||||
<app name="application/vnd.sun.xml.calc.template">
|
||||
<action name="edit" ext="stc"/>
|
||||
<action name="view" ext="stc"/>
|
||||
</app>
|
||||
<app name="application/vnd.oasis.opendocument.spreadsheet-template">
|
||||
<action name="edit" ext="ots"/>
|
||||
|
@ -102,7 +102,7 @@
|
|||
|
||||
<!-- Presentation template documents -->
|
||||
<app name="application/vnd.sun.xml.impress.template">
|
||||
<action name="edit" ext="sti"/>
|
||||
<action name="view" ext="sti"/>
|
||||
</app>
|
||||
<app name="application/vnd.oasis.opendocument.presentation-template">
|
||||
<action name="edit" ext="otp"/>
|
||||
|
@ -110,7 +110,7 @@
|
|||
|
||||
<!-- Drawing template documents -->
|
||||
<app name="application/vnd.sun.xml.draw.template">
|
||||
<action name="edit" ext="std"/>
|
||||
<action name="view" ext="std"/>
|
||||
</app>
|
||||
<app name="application/vnd.oasis.opendocument.graphics-template">
|
||||
<action name="edit" ext="otg"/>
|
||||
|
@ -123,7 +123,7 @@
|
|||
|
||||
<!-- Extensions -->
|
||||
<app name="application/vnd.openofficeorg.extension">
|
||||
<action name="edit" ext="otx"/>
|
||||
<action name="edit" ext="oxt"/>
|
||||
</app>
|
||||
|
||||
<!-- Microsoft Word Template -->
|
||||
|
@ -139,18 +139,18 @@
|
|||
<action name="edit" ext="docm"/>
|
||||
</app>
|
||||
<app name="application/vnd.openxmlformats-officedocument.wordprocessingml.template">
|
||||
<action name="edit" ext="dotx"/>
|
||||
<action name="view" ext="dotx"/>
|
||||
</app>
|
||||
<app name="application/vnd.ms-word.template.macroEnabled.12">
|
||||
<action name="edit" ext="dotm"/>
|
||||
<action name="view" ext="dotm"/>
|
||||
</app>
|
||||
|
||||
<!-- OOXML spreadsheet -->
|
||||
<app name="application/vnd.openxmlformats-officedocument.spreadsheetml.template">
|
||||
<action name="edit" ext="xltx"/>
|
||||
<action name="view" ext="xltx"/>
|
||||
</app>
|
||||
<app name="application/vnd.ms-excel.template.macroEnabled.12">
|
||||
<action name="edit" ext="xltm"/>
|
||||
<action name="view" ext="xltm"/>
|
||||
</app>
|
||||
<app name="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
|
||||
<action name="edit" ext="xlsx"/>
|
||||
|
@ -178,19 +178,19 @@
|
|||
|
||||
<!-- Others -->
|
||||
<app name="application/vnd.wordperfect">
|
||||
<action name="edit" ext="wpd"/>
|
||||
<action name="view" ext="wpd"/>
|
||||
</app>
|
||||
<app name="application/x-aportisdoc">
|
||||
<action name="edit" ext="pdb"/>
|
||||
<action name="view" ext="pdb"/>
|
||||
</app>
|
||||
<app name="application/x-hwp">
|
||||
<action name="edit" ext="hwp"/>
|
||||
<action name="view" ext="hwp"/>
|
||||
</app>
|
||||
<app name="application/vnd.ms-works">
|
||||
<action name="edit" ext="wps"/>
|
||||
<action name="view" ext="wps"/>
|
||||
</app>
|
||||
<app name="application/x-mswrite">
|
||||
<action name="edit" ext="wri"/>
|
||||
<action name="view" ext="wri"/>
|
||||
</app>
|
||||
<app name="application/x-dif-document">
|
||||
<action name="edit" ext="dif"/>
|
||||
|
@ -205,31 +205,31 @@
|
|||
<action name="edit" ext="dbf"/>
|
||||
</app>
|
||||
<app name="application/vnd.lotus-1-2-3">
|
||||
<action name="edit" ext="wk1"/>
|
||||
<action name="view" ext="wk1"/>
|
||||
</app>
|
||||
<app name="image/cgm">
|
||||
<action name="edit" ext="cgm"/>
|
||||
<action name="view" ext="cgm"/>
|
||||
</app>
|
||||
<app name="image/vnd.dxf">
|
||||
<action name="edit" ext="dxf"/>
|
||||
<action name="view" ext="dxf"/>
|
||||
</app>
|
||||
<app name="image/x-emf">
|
||||
<action name="edit" ext="emf"/>
|
||||
<action name="view" ext="emf"/>
|
||||
</app>
|
||||
<app name="image/x-wmf">
|
||||
<action name="edit" ext="wmf"/>
|
||||
<action name="view" ext="wmf"/>
|
||||
</app>
|
||||
<app name="application/coreldraw">
|
||||
<action name="edit" ext="cdr"/>
|
||||
<action name="view" ext="cdr"/>
|
||||
</app>
|
||||
<app name="application/vnd.visio2013">
|
||||
<action name="edit" ext="vsd"/>
|
||||
<action name="view" ext="vsd"/>
|
||||
</app>
|
||||
<app name="application/vnd.visio">
|
||||
<action name="edit" ext="vss"/>
|
||||
<action name="view" ext="vss"/>
|
||||
</app>
|
||||
<app name="application/x-mspublisher">
|
||||
<action name="edit" ext="pub"/>
|
||||
<action name="view" ext="pub"/>
|
||||
</app>
|
||||
</net-zone>
|
||||
</wopi-discovery>
|
||||
|
|
|
@ -0,0 +1,213 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# This file is part of the LibreOffice project.
|
||||
#
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, you can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# Makes sure that discovery.xml in online.git is in sync with
|
||||
# filter/source/config/fragments/ in core.git.
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
import xml.sax
|
||||
|
||||
|
||||
# Parses an online.git discovery.xml.
|
||||
class DiscoveryHandler(xml.sax.handler.ContentHandler):
|
||||
def __init__(self):
|
||||
# List of app <-> action types.
|
||||
self.appActions = []
|
||||
self.inApp = False
|
||||
self.app = None
|
||||
self.inAction = False
|
||||
self.action = None
|
||||
|
||||
def startElement(self, name, attrs):
|
||||
if name == "app":
|
||||
self.inApp = True
|
||||
for k, v in list(attrs.items()):
|
||||
if k == "name":
|
||||
self.app = v
|
||||
elif name == "action":
|
||||
self.inAction = True
|
||||
for k, v in list(attrs.items()):
|
||||
if k == "name":
|
||||
self.action = v
|
||||
|
||||
def endElement(self, name):
|
||||
if name == "app":
|
||||
self.inApp = False
|
||||
if self.app and self.action:
|
||||
self.appActions.append([self.app, self.action])
|
||||
self.app = None
|
||||
self.action = None
|
||||
elif name == "action":
|
||||
self.inAction = False
|
||||
|
||||
|
||||
# Parses core.git filter/source/config/fragments/types/*.xcu.
|
||||
class FilterTypeHandler(xml.sax.handler.ContentHandler):
|
||||
def __init__(self):
|
||||
self.name = None
|
||||
self.inMediaType = False
|
||||
self.content = []
|
||||
self.mediaType = None
|
||||
|
||||
def startElement(self, name, attrs):
|
||||
if name == "node":
|
||||
for k, v in list(attrs.items()):
|
||||
if k == "oor:name":
|
||||
self.name = v
|
||||
elif name == "prop":
|
||||
for k, v in list(attrs.items()):
|
||||
if k == "oor:name" and v == "MediaType":
|
||||
self.inMediaType = True
|
||||
|
||||
def endElement(self, name):
|
||||
if name == "prop" and self.inMediaType:
|
||||
self.inMediaType = False
|
||||
self.mediaType = "".join(self.content).strip()
|
||||
self.content = []
|
||||
|
||||
def characters(self, content):
|
||||
if self.inMediaType:
|
||||
self.content.append(content)
|
||||
|
||||
|
||||
# Parses core.git filter/source/config/fragments/filters/*.xcu.
|
||||
class FilterFragmentHandler(xml.sax.handler.ContentHandler):
|
||||
def __init__(self):
|
||||
self.inType = False
|
||||
self.typeName = None
|
||||
self.inFlags = False
|
||||
self.flags = None
|
||||
self.content = []
|
||||
|
||||
def startElement(self, name, attrs):
|
||||
if name == "prop":
|
||||
for k, v in list(attrs.items()):
|
||||
if k == "oor:name" and v == "Type":
|
||||
self.inType = True
|
||||
elif k == "oor:name" and v == "Flags":
|
||||
self.inFlags = True
|
||||
|
||||
def endElement(self, name):
|
||||
if name == "prop" and self.inType:
|
||||
self.inType = False
|
||||
self.typeName = "".join(self.content).strip()
|
||||
self.content = []
|
||||
elif name == "prop" and self.inFlags:
|
||||
self.inFlags = False
|
||||
encodedFlags = "".join(self.content).strip().encode("utf-8")
|
||||
self.flags = encodedFlags.split(" ")
|
||||
self.content = []
|
||||
|
||||
def characters(self, content):
|
||||
if self.inType or self.inFlags:
|
||||
self.content.append(content)
|
||||
|
||||
|
||||
# Builds a MIME type -> filter flag dictionary.
|
||||
def getFilterFlags(filterDir):
|
||||
# Build a MIME type -> type name dictionary.
|
||||
filterNames = {}
|
||||
typeFragments = os.path.join(filterDir, "types")
|
||||
for typeFragment in os.listdir(typeFragments):
|
||||
if not typeFragment.endswith(".xcu"):
|
||||
continue
|
||||
|
||||
parser = xml.sax.make_parser()
|
||||
filterTypeHandler = FilterTypeHandler()
|
||||
parser.setContentHandler(filterTypeHandler)
|
||||
parser.parse(os.path.join(typeFragments, typeFragment))
|
||||
# Did we find a MIME type?
|
||||
if filterTypeHandler.mediaType:
|
||||
filterNames[filterTypeHandler.mediaType] = filterTypeHandler.name
|
||||
|
||||
# core.git doesn't declares this, but probably this is the intention.
|
||||
filterNames["application/x-dif-document"] = "calc_DIF"
|
||||
filterNames["application/x-dbase"] = "calc_dBase"
|
||||
|
||||
# Build a 'type name' -> 'filter flag list' dictionary.
|
||||
typeNameFlags = {}
|
||||
filterFragments = os.path.join(filterDir, "filters")
|
||||
for filterFragment in os.listdir(filterFragments):
|
||||
if not filterFragment.endswith(".xcu"):
|
||||
continue
|
||||
|
||||
parser = xml.sax.make_parser()
|
||||
handler = FilterFragmentHandler()
|
||||
parser.setContentHandler(handler)
|
||||
parser.parse(os.path.join(filterFragments, filterFragment))
|
||||
typeNameFlags[handler.typeName] = handler.flags
|
||||
|
||||
# Now build the combined MIME type -> filter flags one.
|
||||
filterFlags = {}
|
||||
for i in filterNames.keys():
|
||||
typeName = filterNames[i]
|
||||
if typeName in typeNameFlags.keys():
|
||||
filterFlags[i] = typeNameFlags[typeName]
|
||||
|
||||
return filterFlags
|
||||
|
||||
# How it's described in discovery.xml -> how core.git knows it.
|
||||
mimeTypeAliases = {
|
||||
'application/coreldraw': 'application/vnd.corel-draw',
|
||||
'application/vnd.visio2013': 'application/vnd.visio',
|
||||
}
|
||||
|
||||
# We know that these can be edited.
|
||||
mimeTypeWhiteList = {
|
||||
'application/vnd.ms-excel',
|
||||
'application/vnd.oasis.opendocument.text',
|
||||
'application/msword',
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
discoveryXml = "discovery.xml"
|
||||
repoGuess = os.path.join(os.environ["HOME"], "git/libreoffice/master")
|
||||
filterDir = os.path.join(repoGuess, "filter/source/config/fragments")
|
||||
if len(sys.argv) >= 3:
|
||||
discoveryXml = sys.argv[1]
|
||||
filterDir = sys.arv[2]
|
||||
|
||||
# Parse discovery.xml, which describes what online.git exposes at the
|
||||
# moment.
|
||||
parser = xml.sax.make_parser()
|
||||
discoveryHandler = DiscoveryHandler()
|
||||
parser.setContentHandler(discoveryHandler)
|
||||
parser.parse(discoveryXml)
|
||||
|
||||
# Parse core.git filter definitions to build a MIME type <-> filter flag
|
||||
# dictionary.
|
||||
filterFlags = getFilterFlags(filterDir)
|
||||
|
||||
# Now look up the filter flags in core.git for the MIME type.
|
||||
for i in discoveryHandler.appActions:
|
||||
mimeType = i[0]
|
||||
discoveryAction = i[1]
|
||||
if mimeType in mimeTypeWhiteList:
|
||||
continue
|
||||
if mimeType in mimeTypeAliases.keys():
|
||||
mimeType = mimeTypeAliases[mimeType]
|
||||
if mimeType in filterFlags.keys():
|
||||
flags = filterFlags[mimeType]
|
||||
if "IMPORT" in flags and "EXPORT" in flags:
|
||||
coreAction = "edit"
|
||||
else:
|
||||
coreAction = "view"
|
||||
|
||||
if discoveryAction != coreAction:
|
||||
# Inconsistency found.
|
||||
print("warning: action for '" + mimeType + "' " +
|
||||
"is '" + discoveryAction + "', " +
|
||||
"but it should be '" + coreAction + "'")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|
Loading…
Reference in New Issue