From 8526058d24faec5f83ffd66758fef8d8c8159f73 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 13 May 2013 15:57:00 +0100 Subject: Use libxml++ for writing XML. --- src/dcp.cc | 92 ++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 44 insertions(+), 48 deletions(-) (limited to 'src/dcp.cc') diff --git a/src/dcp.cc b/src/dcp.cc index 7a43e9b2..c7634b5d 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -28,6 +28,7 @@ #include #include #include +#include #include #include "dcp.h" #include "asset.h" @@ -48,6 +49,7 @@ using std::stringstream; using std::ofstream; using std::ostream; using boost::shared_ptr; +using boost::lexical_cast; using namespace libdcp; DCP::DCP (string directory) @@ -80,30 +82,29 @@ DCP::write_pkl (string pkl_uuid, XMLMetadata const & metadata) const stringstream s; s << pkl_uuid << "_pkl.xml"; p /= s.str(); - ofstream pkl (p.string().c_str()); - - pkl << "\n" - << "\n" - << " urn:uuid:" << pkl_uuid << "\n" - /* XXX: this is a bit of a hack */ - << " " << _cpls.front()->name() << "\n" - << " " << metadata.issue_date << "\n" - << " " << metadata.issuer << "\n" - << " " << metadata.creator << "\n" - << " \n"; + + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("PackingList", "http://www.smpte-ra.org/schemas/429-8/2007/PKL"); + + root->add_child("Id")->add_child_text ("urn:uuid:" + pkl_uuid); + /* XXX: this is a bit of a hack */ + root->add_child("AnnotationText")->add_child_text (_cpls.front()->name()); + root->add_child("IssueDate")->add_child_text (metadata.issue_date); + root->add_child("Issuer")->add_child_text (metadata.issuer); + root->add_child("Creator")->add_child_text (metadata.creator); + + xmlpp::Node* asset_list = root->add_child ("AssetList"); list > a = assets (); for (list >::const_iterator i = a.begin(); i != a.end(); ++i) { - (*i)->write_to_pkl (pkl); + (*i)->write_to_pkl (asset_list); } for (list >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { - (*i)->write_to_pkl (pkl); + (*i)->write_to_pkl (asset_list); } - pkl << " \n" - << "\n"; - + doc.write_to_file_formatted (p.string (), "UTF-8"); return p.string (); } @@ -113,12 +114,11 @@ DCP::write_volindex () const boost::filesystem::path p; p /= _directory; p /= "VOLINDEX.xml"; - ofstream vi (p.string().c_str()); - vi << "\n" - << "\n" - << " 1\n" - << "\n"; + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("VolumeIndex", "http://www.smpte-ra.org/schemas/429-9/2007/AM"); + root->add_child("Index")->add_child_text ("1"); + doc.write_to_file_formatted (p.string (), "UTF-8"); } void @@ -127,41 +127,37 @@ DCP::write_assetmap (string pkl_uuid, int pkl_length, XMLMetadata const & metada boost::filesystem::path p; p /= _directory; p /= "ASSETMAP.xml"; - ofstream am (p.string().c_str()); - - am << "\n" - << "\n" - << " urn:uuid:" << make_uuid() << "\n" - << " " << metadata.creator << "\n" - << " 1\n" - << " " << metadata.issue_date << "\n" - << " " << metadata.issuer << "\n" - << " \n"; - - am << " \n" - << " urn:uuid:" << pkl_uuid << "\n" - << " true\n" - << " \n" - << " \n" - << " " << pkl_uuid << "_pkl.xml\n" - << " 1\n" - << " 0\n" - << " " << pkl_length << "\n" - << " \n" - << " \n" - << " \n"; + + xmlpp::Document doc; + xmlpp::Element* root = doc.create_root_node ("AssetMap", "http://www.smpte-ra.org/schemas/429-9/2007/AM"); + + root->add_child("Id")->add_child_text ("urn:uuid:" + make_uuid()); + root->add_child("Creator")->add_child_text (metadata.creator); + root->add_child("VolumeCount")->add_child_text ("1"); + root->add_child("IssueDate")->add_child_text (metadata.issue_date); + root->add_child("Issuer")->add_child_text (metadata.issuer); + xmlpp::Node* asset_list = root->add_child ("AssetList"); + + xmlpp::Node* asset = asset_list->add_child ("Asset"); + asset->add_child("Id")->add_child_text ("urn:uuid:" + pkl_uuid); + asset->add_child("PackingList")->add_child_text ("true"); + xmlpp::Node* chunk_list = asset->add_child ("ChunkList"); + xmlpp::Node* chunk = chunk_list->add_child ("Chunk"); + chunk->add_child("Path")->add_child_text (pkl_uuid + "_pkl.xml"); + chunk->add_child("VolumeIndex")->add_child_text ("1"); + chunk->add_child("Offset")->add_child_text ("0"); + chunk->add_child("Length")->add_child_text (lexical_cast (pkl_length)); for (list >::const_iterator i = _cpls.begin(); i != _cpls.end(); ++i) { - (*i)->write_to_assetmap (am); + (*i)->write_to_assetmap (asset_list); } list > a = assets (); for (list >::const_iterator i = a.begin(); i != a.end(); ++i) { - (*i)->write_to_assetmap (am); + (*i)->write_to_assetmap (asset_list); } - am << " \n" - << "\n"; + doc.write_to_file_formatted (p.string (), "UTF-8"); } -- cgit v1.2.3