From 0bab7b928a212f095ef040cf34a984d3797871fa Mon Sep 17 00:00:00 2001 From: fgerlits Date: Fri, 15 Sep 2006 16:16:12 +0000 Subject: [PATCH] adding more metadata checking stuff; this fixes #1802 --- livesupport/src/modules/core/etc/Makefile.in | 4 +- .../core/etc/metadataTypeContainer.xml | 280 +++++++++------- .../LiveSupport/Core/MetadataTypeContainer.h | 6 +- .../core/src/EnumerationConstraint.cxx | 134 ++++++++ .../modules/core/src/EnumerationConstraint.h | 174 ++++++++++ .../modules/core/src/MetadataConstraint.cxx | 13 +- .../core/src/MetadataTypeContainer.cxx | 4 +- .../core/src/MetadataTypeContainerTest.cxx | 28 +- .../modules/core/src/NumericConstraint.cxx | 10 +- .../src/modules/core/src/NumericConstraint.h | 13 +- .../core/src/NumericRangeConstraint.cxx | 161 +++++++++ .../modules/core/src/NumericRangeConstraint.h | 194 +++++++++++ .../gLiveSupport/etc/gLiveSupport.xml | 315 ++++++++++-------- .../etc/gLiveSupport.xml.template | 315 ++++++++++-------- .../etc/gLiveSupport.xml.user-template | 315 ++++++++++-------- .../gLiveSupport/src/UploadFileWindow.cxx | 16 +- .../src/products/gLiveSupport/var/root.txt | 1 + 17 files changed, 1394 insertions(+), 589 deletions(-) create mode 100644 livesupport/src/modules/core/src/EnumerationConstraint.cxx create mode 100644 livesupport/src/modules/core/src/EnumerationConstraint.h create mode 100644 livesupport/src/modules/core/src/NumericRangeConstraint.cxx create mode 100644 livesupport/src/modules/core/src/NumericRangeConstraint.h diff --git a/livesupport/src/modules/core/etc/Makefile.in b/livesupport/src/modules/core/etc/Makefile.in index ee45c8875..d082dd252 100644 --- a/livesupport/src/modules/core/etc/Makefile.in +++ b/livesupport/src/modules/core/etc/Makefile.in @@ -143,7 +143,9 @@ CORE_LIB_OBJS = ${TMP_DIR}/UniqueId.o \ ${TMP_DIR}/FileTools.o \ ${TMP_DIR}/AsyncState.o \ ${TMP_DIR}/MetadataConstraint.o \ - ${TMP_DIR}/NumericConstraint.o + ${TMP_DIR}/NumericConstraint.o \ + ${TMP_DIR}/NumericRangeConstraint.o \ + ${TMP_DIR}/EnumerationConstraint.o TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \ ${TMP_DIR}/FileToolsTest.o \ diff --git a/livesupport/src/modules/core/etc/metadataTypeContainer.xml b/livesupport/src/modules/core/etc/metadataTypeContainer.xml index 555446ff8..e0f16dfb5 100644 --- a/livesupport/src/modules/core/etc/metadataTypeContainer.xml +++ b/livesupport/src/modules/core/etc/metadataTypeContainer.xml @@ -12,153 +12,201 @@ - + ]> - - - - - + + + 0 + 3000 + - - - - - + + + mp3 + mpeg + ogg + - - - - - + + - - + + + + + - - - - - - + + - - + + + + + - - + + + - - - - - - - - - - - - - - - + + + + + diff --git a/livesupport/src/modules/core/include/LiveSupport/Core/MetadataTypeContainer.h b/livesupport/src/modules/core/include/LiveSupport/Core/MetadataTypeContainer.h index bd0a39088..4c52d6bc8 100644 --- a/livesupport/src/modules/core/include/LiveSupport/Core/MetadataTypeContainer.h +++ b/livesupport/src/modules/core/include/LiveSupport/Core/MetadataTypeContainer.h @@ -248,15 +248,15 @@ class MetadataTypeContainer : public Configurable, * If the metadata type has no constraints, it returns true. * If the constraint throws an exception, it returns false. * - * @param dcName the metadata type, by its Dublin Core name. * @param value the value to be checked against the constraint. + * @param dcName the metadata type, by its Dublin Core name. * @return true if the value satisfies the constraint. * @exception std::invalid_argument if no metadata type exists * with the suplied name. */ bool - check(const Glib::ustring & dcName, - Ptr::Ref value) + check(Ptr::Ref value, + const Glib::ustring & dcName) throw (std::invalid_argument); }; diff --git a/livesupport/src/modules/core/src/EnumerationConstraint.cxx b/livesupport/src/modules/core/src/EnumerationConstraint.cxx new file mode 100644 index 000000000..9d1ad92c6 --- /dev/null +++ b/livesupport/src/modules/core/src/EnumerationConstraint.cxx @@ -0,0 +1,134 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author$ + Version : $Revision$ + Location : $URL$ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#include "EnumerationConstraint.h" + + +using namespace LiveSupport::Core; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +namespace { + +/*------------------------------------------------------------------------------ + * The value of the type attribute for this class. + *----------------------------------------------------------------------------*/ +const std::string typeAttributeValue = "enumeration"; + +} + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Create a constraint element object based on an XML element. + *----------------------------------------------------------------------------*/ +void +EnumerationConstraint :: configure(const xmlpp::Element & element) + throw (std::invalid_argument) +{ + if (element.get_name() != getConfigElementName()) { + throw std::invalid_argument("bad configuration element " + + element.get_name()); + } + + const xmlpp::Attribute* typeAttribute; + if (!(typeAttribute = element.get_attribute(typeAttributeName))) { + throw std::invalid_argument("missing attribute " + typeAttributeName); + } + std::string type = typeAttribute->get_value(); + + if (type != typeAttributeValue) { + throw std::invalid_argument(typeAttributeValue + + " constraint configured with a" + + " constraint element of type " + + type); + } + + xmlpp::Node::NodeList childNodes = element.get_children(valueElementName); + xmlpp::Node::NodeList::iterator it = childNodes.begin(); + + if (it == childNodes.end()) { + throw std::invalid_argument("empty enumeration constraint"); + } + + for (; it != childNodes.end(); ++it) { + readValue(*it); + } +} + + +/*------------------------------------------------------------------------------ + * Read an enumeration value from an XML node. + *----------------------------------------------------------------------------*/ +void +EnumerationConstraint :: readValue(const xmlpp::Node * node) + throw (std::invalid_argument) +{ + const xmlpp::Element * valueElement + = dynamic_cast (node); + if (valueElement) { + allowedValues.push_back(valueElement->get_child_text() + ->get_content() ); + } else { + throw std::invalid_argument("bad sub-element found in constraint"); + } +} + + +/*------------------------------------------------------------------------------ + * Check that the given value satisfies the constraint. + *----------------------------------------------------------------------------*/ +bool +EnumerationConstraint :: check(Ptr::Ref value) const + throw (std::logic_error) +{ + if (!value) { + throw std::logic_error("EnumerationConstraint::check() called with " + "a 0 pointer value"); + } + + ListType::const_iterator it; + for (it = allowedValues.begin(); it != allowedValues.end(); ++it) { + if (*it == *value) { + return true; + } + } + + return false; +} + diff --git a/livesupport/src/modules/core/src/EnumerationConstraint.h b/livesupport/src/modules/core/src/EnumerationConstraint.h new file mode 100644 index 000000000..1015ff26d --- /dev/null +++ b/livesupport/src/modules/core/src/EnumerationConstraint.h @@ -0,0 +1,174 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author$ + Version : $Revision$ + Location : $URL$ + +------------------------------------------------------------------------------*/ +#ifndef LiveSupport_Core_EnumerationConstraint_h +#define LiveSupport_Core_EnumerationConstraint_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "LiveSupport/Core/MetadataConstraint.h" + + +namespace LiveSupport { +namespace Core { + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * A class for representing a metadata constraint allowing only strings from + * a given list of values. + * + * This is a concrete subclass of MetadataConstraint. Do not explicitly + * instantiate this class; create a MetadataConstraint object instead, and + * configure it with an XML element with the appropriate type attribute. + * + * This object has to be configured with an XML configuration element + * called constraint. This may look like the following: + * + *

