PageConfig.java revision 1470
304N/A * The contents of this file are subject to the terms of the 304N/A * Common Development and Distribution License (the "License"). 304N/A * You may not use this file except in compliance with the License. 304N/A * language governing permissions and limitations under the License. 304N/A * When distributing Covered Code, include this CDDL HEADER in each 304N/A * If applicable, add the following below this CDDL HEADER, with the 304N/A * fields enclosed by brackets "[]" replaced with your own identifying 304N/A * information: Portions Copyright [yyyy] [name of copyright owner] 304N/A * Copyright (c) 2011 Jens Elkner. 304N/A * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * A simple container to lazy initialize common vars wrt. a single request. * It MUST NOT be shared between several requests and * {@link #cleanup(ServletRequest)} should be called before the page context * gets destroyed (e.g.when leaving the {@code 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 * General contract for this class (i.e. if not explicitly documented): * no method of this class changes neither the request nor the response. // TODO if still used, get it from the app context * Add the given data to the <head> section of the html page to * @param data data to add. It is copied as is, so remember to escape * Get addition data, which should be added as is to the <head> * section of the html page. * @return an empty string if nothing to add, the data otherwise. * Get all data required to create a diff view wrt. to this request in one go. * @return an instance with just enough information to render a sufficient * view. If not all required parameters were given either they are * supplemented with reasonable defaults if possible, otherwise the * related field(s) are {@code null}. {@link DiffData#errorMsg} * {@code != null} indicates, that an error occured and one should not * try to render a diff view. for (
int i =
1; i <=
2; i++) {
data.
errorMsg =
"Please pick two revisions to compare the changed " // would be nice, if history db could store genre as well, so that one // does not need to fetch undiffable binary files ... for (
int i =
0; i <
2; i++) {
data.
errorMsg =
"Error when trying to determine the file type of " +
genre[
0] +
" vs. " +
genre[
1] +
") are not supported.";
for (
int i =
0; i <
2; i++) {
for (
int i =
0; i <
2; i++) {
for (
int i =
0; i <
2; i++) {
* Get the diff display type to use wrt. the request parameter {@code format}. * @return {@link DiffType#SIDEBYSIDE} if the request contains no such parameter * or one with an unknown value, the recognized diff type otherwise. * @see DiffType#get(String) * @see DiffType#getAbbrev() * @see DiffType#toString() * Check, whether a full diff should be displayed. * @return {@code true} if a request parameter {@code full} with the * literal value {@code 1} was found. * Check, whether the request contains minimal information required to * produce a valid page. If this method returns an empty string, the * referred file or directory actually exists below the source root * directory and is readable. * @return {@code 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 * @see #resourceNotAvailable() * @see #getDirectoryRedirect() // if it is a history request, the requested resource does not need to // exist in the current tree anymore - take care of it //TODO: could be the same case as above for listing of revisioned files // jel: outfactored from list.jsp - seems to be bogus * Get a list of filenames in the requested path. * @return an empty list, if the resource does not exist, is not a * directory or an error occurred when reading it, otherwise a list of * filenames in that directory, sorted alphabetically * @see #getResourceFile() * Get the time of last modification of the related file or directory. * @return the last modification time of the related file or directory. * @see File#lastModified() * Get all RSS related directories from the request using its {@code also} * @return an empty string if the requested resource is not a directory, a * space (' ') separated list of unchecked directory names otherwise. * Get the int value of the given request parameter. * @param name name of the parameter to lookup. * @param defaultValue value to return, if the parameter is not set, is not * a number, or is < 0. * @return the parsed int value on success, the given default value otherwise. log.
info(
"Failed to parse integer " + s);
* Get the <b>start</b> index for a search result to return by looking up * the {@code start} request parameter. * @return 0 if the corresponding start parameter is not set or not a number, * the number found otherwise. * Get the number of search results to max. return by looking up the * {@code n} request parameter. * @return the default number of hits if the corresponding start parameter * is not set or not a number, the number found otherwise. * Get sort orders from the request parameter {@code sort} and if this list * would be empty from the cookie {@code OpenGrokorting}. * @return a possible empty list which contains the sort order values in * the same order supplied by the request parameter or cookie(s). * Get a reference to the {@code QueryBuilder} wrt. to the current request * <dd>freetext lookup rules</dd> * <dd>definitions lookup rules</dd> * <dd>path related rules</dd> * <dd>history related rules</dd> * @return a query builder with all relevant fields populated. // This is for backward compatibility with links created by OpenGrok // 0.8.x and earlier. We used to concatenate the entire query into a // single string and send it in the t parameter. If we get such a // link, just add it to the freetext field, and we'll get the old // behaviour. We can probably remove this code in the first feature * Get the eftar reader for the opengrok data directory. If it has been * already opened and not closed, this instance gets returned. One should * not close it once used: {@link #cleanup(ServletRequest)} takes care to * @return {@code null} if a reader can't be established, the reader * Get the definition tag for the request related file or directory. * @return an empty string if not found, the tag otherwise. // cfg.getPrefix() != Prefix.XREF_S) { * Get the revision parameter {@code r} from the request. * @return {@code "r=<i>revision</i>"} if found, an empty string otherwise. * Check, whether the request related resource has history information. * @return {@code true} if history is available. * @see HistoryGuru#hasHistory(File) * Check, whether annotations are available for the related resource. * @return {@code true} if annotions are available. * Check, whether the resource to show should be annotated. * @return {@code true} if annotation is desired and available. // TODO: remove ?a=true support? * Get the annotation for the reqested resource (revision parameter is * automagically honored). * @return {@code null} if not available or annotation was not requested, * the cached annotation otherwise. * @see #getRequestedRevision() * Get the name which should be shown as "Crossfile" * @return the name of the related file or directory. * Get the {@code path} parameter and display value for "Search only in" * @return always an array of 3 fields, whereby field[0] contains the * htmlized path value to use (starts and ends always with a '/'). Field[1] * is set to {@code disabled=""} if the current path is the "/" directory, * otherwise set to an empty string. ?
new String[] {
"/",
"disabled=\"\""}
* Get the project {@link #getPath()} refers to. * @return {@code null} if not available, the project otherwise. * Same as {@link #getRequestedProjects()} but returns the project names as * a coma separated String. * @return a possible empty String but never {@code null}. * Get the document hash provided by the request parameter {@code h}. * @return {@code null} if the request does not contain such a parameter, * Get a reference to a set of requested projects via request parameter * {@code project} or cookies or defaults. * NOTE: This method assumes, that project names do <b>not</b> contain * a comma (','), since this character is used as name separator! * @return a possible empty set of project names aka descriptions but never * {@code null}. It is determined as * <li>If there is no project in the runtime environment (RTE) an empty * set is returned. Otherwise:</li> * <li>If there is only one project in the RTE, this one gets returned (no * matter, what the request actually says). Otherwise</li> * <li>If the request parameter {@code project} contains any available * project, the set with invalid projects removed gets returned. * <li>If the request has a cookie with the name {@code OpenGrokProject} * and it contains any available project, the set with invalid * projects removed gets returned. Otherwise:</li> * <li>If a default project is set in the RTE, this project gets returned. for (
int k =
0; k < p.
length; k++) {
* Get the cookie values for the given name. Splits comma separated values * automatically into a list of Strings. * @param cookieName name of the cookie. * @return a possible empty list. * Get the parameter values for the given name. Splits comma separated * values automatically into a list of Strings. * @param name name of the parameter. * @return a possible empty list. * Same as {@link #getRequestedProjects()}, but with a variable cookieName * and parameter name. This way it is trivial to implement a project filter * @param paramName the name of the request parameter, which possibly * contains the project list in question. * @param cookieName name of the cookie which possible contains project * @return a possible empty set but never {@code null}. * Set the page title to use. * @param title title to set (might be {@code null}). * Get the page title to use. * @return {@code null} if not set, the page title otherwise. * Get the base path to use to refer to CSS stylesheets and related * resources. Usually used to create links. * @return the appropriate application directory prefixed with the * @see HttpServletRequest#getContextPath() * @see Configuration#getWebappLAF() * Get the current runtime environment. * @return the runtime env. * @see RuntimeEnvironment#getInstance() * @see RuntimeEnvironment#register() * Get the name patterns used to determine, whether a file should be * @return the corresponding value from the current runtime config.. * Get the canonical path to root of the source tree. File separators are * @return The on disk source root directory. * @see Configuration#getSourceRoot() * Get the prefix for the related request. * @return {@link Prefix#UNKNOWN} if the servlet path matches any known * prefix, the prefix otherwise. * Get the canonical path of the related resource relative to the * source root directory (used file separators are all '/'). No check is * made, whether the obtained path is really an accessible resource on disk. * @see HttpServletRequest#getPathInfo() * @return a possible empty String (denotes the source root directory) but * If a requested resource is not available, append "/on/" to * the source root directory and try again to resolve it. * @return on success a none-{@code null} gets returned, which should be * used to redirect the client to the propper path. * Get the on disk file to the request related file or directory. * NOTE: If a repository contains hard or symbolic links, the returned * file may finally point to a file outside of the source root directory. * @return {@code 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. * @see #getSourceRootPath() * Get the canonical on disk path to the request related file or directory * with all file separators replaced by a '/'. * @return "/" if the evaluated path is invalid or outside the source root * directory), otherwise the path to the readable file or directory. * @see #getResourceFile() * Check, whether the related request resource matches a valid file or * directory below the source root directory and wether it matches an * @return {@code true} if the related resource does not exists or should be * @see #getIgnoredNames() * @see #getResourcePath() * Check, whether the request related path represents a directory. * @return {@code true} if directory related request // doesn't exist in the current tree so ask the guru * Find the files with the given names in the {@link #getPath()} directory * relative to the crossfile directory of the opengrok data directory. * @param filenames filenames to lookup. * @return an empty array if the related directory does not exist or the * given list is {@code null} or empty, otherwise an array, which may * contain {@code null} entries (when the related file could not be found * or the related source file is younger) having the same order as the * Lookup the file {@link #getPath()} relative to the crossfile directory * of the opengrok data directory. * @return {@code null} if not found or the related source file is younger * than the crossfile, the crossfile otherwise. * Get the path the request should be redirected (if any). * @return {@code null} if there is no reason to redirect, the URI encoded * redirect path to use otherwise. //if it is an existing dir perhaps people wanted dir xref * 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). * @return an URI encoded path which might be an empty string but not * Get opengrok's configured dataroot directory. * It is veriefied, that the used environment has a valid opengrok data root * set and that it is an accessable directory. * @return the opengrok data directory. * @throws InvalidParameterException if inaccessable or not set. +
"' refers to a none-exsting or unreadable directory!");
* Prepare a search helper with all required information, ready to execute * the query implied by the related request parameters and cookies. * NOTE: One should check the {@link SearchHelper#errorMsg} as well as * {@link 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. * @return a search helper. // Entry page show the map // jel: this should be IMHO a config param since not only core dependend * Get the config wrt. the given request. If there is none yet, a new config * gets created, attached to the request and returned. * @param request the request to use to initialize the config parameters. * @return always the same none-{@code null} config for a given request. * @throws NullPointerException * if the given parameter is {@code null}. * Cleanup all allocated resources (if any) from the instance attached to * @param sr request to check, cleanup. Ignored if {@code null}. * @see PageConfig#get(HttpServletRequest)