xlnt/source/packaging/manifest.cpp

81 lines
2.8 KiB
C++
Raw Normal View History

2015-12-25 06:10:02 +08:00
// Copyright (c) 2014-2016 Thomas Fussell
// Copyright (c) 2010-2015 openpyxl
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, WRISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE
//
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
2015-11-01 22:48:51 +08:00
#include <algorithm>
#include <stdexcept>
2015-11-01 22:48:51 +08:00
#include <xlnt/packaging/manifest.hpp>
2015-10-30 01:46:56 +08:00
namespace xlnt {
2016-07-30 05:50:33 +08:00
void manifest::clear()
{
default_types_.clear();
override_types_.clear();
}
bool manifest::has_default_type(const std::string &extension) const
2015-10-30 01:46:56 +08:00
{
2016-07-23 10:24:45 +08:00
return default_types_.find(extension) != default_types_.end();
2015-10-30 01:46:56 +08:00
}
bool manifest::has_override_type(const std::string &part_name) const
2015-10-30 01:46:56 +08:00
{
2016-07-23 10:24:45 +08:00
auto absolute = part_name.front() == '/' ? part_name : ("/" + part_name);
return override_types_.find(absolute) != override_types_.end();
2015-10-31 06:54:04 +08:00
}
void manifest::add_default_type(const std::string &extension, const std::string &content_type)
2015-10-31 06:54:04 +08:00
{
2016-07-23 10:24:45 +08:00
default_types_[extension] = default_type(extension, content_type);
2015-10-31 06:54:04 +08:00
}
void manifest::add_override_type(const std::string &part_name, const std::string &content_type)
2015-10-31 06:54:04 +08:00
{
2016-07-23 10:24:45 +08:00
auto absolute = part_name.front() == '/' ? part_name : ("/" + part_name);
override_types_[absolute] = override_type(absolute, content_type);
2015-10-30 01:46:56 +08:00
}
std::string manifest::get_default_type(const std::string &extension) const
2015-10-30 01:46:56 +08:00
{
2016-07-23 10:24:45 +08:00
return default_types_.at(extension).get_content_type();
2015-10-30 01:46:56 +08:00
}
std::string manifest::get_override_type(const std::string &part_name) const
2015-10-30 01:46:56 +08:00
{
2016-07-23 10:24:45 +08:00
auto absolute = part_name.front() == '/' ? part_name : ("/" + part_name);
return override_types_.at(absolute).get_content_type();
2015-10-30 01:46:56 +08:00
}
2016-07-23 10:24:45 +08:00
const std::unordered_map<std::string, default_type> &manifest::get_default_types() const
{
return default_types_;
}
2016-07-23 10:24:45 +08:00
const std::unordered_map<std::string, override_type> &manifest::get_override_types() const
{
return override_types_;
}
2015-10-30 01:46:56 +08:00
} // namespace xlnt