+ *  
+ *      Monday
+ *      ...
+ *      Sunday
+ *  
+ *  
+ * + * A metadata type with this kind of constraint can only accept one of the + * strings listed in the value elements (in a case-sensitive way). + * + * The DTD for the expected XML element looks like the following: + * + *

+ *  
+ *  
+ *  
+ *  
+ * + * @author $Author$ + * @version $Revision$ + * @see EnumerationConstraintContainer + */ +class EnumerationConstraint : public MetadataConstraint +{ + private: + /** + * The type for storing the enumeration values. + */ + typedef std::vector ListType; + + /** + * The list of allowed enumeration values. + */ + ListType allowedValues; + + /** + * Read an enumeration value from an XML node. + * + * @param node the node containing the value. + * @exception std::invalid_argument if the XML node is not + * of the expected form. + */ + void + readValue(const xmlpp::Node * node) throw (std::invalid_argument); + + + public: + /** + * Constructor. + */ + EnumerationConstraint() throw () + { + } + + /** + * A virtual destructor, as this class has virtual functions. + */ + virtual + ~EnumerationConstraint(void) throw () + { + } + + /** + * Return the name of the XML element this object expects + * to be sent to a call to configure(). + * + * @return the name of the expected XML configuration element. + */ + static const std::string + getConfigElementName(void) throw () + { + return MetadataConstraint::getConfigElementName(); + } + + /** + * Configure the metadata object based on an XML configuration element. + * + * @param elemen the XML configuration element. + * @exception std::invalid_argument of the supplied XML element + * contains bad configuration information + */ + virtual void + configure(const xmlpp::Element &element) + throw (std::invalid_argument); + + /** + * Check that the given value satisfies the constraint. + * + * @param value the value to be checked against the constraint. + * @return true if the value satisfies the constraint. + * @exception std::logic_error if the parameter is a 0 pointer. + */ + virtual bool + check(Ptr::Ref value) const + throw (std::logic_error); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Core +} // namespace LiveSupport + +#endif // LiveSupport_Core_EnumerationConstraint_h + diff --git a/livesupport/src/modules/core/src/MetadataConstraint.cxx b/livesupport/src/modules/core/src/MetadataConstraint.cxx index 08305f7c3..5d5853eff 100644 --- a/livesupport/src/modules/core/src/MetadataConstraint.cxx +++ b/livesupport/src/modules/core/src/MetadataConstraint.cxx @@ -29,8 +29,11 @@ /* ============================================================ include files */ -#include "LiveSupport/Core/MetadataConstraint.h" #include "NumericConstraint.h" +#include "NumericRangeConstraint.h" +#include "EnumerationConstraint.h" + +#include "LiveSupport/Core/MetadataConstraint.h" using namespace LiveSupport::Core; @@ -83,6 +86,14 @@ MetadataConstraint :: configure(const xmlpp::Element & element) concreteConstraint.reset(new NumericConstraint()); concreteConstraint->configure(element); + } else if (type == "numericRange") { + concreteConstraint.reset(new NumericRangeConstraint()); + concreteConstraint->configure(element); + + } else if (type == "enumeration") { + concreteConstraint.reset(new EnumerationConstraint()); + concreteConstraint->configure(element); + } else { throw std::invalid_argument("unknown metadata constraint" + type); } diff --git a/livesupport/src/modules/core/src/MetadataTypeContainer.cxx b/livesupport/src/modules/core/src/MetadataTypeContainer.cxx index 24132a363..fa69962e0 100644 --- a/livesupport/src/modules/core/src/MetadataTypeContainer.cxx +++ b/livesupport/src/modules/core/src/MetadataTypeContainer.cxx @@ -161,8 +161,8 @@ MetadataTypeContainer :: getById3Tag(const Glib::ustring id3Tag) * Check that the given value satisfies the constraint of a metadata type. *----------------------------------------------------------------------------*/ bool -MetadataTypeContainer :: check(const Glib::ustring & dcName, - Ptr::Ref value) +MetadataTypeContainer :: check(Ptr::Ref value, + const Glib::ustring & dcName) throw (std::invalid_argument) { Ptr::Ref metadataType = getByDcName(dcName); diff --git a/livesupport/src/modules/core/src/MetadataTypeContainerTest.cxx b/livesupport/src/modules/core/src/MetadataTypeContainerTest.cxx index d02a96383..b31767c54 100644 --- a/livesupport/src/modules/core/src/MetadataTypeContainerTest.cxx +++ b/livesupport/src/modules/core/src/MetadataTypeContainerTest.cxx @@ -314,16 +314,30 @@ MetadataTypeContainerTest :: constraintTest(void) { // test the case of no constraint; everything is OK Ptr::Ref title; - CPPUNIT_ASSERT(!container->check("dc:title", title)); // except a 0 pointer + CPPUNIT_ASSERT(!container->check(title, "dc:title")); // except a 0 pointer title.reset(new Glib::ustring("Some title")); - CPPUNIT_ASSERT(container->check("dc:title", title)); + CPPUNIT_ASSERT(container->check(title, "dc:title")); // test the numeric constraint; [0-9]+ required + Ptr::Ref bpm(new Glib::ustring ("1000")); + CPPUNIT_ASSERT(container->check(bpm, "ls:bpm")); + bpm->assign("2000 or more"); + CPPUNIT_ASSERT(!container->check(bpm, "ls:bpm")); + bpm->assign(""); + CPPUNIT_ASSERT(!container->check(bpm, "ls:bpm")); + + // test the numeric range constraint; [0-9]+ required, between 0 and 3000 Ptr::Ref year(new Glib::ustring ("1000")); - CPPUNIT_ASSERT(container->check("ls:bpm", year)); - year->assign("2000 or more"); - CPPUNIT_ASSERT(!container->check("ls:bpm", year)); - year->assign(""); - CPPUNIT_ASSERT(!container->check("ls:bpm", year)); + CPPUNIT_ASSERT(container->check(year, "ls:year")); + year->assign("1066 AD"); + CPPUNIT_ASSERT(!container->check(year, "ls:year")); + year->assign("20066"); + CPPUNIT_ASSERT(!container->check(year, "ls:year")); + + // test the enumeration constraint; "mp3", "mpeg" or "ogg" are allowed + Ptr::Ref format(new Glib::ustring ("mp3")); + CPPUNIT_ASSERT(container->check(format, "dc:format")); + format->assign("wma"); + CPPUNIT_ASSERT(!container->check(format, "dc:format")); } diff --git a/livesupport/src/modules/core/src/NumericConstraint.cxx b/livesupport/src/modules/core/src/NumericConstraint.cxx index fc9b7d328..fc4ff2447 100644 --- a/livesupport/src/modules/core/src/NumericConstraint.cxx +++ b/livesupport/src/modules/core/src/NumericConstraint.cxx @@ -42,7 +42,7 @@ using namespace LiveSupport::Core; namespace { /*------------------------------------------------------------------------------ - * The value of the type attribute for this class + * The value of the type attribute for this class. *----------------------------------------------------------------------------*/ const std::string typeAttributeValue = "numeric"; @@ -61,7 +61,7 @@ void NumericConstraint :: configure(const xmlpp::Element & element) throw (std::invalid_argument) { - if (element.get_name() != MetadataConstraint::getConfigElementName()) { + if (element.get_name() != getConfigElementName()) { throw std::invalid_argument("bad configuration element " + element.get_name()); } @@ -73,8 +73,10 @@ NumericConstraint :: configure(const xmlpp::Element & element) std::string type = typeAttribute->get_value(); if (type != typeAttributeValue) { - throw std::invalid_argument("numeric constraint configured with a " - "constraint element of type " + type); + throw std::invalid_argument(typeAttributeValue + + " constraint configured with a" + + " constraint element of type " + + type); } } diff --git a/livesupport/src/modules/core/src/NumericConstraint.h b/livesupport/src/modules/core/src/NumericConstraint.h index e98ae4673..4af9fbfda 100644 --- a/livesupport/src/modules/core/src/NumericConstraint.h +++ b/livesupport/src/modules/core/src/NumericConstraint.h @@ -54,8 +54,8 @@ namespace Core { /** * A class for representing a numeric metadata constraint. * - * This is a concrete subclass of NumericConstraint. Do not explicitly - * instantiate this class; create a NumericConstraint object instead, and + * This is a concrete subclass of MetadataConstraint. Do not explicitly + * instantiate this class; create a MetadataConstraint object instead, and * configure it with an XML element with the appropriate type attribute. * * This object has to be configured with an XML configuration element @@ -81,13 +81,6 @@ namespace Core { */ class NumericConstraint : public MetadataConstraint { - private: - /** - * The name of the configuration XML element used by NumericConstraint. - */ - static const std::string configElementNameStr; - - public: /** * Constructor. @@ -113,7 +106,7 @@ class NumericConstraint : public MetadataConstraint static const std::string getConfigElementName(void) throw () { - return configElementNameStr; + return MetadataConstraint::getConfigElementName(); } /** diff --git a/livesupport/src/modules/core/src/NumericRangeConstraint.cxx b/livesupport/src/modules/core/src/NumericRangeConstraint.cxx new file mode 100644 index 000000000..c8a72e8b8 --- /dev/null +++ b/livesupport/src/modules/core/src/NumericRangeConstraint.cxx @@ -0,0 +1,161 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author$ + Version : $Revision$ + Location : $URL$ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#include + +#include "NumericConstraint.h" + +#include "NumericRangeConstraint.h" + + +using namespace LiveSupport::Core; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +namespace { + +/*------------------------------------------------------------------------------ + * The value of the type attribute for this class. + *----------------------------------------------------------------------------*/ +const std::string typeAttributeValue = "numericRange"; + +} + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Create a constraint element object based on an XML element. + *----------------------------------------------------------------------------*/ +void +NumericRangeConstraint :: configure(const xmlpp::Element & element) + throw (std::invalid_argument) +{ + if (element.get_name() != getConfigElementName()) { + throw std::invalid_argument("bad configuration element " + + element.get_name()); + } + + const xmlpp::Attribute* typeAttribute; + if (!(typeAttribute = element.get_attribute(typeAttributeName))) { + throw std::invalid_argument("missing attribute " + typeAttributeName); + } + std::string type = typeAttribute->get_value(); + + if (type != typeAttributeValue) { + throw std::invalid_argument(typeAttributeValue + + " constraint configured with a" + + " constraint element of type " + + type); + } + + xmlpp::Node::NodeList childNodes = element.get_children(valueElementName); + xmlpp::Node::NodeList::iterator it = childNodes.begin(); + + if (it != childNodes.end()) { + minValue = readNumberFromNode(*it); + } else { + throw std::invalid_argument("sub-element not found in constraint"); + } + + ++it; + if (it != childNodes.end()) { + maxValue = readNumberFromNode(*it); + } else { + throw std::invalid_argument("sub-element not found in constraint"); + } +} + + +/*------------------------------------------------------------------------------ + * Read a number from an xml element. + *----------------------------------------------------------------------------*/ +NumericRangeConstraint :: ValueType +NumericRangeConstraint :: readNumberFromNode( + const xmlpp::Node * node) const + throw (std::invalid_argument) +{ + const xmlpp::Element * valueElement + = dynamic_cast (node); + if (valueElement) { + Ptr::Ref value(new Glib::ustring( + valueElement->get_child_text() + ->get_content() )); + return readNumber(value); + } else { + throw std::invalid_argument("bad sub-element found in constraint"); + } +} + + +/*------------------------------------------------------------------------------ + * Read a number from a string. + *----------------------------------------------------------------------------*/ +NumericRangeConstraint :: ValueType +NumericRangeConstraint :: readNumber( + Ptr::Ref value) const + throw (std::invalid_argument) +{ + NumericConstraint numericConstraint; + if (!numericConstraint.check(value)) { + throw std::invalid_argument("bad number found in constraint"); + } + + std::istringstream valueStream(*value); + ValueType valueNumber; + valueStream >> valueNumber; + + return valueNumber; +} + + +/*------------------------------------------------------------------------------ + * Check that the given value satisfies the constraint. + *----------------------------------------------------------------------------*/ +bool +NumericRangeConstraint :: check(Ptr::Ref value) const + throw (std::logic_error) +{ + ValueType valueNumber = readNumber(value); + + if (valueNumber >= minValue && valueNumber <= maxValue) { + return true; + } else { + return false; + } +} + diff --git a/livesupport/src/modules/core/src/NumericRangeConstraint.h b/livesupport/src/modules/core/src/NumericRangeConstraint.h new file mode 100644 index 000000000..de0405370 --- /dev/null +++ b/livesupport/src/modules/core/src/NumericRangeConstraint.h @@ -0,0 +1,194 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author$ + Version : $Revision$ + Location : $URL$ + +------------------------------------------------------------------------------*/ +#ifndef LiveSupport_Core_NumericRangeConstraint_h +#define LiveSupport_Core_NumericRangeConstraint_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "LiveSupport/Core/MetadataConstraint.h" + + +namespace LiveSupport { +namespace Core { + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * A class for representing a metadata constraint which allows numbers between + * two given values (inclusive). + * + * This is a concrete subclass of MetadataConstraint. Do not explicitly + * instantiate this class; create a MetadataConstraint object instead, and + * configure it with an XML element with the appropriate type attribute. + * + * This object has to be configured with an XML configuration element + * called constraint. This may look like the following: + * + *

