summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tools/urlobj.hxx11
-rw-r--r--tools/qa/cppunit/test_urlobj.cxx40
-rw-r--r--tools/source/fsys/urlobj.cxx16
3 files changed, 67 insertions, 0 deletions
diff --git a/include/tools/urlobj.hxx b/include/tools/urlobj.hxx
index 77786661152d..d487851eb575 100644
--- a/include/tools/urlobj.hxx
+++ b/include/tools/urlobj.hxx
@@ -390,6 +390,17 @@ public:
inline INetProtocol GetProtocol() const { return m_eScheme; }
+ bool isSchemeEqualTo(INetProtocol scheme) const { return scheme == m_eScheme; }
+
+ bool isSchemeEqualTo(OUString const & scheme) const;
+
+ /** Check if the scheme is one of the WebDAV scheme
+ * we know about.
+ *
+ * @return true is one othe scheme either public scheme or private scheme.
+ */
+ bool isAnyKnownWebDAVScheme() const;
+
/** Return the URL 'prefix' for a given scheme.
@param eTheScheme One of the supported URL schemes.
diff --git a/tools/qa/cppunit/test_urlobj.cxx b/tools/qa/cppunit/test_urlobj.cxx
index b591156b52c7..6115bc896481 100644
--- a/tools/qa/cppunit/test_urlobj.cxx
+++ b/tools/qa/cppunit/test_urlobj.cxx
@@ -329,6 +329,44 @@ namespace tools_urlobj
CPPUNIT_ASSERT(strm == 0);
}
+ void urlobjTest_isSchemeEqualTo() {
+ CPPUNIT_ASSERT(INetURLObject().isSchemeEqualTo(INetProtocol::NotValid));
+ CPPUNIT_ASSERT(!INetURLObject().isSchemeEqualTo(""));
+ CPPUNIT_ASSERT(
+ INetURLObject("http://example.org").isSchemeEqualTo(
+ INetProtocol::Http));
+ CPPUNIT_ASSERT(
+ !INetURLObject("http://example.org").isSchemeEqualTo(
+ INetProtocol::Https));
+ CPPUNIT_ASSERT(
+ INetURLObject("http://example.org").isSchemeEqualTo("Http"));
+ CPPUNIT_ASSERT(
+ !INetURLObject("http://example.org").isSchemeEqualTo("dav"));
+ CPPUNIT_ASSERT(
+ INetURLObject("dav://example.org").isSchemeEqualTo("dav"));
+ }
+
+ void urlobjTest_isAnyKnownWebDAVScheme() {
+ CPPUNIT_ASSERT(
+ INetURLObject("http://example.org").isAnyKnownWebDAVScheme());
+ CPPUNIT_ASSERT(
+ INetURLObject("https://example.org").isAnyKnownWebDAVScheme());
+ CPPUNIT_ASSERT(
+ INetURLObject("vnd.sun.star.webdav://example.org").isAnyKnownWebDAVScheme());
+ CPPUNIT_ASSERT(
+ INetURLObject("vnd.sun.star.webdavs://example.org").isAnyKnownWebDAVScheme());
+ CPPUNIT_ASSERT(
+ !INetURLObject("ftp://example.org").isAnyKnownWebDAVScheme());
+ CPPUNIT_ASSERT(
+ !INetURLObject("file://example.org").isAnyKnownWebDAVScheme());
+ CPPUNIT_ASSERT(
+ !INetURLObject("dav://example.org").isAnyKnownWebDAVScheme());
+ CPPUNIT_ASSERT(
+ !INetURLObject("davs://example.org").isAnyKnownWebDAVScheme());
+ CPPUNIT_ASSERT(
+ !INetURLObject("vnd.sun.star.pkg://example.org").isAnyKnownWebDAVScheme());
+ }
+
// Change the following lines only, if you add, remove or rename
// member functions of the current class,
// because these macros are need by auto register mechanism.
@@ -343,6 +381,8 @@ namespace tools_urlobj
CPPUNIT_TEST( urlobjCmisTest );
CPPUNIT_TEST( urlobjTest_emptyPath );
CPPUNIT_TEST( urlobjTest_data );
+ CPPUNIT_TEST( urlobjTest_isSchemeEqualTo );
+ CPPUNIT_TEST( urlobjTest_isAnyKnownWebDAVScheme );
CPPUNIT_TEST_SUITE_END( );
}; // class createPool
diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx
index 51887b7b722e..115d6760fb71 100644
--- a/tools/source/fsys/urlobj.cxx
+++ b/tools/source/fsys/urlobj.cxx
@@ -3911,6 +3911,22 @@ OUString INetURLObject::getExternalURL(DecodeMechanism eMechanism,
return aTheExtURIRef;
}
+bool INetURLObject::isSchemeEqualTo(OUString const & scheme) const {
+ return m_aScheme.isPresent()
+ && (rtl_ustr_compareIgnoreAsciiCase_WithLength(
+ scheme.getStr(), scheme.getLength(),
+ m_aAbsURIRef.getStr() + m_aScheme.getBegin(),
+ m_aScheme.getLength())
+ == 0);
+}
+
+bool INetURLObject::isAnyKnownWebDAVScheme() const {
+ return ( isSchemeEqualTo( INetProtocol::Http ) ||
+ isSchemeEqualTo( INetProtocol::Https ) ||
+ isSchemeEqualTo( INetProtocol::VndSunStarWebdav ) ||
+ isSchemeEqualTo( "vnd.sun.star.webdavs" ) );
+}
+
// static
OUString INetURLObject::GetScheme(INetProtocol eTheScheme)
{