23 #include <itksys/SystemTools.hxx>
27 class FindCaseInsensitive
30 FindCaseInsensitive(std::string value)
32 lcValue.resize(value.size());
33 std::transform(value.begin(), value.end(), lcValue.begin(), ::tolower);
36 bool operator()(std::string elem)
38 std::transform(elem.begin(), elem.end(), elem.begin(), ::tolower);
39 return elem == lcValue;
46 struct CustomMimeType::Impl
49 std::string m_Category;
50 std::vector<std::string> m_Extensions;
51 std::string m_Comment;
85 if (!d->m_Comment.empty())
87 if (!d->m_Extensions.empty())
89 return d->m_Extensions.front() +
" File";
98 return ParsePathForExtension(path, extension, filename);
104 ParsePathForExtension(path, extension, filename);
111 ParsePathForExtension(path, extension, filename);
115 bool CustomMimeType::ParsePathForExtension(
const std::string &path,
116 std::string &extension,
119 for (std::vector<std::string>::const_iterator iter = d->m_Extensions.begin(), iterEnd = d->m_Extensions.end();
123 if (!iter->empty() && path.size() >= iter->size())
125 FindCaseInsensitive cmp(*iter);
126 if (cmp(path.substr(path.size() - iter->size())))
128 extension =
"." + *iter;
129 std::string filenameWithExtension = itksys::SystemTools::GetFilenameName(path);
130 filename = filenameWithExtension.substr(0, filenameWithExtension.size() - extension.size());
142 d->m_Extensions.clear();
143 d->m_Extensions.push_back(extension);
148 if (std::find_if(d->m_Extensions.begin(), d->m_Extensions.end(), FindCaseInsensitive(extension)) ==
149 d->m_Extensions.end())
151 d->m_Extensions.push_back(extension);
std::vector< std::string > GetExtensions() const
Returns all extensions that this MimeType can handle.
bool MatchesExtension(const std::string &path) const
Checks if the MimeType can handle the etension of the given path.
std::string GetFilenameWithoutExtension(const std::string &path) const
Provides the filename minus the extension.
std::string GetCategory() const
Returns the human-readable Category of the mime-type. Allows grouping of similar mime-types (like Sur...
CustomMimeType & operator=(const CustomMimeType &other)
void SetExtension(const std::string &extension)
DataCollection - Class to facilitate loading/accessing structured data.
virtual bool AppliesTo(const std::string &path) const
Checks if the MimeType can handle file at the given location.
std::vector< std::string > GetExtensions() const
void SetComment(const std::string &comment)
std::string GetName() const
std::string GetComment() const
Returns the Human readable comment of the MimeType, a string that describes its unique role...
The CustomMimeType class represents a custom mime-type which may be registered as a service object...
virtual CustomMimeType * Clone() const
static const std::string filename
std::string GetName() const
Returns the unique name for the MimeType.
void swap(CustomMimeType &l, CustomMimeType &r)
virtual ~CustomMimeType()
void AddExtension(const std::string &extension)
The MimeType class represens a registered mime-type. It is an immutable wrapper for mitk::CustomMimeT...
void SetCategory(const std::string &category)
std::string GetExtension(const std::string &path) const
Provides the first matching extension.
void Swap(CustomMimeType &r)
std::string GetComment() const
std::string GetCategory() const
void SetName(const std::string &name)