Class OFDReader

java.lang.Object
org.ofdrw.reader.OFDReader
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
DLOFDReader, SealOFDReader

public class OFDReader extends Object implements Closeable
OFD解析器
Since:
2020-04-01 21:39:25
Author:
权观宇
  • Field Details

    • rl

      protected ResourceLocator rl
      资源定位器

      解析路径获取资源

  • Constructor Details

    • OFDReader

      public OFDReader(Path ofdFile) throws IOException
      构造一个 OFDReader
      Parameters:
      ofdFile - OFD文件
      Throws:
      IOException - OFD文件操作IO异常
    • OFDReader

      public OFDReader(String ofdFileLoc) throws IOException
      构造一个 OFDReader
      Parameters:
      ofdFileLoc - OFD文件位置,例如:”/home/user/myofd.ofd“
      Throws:
      IOException - OFD文件操作IO异常
    • OFDReader

      public OFDReader(InputStream stream) throws IOException
      构造一个 OFDReader
      Parameters:
      stream - OFD文件输入流,流由调用者负责关闭。
      Throws:
      IOException - OFD文件操作IO异常
    • OFDReader

      public OFDReader(String unzippedPathRoot, boolean deleteOnClose)
      因一些ofd文件无法使用ZipUtil解压缩,可以让用户自己在外面解压缩好后,传入根目录创建 例如用户可以使用unzip或者unar等命令行方式解压缩,因此通过参数控制是否删除目录。
      Parameters:
      unzippedPathRoot - 已经解压的OFD根目录位置
      deleteOnClose - 退出时是否删除 unzippedPathRoot 文件, true - 退出时删除;false - 不删除
  • Method Details

    • getWorkDir

      public Path getWorkDir()
    • setZipFileMaxSize

      @Deprecated public static void setZipFileMaxSize(long size)
      Deprecated.
      该参数已经弃用。
      设置 OFD解压后最大占用文件大小

      默认值: 100MB

      Parameters:
      size - 解压文件大小,单位字节(Byte)
    • getOFDDir

      public OFDDir getOFDDir()
      获取文档虚拟容器
      Returns:
      OFD文档虚拟容器
    • getDefaultDocSignaturesPath

      public ST_Loc getDefaultDocSignaturesPath()
      获取默认文档Doc_0中的签名列表文件的绝对路径
      Returns:
      签名列表文件绝对路径
      Throws:
      BadOFDException - 错误OFD结构和文件格式导致结构无法解析
    • getDefaultSignatures

      public Signatures getDefaultSignatures()
      获取默认的签名列表对象

      如果文件不存在则返还null

      Returns:
      签名列表对象
    • hasSignature

      public boolean hasSignature()
      文档是否包含数字签名
      Returns:
      true - 含有;false - 不含;
    • getAnnotations

      public Annotations getAnnotations()
      获取注解列表文件对象

      如果文档中没有注释文件,那么返还null

      Returns:
      注解列表文件对象或null
    • getNumberOfPages

      public int getNumberOfPages()
      获取OFD含有的总页面数量
      Returns:
      总页数
    • getPageInfo

      public PageInfo getPageInfo(int pageNum)
      获取页面信息
      Parameters:
      pageNum - 页码,从1开始
      Returns:
      页面信息
    • getPageList

      public List<PageInfo> getPageList()
      获取 页面信息集合
      Returns:
      页面信息集合
    • getTemplate

      public TemplatePageEntity getTemplate(String id)
      解析页面模板对象
      Parameters:
      id - 模板ID
      Returns:
      模板实体,如果模板不存在返还null
    • cdDoc

      public Document cdDoc(int numOfDoc) throws org.dom4j.DocumentException, FileNotFoundException
      切换目录到指定的文档下

      该操作将会导致资源加载器变更目录

      如果需要恢复被切换的目录请主动在外部调用restore

      Parameters:
      numOfDoc - 文档序号
      Returns:
      文档对象
      Throws:
      org.dom4j.DocumentException - 文档解析异常
      FileNotFoundException - Document.xml文档不存在
    • getDoc

      public Document getDoc(int numOfDoc) throws org.dom4j.DocumentException, FileNotFoundException
      获取文档对象
      Parameters:
      numOfDoc - 文档序号
      Returns:
      文档对象
      Throws:
      org.dom4j.DocumentException - 文档解析异常
      FileNotFoundException - Document.xml文档不存在
    • cdDefaultDoc

      public Document cdDefaultDoc() throws org.dom4j.DocumentException, FileNotFoundException
      切换目录到默认的文档目录下下

      该操作将会导致资源加载器变更目录

      如果需要恢复被切换的目录请主动在外部调用restore

      Returns:
      文档对象
      Throws:
      org.dom4j.DocumentException - 文档解析异常
      FileNotFoundException - Document.xml文档不存在
    • getPageSize

      public ST_Box getPageSize(Page page)
      获取页面物理大小

      如果页面没有定义页面区域,则使用文件 CommonData中的定义

      Parameters:
      page - 页面对象,null 表示获取默认物理页面大小。
      Returns:
      页面物理大小
    • getPageArea

      public CT_PageArea getPageArea(int num)
      获取 页面区域
      Parameters:
      num - 页码,从1起,若页码存在或超过最大最小页码则返还默认页面区域。
      Returns:
      页面区域
    • getPageSize

      public ST_Box getPageSize(int num)
      获取页面物理大小
      Parameters:
      num - 页码,从1起,当页码不存在时返回文档中的默认 页面物理大小。
      Returns:
      页面物理尺寸
    • getPageArea

      public CT_PageArea getPageArea(Page page)
      获取 页面区域
      Parameters:
      page - 页面对象,若为null 则返回文档默认页面区域大小。
      Returns:
      页面区域
    • getPage

      public Page getPage(int pageNum)
      通过页面页码获取页面对象
      Parameters:
      pageNum - 页码,从1起
      Returns:
      页面对象
      Throws:
      NumberFormatException - 页码小于1
      RuntimeException - 路径不存在,或文档解析异常
    • getPageAbsLoc

      public ST_Loc getPageAbsLoc(int pageNum)
      获取制定页码页面文件的在文档中的绝对路径 (以 "/" 开头)
      Parameters:
      pageNum - 页码
      Returns:
      页面文件的在文档中的绝对路径
      Throws:
      NumberFormatException - 页码小于1
      RuntimeException - 路径不存在
    • getPageObjectId

      public ST_ID getPageObjectId(int pageNum)
      获取页面的对象ID
      Parameters:
      pageNum - 页码
      Returns:
      对象ID
    • getResourceLocator

      public ResourceLocator getResourceLocator()
      获取资源定位器
      Returns:
      资源定位器
    • getAttachmentList

      public List<CT_Attachment> getAttachmentList()
      获取所有附件对象

      注意该对象均为只读

      Returns:
      附件数组,如果没有附件返还空数组
      Throws:
      BadOFDException - 文档结构损坏
    • getAttachmentFile

      public Path getAttachmentFile(CT_Attachment attachment)
      获取附件文件

      注意:该文件会在Close Reader时候被删除,请在之前复制到其他地方

      Parameters:
      attachment - 附件信息
      Returns:
      附件文件路径
    • getAttachment

      public CT_Attachment getAttachment(String name)
      获取附件对象

      该方法不会恢复资源定位器

      Parameters:
      name - 附件名称
      Returns:
      附件对象
    • getAttachmentFile

      public Path getAttachmentFile(String name)
      获取附件文件

      注意:该文件会在Close Reader时候被删除,请在之前复制到其他地方

      Parameters:
      name - 附件名称
      Returns:
      附件文件路径
    • getStampAnnots

      public List<StampAnnotEntity> getStampAnnots()
      获取默认文档中的签章信息
      Returns:
      签章信息
    • getAnnotationEntities

      public List<AnnotionEntity> getAnnotationEntities()
      获取默认文档中的所有注释信息
      Returns:
      注释实体信息列表
    • getResMgt

      public ResourceManage getResMgt()
      获取资源管理器

      资源管理器获取到的对象均为只读对象

      Returns:
      资源管理器
    • setNamespaceStrictMode

      public static void setNamespaceStrictMode(boolean enable)
      启用或关闭命名空间严格解析模式

      启用严格模式后将会忽略非ofd命名空间的元素。

      默认:关闭严格模式

      Parameters:
      enable - true - 启用; false - 兼容模式(默认),兼容ofd命名空间
    • close

      public void close() throws IOException
      关闭文档

      删除工作区

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - 工作区删除异常