Class SSIServletExternalResolver
java.lang.Object
org.apache.catalina.ssi.SSIServletExternalResolver
- All Implemented Interfaces:
SSIExternalResolver
An implementation of SSIExternalResolver that is used with servlets.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ServletContextThe servlet context for resource access.protected final intDebug level for SSI processing.protected final StringCharacter encoding for included file content.protected final booleanWhether virtual paths are relative to the webapp.protected final HttpServletRequestThe current HTTP servlet request.protected final HttpServletResponseThe current HTTP servlet response.protected final String[]Standard CGI variable names exposed to SSI. -
Constructor Summary
ConstructorsConstructorDescriptionSSIServletExternalResolver(ServletContext context, HttpServletRequest req, HttpServletResponse res, boolean isVirtualWebappRelative, int debug, String inputEncoding) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddVariableNames(Collection<String> variableNames) Add standard CGI variable names to the given collection.protected StringgetAbsolutePath(String path) Resolve a relative path to an absolute normalized path.protected StringgetCGIVariable(String name) Get the value of a CGI variable by name.Get the current date.longgetFileLastModified(String path, boolean virtual) Get the last modified time of a file.longgetFileSize(String path, boolean virtual) Get the size of a file.getFileText(String originalPath, boolean virtual) Get the text content of a file.protected StringgetPathWithoutContext(String contextPath, String servletPath) Remove the context path prefix from a servlet path.protected StringgetPathWithoutFileName(String servletPath) Get the path portion without the file name.protected ObjectgetReqAttributeIgnoreCase(String targetName) Get a request attribute by name, case-insensitive.getServletContextAndPath(String originalPath, boolean virtual) Resolve a path to a servlet context and path.getServletContextAndPathFromNonVirtualPath(String nonVirtualPath) Resolve a non-virtual (relative) path to a servlet context and path.getServletContextAndPathFromVirtualPath(String virtualPath) Resolve a virtual path to a servlet context and path.protected URLConnectiongetURLConnection(String originalPath, boolean virtual) Get a URL connection for the given path.getVariableValue(String name) Get the value of an SSI variable.protected booleanisNameReserved(String name) Check if a name is reserved (java.,javax.,sun.,jakarta.,org.apache.catalina.andorg.apache.tomcat.prefixes).protected booleanisRootContext(ServletContext servletContext) Check if the given servlet context is the root context.voidLog a message with an optional throwable.protected StringnullToEmptyString(String string) Convert null to an empty string.voidsetVariableValue(String name, String value) Set an SSI variable value as a request attribute.
-
Field Details
-
VARIABLE_NAMES
Standard CGI variable names exposed to SSI. -
context
The servlet context for resource access. -
req
The current HTTP servlet request. -
res
The current HTTP servlet response. -
isVirtualWebappRelative
protected final boolean isVirtualWebappRelativeWhether virtual paths are relative to the webapp. -
debug
protected final int debugDebug level for SSI processing. -
inputEncoding
Character encoding for included file content.
-
-
Constructor Details
-
SSIServletExternalResolver
public SSIServletExternalResolver(ServletContext context, HttpServletRequest req, HttpServletResponse res, boolean isVirtualWebappRelative, int debug, String inputEncoding) Constructor.- Parameters:
context- the servlet contextreq- the HTTP servlet requestres- the HTTP servlet responseisVirtualWebappRelative- whether virtual paths are relative to the webappdebug- debug levelinputEncoding- character encoding for included file content
-
-
Method Details
-
log
Log a message with an optional throwable.- Specified by:
login interfaceSSIExternalResolver- Parameters:
message- the message to logthrowable- the optional throwable
-
addVariableNames
Add standard CGI variable names to the given collection.- Specified by:
addVariableNamesin interfaceSSIExternalResolver- Parameters:
variableNames- the collection to add variable names to
-
getReqAttributeIgnoreCase
-
isNameReserved
Check if a name is reserved (java.,javax.,sun.,jakarta.,org.apache.catalina.andorg.apache.tomcat.prefixes).- Parameters:
name- the name to check- Returns:
- true if the name is reserved
-
setVariableValue
Set an SSI variable value as a request attribute.- Specified by:
setVariableValuein interfaceSSIExternalResolver- Parameters:
name- the variable namevalue- the variable value
-
getVariableValue
Get the value of an SSI variable.- Specified by:
getVariableValuein interfaceSSIExternalResolver- Parameters:
name- the variable name- Returns:
- the variable value or null
-
getCGIVariable
-
getCurrentDate
Get the current date.- Specified by:
getCurrentDatein interfaceSSIExternalResolver- Returns:
- the current date
-
nullToEmptyString
-
getPathWithoutFileName
-
getPathWithoutContext
-
getAbsolutePath
Resolve a relative path to an absolute normalized path.- Parameters:
path- the relative path- Returns:
- the absolute normalized path
- Throws:
IOException- if path normalization fails
-
getServletContextAndPathFromNonVirtualPath
protected SSIServletExternalResolver.ServletContextAndPath getServletContextAndPathFromNonVirtualPath(String nonVirtualPath) throws IOException Resolve a non-virtual (relative) path to a servlet context and path.- Parameters:
nonVirtualPath- the non-virtual path- Returns:
- the servlet context and resolved path
- Throws:
IOException- if the path is invalid
-
getServletContextAndPathFromVirtualPath
protected SSIServletExternalResolver.ServletContextAndPath getServletContextAndPathFromVirtualPath(String virtualPath) throws IOException Resolve a virtual path to a servlet context and path.- Parameters:
virtualPath- the virtual path- Returns:
- the servlet context and resolved path
- Throws:
IOException- if the path cannot be resolved
-
isRootContext
Check if the given servlet context is the root context.- Parameters:
servletContext- the servlet context- Returns:
- true if the context is the root
-
getServletContextAndPath
protected SSIServletExternalResolver.ServletContextAndPath getServletContextAndPath(String originalPath, boolean virtual) throws IOException Resolve a path to a servlet context and path.- Parameters:
originalPath- the original pathvirtual- whether the path is virtual- Returns:
- the servlet context and resolved path
- Throws:
IOException- if the path cannot be resolved
-
getURLConnection
Get a URL connection for the given path.- Parameters:
originalPath- the original pathvirtual- whether the path is virtual- Returns:
- the URL connection
- Throws:
IOException- if the resource is not found
-
getFileLastModified
Get the last modified time of a file.- Specified by:
getFileLastModifiedin interfaceSSIExternalResolver- Parameters:
path- the file pathvirtual- whether the path is virtual- Returns:
- the last modified time in milliseconds
- Throws:
IOException- if the file cannot be accessed
-
getFileSize
Get the size of a file.- Specified by:
getFileSizein interfaceSSIExternalResolver- Parameters:
path- the file pathvirtual- whether the path is virtual- Returns:
- the file size in bytes or -1 if unknown
- Throws:
IOException- if the file cannot be accessed
-
getFileText
Get the text content of a file.- Specified by:
getFileTextin interfaceSSIExternalResolver- Parameters:
originalPath- the original file pathvirtual- whether the path is virtual- Returns:
- the file content as text
- Throws:
IOException- if the file cannot be read
-