+ *  
+ *      1
+ *      12
+ *  
+ *  
+ * + * A metadata type with this kind of constraint can only accept (decimal, + * non-negative) integer values, i.e., [0-9]+, which are greater than or + * equal to the first value given, and less than or equal to the second + * value given. + * + * The DTD for the expected XML element looks like the following: + * + *

+ *  
+ *  
+ *  
+ *  
+ * + * @author $Author$ + * @version $Revision$ + * @see NumericRangeConstraintContainer + */ +class NumericRangeConstraint : public MetadataConstraint +{ + private: + /** + * The integer type used by the constraint. + */ + typedef unsigned long long ValueType; + + /** + * The smallest value allowed by the constraint. + */ + ValueType minValue; + + /** + * The largest value allowed by the constraint. + */ + ValueType maxValue; + + /** + * Read a number from an XML node. + * + * @param node the node containing the number. + * @return the number read from the node. + * @exception std::invalid_argument if the XML node is not + * of the expected form. + */ + ValueType + readNumberFromNode(const xmlpp::Node * node) const + throw (std::invalid_argument); + + /** + * Read a number from a string. + * + * @param value the string containing the number. + * @return the number read from the string. + * @exception std::invalid_argument if the string does not contain + * a number. + */ + ValueType + readNumber(Ptr::Ref value) const + throw (std::invalid_argument); + + + public: + /** + * Constructor. + */ + NumericRangeConstraint() throw () + { + } + + /** + * A virtual destructor, as this class has virtual functions. + */ + virtual + ~NumericRangeConstraint(void) throw () + { + } + + /** + * Return the name of the XML element this object expects + * to be sent to a call to configure(). + * + * @return the name of the expected XML configuration element. + */ + static const std::string + getConfigElementName(void) throw () + { + return MetadataConstraint::getConfigElementName(); + } + + /** + * Configure the metadata object based on an XML configuration element. + * + * @param elemen the XML configuration element. + * @exception std::invalid_argument of the supplied XML element + * contains bad configuration information + */ + virtual void + configure(const xmlpp::Element &element) + throw (std::invalid_argument); + + /** + * Check that the given value satisfies the constraint. + * + * @param value the value to be checked against the constraint. + * @return true if the value satisfies the constraint. + * @exception std::logic_error if the parameter is a 0 pointer. + */ + virtual bool + check(Ptr::Ref value) const + throw (std::logic_error); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Core +} // namespace LiveSupport + +#endif // LiveSupport_Core_NumericRangeConstraint_h + diff --git a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml index aa2df8d8c..600e080d1 100644 --- a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml +++ b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml @@ -89,20 +89,25 @@ - - - + + + - + + + + + + @@ -178,182 +183,196 @@ - - - - + + 0 + 3000 + + + - - + + mp3 + mpeg + ogg + + + + + + - - - + + + + + + - - - + + + - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.template b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.template index 1fb649073..e2951591a 100644 --- a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.template +++ b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.template @@ -89,20 +89,25 @@ - - - + + + - + + + + + + @@ -177,182 +182,196 @@ - - - - + + 0 + 3000 + + + - - + + mp3 + mpeg + ogg + + + + + + - - - + + + + + + - - - + + + - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.user-template b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.user-template index 9ffa102a2..36264b037 100644 --- a/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.user-template +++ b/livesupport/src/products/gLiveSupport/etc/gLiveSupport.xml.user-template @@ -89,20 +89,25 @@ - - - + + + - + + + + + + @@ -177,182 +182,196 @@ - - - - + + 0 + 3000 + + + - - + + mp3 + mpeg + ogg + + + + + + - - - + + + + + + - - - + + + - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/livesupport/src/products/gLiveSupport/src/UploadFileWindow.cxx b/livesupport/src/products/gLiveSupport/src/UploadFileWindow.cxx index 54bcd8fb2..e2617208f 100644 --- a/livesupport/src/products/gLiveSupport/src/UploadFileWindow.cxx +++ b/livesupport/src/products/gLiveSupport/src/UploadFileWindow.cxx @@ -438,6 +438,9 @@ UploadFileWindow :: onUploadButtonClicked(void) throw () void UploadFileWindow :: uploadAudioClip(void) throw () { + Ptr::Ref + metadataTypes = gLiveSupport->getMetadataTypeContainer(); + for (unsigned int i=0; i < metadataKeys.size(); ++i) { Ptr::Ref metadataKey = metadataKeys[i]; Gtk::Entry * metadataEntry = metadataEntries[i]; @@ -445,7 +448,17 @@ UploadFileWindow :: uploadAudioClip(void) throw () Ptr::Ref metadataValue(new Glib::ustring( metadataEntry->get_text() )); if (*metadataValue != "") { - audioClip->setMetadata(metadataValue, *metadataKey); + if (metadataTypes->check(metadataValue, *metadataKey)) { + audioClip->setMetadata(metadataValue, *metadataKey); + } else { + Ptr::Ref + metadata = metadataTypes->getByDcName(*metadataKey); + Ptr::Ref + localizedName = metadata->getLocalizedName(); + statusBar->set_text(*formatMessage("badMetadataMsg", + *localizedName)); + return; + } } } @@ -459,6 +472,7 @@ UploadFileWindow :: uploadAudioClip(void) throw () gLiveSupport->uploadAudioClip(audioClip); } catch (XmlRpcException &e) { statusBar->set_text(e.what()); + std::cerr << e.what(); return; } diff --git a/livesupport/src/products/gLiveSupport/var/root.txt b/livesupport/src/products/gLiveSupport/var/root.txt index 0ecad0dd1..b316c1e56 100644 --- a/livesupport/src/products/gLiveSupport/var/root.txt +++ b/livesupport/src/products/gLiveSupport/var/root.txt @@ -128,6 +128,7 @@ root:table unsupportedFileTypeMsg:string { "Unsupported file type." } missingTitleMsg:string { "Please enter a title." } + badMetadataMsg:string { "Invalid data for {0}." } } simplePlaylistManagementWindow:table