Regain 2.1.0-STABLE API

net.sf.regain.search
Class SearchToolkit

java.lang.Object
  extended by net.sf.regain.search.SearchToolkit

public class SearchToolkit
extends Object

A toolkit for the search JSPs containing helper methods.

Author:
Til Schneider, www.murfman.de

Field Summary
private static String FIELD_PREFIX
          The prefix for request parameters that contain additional field values.
private static String FIELD_PREFIX_NOSTRING
          The prefix for request parameters that contain additional field values that is not a string.
private static String INDEX_CONFIG_CONTEXT_ARRAY_ATTR_NAME
          The name of the page context attribute that holds the IndexConfig array.
private static SearchConfig mConfig
          The configuration of the search mask.
private static HashMap<String,String> mMimeTypeHash
          Holds for an extension the mime type.
private static String SEARCH_QUERY_CONTEXT_ATTR_NAME
          The name of the page context attribute that holds the search query.
private static String SEARCH_RESULTS_ATTR_NAME
          The name of the page context attribute that holds the SearchResults.
 
Constructor Summary
SearchToolkit()
           
 
Method Summary
static org.apache.lucene.search.BooleanQuery addAccessControlToQuery(org.apache.lucene.search.Query query, String[] allGroups)
          Restrict query: only allow documents that have one group of allGroups (To be used together with SearchAccessController)
static boolean allowFileAccess(PageRequest request, String fileUrl)
          Decides whether the remote access to a file should be allowed.
static String encodeFileUrl(String url, String encoding)
          Create a URL that targets the file-to-http-bridge Counterpart to extractFileUrl
static String extractFileUrl(String requestPath, String encoding)
          Extracts the file URL from a request path.
static IndexConfig[] getAllIndexConfigArr(PageRequest request)
          Gets the IndexConfig array from the configurationn.
static String getCompressedFieldValue(org.apache.lucene.document.Document doc, String fieldname)
          Get the content of a compressed lucene field.
static IndexConfig[] getIndexConfigArr(PageRequest request)
          Gets the IndexConfig array from the PageContext.
static IndexConfig[] getIndexConfigArrWithParent(PageRequest request)
          Gets the IndexConfig array from the PageContext.
static String getSearchQuery(PageRequest request)
          Gets the search query.
static SearchResults getSearchResults(PageRequest request)
          Gets the SearchResults from the PageContext.
private static void loadConfiguration(PageRequest request)
          Loads the configuration of the search mask.
static void sendFile(PageRequest request, PageResponse response, File file)
          Sends a file to the client.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEARCH_QUERY_CONTEXT_ATTR_NAME

private static final String SEARCH_QUERY_CONTEXT_ATTR_NAME
The name of the page context attribute that holds the search query.

See Also:
Constant Field Values

SEARCH_RESULTS_ATTR_NAME

private static final String SEARCH_RESULTS_ATTR_NAME
The name of the page context attribute that holds the SearchResults.

See Also:
Constant Field Values

INDEX_CONFIG_CONTEXT_ARRAY_ATTR_NAME

private static final String INDEX_CONFIG_CONTEXT_ARRAY_ATTR_NAME
The name of the page context attribute that holds the IndexConfig array.

See Also:
Constant Field Values

FIELD_PREFIX

private static final String FIELD_PREFIX
The prefix for request parameters that contain additional field values.

See Also:
Constant Field Values

FIELD_PREFIX_NOSTRING

private static final String FIELD_PREFIX_NOSTRING
The prefix for request parameters that contain additional field values that is not a string.

See Also:
Constant Field Values

mConfig

private static SearchConfig mConfig
The configuration of the search mask.


mMimeTypeHash

private static HashMap<String,String> mMimeTypeHash
Holds for an extension the mime type.

Constructor Detail

SearchToolkit

public SearchToolkit()
Method Detail

getIndexConfigArr

public static IndexConfig[] getIndexConfigArr(PageRequest request)
                                       throws RegainException
Gets the IndexConfig array from the PageContext. It contains the configurations of all indexes the search query is searching on.

If there is no IndexConfig array in the PageContext it is put in the PageContext, so the next call will find it.

Parameters:
request - The page request where the IndexConfig array will be taken from or put to.
Returns:
The IndexConfig array for the page the context is for.
Throws:
RegainException - If there is no IndexConfig for the specified index.

