/** * * @param priority * @return a new instance of builder */ public static Builder builder(int priority) { return new Builder().setPriority(priority); }
/** * * @param priority * @param suffix * @param rootPath */ public PathTemplateLocator(int priority, String rootPath, String suffix) { super(priority); this.suffix = suffix; this.rootPath = initRootPath(rootPath); }
/** * * @return */ public FileSystemTemplateLocator build() { return new FileSystemTemplateLocator(priority, rootPath, suffix); }
public ClassPathTemplateLocator build() { ClassLoader cl; if (classLoader != null) { cl = classLoader; } else { cl = SecurityActions.getContextClassLoader(); if (cl == null) { cl = ClassPathTemplateLocator.class.getClassLoader(); } } return new ClassPathTemplateLocator(priority, rootPath, suffix, cl, scanClasspath); }
@Override public String toString() { return String.format("%s [priority: %s, suffix: %s, rootPath: %s]", getClass().getName(), getPriority(), getSuffix(), getRootPath()); }
@Override public Reader locate(String templateId) { return locateRealPath(toRealPath(templateId)); }
@Override public Reader locate(String filePath) { return locateRealPath(toRealPath(filePath)); }
/** * * @param priority * @param suffix * If null, a full template name must be used * @param rootPath * If null, no templates will be available for precompilation * @param classLoader * If null, use the TCCL or the CL of this class * @param scanClasspath * If set to <code>true</code> the locator will attempt to scan * the classpath to get all available template identifiers. */ public ClassPathTemplateLocator(int priority, String rootPath, String suffix, ClassLoader classLoader, boolean scanClasspath) { super(priority, rootPath, suffix); if (classLoader == null) { classLoader = SecurityActions.getContextClassLoader(); if (classLoader == null) { classLoader = SecurityActions .getClassLoader(ClassPathTemplateLocator.class); } } this.classLoader = classLoader; this.scanClasspath = scanClasspath; }
@Override public void init() { this.virtualPathSeparator = configuration .getStringPropertyValue(VIRTUAL_PATH_SEPARATOR_KEY); this.defaultFileEncoding = configuration.getStringPropertyValue( EngineConfigurationKey.DEFAULT_FILE_ENCODING); LOGGER.info( "{} initialized [virtualPathSeparator: {}, defaultFileEncoding: {}]", getClass().getSimpleName(), getVirtualPathSeparator(), getDefaultFileEncoding()); }
builder.addTemplateLocator(new ClassPathTemplateLocator(10, pathPrefix, MUSTACHE));
/** * * @param priority * @return a new instance of builder */ public static Builder builder() { return new Builder(); }
/** * * @param priority * @return a new instance of builder */ public static Builder builder() { return new Builder(); }
public static Builder builder() { return new Builder(); }
@Override protected File getRootDir() { return new File(getRootPath()); }
public MapTemplateLocator build() { return new MapTemplateLocator(new HashMap<>(templates)); }
private String initRootPath(String rootPath) { if (Strings.isEmpty(rootPath)) { return null; } return rootPath.endsWith(getRealPathSeparator()) ? rootPath : (rootPath + getRealPathSeparator()); }
/** * * @param priority * @param rootPath * @param suffix * @see Builder */ public FileSystemTemplateLocator(int priority, String rootPath, String suffix) { super(priority, rootPath, suffix); Checker.checkArgumentNotEmpty(rootPath); checkRootDir(); }
@Override public String toString() { return String.format("%s [priority: %s]", getClass().getName(), getPriority()); }
private Reader locate(String templateId) { List<TemplateLocator> locators = configuration.getTemplateLocators(); if (locators == null || locators.isEmpty()) { return null; } Reader reader = null; for (TemplateLocator locator : locators) { reader = locator.locate(templateId); if (reader != null) { break; } } return reader; }
protected void checkRootDir() { File rootDir = getRootDir(); if(rootDir == null) { return; } if (!Files.isDirectoryUsable(rootDir)) { throw new MustacheException( MustacheProblem.TEMPLATE_LOCATOR_INVALID_CONFIGURATION, "Invalid root dir: %s", rootDir); } }