Class ResourceLocator

java.lang.Object
org.ofdrw.reader.ResourceLocator

public class ResourceLocator extends Object
资源定位器

通过给与的资源地址获取对应的资源文件或对象

Since:
2020-04-08 20:05:14
Author:
权观宇
  • Field Details

    • PtDoc

      public static Pattern PtDoc
      路径匹配正则列表
    • PtSigns

      public static Pattern PtSigns
    • PtSign

      public static Pattern PtSign
    • PtPages

      public static Pattern PtPages
    • PtPage

      public static Pattern PtPage
    • PtPageRes

      public static Pattern PtPageRes
    • PtDocRes

      public static Pattern PtDocRes
  • Constructor Details

    • ResourceLocator

      public ResourceLocator(OFDDir ofdDir)
    • ResourceLocator

      public ResourceLocator(VirtualContainer vc)
      通过虚拟容器创建资源加载器 创建资源加载器的同时切换路径至虚拟容器的目录
      Parameters:
      vc - 虚拟容器
  • Method Details

    • save

      public ResourceLocator save()
      保存当前工作路径
      Returns:
      this
    • restore

      public ResourceLocator restore()
      还原原有工作区

      如果没有保存过工作区,那么不会造成任何影响

      Returns:
      this
    • toAbsolutePath

      public String toAbsolutePath(ST_Loc path)
      转换路径对象为绝对路径字符串
      Parameters:
      path - 路径对象
      Returns:
      绝对路径字符串
    • toAbsolutePath

      public String toAbsolutePath(String path)
      路径转换为绝对路径
      Parameters:
      path - 容器路径
      Returns:
      绝对路径字符串
    • restWd

      public ResourceLocator restWd()
      重置工作路径

      重置后将回到根路径

      Returns:
      this
    • cd

      切换到制定的虚拟容器目录下
      Parameters:
      vc - 虚拟容器
      Returns:
      this
    • cd

      public ResourceLocator cd(String path)
      改变目录 Change Directory
      Parameters:
      path - 路径位置
      Returns:
      this
      Throws:
      ErrorPathException - 路径不存在
    • cd

      public ResourceLocator cd(LinkedList<String> workDir, String path)
      改变目录 Change Directory

      路径最后如果是目录也不加 "/"

      Parameters:
      workDir - 已有工作目录
      path - 路径位置
      Returns:
      this
      Throws:
      ErrorPathException - 路径不存在
    • exist

      public boolean exist(String path)
      路径是否存在
      Parameters:
      path - 末端路径
      Returns:
      true -存在,false - 不存在
    • exist

      public boolean exist(LinkedList<String> workDir)
      判断路径是否存在
      Parameters:
      workDir - 路径集合
      Returns:
      true -存在,false - 不存在
    • dirExit

      public boolean dirExit(LinkedList<String> workDir)
      判断路径是否存在
      Parameters:
      workDir - 工作路径
      Returns:
      true -存在,false - 不存在
    • pwd

      public String pwd()
      打印工作目录 Print Work Directory

      路径最后如果是目录也不加 "/"

      Returns:
      工作目录路径
    • pwd

      public String pwd(List<String> workDir)
      打印工作目录 Print Work Directory
      Parameters:
      workDir - 工作目录
      Returns:
      工作目录路径
    • getAbsTo

      public ST_Loc getAbsTo(ST_Loc to)
      获取以当前路径为基础的容器内绝对路径
      Parameters:
      to - 目标路径
      Returns:
      容器内绝对路径
    • get

      public <R> R get(ST_Loc loc, Function<org.dom4j.Element, R> mapper) throws FileNotFoundException, org.dom4j.DocumentException
      根据路径获取获取对应的资源对象
      Type Parameters:
      R - 映射对象
      Parameters:
      loc - 路径地址
      mapper - 对象映射构造器
      Returns:
      对象
      Throws:
      FileNotFoundException - 文件不存在
      org.dom4j.DocumentException - 文件解析异常
    • get

      public <R> R get(String loc, Function<org.dom4j.Element, R> mapper) throws FileNotFoundException, org.dom4j.DocumentException
      根据路径获取获取对应的资源对象
      Type Parameters:
      R - 映射对象
      Parameters:
      loc - 路径地址
      mapper - 对象映射构造器
      Returns:
      对象
      Throws:
      FileNotFoundException - 文件不存在
      org.dom4j.DocumentException - 文件解析异常
    • getFile

      public Path getFile(ST_Loc stLoc) throws FileNotFoundException
      获取路径下的文件
      Parameters:
      stLoc - 路径
      Returns:
      系统文件路径
      Throws:
      FileNotFoundException - 文件或路径不存在
    • getFile

      public Path getFile(String loc) throws FileNotFoundException
      获取路径下的文件
      Parameters:
      loc - 路径
      Returns:
      系统文件路径
      Throws:
      FileNotFoundException - 文件或路径不存在
    • getContainer

      public VirtualContainer getContainer(LinkedList<String> workDir) throws FileNotFoundException
      通过路径获取容器
      Parameters:
      workDir - 路径序列
      Returns:
      虚拟容器
      Throws:
      FileNotFoundException - 路径不存在
    • getContainer

      public VirtualContainer getContainer(String containerPath) throws FileNotFoundException
      根据路径获取虚拟容器对象

      获取的同时会缓存整个容器链路

      Parameters:
      containerPath - 容器目录
      Returns:
      虚拟容器
      Throws:
      FileNotFoundException - 路径不存在
    • toString

      public String toString()
      Overrides:
      toString in class Object