Package org.apache.catalina.ssi
Class SSIServletExternalResolver
- java.lang.Object
-
- org.apache.catalina.ssi.SSIServletExternalResolver
-
- All Implemented Interfaces:
SSIExternalResolver
public class SSIServletExternalResolver extends java.lang.Object implements SSIExternalResolver
An implementation of SSIExternalResolver that is used with servlets.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classSSIServletExternalResolver.ServletContextAndPath
-
Field Summary
Fields Modifier and Type Field Description protected ServletContextcontextThe servlet context for resource access.protected intdebugDebug level for SSI processing.protected java.lang.StringinputEncodingCharacter encoding for included file content.protected booleanisVirtualWebappRelativeWhether virtual paths are relative to the webapp.protected HttpServletRequestreqThe current HTTP servlet request.protected HttpServletResponseresThe current HTTP servlet response.protected java.lang.String[]VARIABLE_NAMESStandard CGI variable names exposed to SSI.
-
Constructor Summary
Constructors Constructor Description SSIServletExternalResolver(ServletContext context, HttpServletRequest req, HttpServletResponse res, boolean isVirtualWebappRelative, int debug, java.lang.String inputEncoding)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddVariableNames(java.util.Collection<java.lang.String> variableNames)Add standard CGI variable names to the given collection.protected java.lang.StringgetAbsolutePath(java.lang.String path)Resolve a relative path to an absolute normalized path.protected java.lang.StringgetCGIVariable(java.lang.String name)Get the value of a CGI variable by name.java.util.DategetCurrentDate()Get the current date.longgetFileLastModified(java.lang.String path, boolean virtual)Get the last modified time of a file.longgetFileSize(java.lang.String path, boolean virtual)Get the size of a file.java.lang.StringgetFileText(java.lang.String originalPath, boolean virtual)Get the text content of a file.protected java.lang.StringgetPathWithoutContext(java.lang.String contextPath, java.lang.String servletPath)Remove the context path prefix from a servlet path.protected java.lang.StringgetPathWithoutFileName(java.lang.String servletPath)Get the path portion without the file name.protected java.lang.ObjectgetReqAttributeIgnoreCase(java.lang.String targetName)Get a request attribute by name, case-insensitive.protected SSIServletExternalResolver.ServletContextAndPathgetServletContextAndPath(java.lang.String originalPath, boolean virtual)Resolve a path to a servlet context and path.protected SSIServletExternalResolver.ServletContextAndPathgetServletContextAndPathFromNonVirtualPath(java.lang.String nonVirtualPath)Resolve a non-virtual (relative) path to a servlet context and path.protected SSIServletExternalResolver.ServletContextAndPathgetServletContextAndPathFromVirtualPath(java.lang.String virtualPath)Resolve a virtual path to a servlet context and path.protected java.net.URLConnectiongetURLConnection(java.lang.String originalPath, boolean virtual)Get a URL connection for the given path.java.lang.StringgetVariableValue(java.lang.String name)Get the value of an SSI variable.protected booleanisNameReserved(java.lang.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(java.lang.String message, java.lang.Throwable throwable)Log a message with an optional throwable.protected java.lang.StringnullToEmptyString(java.lang.String string)Convert null to an empty string.voidsetVariableValue(java.lang.String name, java.lang.String value)Set an SSI variable value as a request attribute.
-
-
-
Field Detail
-
VARIABLE_NAMES
protected final java.lang.String[] VARIABLE_NAMES
Standard CGI variable names exposed to SSI.
-
context
protected final ServletContext context
The servlet context for resource access.
-
req
protected final HttpServletRequest req
The current HTTP servlet request.
-
res
protected final HttpServletResponse res
The current HTTP servlet response.
-
isVirtualWebappRelative
protected final boolean isVirtualWebappRelative
Whether virtual paths are relative to the webapp.
-
debug
protected final int debug
Debug level for SSI processing.
-
inputEncoding
protected final java.lang.String inputEncoding
Character encoding for included file content.
-
-
Constructor Detail
-
SSIServletExternalResolver
public SSIServletExternalResolver(ServletContext context, HttpServletRequest req, HttpServletResponse res, boolean isVirtualWebappRelative, int debug, java.lang.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 Detail
-
log
public void log(java.lang.String message, java.lang.Throwable throwable)Log a message with an optional throwable.- Specified by:
login interfaceSSIExternalResolver- Parameters:
message- the message to logthrowable- the optional throwable
-
addVariableNames
public void addVariableNames(java.util.Collection<java.lang.String> variableNames)
Add standard CGI variable names to the given collection.- Specified by:
addVariableNamesin interfaceSSIExternalResolver- Parameters:
variableNames- the collection to add variable names to
-
getReqAttributeIgnoreCase
protected java.lang.Object getReqAttributeIgnoreCase(java.lang.String targetName)
Get a request attribute by name, case-insensitive.- Parameters:
targetName- the attribute name- Returns:
- the attribute value or null
-
isNameReserved
protected boolean isNameReserved(java.lang.String name)
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
public void setVariableValue(java.lang.String name, java.lang.String value)Set an SSI variable value as a request attribute.- Specified by:
setVariableValuein interfaceSSIExternalResolver- Parameters:
name- the variable namevalue- the variable value
-
getVariableValue
public java.lang.String getVariableValue(java.lang.String name)
Get the value of an SSI variable.- Specified by:
getVariableValuein interfaceSSIExternalResolver- Parameters:
name- the variable name- Returns:
- the variable value or null
-
getCGIVariable
protected java.lang.String getCGIVariable(java.lang.String name)
Get the value of a CGI variable by name.- Parameters:
name- the CGI variable name- Returns:
- the variable value or null
-
getCurrentDate
public java.util.Date getCurrentDate()
Get the current date.- Specified by:
getCurrentDatein interfaceSSIExternalResolver- Returns:
- the current date
-
nullToEmptyString
protected java.lang.String nullToEmptyString(java.lang.String string)
Convert null to an empty string.- Parameters:
string- the input string- Returns:
- the string or empty string if null
-
getPathWithoutFileName
protected java.lang.String getPathWithoutFileName(java.lang.String servletPath)
Get the path portion without the file name.- Parameters:
servletPath- the servlet path- Returns:
- the path without file name or null
-
getPathWithoutContext
protected java.lang.String getPathWithoutContext(java.lang.String contextPath, java.lang.String servletPath)Remove the context path prefix from a servlet path.- Parameters:
contextPath- the context pathservletPath- the servlet path- Returns:
- the path without context prefix
-
getAbsolutePath
protected java.lang.String getAbsolutePath(java.lang.String path) throws java.io.IOExceptionResolve a relative path to an absolute normalized path.- Parameters:
path- the relative path- Returns:
- the absolute normalized path
- Throws:
java.io.IOException- if path normalization fails
-
getServletContextAndPathFromNonVirtualPath
protected SSIServletExternalResolver.ServletContextAndPath getServletContextAndPathFromNonVirtualPath(java.lang.String nonVirtualPath) throws java.io.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:
java.io.IOException- if the path is invalid
-
getServletContextAndPathFromVirtualPath
protected SSIServletExternalResolver.ServletContextAndPath getServletContextAndPathFromVirtualPath(java.lang.String virtualPath) throws java.io.IOException
Resolve a virtual path to a servlet context and path.- Parameters:
virtualPath- the virtual path- Returns:
- the servlet context and resolved path
- Throws:
java.io.IOException- if the path cannot be resolved
-
isRootContext
protected boolean isRootContext(ServletContext servletContext)
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(java.lang.String originalPath, boolean virtual) throws java.io.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:
java.io.IOException- if the path cannot be resolved
-
getURLConnection
protected java.net.URLConnection getURLConnection(java.lang.String originalPath, boolean virtual) throws java.io.IOExceptionGet a URL connection for the given path.- Parameters:
originalPath- the original pathvirtual- whether the path is virtual- Returns:
- the URL connection
- Throws:
java.io.IOException- if the resource is not found
-
getFileLastModified
public long getFileLastModified(java.lang.String path, boolean virtual) throws java.io.IOExceptionGet 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:
java.io.IOException- if the file cannot be accessed
-
getFileSize
public long getFileSize(java.lang.String path, boolean virtual) throws java.io.IOExceptionGet 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:
java.io.IOException- if the file cannot be accessed
-
getFileText
public java.lang.String getFileText(java.lang.String originalPath, boolean virtual) throws java.io.IOExceptionGet 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:
java.io.IOException- if the file cannot be read
-
-