public class FileVar extends DefaultingVar
The format for this var is
File variables resolve to the contents of resource files located on the classpath or local JVM directory.
They use the RestRequest.getClasspathReaderResource(String)
method to retrieve the contents of the file.
That in turn uses the ClasspathResourceFinder
associated with the servlet class to find the file.
The ClasspathResourceFinder
is similar to Class.getResourceAsStream(String)
except if it doesn't find the
resource on this class, it searches up the parent hierarchy chain.
If the resource cannot be found in the classpath, then an attempt is made to look in the JVM working directory.
Path traversals outside the working directory are not allowed for security reasons.
Localized resources (based on the locale of the HTTP request) are supported.
For example, if looking for the resource
Example:
Files of type HTML, XHTML, XML, JSON, Javascript, and CSS will be stripped of comments. This allows you to place license headers in files without them being serialized to the output.
Modifier and Type | Field and Description |
---|---|
static String |
NAME
The name of this variable.
|
Constructor and Description |
---|
FileVar()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canResolve(VarResolverSession session)
Returns
|
String |
resolve(VarResolverSession session,
String key)
The interface that needs to be implemented for subclasses of
SimpleVar . |
doResolve
allowNested, allowRecurse, getName
public static final String NAME
public FileVar()
public String resolve(VarResolverSession session, String key) throws Exception
Var
SimpleVar
.public boolean canResolve(VarResolverSession session)
Var
For example, some variable cannot resolve unless specific context or session objects are available.
canResolve
in class Var
session
- The current session.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.