Added reg command to utility, fixed set command to wrok better with XMP arrays, modified LangAlt write method to write default first, fixed registerNs bug.

v0.27.3
Andreas Huggel 18 years ago
parent 0207c59c24
commit 595665be33

@ -1268,8 +1268,11 @@ namespace Action {
case del: case del:
delMetadatum(pImage, *i); delMetadatum(pImage, *i);
break; break;
case reg:
regNamespace(*i);
break;
case invalidCmdId: case invalidCmdId:
// Todo: complain assert(invalidCmdId == i->cmdId_);
break; break;
} }
} }
@ -1342,7 +1345,9 @@ namespace Action {
if (metadatum) { if (metadatum) {
value = metadatum->getValue(); value = metadatum->getValue();
} }
if (modifyCmd.explicitType_ || value.get() == 0) { if ( value.get() == 0
|| ( modifyCmd.explicitType_
&& modifyCmd.typeId_ != value->typeId())) {
value = Exiv2::Value::create(modifyCmd.typeId_); value = Exiv2::Value::create(modifyCmd.typeId_);
} }
if (0 == value->read(modifyCmd.value_)) { if (0 == value->read(modifyCmd.value_)) {
@ -1402,6 +1407,15 @@ namespace Action {
} }
} }
void Modify::regNamespace(const ModifyCmd& modifyCmd)
{
if (Params::instance().verbose_) {
std::cout << _("Reg ") << modifyCmd.key_ << "=\""
<< modifyCmd.value_ << "\"" << std::endl;
}
Exiv2::XmpProperties::registerNs(modifyCmd.value_, modifyCmd.key_);
}
Modify::AutoPtr Modify::clone() const Modify::AutoPtr Modify::clone() const
{ {
return AutoPtr(clone_()); return AutoPtr(clone_());

@ -339,6 +339,8 @@ namespace Action {
//! Delete a metadatum from \em pImage according to \em modifyCmd //! Delete a metadatum from \em pImage according to \em modifyCmd
static void delMetadatum(Exiv2::Image* pImage, static void delMetadatum(Exiv2::Image* pImage,
const ModifyCmd& modifyCmd); const ModifyCmd& modifyCmd);
//! Register an XMP namespace according to \em modifyCmd
static void regNamespace(const ModifyCmd& modifyCmd);
}; // class Modify }; // class Modify

@ -60,6 +60,7 @@ namespace {
{ add, "add" }, { add, "add" },
{ set, "set" }, { set, "set" },
{ del, "del" }, { del, "del" },
{ reg, "reg" },
{ invalidCmdId, "invalidCmd" } // End of list marker { invalidCmdId, "invalidCmd" } // End of list marker
}; };
@ -886,35 +887,36 @@ namespace {
Exiv2::TypeId defaultType = Exiv2::invalidTypeId; Exiv2::TypeId defaultType = Exiv2::invalidTypeId;
std::string key(line.substr(keyStart, keyEnd-keyStart)); std::string key(line.substr(keyStart, keyEnd-keyStart));
MetadataId metadataId = invalidMetadataId; MetadataId metadataId = invalidMetadataId;
try { if (cmdId != reg) {
Exiv2::IptcKey iptcKey(key);
metadataId = iptc;
defaultType = Exiv2::IptcDataSets::dataSetType(iptcKey.tag(),
iptcKey.record());
}
catch (const Exiv2::AnyError&) {}
if (metadataId == invalidMetadataId) {
try { try {
Exiv2::ExifKey exifKey(key); Exiv2::IptcKey iptcKey(key);
metadataId = exif; metadataId = iptc;
defaultType = Exiv2::ExifTags::tagType(exifKey.tag(), defaultType = Exiv2::IptcDataSets::dataSetType(iptcKey.tag(),
exifKey.ifdId()); iptcKey.record());
} }
catch (const Exiv2::AnyError&) {} catch (const Exiv2::AnyError&) {}
} if (metadataId == invalidMetadataId) {
if (metadataId == invalidMetadataId) { try {
try { Exiv2::ExifKey exifKey(key);
Exiv2::XmpKey xmpKey(key); metadataId = exif;
metadataId = xmp; defaultType = Exiv2::ExifTags::tagType(exifKey.tag(),
defaultType = Exiv2::XmpProperties::propertyType(xmpKey); exifKey.ifdId());
}
catch (const Exiv2::AnyError&) {}
}
if (metadataId == invalidMetadataId) {
try {
Exiv2::XmpKey xmpKey(key);
metadataId = xmp;
defaultType = Exiv2::XmpProperties::propertyType(xmpKey);
}
catch (const Exiv2::AnyError&) {}
}
if (metadataId == invalidMetadataId) {
throw Exiv2::Error(1, Exiv2::toString(num)
+ ": " + _("Invalid key") + " `" + key + "'");
} }
catch (const Exiv2::AnyError&) {}
}
if (metadataId == invalidMetadataId) {
throw Exiv2::Error(1, Exiv2::toString(num)
+ ": " + _("Invalid key") + " `" + key + "'");
} }
std::string value; std::string value;
Exiv2::TypeId type = defaultType; Exiv2::TypeId type = defaultType;
bool explicitType = false; bool explicitType = false;
@ -934,7 +936,7 @@ namespace {
+ ": " + _("Invalid command line") + " " ); + ": " + _("Invalid command line") + " " );
} }
if (typeEnd != std::string::npos) { if (cmdId != reg && typeEnd != std::string::npos) {
std::string typeStr(line.substr(typeStart, typeEnd-typeStart)); std::string typeStr(line.substr(typeStart, typeEnd-typeStart));
Exiv2::TypeId tmpType = Exiv2::TypeInfo::typeId(typeStr); Exiv2::TypeId tmpType = Exiv2::TypeInfo::typeId(typeStr);
if (tmpType != Exiv2::invalidTypeId) { if (tmpType != Exiv2::invalidTypeId) {

@ -43,7 +43,7 @@
// class definitions // class definitions
//! Command identifiers //! Command identifiers
enum CmdId { invalidCmdId, add, set, del }; enum CmdId { invalidCmdId, add, set, del, reg };
//! Metadata identifiers //! Metadata identifiers
enum MetadataId { invalidMetadataId, iptc, exif, xmp }; enum MetadataId { invalidMetadataId, iptc, exif, xmp };
//! Structure for one parsed modification command //! Structure for one parsed modification command

@ -637,11 +637,18 @@ namespace Exiv2 {
std::ostream& LangAltValue::write(std::ostream& os) const std::ostream& LangAltValue::write(std::ostream& os) const
{ {
for (ValueType::const_iterator i = value_.begin(); bool first = true;
i != value_.end(); ++i) { // Write the default entry first
if (i != value_.begin()) os << ", "; ValueType::const_iterator i = value_.find("x-default");
os << "lang=\"" << i->first << "\" " if (i != value_.end()) {
<< i->second; os << "lang=\"" << i->first << "\" " << i->second;
first = false;
}
for (i = value_.begin(); i != value_.end(); ++i) {
if (i->first == "x-default") continue;
if (!first) os << ", ";
os << "lang=\"" << i->first << "\" " << i->second;
first = false;
} }
return os; return os;
} }

@ -381,7 +381,7 @@ namespace Exiv2 {
bool XmpParser::registerNs(const std::string& ns, bool XmpParser::registerNs(const std::string& ns,
const std::string& prefix) const std::string& prefix)
{ { try {
initialize(); initialize();
#ifdef EXV_HAVE_XMP_TOOLKIT #ifdef EXV_HAVE_XMP_TOOLKIT
return SXMPMeta::RegisterNamespace(ns.c_str(), prefix.c_str(), 0); return SXMPMeta::RegisterNamespace(ns.c_str(), prefix.c_str(), 0);
@ -389,6 +389,9 @@ namespace Exiv2 {
return true; return true;
#endif #endif
} }
catch (const XMP_Error& e) {
throw Error(40, e.GetID(), e.GetErrMsg());
}} // XmpParser::registerNs
#ifdef EXV_HAVE_XMP_TOOLKIT #ifdef EXV_HAVE_XMP_TOOLKIT
int XmpParser::decode( XmpData& xmpData, int XmpParser::decode( XmpData& xmpData,

Loading…
Cancel
Save