Class ClasspathStringResourceLoader

java.lang.Object
org.beetl.core.resource.ClasspathResourceLoader
tech.riemann.nif.nutz.dao.sqltpl.beetl.ClasspathStringResourceLoader
All Implemented Interfaces:
Closeable, Serializable, AutoCloseable, org.beetl.core.ResourceLoader<String>

public class ClasspathStringResourceLoader extends org.beetl.core.resource.ClasspathResourceLoader
ClasspathStringResourceLoader 类扩展了 ClasspathResourceLoader, 用于同时支持从类路径加载资源和直接使用字符串作为模板资源。 当资源键以 "/" 开头时,使用父类的类路径资源加载机制; 否则将键直接作为字符串模板处理。
Author:
Kerbores(kerbores@gmail.com)
See Also:
  • Field Summary

    Fields inherited from class org.beetl.core.resource.ClasspathResourceLoader

    charset
  • Constructor Summary

    Constructors
    Constructor
    Description
    默认构造函数,调用父类的默认构造函数
    构造函数,使用指定的类加载器初始化资源加载器
    构造函数,使用指定的类加载器和根路径初始化资源加载器
    构造函数,使用指定的类加载器、根路径和字符集初始化资源加载器
    构造函数,使用指定的根路径初始化资源加载器
    构造函数,使用指定的根路径和字符集初始化资源加载器
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    检查指定键对应的资源是否存在 如果键以 "/" 开头,则使用父类的存在性检查机制; 否则直接返回 true,因为字符串模板总是存在的。
    org.beetl.core.Resource<?>
    获取指定键对应的资源 如果键以 "/" 开头,则使用父类的资源获取机制从类路径加载资源; 否则将键作为字符串模板直接创建 StringTemplateResource 对象。

    Methods inherited from class org.beetl.core.resource.ClasspathResourceLoader

    checkRoot, close, getCharset, getChildPath, getClassLoader, getInfo, getResourceId, getRoot, init, isAutoCheck, isModified, setAutoCheck, setCharset, setClassLoader

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ClasspathStringResourceLoader

      public ClasspathStringResourceLoader()
      默认构造函数,调用父类的默认构造函数
    • ClasspathStringResourceLoader

      public ClasspathStringResourceLoader(ClassLoader classLoader, String root, String charset)
      构造函数,使用指定的类加载器、根路径和字符集初始化资源加载器
      Parameters:
      classLoader - 类加载器,用于加载类路径资源
      root - 根路径,资源查找的基准路径
      charset - 字符集,用于读取资源时的字符编码
    • ClasspathStringResourceLoader

      public ClasspathStringResourceLoader(ClassLoader classLoader, String root)
      构造函数,使用指定的类加载器和根路径初始化资源加载器
      Parameters:
      classLoader - 类加载器,用于加载类路径资源
      root - 根路径,资源查找的基准路径
    • ClasspathStringResourceLoader

      public ClasspathStringResourceLoader(ClassLoader classLoader)
      构造函数,使用指定的类加载器初始化资源加载器
      Parameters:
      classLoader - 类加载器,用于加载类路径资源
    • ClasspathStringResourceLoader

      public ClasspathStringResourceLoader(String root, String charset)
      构造函数,使用指定的根路径和字符集初始化资源加载器
      Parameters:
      root - 根路径,资源查找的基准路径
      charset - 字符集,用于读取资源时的字符编码
    • ClasspathStringResourceLoader

      public ClasspathStringResourceLoader(String root)
      构造函数,使用指定的根路径初始化资源加载器
      Parameters:
      root - 根路径,资源查找的基准路径
  • Method Details

    • getResource

      public org.beetl.core.Resource<?> getResource(String key)
      获取指定键对应的资源 如果键以 "/" 开头,则使用父类的资源获取机制从类路径加载资源; 否则将键作为字符串模板直接创建 StringTemplateResource 对象。
      Specified by:
      getResource in interface org.beetl.core.ResourceLoader<String>
      Overrides:
      getResource in class org.beetl.core.resource.ClasspathResourceLoader
      Parameters:
      key - 资源键,用于标识要获取的资源
      Returns:
      Resource<?> 资源对象,可以是类路径资源或字符串模板资源
    • exist

      public boolean exist(String key)
      检查指定键对应的资源是否存在 如果键以 "/" 开头,则使用父类的存在性检查机制; 否则直接返回 true,因为字符串模板总是存在的。
      Specified by:
      exist in interface org.beetl.core.ResourceLoader<String>
      Overrides:
      exist in class org.beetl.core.resource.ClasspathResourceLoader
      Parameters:
      key - 资源键,用于标识要检查的资源
      Returns:
      boolean 资源存在返回 true,否则返回 false