diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-11-29 20:36:41 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-11-29 20:36:41 +0100 |
commit | 6ec0844a732a8d8b1aebbee3bf3dec1441af5bbd (patch) | |
tree | ace48eac0440d4fd9bd9b7081f4294409981ec3e /src/exiv2wrapper.cpp | |
parent | 17c9ce29dd1b25537b9570191276e13cc3baa690 (diff) | |
download | pyexiv2-6ec0844a732a8d8b1aebbee3bf3dec1441af5bbd.tar.gz |
Functions in the xmp module to register and unregister custom namespaces.
Diffstat (limited to 'src/exiv2wrapper.cpp')
-rw-r--r-- | src/exiv2wrapper.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/exiv2wrapper.cpp b/src/exiv2wrapper.cpp index 0d80e05..4512222 100644 --- a/src/exiv2wrapper.cpp +++ b/src/exiv2wrapper.cpp @@ -34,6 +34,9 @@ #define NON_REPEATABLE 102 #define KEY_NOT_FOUND 103 #define INVALID_VALUE 104 +#define EXISTING_PREFIX 105 +#define BUILTIN_NS 106 +#define NOT_REGISTERED 107 // Custom macros #define CHECK_METADATA_READ \ @@ -1279,6 +1282,15 @@ void translateExiv2Error(Exiv2::Error const& error) case INVALID_VALUE: PyErr_SetString(PyExc_ValueError, "Invalid value"); break; + case EXISTING_PREFIX: + PyErr_SetString(PyExc_KeyError, "A namespace with this prefix already exists"); + break; + case BUILTIN_NS: + PyErr_SetString(PyExc_KeyError, "Cannot unregister a builtin namespace"); + break; + case NOT_REGISTERED: + PyErr_SetString(PyExc_KeyError, "No namespace registered under this name"); + break; // Default handler default: @@ -1286,5 +1298,52 @@ void translateExiv2Error(Exiv2::Error const& error) } } + +void registerXmpNs(const std::string& name, const std::string& prefix) +{ + try + { + const std::string& ns = Exiv2::XmpProperties::ns(prefix); + } + catch (Exiv2::Error& error) + { + // No namespace exists with the requested prefix, it is safe to + // register a new one. + Exiv2::XmpProperties::registerNs(name, prefix); + return; + } + throw Exiv2::Error(EXISTING_PREFIX, prefix); +} + +void unregisterXmpNs(const std::string& name) +{ + const std::string& prefix = Exiv2::XmpProperties::prefix(name); + if (prefix != "") + { + Exiv2::XmpProperties::unregisterNs(name); + try + { + const Exiv2::XmpNsInfo* info = Exiv2::XmpProperties::nsInfo(prefix); + } + catch (Exiv2::Error& error) + { + // The namespace has been successfully unregistered. + return; + } + // The namespace hasn’t been unregistered because it’s builtin. + throw Exiv2::Error(BUILTIN_NS, name); + } + else + { + throw Exiv2::Error(NOT_REGISTERED, name); + } +} + +void unregisterAllXmpNs() +{ + // Unregister all custom namespaces. + Exiv2::XmpProperties::unregisterNs(); +} + } // End of namespace exiv2wrapper |