summaryrefslogtreecommitdiff
path: root/desktop/source/app/cmdlineargs.cxx
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2016-07-11 06:38:50 +1000
committerStephan Bergmann <sbergman@redhat.com>2016-07-19 07:01:10 +0000
commitc697ad1a44323e3491451ebdc25019751d8a1bc1 (patch)
tree8426419a2944c3f671ff48e769564df48aa4f60c /desktop/source/app/cmdlineargs.cxx
parent4306e6600623262964c88c1f8f66188896c3d2a6 (diff)
tdf#100837: Support Office URI Schemes
This patch adds support for Office URI Schemes (see https://msdn.microsoft.com/en-us/library/dn906146). This will enable browser (non-CMIS) integration of LibreOffice with MS SharePoint server (v.2013 tested). In this patch, in addition to ms-* schemes, a new scheme is introduced: vnd.libreoffice.command, which is analogous to ms-*. Its purpose is to enable flexible configuration of server and client, where some types of documents are declared as handled by LibreOffice, and other are handled by other software. E.g., ODTs may have "vnd.libreoffice.command" scheme, while DOCXs could be "ms-word". Client may register LibreOffice to handle both, or to handle only "vnd.libreoffice.command" scheme. Unit test included. TODO in a later patch: add a mechanism to register LibreOffice to the schemes with OS. Change-Id: I1c449a211102036f87163058a4c90a93eb32c948 Reviewed-on: https://gerrit.libreoffice.org/27094 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'desktop/source/app/cmdlineargs.cxx')
-rw-r--r--desktop/source/app/cmdlineargs.cxx84
1 files changed, 83 insertions, 1 deletions
diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx
index 344dd4a69ea3..c4ae61a330f5 100644
--- a/desktop/source/app/cmdlineargs.cxx
+++ b/desktop/source/app/cmdlineargs.cxx
@@ -102,6 +102,80 @@ private:
sal_uInt32 m_index;
};
+// Office URI Schemes : see https://msdn.microsoft.com/en-us/library/dn906146
+class OfficeURISchemeCommandLineSupplier : public CommandLineArgs::Supplier {
+public:
+ static bool IsOfficeURI(const OUString& URI, OUString* rest = nullptr)
+ {
+ return ( URI.startsWithIgnoreAsciiCase("vnd.libreoffice.command:", rest) // Proposed extended schema
+ || URI.startsWithIgnoreAsciiCase("ms-word:", rest)
+ || URI.startsWithIgnoreAsciiCase("ms-powerpoint:", rest)
+ || URI.startsWithIgnoreAsciiCase("ms-excel:", rest)
+ || URI.startsWithIgnoreAsciiCase("ms-visio:", rest)
+ || URI.startsWithIgnoreAsciiCase("ms-access:", rest));
+ }
+ OfficeURISchemeCommandLineSupplier(boost::optional< OUString > cwdUrl, const OUString& URI)
+ : m_cwdUrl(cwdUrl)
+ {
+ // 1. Strip the scheme name
+ OUString rest1;
+ bool isOfficeURI = IsOfficeURI(URI, &rest1);
+ assert(isOfficeURI);
+ (void) isOfficeURI;
+
+ OUString rest2;
+ long nURIlen = -1;
+ // 2. Discriminate by command name (incl. 1st command argument descriptor)
+ // Extract URI: everything up to possible next argument
+ if (rest1.startsWith("ofv|u|", &rest2))
+ {
+ // Open for view
+ m_args.push_back("--view");
+ nURIlen = rest2.indexOf("|");
+ }
+ else if (rest1.startsWith("ofe|u|", &rest2))
+ {
+ // Open for editing
+ m_args.push_back("-o");
+ nURIlen = rest2.indexOf("|");
+ }
+ else if (rest1.startsWith("nft|u|", &rest2))
+ {
+ // New from template
+ m_args.push_back("-n");
+ nURIlen = rest2.indexOf("|");
+ // TODO: process optional second argument (default save-to location)
+ // For now, we just ignore it
+ }
+ else
+ {
+ // Abbreviated schema: <scheme-name>:URI
+ // "ofv|u|" implied
+ rest2 = rest1;
+ m_args.push_back("--view");
+ }
+ if (nURIlen < 0)
+ nURIlen = rest2.getLength();
+ m_args.push_back(rest2.copy(0, nURIlen));
+ }
+ virtual ~OfficeURISchemeCommandLineSupplier() {}
+ virtual boost::optional< OUString > getCwdUrl() override { return m_cwdUrl; }
+ virtual bool next(OUString * argument) override {
+ assert(argument != nullptr);
+ if (m_index < m_args.size()) {
+ *argument = m_args[m_index++];
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+private:
+ boost::optional< OUString > m_cwdUrl;
+ std::vector< OUString > m_args;
+ std::vector< OUString >::size_type m_index = 0;
+};
+
}
CommandLineArgs::Supplier::Exception::Exception() {}
@@ -538,7 +612,15 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier )
else
{
// handle this argument as a filename
- if ( bOpenEvent )
+
+ // 1. Check if this is an Office URI
+ if (!bDisplaySpec && OfficeURISchemeCommandLineSupplier::IsOfficeURI(aArg))
+ {
+ OfficeURISchemeCommandLineSupplier OfficeURISupplier(getCwdUrl(), aArg);
+ // Add the file according its command, ignore current event
+ ParseCommandLine_Impl(OfficeURISupplier);
+ }
+ else if ( bOpenEvent )
{
m_openlist.push_back(aArg);
bOpenDoc = true;