public class ScriptEnvironment extends Object
Constructor and Description |
---|
ScriptEnvironment(javax.servlet.http.HttpServletRequest req,
javax.servlet.ServletContext context,
String scriptPathPrefix)
Creates a CGIEnvironment and derives the necessary environment,
query parameters, working directory, cgi command, etc.
|
Modifier and Type | Method and Description |
---|---|
protected String |
blanksToString(String couldBeBlank,
String subForBlanks)
Converts blank strings to another string
|
protected void |
expandScript()
Extracts requested resource from web app archive to context work
directory to enable script to be executed.
|
protected String[] |
findScript(String pathInfo,
String webAppRootDir,
String contextPath,
String servletPath,
String scriptPathPrefix)
Resolves core information about the php script.
|
Hashtable |
getEnvironment()
Gets derived Script environment
|
String[] |
getEnvironmentArray()
Converts Environment Hastable to String array
|
String |
getFullPath()
Gets derived script full path
|
ArrayList |
getParameters()
Gets derived Script query parameters
|
File |
getScriptFile()
Gets derived Script file
|
File |
getWorkingDirectory()
Gets derived Script working directory
|
static String[] |
hashToStringArray(Hashtable h)
Converts a Hashtable to a String array by converting each
key/value pair in the Hashtable to two consecutive Strings
|
boolean |
isValid()
Gets validity status
|
protected String |
nullsToBlanks(String s)
Converts null strings to blank strings ("")
|
protected String |
nullsToString(String couldBeNull,
String subForNulls)
Converts null strings to another string
|
protected boolean |
setEnvironment(javax.servlet.http.HttpServletRequest req)
Constructs the CGI environment to be supplied to the invoked CGI
script; relies heavliy on Servlet API methods and findCGI
|
public ScriptEnvironment(javax.servlet.http.HttpServletRequest req, javax.servlet.ServletContext context, String scriptPathPrefix) throws IOException
req
- HttpServletRequest for information provided by
the Servlet APIcontext
- ServletContext for information provided by the
Servlet APIIOException
protected String[] findScript(String pathInfo, String webAppRootDir, String contextPath, String servletPath, String scriptPathPrefix)
Example URI:
/servlet/scriptGateway/dir1/realScript/pathinfo1
path
= $CATALINA_HOME/mywebapp/dir1/realScript
scriptName
= /servlet/scriptGateway/dir1/realScript
fullName
= /dir1/realScript
name
= realScript
Script search algorithm: search the real path below <my-webapp-root> and find the first non-directory in the getPathTranslated("/"), reading/searching from left-to-right.
The Script search path will start at webAppRootDir + File.separator + scriptPathPrefix (or webAppRootDir alone if scriptPathPrefix is null).
scriptPathPrefix is defined by setting this servlet's scriptPathPrefix init parameter
pathInfo
- String from HttpServletRequest.getPathInfo()webAppRootDir
- String from context.getRealPath("/")contextPath
- String as from
HttpServletRequest.getContextPath()servletPath
- String as from
HttpServletRequest.getServletPath()scriptPathPrefix
- Subdirectory of webAppRootDir below which
the web app's Scripts may be stored; can be null.
The Script search path will start at
webAppRootDir + File.separator + scriptPathPrefix
(or webAppRootDir alone if scriptPathPrefix is
null). scriptPathPrefix is defined by setting
the servlet's scriptPathPrefix init parameter.path
- full file-system path to valid script file,
or null if no script file was found
scriptName
-
Script variable SCRIPT_NAME; the full URL path
to valid script file or null if no script was
found
fullName
- servlet pathInfo fragment corresponding to
the script itself, or null if not found
name
- simple name (no directories) of the
script, or null if no script was found
protected void expandScript()
protected boolean setEnvironment(javax.servlet.http.HttpServletRequest req) throws IOException
req
- request associated with the CGI
invokationIOException
public String getFullPath()
public File getScriptFile()
public File getWorkingDirectory()
public Hashtable getEnvironment()
public ArrayList getParameters()
public boolean isValid()
protected String nullsToBlanks(String s)
s
- string to be converted if necessarynull
protected String nullsToString(String couldBeNull, String subForNulls)
couldBeNull
- string to be converted if necessarysubForNulls
- string to return instead of a null stringnull
protected String blanksToString(String couldBeBlank, String subForBlanks)
couldBeBlank
- string to be converted if necessarysubForBlanks
- string to return instead of a blank stringnull
or empty ("")public String[] getEnvironmentArray() throws NullPointerException
NullPointerException
- if a hash key has a null valuepublic static String[] hashToStringArray(Hashtable h) throws NullPointerException
h
- Hashtable to convertNullPointerException
- if a hash key has a null valueCopyright © 2016 JBoss by Red Hat. All rights reserved.