gufo_common/
xmp.rs

1/// XMP field
2pub trait Field {
3    /// XMP field name
4    const NAME: &'static str;
5    /// Set to true if value uses exifEX namespace
6    ///
7    /// If set to true, this field is from Exif 2.21 or later and uses the `http://cipa.jp/exif/1.0/` namespace (exifEX). Otherwise, it uses the legacy namespace `http://ns.adobe.com/exif/1.0/` (exif).
8    const NAMESPACE: Namespace;
9}
10
11/// Namespace for fields defined in TIFF
12const XML_NS_TIFF: &str = "http://ns.adobe.com/tiff/1.0/";
13/// Namespace for fields defined in Exif 2.2 or earlier
14const XML_NS_EXIF: &str = "http://ns.adobe.com/exif/1.0/";
15/// Namespace for fields defined in Exif 2.21 or later
16const XML_NS_EXIF_EX: &str = "http://cipa.jp/exif/1.0/";
17
18const XML_NS_XMP: &str = "http://ns.adobe.com/xap/1.0/";
19const XML_NS_XMP_RIGHTS: &str = "http://ns.adobe.com/xap/1.0/rights/";
20/// RDF
21pub const XML_NS_RDF: &str = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
22const XML_NS_PS: &str = "http://ns.adobe.com/photoshop/1.0/";
23const XML_NS_DC: &str = "http://purl.org/dc/elements/1.1/";
24
25#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
26pub enum Namespace {
27    /// Namespace for fields defined in TIFF
28    Tiff,
29    /// Namespace for fields defined in Exif 2.2 or earlier
30    Exif,
31    /// Namespace for fields defined in Exif 2.21 or later
32    ExifEX,
33    Ps,
34    Dc,
35    Xmp,
36    XmpRights,
37    Unknown(String),
38}
39
40impl Namespace {
41    pub fn from_url(url: &str) -> Self {
42        match url {
43            XML_NS_TIFF => Namespace::Tiff,
44            XML_NS_EXIF => Namespace::Exif,
45            XML_NS_EXIF_EX => Namespace::ExifEX,
46            XML_NS_XMP => Namespace::Xmp,
47            XML_NS_XMP_RIGHTS => Namespace::XmpRights,
48            XML_NS_PS => Namespace::Ps,
49            XML_NS_DC => Namespace::Dc,
50            namespace => Namespace::Unknown(namespace.to_string()),
51        }
52    }
53
54    pub fn to_url(&self) -> &str {
55        match self {
56            Namespace::Tiff => XML_NS_TIFF,
57            Namespace::Exif => XML_NS_EXIF,
58            Namespace::ExifEX => XML_NS_EXIF_EX,
59            Namespace::Xmp => XML_NS_XMP,
60            Namespace::XmpRights => XML_NS_XMP_RIGHTS,
61            Namespace::Ps => XML_NS_PS,
62            Namespace::Dc => XML_NS_DC,
63            Namespace::Unknown(namespace) => namespace.as_str(),
64        }
65    }
66}