Skip to main content

easyofd_reader/model/
ofd_page_vo.rs

1//! OFD 页面视图对象。
2//!
3//! 对应 Java: org.ofdrw.reader.model.OfdPageVo
4//!
5//! 已废弃:Java 原始类标记为 `@Deprecated`,建议使用 `PageInfo`。
6//! 此处保留类型以保持 API 兼容。
7
8/// OFD 页面视图对象,包含内容页面和可选的模板页面。
9///
10/// 对应 Java: `org.ofdrw.reader.model.OfdPageVo`
11///
12/// **废弃**:Java 原始类标记为 `@Deprecated`,建议使用 [`PageInfo`](crate::PageInfo)。
13#[derive(Debug, Clone)]
14#[deprecated(since = "1.0.0", note = "使用 PageInfo 替代")]
15#[allow(deprecated)]
16pub struct OfdPageVo {
17    /// 内容页面路径。
18    pub content_page_path: String,
19    /// 模板页面路径(可选)。
20    pub template_page_path: Option<String>,
21}
22
23#[allow(deprecated)]
24impl OfdPageVo {
25    /// 创建新的页面视图对象。
26    #[must_use]
27    pub fn new(content_page_path: impl Into<String>, template_page_path: Option<String>) -> Self {
28        Self {
29            content_page_path: content_page_path.into(),
30            template_page_path,
31        }
32    }
33
34    /// 是否有模板页面。
35    #[must_use]
36    pub fn has_template(&self) -> bool {
37        self.template_page_path.is_some()
38    }
39}
40
41#[allow(deprecated)]
42#[cfg(test)]
43mod tests {
44    #[allow(deprecated)]
45    use super::*;
46
47    #[test]
48    #[allow(deprecated)]
49    fn test_ofd_page_vo_new() {
50        let vo = OfdPageVo::new("Pages/Page_0/Content.xml", None);
51        assert_eq!(vo.content_page_path, "Pages/Page_0/Content.xml");
52        assert!(!vo.has_template());
53    }
54
55    #[test]
56    #[allow(deprecated)]
57    fn test_ofd_page_vo_with_template() {
58        let vo = OfdPageVo::new(
59            "Pages/Page_0/Content.xml",
60            Some("Pages/Page_0/Template.xml".into()),
61        );
62        assert!(vo.has_template());
63    }
64}