public final class PageConfig
extends java.lang.Object
cleanup()
should
be called before the page context gets destroyed (e.g. by overwriting
jspDestroy()
or when leaving the service
method.
Purpose is to decouple implementation details from web design, so that the JSP developer does not need to know every implementation detail and normally has to deal with this class/wrapper, only (so some people may like to call this class a bean with request scope ;-)). Furthermore it helps to keep the pages (how content gets generated) consistent and to document the request parameters used.
General contract for this class (i.e. if not explicitly documented): no method of this class changes neither the request nor the response.
Modifier and Type | Method and Description |
---|---|
void |
addHeaderData(java.lang.String data)
Add the given data to the <head> section of the html page to
generate.
|
boolean |
annotate()
Check, whether the resource to show should be annotated.
|
java.lang.String |
canProcess()
Check, whether the request contains minimal information required to
produce a valid page.
|
void |
cleanup()
Cleanup all allocated resources.
|
java.io.File |
findDataFile()
Lookup the file
getPath() relative to the crossfile directory
of the opengrok data directory. |
java.io.File[] |
findDataFiles(java.util.List<java.lang.String> filenames)
Find the files with the given names in the
getPath() directory
relative to the crossfile directory of the opengrok data directory. |
boolean |
fullDiff()
Check, whether a full diff should be displayed.
|
static PageConfig |
get(javax.servlet.http.HttpServletRequest request)
Get the config wrt.
|
Annotation |
getAnnotation()
Get the annotation for the reqested resource.
|
java.util.List<java.lang.String> |
getCookieVals(java.lang.String cookieName)
Get the cookie values for the given name.
|
java.lang.String |
getCrossFilename()
Get the name which should be show as "Crossfile"
|
java.lang.String |
getCssDir()
Get the base path to use to refer to CSS stylesheets and related
resources.
|
java.io.File |
getDataRoot()
Get opengrok's configured dataroot directory.
|
java.lang.String |
getDefineTagsIndex()
Get the definition tag for the request related file or directory.
|
DiffData |
getDiffData()
Get all data required to create a diff view wrt.
|
DiffType |
getDiffType()
Get the diff display type to use wrt.
|
java.lang.String |
getDirectoryRedirect()
Get the path the request should be redirected (if any).
|
java.lang.String |
getDocumentHash()
Get the document hash provided by the request parameter
h . |
EftarFileReader |
getEftarReader()
Get the eftar reader for the opengrok data directory.
|
RuntimeEnvironment |
getEnv()
Get the current runtime environment.
|
java.lang.String |
getHeaderData()
Get addition data, which should be added as is to the <head>
section of the html page.
|
java.lang.String |
getHistoryDirs()
Get all RSS related directories from the request using its
also
parameter. |
IgnoredNames |
getIgnoredNames()
Get the name patterns used to determine, whether a file should be
ignored.
|
int |
getIntParam(java.lang.String name,
int defaultValue)
Get the int value of the given request parameter.
|
long |
getLastModified()
Get the time of last modification of the related file or directory.
|
java.lang.String |
getOnRedirect()
If a requested resource is not available, append "/on/" to
the source root directory and try again to resolve it.
|
java.lang.String |
getPath()
Get the canonical path of the related resource relative to the
source root directory (used file separators are all '/').
|
Prefix |
getPrefix()
Get the prefix for the related request.
|
Project |
getProject()
Get the project
getPath() refers to. |
QueryBuilder |
getQueryBuilder()
Get a reference to the
QueryBuilder wrt. |
java.util.SortedSet<java.lang.String> |
getRequestedProjects()
Get a reference to a set of requested projects via request parameter
project or cookies or defaults. |
protected java.util.SortedSet<java.lang.String> |
getRequestedProjects(java.lang.String paramName,
java.lang.String cookieName)
Same as
getRequestedProjects() , but with a variable cookieName
and parameter name. |
java.lang.String |
getRequestedProjectsAsString()
Same as
getRequestedProjects() but returns the project names as
a coma separated String. |
java.lang.String |
getRequestedRevision()
Get the revision parameter
r from the request. |
java.io.File |
getResourceFile()
Get the on disk file to the request related file or directory.
|
java.util.List<java.lang.String> |
getResourceFileList()
Get a list of filenames in the requested path.
|
java.lang.String |
getResourcePath()
Get the canonical on disk path to the request related file or directory
with all file separators replaced by a '/'.
|
int |
getSearchMaxItems()
Get the number of search results to max.
|
java.lang.String[] |
getSearchOnlyIn()
Get the
path parameter and display value for "Search only in"
option. |
int |
getSearchStart()
Get the start index for a search result to return by looking up
the
start request parameter. |
java.util.List<SortOrder> |
getSortOrder()
Get sort orders from the request parameter
sort and if this list
would be empty from the cookie OpenGrokorting . |
java.lang.String |
getSourceRootPath()
Get the canonical path to root of the source tree.
|
java.lang.String |
getTitle()
Get the page title to use.
|
java.lang.String |
getUriEncodedPath()
Get the URI encoded canonical path to the related file or directory
(the URI part between the servlet path and the start of the query string).
|
boolean |
hasAnnotations()
Check, whether annotations are available for the related resource.
|
boolean |
hasHistory()
Check, whether the request related resource has history information.
|
boolean |
isDir()
Check, whether the request related path represents a directory.
|
SearchHelper |
prepareSearch()
Prepare a search helper with all required information, ready to execute
the query implied by the related request parameters and cookies.
|
boolean |
resourceNotAvailable()
Check, whether the related request resource matches a valid file or
directory below the source root directory and wether it matches an
ignored pattern.
|
void |
setTitle(java.lang.String title)
Set the page title to use.
|
public void addHeaderData(java.lang.String data)
data
- data to add. It is copied as is, so remember to escape
special characters ...public java.lang.String getHeaderData()
public DiffData getDiffData()
null
. DiffData.errorMsg
!= null
indicates, that an error occured and one should not
try to render a view.public DiffType getDiffType()
format
.DiffType.SIDEBYSIDE
if the request contains no such parameter
or one with an unknown value, the recognized diff type otherwise.DiffType.get(String)
,
DiffType.getAbbrev()
,
DiffType.toString()
public boolean fullDiff()
true
if a request parameter full
with the
literal value 1
was found.public java.lang.String canProcess()
null
if the referred src file, directory or history is not
available, an empty String if further processing is ok and a non-empty
string which contains the URI encoded redirect path if the request
should be redirected.resourceNotAvailable()
,
getOnRedirect()
,
getDirectoryRedirect()
public java.util.List<java.lang.String> getResourceFileList()
getResourceFile()
,
isDir()
public long getLastModified()
File.lastModified()
public java.lang.String getHistoryDirs()
also
parameter.public int getIntParam(java.lang.String name, int defaultValue)
name
- name of the parameter to lookup.defaultValue
- value to return, if the parameter is not set, is not
a number, or is < 0.public int getSearchStart()
start
request parameter.public int getSearchMaxItems()
n
request parameter.public java.util.List<SortOrder> getSortOrder()
sort
and if this list
would be empty from the cookie OpenGrokorting
.public QueryBuilder getQueryBuilder()
QueryBuilder
wrt. to the current request
parameters:
public EftarFileReader getEftarReader()
cleanup()
takes care to close it.null
if a reader can't be established, the reader
otherwise.public java.lang.String getDefineTagsIndex()
public java.lang.String getRequestedRevision()
r
from the request."r=<i>revision</i>"
if found, an empty string otherwise.public boolean hasHistory()
true
if history is available.HistoryGuru.hasHistory(File)
public boolean hasAnnotations()
true
if annotions are available.public boolean annotate()
true
if annotation is desired and available.public Annotation getAnnotation()
null
if not available or annotation was not requested,
the cached annotation otherwise.public java.lang.String getCrossFilename()
public java.lang.String[] getSearchOnlyIn()
path
parameter and display value for "Search only in"
option.disabled=""
if the current path is the "/" directory,
otherwise set to an empty string.public Project getProject()
getPath()
refers to.null
if not available, the project otherwise.public java.lang.String getRequestedProjectsAsString()
getRequestedProjects()
but returns the project names as
a coma separated String.null
.public java.lang.String getDocumentHash()
h
.null
if the request does not contain such a parameter,
its value otherwise.public java.util.SortedSet<java.lang.String> getRequestedProjects()
project
or cookies or defaults.
NOTE: This method assumes, that project names do not contain a comma (','), since this character is used as name separator!
null
. It is determined as
follows:
project
contains any available
project, the set with invalid projects removed gets returned.
Otherwise:OpenGrokProject
and it contains any available project, the set with invalid
projects removed gets returned. Otherwise:public java.util.List<java.lang.String> getCookieVals(java.lang.String cookieName)
cookieName
- name of the cookie.protected java.util.SortedSet<java.lang.String> getRequestedProjects(java.lang.String paramName, java.lang.String cookieName)
getRequestedProjects()
, but with a variable cookieName
and parameter name. This way it is trivial to implement a project filter
...paramName
- the name of the request parameter, which possibly
contains the project list in question.cookieName
- name of the cookie which possible contains project
lists used as fallbacknull
.public void setTitle(java.lang.String title)
title
- title to set (might be null
).public java.lang.String getTitle()
null
if not set, the page title otherwise.public java.lang.String getCssDir()
HttpServletRequest.getContextPath()
,
RuntimeEnvironment.getWebappLAF()
public RuntimeEnvironment getEnv()
RuntimeEnvironment.getInstance()
,
RuntimeEnvironment.register()
public IgnoredNames getIgnoredNames()
public java.lang.String getSourceRootPath()
RuntimeEnvironment.getSourceRootPath()
public Prefix getPrefix()
Prefix.UNKNOWN
if the servlet path matches any known
prefix, the prefix otherwise.public java.lang.String getPath()
null
.HttpServletRequest.getPathInfo()
public java.lang.String getOnRedirect()
null
gets returned, which should be
used to redirect the client to the propper path.public java.io.File getResourceFile()
new File("/")
if the related file or directory is not
available (can not be find below the source root directory),
the readable file or directory otherwise.getSourceRootPath()
,
getPath()
public java.lang.String getResourcePath()
getResourceFile()
public boolean resourceNotAvailable()
true
if the related resource does not exists or should be
ignored.getIgnoredNames()
,
getResourcePath()
public boolean isDir()
true
if directory related requestpublic java.io.File[] findDataFiles(java.util.List<java.lang.String> filenames)
getPath()
directory
relative to the crossfile directory of the opengrok data directory. It
is tried to find the compressed file first by appending the file extension
".gz" to the filename. If that fails or an uncompressed version of the
file is younger than its compressed version, the uncompressed file gets
used.filenames
- filenames to lookup.null
or empty, otherwise an array, which may
contain null
entries (when the related file could not be found)
having the same order as the given list.public java.io.File findDataFile()
getPath()
relative to the crossfile directory
of the opengrok data directory. It is tried to find the compressed file
first by appending the file extension ".gz" to the filename. If that
fails or an uncompressed version of the file is younger than its
compressed version, the uncompressed file gets used.null
if not found, the file otherwise.public java.lang.String getDirectoryRedirect()
null
if there is no reason to redirect, the URI encoded
redirect path to use otherwise.public java.lang.String getUriEncodedPath()
null
.getPath()
public java.io.File getDataRoot()
java.security.InvalidParameterException
- if inaccessable or not set.public SearchHelper prepareSearch()
NOTE: One should check the SearchHelper.errorMsg
as well as
SearchHelper.redirect
and take the appropriate action before
executing the prepared query or continue processing.
This method stops populating fields as soon as an error occurs.
public static PageConfig get(javax.servlet.http.HttpServletRequest request)
request
- the request to use to initialize the config parameters.null
config for a given request.java.lang.NullPointerException
- if the given parameter is null
.public void cleanup()