spreadsheet_ods/metadata.rs
1//! Document metadata.
2
3use crate::xlink::{XLinkActuate, XLinkShow, XLinkType};
4use chrono::{Duration, NaiveDateTime};
5use get_size2::GetSize;
6
7/// Metadata
8#[derive(Debug, Clone, Default)]
9pub struct Metadata {
10 /// The <meta:generator> element contains a string that identifies the OpenDocument producer
11 /// that was used to create or last modify the document. This string should match the definition for
12 /// user-agents in the HTTP protocol as specified in section 14.43 of RFC2616. The generator string
13 /// should allow OpenDocument consumers to distinguish between all released versions of a
14 /// producer.
15 /// Note: Release versions of a producer could be distinguished based on build
16 /// identifiers or patch-level information.
17 /// If an OpenDocument producer that creates a document cannot provide an identifier string, the
18 /// producer shall not export this element. If a producer stores a modified document created by
19 /// another producer cannot provide a unique identifier, it shall not export the original identifier
20 /// belonging to the producer that created the document.
21 pub generator: String,
22 /// The dc:title element specifies the title of a document
23 pub title: String,
24 /// The dc:description element contains a description of a document.
25 pub description: String,
26 /// The dc:subject element specifies the subject of a document
27 pub subject: String,
28 /// The meta:keyword element contains a keyword pertaining to a document.
29 pub keyword: String,
30 /// The meta:initial-creator element specifies the name of the initial creator of a document
31 pub initial_creator: String,
32 /// The dc:creator element specifies the name of the person who last modified a
33 /// document, who created an annotation, who authored a change .
34 pub creator: String,
35 /// The meta:printed-by element specifies the name of the last person who printed a
36 /// document.
37 pub printed_by: String,
38 /// The meta:creation-date element specifies the date and time when a document was
39 /// created.
40 pub creation_date: Option<NaiveDateTime>,
41 /// The dc:date element specifies the date and time when the document was last
42 /// modified, when an annotation was created, when a change was made.
43 pub date: Option<NaiveDateTime>,
44 /// The meta:print-date element specifies the date and time when a document was last
45 /// printed.
46 pub print_date: Option<NaiveDateTime>,
47 /// The dc:language element specifies the default language of a document
48 pub language: String,
49 /// The meta:editing-cycles element specifies the number of times a document has been
50 /// edited. When a document is created, this value is set to 1. Each time a document is saved, the
51 /// editing-cycles number is incremented by 1.
52 pub editing_cycles: u32,
53 /// The meta:editing-duration element specifies the total time spent editing a document.
54 pub editing_duration: Duration,
55 /// The <meta:template> element specifies an IRI for the document template that was used to
56 /// create a document. The IRI is specified using the xlink:href attribute.
57 pub template: MetaTemplate,
58 /// The meta:auto-reload element specifies whether a document is reloaded or replaced by
59 /// another document after a specified period of time has elapsed.
60 pub auto_reload: MetaAutoReload,
61 /// The meta:hyperlink-behaviour element specifies the default behavior for hyperlinks in a
62 /// document.
63 pub hyperlink_behaviour: MetaHyperlinkBehaviour,
64 /// The meta:document-statistic element represents statistics about a document.
65 pub document_statistics: MetaDocumentStatistics,
66 /// The <meta:user-defined> element specifies any additional user-defined metadata for a
67 /// document.
68 pub user_defined: Vec<MetaUserDefined>,
69}
70
71impl GetSize for Metadata {
72 fn get_heap_size(&self) -> usize {
73 self.generator.get_heap_size()
74 + self.title.get_heap_size()
75 + self.description.get_heap_size()
76 + self.subject.get_heap_size()
77 + self.keyword.get_heap_size()
78 + self.initial_creator.get_heap_size()
79 + self.creator.get_heap_size()
80 + self.printed_by.get_heap_size()
81 + self.language.get_heap_size()
82 + self.editing_cycles.get_heap_size()
83 + self.template.get_heap_size()
84 + self.auto_reload.get_heap_size()
85 + self.hyperlink_behaviour.get_heap_size()
86 + self.document_statistics.get_heap_size()
87 + self.user_defined.get_heap_size()
88 }
89}
90
91/// Specifies an IRI for the document template that was used to
92/// create a document.
93#[derive(Debug, Default, Clone)]
94pub struct MetaTemplate {
95 /// The meta:date attribute specifies the date and time when a template was last modified, prior to
96 /// being used to create the current document.
97 pub date: Option<NaiveDateTime>,
98 /// See XLink
99 pub actuate: Option<XLinkActuate>,
100 /// See XLink
101 pub href: Option<String>,
102 /// See XLink
103 pub title: Option<String>,
104 /// See XLink
105 pub link_type: Option<XLinkType>,
106}
107
108impl GetSize for MetaTemplate {
109 fn get_heap_size(&self) -> usize {
110 self.actuate.get_heap_size()
111 + self.href.get_heap_size()
112 + self.title.get_heap_size()
113 + self.link_type.get_heap_size()
114 }
115}
116
117impl MetaTemplate {
118 /// Everything is None.
119 pub fn is_empty(&self) -> bool {
120 self.date.is_none()
121 && self.actuate.is_none()
122 && self.href.is_none()
123 && self.title.is_none()
124 && self.link_type.is_none()
125 }
126}
127
128/// Specifies whether a document is reloaded or replaced by
129/// another document after a specified period of time has elapsed.
130#[derive(Debug, Default, Clone)]
131pub struct MetaAutoReload {
132 /// The meta:delay attribute specifies a reload delay.
133 pub delay: Option<Duration>,
134 /// See XLink
135 pub actuate: Option<XLinkActuate>,
136 /// See XLink
137 pub href: Option<String>,
138 /// See XLink
139 pub show: Option<XLinkShow>,
140 /// See XLink
141 pub link_type: Option<XLinkType>,
142}
143
144impl GetSize for MetaAutoReload {
145 fn get_heap_size(&self) -> usize {
146 self.actuate.get_heap_size()
147 + self.href.get_heap_size()
148 + self.show.get_heap_size()
149 + self.link_type.get_heap_size()
150 }
151}
152
153impl MetaAutoReload {
154 /// Everything is None.
155 pub fn is_empty(&self) -> bool {
156 self.delay.is_none()
157 && self.actuate.is_none()
158 && self.href.is_none()
159 && self.show.is_none()
160 && self.link_type.is_none()
161 }
162}
163
164/// Specifies the default behavior for hyperlinks in a document.
165#[derive(Debug, Default, Clone, GetSize)]
166pub struct MetaHyperlinkBehaviour {
167 /// The office:target-frame-name attribute specifies the name of a target frame.
168 /// The defined values for the office:target-frame-name attribute are:
169 /// • _blank: The referenced document is displayed in a new frame.
170 /// • _parent: The referenced document is displayed in the parent frame of the current frame.
171 /// • _self: The referenced document replaces the content of the current frame.
172 /// • _top: The referenced document is displayed in the topmost frame, that is the frame that
173 /// contains the current frame as a child or descendant but is not contained within another frame.
174 /// • A frame name: The referenced document is displayed in the named frame. If the named frame
175 /// does not exist, a new frame with that name is created.
176 /// The office:target-frame-name attribute may be used together with an xlink:show 19.917
177 /// attribute. In that case, if the value of the attribute is _blank, the xlink:show attribute value
178 /// should be new. If the value of the attribute is any of the other value options, the value of the
179 /// xlink:show attribute should be replace.
180 pub target_frame_name: Option<String>,
181 /// See XLink
182 pub show: Option<XLinkShow>,
183}
184
185impl MetaHyperlinkBehaviour {
186 /// Everything is None.
187 pub fn is_empty(&self) -> bool {
188 self.target_frame_name.is_none() && self.show.is_none()
189 }
190}
191
192/// Represents statistics about a document.
193#[derive(Debug, Default, Clone, GetSize)]
194pub struct MetaDocumentStatistics {
195 /// Metadata
196 pub cell_count: u32,
197 /// Metadata
198 pub object_count: u32,
199 /// Metadata
200 pub ole_object_count: u32,
201 /// Metadata
202 pub table_count: u32,
203}
204
205/// Specifies any additional user-defined metadata for a document.
206#[derive(Debug, Clone, GetSize)]
207pub struct MetaUserDefined {
208 /// Name
209 pub name: String,
210 /// Value
211 pub value: MetaValue,
212}
213
214impl Default for MetaUserDefined {
215 fn default() -> Self {
216 Self {
217 name: "".to_string(),
218 value: MetaValue::String("".to_string()),
219 }
220 }
221}
222
223/// Value for user defined metadata.
224#[derive(Debug, Clone)]
225pub enum MetaValue {
226 /// bool
227 Boolean(bool),
228 /// NaiveDateTime
229 Datetime(NaiveDateTime),
230 /// f64
231 Float(f64),
232 /// Duration
233 TimeDuration(Duration),
234 /// String
235 String(String),
236}
237
238impl GetSize for MetaValue {
239 fn get_heap_size(&self) -> usize {
240 match self {
241 MetaValue::Boolean(_) => 0,
242 MetaValue::Datetime(_) => 0,
243 MetaValue::Float(_) => 0,
244 MetaValue::TimeDuration(_) => 0,
245 MetaValue::String(v) => v.get_heap_size(),
246 }
247 }
248}