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