summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-23 00:31:07 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-23 00:31:07 +0100
commitba52f3f4823faf9c73e9445770a44887f3c2b389 (patch)
tree32d427bdb5b4dbf899708fd2daba2be28a763423
parentef59091033b3f69dd01df009f21927b8ad81f5a9 (diff)
Added mimetype by filename lookup to registry
-rw-r--r--src/core/Registry.cpp12
-rw-r--r--src/core/Registry.hpp9
2 files changed, 21 insertions, 0 deletions
diff --git a/src/core/Registry.cpp b/src/core/Registry.cpp
index 88babb7..044668c 100644
--- a/src/core/Registry.cpp
+++ b/src/core/Registry.cpp
@@ -97,6 +97,18 @@ std::string Registry::getMimetypeForExtension(
return std::string{};
}
+std::string Registry::getMimetypeForFilename(const std::string &filename) const
+{
+ // Fetch the file extension
+ std::string ext = Utils::extractFileExtension(path);
+ if (ext.empty()) {
+ return std::string{};
+ }
+
+ // Fetch the mimetype for the extension
+ return ctx.registry.getMimetypeForExtension(ext);
+}
+
void Registry::registerResourceLocator(ResourceLocator *locator)
{
locators.push_back(locator);
diff --git a/src/core/Registry.hpp b/src/core/Registry.hpp
index f932480..4b4cb65 100644
--- a/src/core/Registry.hpp
+++ b/src/core/Registry.hpp
@@ -121,6 +121,15 @@ public:
std::string getMimetypeForExtension(const std::string &extension) const;
/**
+ * Tries to deduce the mimetype from the given filename.
+ *
+ * @param filename is the filename from which the mimetype should be
+ * deduced.
+ * @return the mimetype or an empty string if no filename could be deduced.
+ */
+ std::string getMimetypeForFilename(const std::string &filename) const;
+
+ /**
* Registers a ResourceLocator instance that should be used for locating
* resources. Two registered ResourceLocator should not be capable of
* accessing Resources at the same location. If this happens, the resource