Normalise XML attribute names to be camelCase (#2241).
authorCarl Hetherington <cth@carlh.net>
Sat, 10 Sep 2022 22:10:22 +0000 (00:10 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 3 Oct 2022 15:53:00 +0000 (17:53 +0200)
src/lib/audio_analysis.cc
src/lib/audio_mapping.cc
src/lib/config.cc
src/lib/dkdm_wrapper.cc
src/lib/film.cc
src/lib/text_content.cc
src/lib/util.h
test/config_test.cc
test/data

index 721ffed07c6e28464ddb159877527c39c8d712db..1fa084de41077f0725f52d3557e81c44ebb6aafb 100644 (file)
@@ -84,11 +84,8 @@ AudioAnalysis::AudioAnalysis (boost::filesystem::path filename)
        }
 
        for (auto i: f.node_children ("SamplePeak")) {
-               _sample_peak.push_back (
-                       PeakTime(
-                               dcp::raw_convert<float>(i->content()), DCPTime(i->number_attribute<Frame>("Time"))
-                               )
-                       );
+               auto const time = number_attribute<Frame>(i, "Time", "time");
+               _sample_peak.push_back(PeakTime(dcp::raw_convert<float>(i->content()), DCPTime(time)));
        }
 
        for (auto i: f.node_children("TruePeak")) {
@@ -155,7 +152,7 @@ AudioAnalysis::write (boost::filesystem::path filename)
        for (size_t i = 0; i < _sample_peak.size(); ++i) {
                auto n = root->add_child("SamplePeak");
                n->add_child_text (raw_convert<string> (_sample_peak[i].peak));
-               n->set_attribute ("Time", raw_convert<string> (_sample_peak[i].time.get()));
+               n->set_attribute("time", raw_convert<string> (_sample_peak[i].time.get()));
        }
 
        for (auto i: _true_peak) {
index 5e8bf4d04713de054caddefd383eb18167b71395..3a1809ae88a89efb04da8b9fd85916cc2085dd8f 100644 (file)
@@ -169,8 +169,8 @@ AudioMapping::AudioMapping (cxml::ConstNodePtr node, int state_version)
                                        );
                        } else {
                                set (
-                                       i->number_attribute<int>("Input"),
-                                       i->number_attribute<int>("Output"),
+                                       number_attribute<int>(i, "Input", "input"),
+                                       number_attribute<int>(i, "Output", "output"),
                                        raw_convert<float>(i->content())
                                        );
                        }
@@ -227,8 +227,8 @@ AudioMapping::as_xml (xmlpp::Node* node) const
        for (int c = 0; c < _input_channels; ++c) {
                for (int d = 0; d < _output_channels; ++d) {
                        auto t = node->add_child ("Gain");
-                       t->set_attribute ("Input", raw_convert<string> (c));
-                       t->set_attribute ("Output", raw_convert<string> (d));
+                       t->set_attribute("input", raw_convert<string>(c));
+                       t->set_attribute("output", raw_convert<string>(d));
                        t->add_child_text (raw_convert<string> (get (c, d)));
                }
        }
index eeb009594a0d1db48b905d78cb9331cdaa3aafd7..d7add48a3692b131e9e2bbd3014394ae7bc6a8d7 100644 (file)
@@ -473,7 +473,7 @@ try
           of the nags.
        */
        for (auto i: f.node_children("Nagged")) {
-               auto const id = i->number_attribute<int>("Id");
+               auto const id = number_attribute<int>(i, "Id", "id");
                if (id >= 0 && id < NAG_COUNT) {
                        _nagged[id] = raw_convert<int>(i->content());
                }
@@ -544,7 +544,7 @@ try
        _default_notify = f.optional_bool_child("DefaultNotify").get_value_or(false);
 
        for (auto i: f.node_children("Notification")) {
-               int const id = i->number_attribute<int>("Id");
+               int const id = number_attribute<int>(i, "Id", "id");
                if (id >= 0 && id < NOTIFICATION_COUNT) {
                        _notification[id] = raw_convert<int>(i->content());
                }
@@ -924,7 +924,7 @@ Config::write_config () const
        /* [XML] Nagged 1 if a particular nag screen has been shown and should not be shown again, otherwise 0. */
        for (int i = 0; i < NAG_COUNT; ++i) {
                xmlpp::Element* e = root->add_child ("Nagged");
-               e->set_attribute ("Id", raw_convert<string>(i));
+               e->set_attribute("id", raw_convert<string>(i));
                e->add_child_text (_nagged[i] ? "1" : "0");
        }
        /* [XML] PreviewSound 1 to use sound in the GUI preview and player, otherwise 0. */
@@ -979,7 +979,7 @@ Config::write_config () const
        /* [XML] Notification 1 if a notification type is enabled, otherwise 0. */
        for (int i = 0; i < NOTIFICATION_COUNT; ++i) {
                xmlpp::Element* e = root->add_child ("Notification");
-               e->set_attribute ("Id", raw_convert<string>(i));
+               e->set_attribute("id", raw_convert<string>(i));
                e->add_child_text (_notification[i] ? "1" : "0");
        }
 
index 532bbb314f9a4ba9aa5c089097b8cc6bceafcf91..5e423eb5f53d6a85c73e2718616ae399d47fceed 100644 (file)
@@ -41,7 +41,11 @@ DKDMBase::read (cxml::ConstNodePtr node)
        if (node->name() == "DKDM") {
                return make_shared<DKDM>(dcp::EncryptedKDM(node->content()));
        } else if (node->name() == "DKDMGroup") {
-               auto group = make_shared<DKDMGroup>(node->string_attribute("Name"));
+               auto name = node->optional_string_attribute("Name");
+               if (!name) {
+                       name = node->string_attribute("name");
+               }
+               auto group = make_shared<DKDMGroup>(*name);
                for (auto i: node->node_children()) {
                        if (auto c = read(i)) {
                                group->add (c);
@@ -72,7 +76,7 @@ void
 DKDMGroup::as_xml (xmlpp::Element* node) const
 {
        auto f = node->add_child("DKDMGroup");
-       f->set_attribute ("Name", _name);
+       f->set_attribute("name", _name);
        for (auto i: _children) {
                i->as_xml (f);
        }
index d5597b5a12dfa49b13255fd49b42f7fd38a65977..6f19418b56579883c48b343efb52215cbc09b077 100644 (file)
@@ -425,7 +425,7 @@ Film::metadata (bool with_content_paths) const
        root->add_child("UserExplicitVideoFrameRate")->add_child_text(_user_explicit_video_frame_rate ? "1" : "0");
        for (map<dcp::Marker, DCPTime>::const_iterator i = _markers.begin(); i != _markers.end(); ++i) {
                auto m = root->add_child("Marker");
-               m->set_attribute("Type", dcp::marker_to_string(i->first));
+               m->set_attribute("type", dcp::marker_to_string(i->first));
                m->add_child_text(raw_convert<string>(i->second.get()));
        }
        for (auto i: _ratings) {
@@ -605,7 +605,11 @@ Film::read_metadata (optional<boost::filesystem::path> path)
        _user_explicit_video_frame_rate = f.optional_bool_child("UserExplicitVideoFrameRate").get_value_or(false);
 
        for (auto i: f.node_children("Marker")) {
-               _markers[dcp::marker_from_string(i->string_attribute("Type"))] = DCPTime(dcp::raw_convert<DCPTime::Type>(i->content()));
+               auto type = i->optional_string_attribute("Type");
+               if (!type) {
+                       type = i->string_attribute("type");
+               }
+               _markers[dcp::marker_from_string(*type)] = DCPTime(dcp::raw_convert<DCPTime::Type>(i->content()));
        }
 
        for (auto i: f.node_children("Rating")) {
index a85b271a88d23dbfca216491e5777e701c720f03..d4468f7e5eb4a3fc4e1baaf9dc685b3ebbdb9b75 100644 (file)
@@ -236,8 +236,11 @@ TextContent::TextContent (Content* parent, cxml::ConstNodePtr node, int version,
        if (lang) {
                try {
                        _language = dcp::LanguageTag(lang->content());
-                       auto add = lang->optional_bool_attribute("Additional");
-                       _language_is_additional = add && *add;
+                       auto additional = lang->optional_bool_attribute("Additional");
+                       if (!additional) {
+                               additional = lang->optional_bool_attribute("additional");
+                       }
+                       _language_is_additional = additional.get_value_or(false);
                } catch (dcp::LanguageTagError&) {
                        /* The language tag can be empty or invalid if it was loaded from a
                         * 2.14.x metadata file; we'll just ignore it in that case.
@@ -410,7 +413,7 @@ TextContent::as_xml (xmlpp::Node* root) const
        if (_language) {
                auto lang = text->add_child("Language");
                lang->add_child_text (_language->to_string());
-               lang->set_attribute ("Additional", _language_is_additional ? "1" : "0");
+               lang->set_attribute("additional", _language_is_additional ? "1" : "0");
        }
 }
 
index c62b98df65c140cfcedc90d13cbfca36e45dd181..7e7a7b96bcadded154f19d924cfdcd3667e096a7 100644 (file)
@@ -32,6 +32,7 @@
 #include "dcpomatic_time.h"
 #include "pixel_quanta.h"
 #include "types.h"
+#include <libcxml/cxml.h>
 #include <dcp/atmos_asset.h>
 #include <dcp/decrypted_kdm.h>
 #include <dcp/util.h>
@@ -150,4 +151,15 @@ list_to_vector (std::list<T> v)
        return l;
 }
 
+template <class T>
+T
+number_attribute(cxml::ConstNodePtr node, std::string name1, std::string name2)
+{
+       auto value = node->optional_number_attribute<T>(name1);
+       if (!value) {
+               value = node->number_attribute<T>(name2);
+       }
+       return *value;
+}
+
 #endif
index 062c1849ac331b9ae97e45c0c6bbd0f96ba04b04..884f3cb0867b8b5c90c622a8f53255c1fcdbc236 100644 (file)
@@ -208,7 +208,11 @@ BOOST_AUTO_TEST_CASE (config_upgrade_test2)
        boost::filesystem::remove_all (dir);
        boost::filesystem::create_directories (dir);
 
+#ifdef DCPOMATIC_WINDOWS
+       boost::filesystem::copy_file("test/data/2.16.config.windows.xml", dir / "config.xml");
+#else
        boost::filesystem::copy_file("test/data/2.16.config.xml", dir / "config.xml");
+#endif
        boost::filesystem::copy_file("test/data/2.14.cinemas.xml", dir / "cinemas.xml");
        Config::instance();
        try {
@@ -216,13 +220,14 @@ BOOST_AUTO_TEST_CASE (config_upgrade_test2)
                Config::instance()->write();
        } catch (...) {}
 
-       check_xml(dir / "config.xml", "test/data/2.16.config.xml", {});
        check_xml(dir / "cinemas.xml", "test/data/2.14.cinemas.xml", {});
 #ifdef DCPOMATIC_WINDOWS
        /* This file has the windows path for dkdm_recipients.xml (with backslashes) */
        check_xml(dir / "2.18" / "config.xml", "test/data/2.18.config.windows.xml", {});
+       check_xml(dir / "config.xml", "test/data/2.16.config.windows.xml", {});
 #else
        check_xml(dir / "2.18" / "config.xml", "test/data/2.18.config.xml", {});
+       check_xml(dir / "config.xml", "test/data/2.16.config.xml", {});
 #endif
        /* cinemas.xml is not copied into 2.18 as its format has not changed */
        BOOST_REQUIRE (!boost::filesystem::exists(dir / "2.18" / "cinemas.xml"));
index de17df3f7bd06e08abd557d8f92a144d66303d7c..e9b91e12e1a951632f6b5fcb8909ba5203131e17 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit de17df3f7bd06e08abd557d8f92a144d66303d7c
+Subproject commit e9b91e12e1a951632f6b5fcb8909ba5203131e17