2015-10-30 01:46:56 +08:00
|
|
|
#include <xlnt/s11n/manifest_serializer.hpp>
|
|
|
|
#include <xlnt/s11n/xml_document.hpp>
|
2015-10-31 06:54:04 +08:00
|
|
|
#include <xlnt/s11n/xml_node.hpp>
|
2015-10-30 01:46:56 +08:00
|
|
|
#include <xlnt/workbook/manifest.hpp>
|
|
|
|
|
|
|
|
#include "detail/constants.hpp"
|
|
|
|
|
|
|
|
namespace xlnt {
|
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
manifest_serializer::manifest_serializer(manifest &m) : manifest_(m)
|
2015-10-30 01:46:56 +08:00
|
|
|
{
|
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void manifest_serializer::read_manifest(const xml_document &xml)
|
|
|
|
{
|
|
|
|
const auto root_node = xml.get_child("Types");
|
2015-10-30 01:46:56 +08:00
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
for(const auto child : root_node.get_children())
|
|
|
|
{
|
|
|
|
if(child.get_name() == "Default")
|
|
|
|
{
|
|
|
|
manifest_.add_default_type(child.get_attribute("Extension"), child.get_attribute("ContentType"));
|
|
|
|
}
|
|
|
|
else if(child.get_name() == "Override")
|
|
|
|
{
|
|
|
|
manifest_.add_override_type(child.get_attribute("PartName"), child.get_attribute("ContentType"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xml_document manifest_serializer::write_manifest() const
|
|
|
|
{
|
|
|
|
xml_document xml;
|
|
|
|
|
|
|
|
auto root_node = xml.add_child("Types");
|
|
|
|
xml.add_namespace("", constants::Namespaces.at("content-types"));
|
|
|
|
|
|
|
|
for(const auto default_type : manifest_.get_default_types())
|
2015-10-30 01:46:56 +08:00
|
|
|
{
|
|
|
|
auto type_node = root_node.add_child("Default");
|
|
|
|
type_node.add_attribute("Extension", default_type.get_extension());
|
2015-10-31 06:54:04 +08:00
|
|
|
type_node.add_attribute("ContentType", default_type.get_content_type());
|
2015-10-30 01:46:56 +08:00
|
|
|
}
|
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
for(const auto override_type : manifest_.get_override_types())
|
2015-10-30 01:46:56 +08:00
|
|
|
{
|
|
|
|
auto type_node = root_node.add_child("Override");
|
|
|
|
type_node.add_attribute("PartName", override_type.get_part_name());
|
|
|
|
type_node.add_attribute("ContentType", override_type.get_content_type());
|
|
|
|
}
|
|
|
|
|
2015-10-31 06:54:04 +08:00
|
|
|
return xml;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string manifest_serializer::determine_document_type() const
|
|
|
|
{
|
|
|
|
if(!manifest_.has_override_type(constants::ArcWorkbook))
|
|
|
|
{
|
|
|
|
return "unsupported";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string type = manifest_.get_override_type(constants::ArcWorkbook);
|
|
|
|
|
|
|
|
if(type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml")
|
|
|
|
{
|
|
|
|
return "excel";
|
|
|
|
}
|
|
|
|
else if(type == "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml")
|
|
|
|
{
|
|
|
|
return "powerpoint";
|
|
|
|
}
|
|
|
|
else if(type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml")
|
|
|
|
{
|
|
|
|
return "word";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "unsupported";
|
2015-10-30 01:46:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace xlnt
|