getIndexConfigArrWithParent

public static IndexConfig[] getIndexConfigArrWithParent(PageRequest request)
                                                 throws RegainException
Gets the IndexConfig array from the PageContext. It contains the configurations of all indexes the search query is searching on.

If there is no IndexConfig array in the PageContext it is put in the PageContext, so the next call will find it.

Parameters:
request - The page request where the IndexConfig array will be taken from or put to.
Returns:
The IndexConfig array for the page the context is for.
Throws:
RegainException - If there is no IndexConfig for the specified index.

getAllIndexConfigArr

public static IndexConfig[] getAllIndexConfigArr(PageRequest request)
                                          throws RegainException
Gets the IndexConfig array from the configurationn. It contains the configurations of all indexes in the configuration file.

Returns:
The IndexConfig array for all indizes.
Throws:
RegainException - If there is no IndexConfig for the specified index.

getSearchQuery

public static String getSearchQuery(PageRequest request)
                             throws RegainException
Gets the search query.

Parameters:
request - The request to get the query from.
Returns:
The search query.
Throws:
RegainException - If getting the query failed.

getSearchResults

public static SearchResults getSearchResults(PageRequest request)
                                      throws RegainException
Gets the SearchResults from the PageContext.

If there is no SearchResults in the PageContext it is created and put in the PageContext, so the next call will find it.

Parameters:
request - The page request where the SearchResults will be taken from or put to.
Returns:
The SearchResults for the page the context is for.
Throws:
RegainException - If the SearchResults could not be created.
See Also:
SearchResults

extractFileUrl

public static String extractFileUrl(String requestPath,
                                    String encoding)
                             throws RegainException
Extracts the file URL from a request path.

Parameters:
requestPath - The request path to extract the file URL from.
encoding - The encoding to use for the URL-docoding of the requestPath.
Returns:
The extracted file URL.
Throws:
RegainException - If extracting the file URL failed.
See Also:
LinkTag

encodeFileUrl

public static String encodeFileUrl(String url,
                                   String encoding)
                            throws RegainException
Create a URL that targets the file-to-http-bridge Counterpart to extractFileUrl

Parameters:
url - URL of the file that should be encoded
encoding - Character encoding to use
Returns:
Encoded File URL
Throws:
RegainException - If encoding the file URL failed.

allowFileAccess

public static boolean allowFileAccess(PageRequest request,
                                      String fileUrl)
                               throws RegainException
Decides whether the remote access to a file should be allowed.

The access is granted if the file is in the index. The access is never granted for indexes that have an access controller.

Parameters:
request - The request that holds the used index.
fileUrl - The URL to file to check.
Returns:
Whether the remote access to a file should be allowed.
Throws:
RegainException - If checking the file failed.

addAccessControlToQuery

public static org.apache.lucene.search.BooleanQuery addAccessControlToQuery(org.apache.lucene.search.Query query,
                                                                            String[] allGroups)
Restrict query: only allow documents that have one group of allGroups (To be used together with SearchAccessController)

Parameters:
query - Query to be modified
allGroups - Groups of the user
Returns:
Modified Query

sendFile

public static void sendFile(PageRequest request,
                            PageResponse response,
                            File file)
                     throws RegainException
Sends a file to the client.

Parameters:
request - The request.
response - The response.
file - The file to send.
Throws:
RegainException - If sending the file failed.

getCompressedFieldValue

public static String getCompressedFieldValue(org.apache.lucene.document.Document doc,
                                             String fieldname)
                                      throws RegainException
Get the content of a compressed lucene field.

Parameters:
doc - Lucene Index entry
fieldname - Index entry name
Returns:
String that was in this field
Throws:
RegainException - If decompression failed.

loadConfiguration

private static void loadConfiguration(PageRequest request)
                               throws RegainException
Loads the configuration of the search mask.

If the configuration is already loaded, nothing is done.

Parameters:
request - The page request. Used to get the "configFile" init parameter, which holds the name of the configuration file.
Throws:
RegainException - If loading failed.

Regain 2.1.0-STABLE API

Regain 2.1.0-STABLE, Copyright (C) 2004-2010 Til Schneider, www.murfman.de, Thomas Tesche, www.clustersystems.info