org.dspace.app.util
Class OpenSearch

java.lang.Object
  extended by org.dspace.app.util.OpenSearch

public class OpenSearch
extends Object

Utility Class with static methods for producing OpenSearch-compliant search results, and the OpenSearch description document.

OpenSearch is a specification for describing and advertising search-engines and their result formats. Commonly, RSS and Atom formats are used, which the current implementation supports, as is HTML (used directly in browsers). NB: this is baseline OpenSearch, no extensions currently supported.

The value of the "scope" parameter should either be absent (which means no scope restriction), or the handle of a community or collection.

Author:
Richard Rodgers

Constructor Summary
OpenSearch()
           
 
Method Summary
static String getContentType(String format)
          Returns a mime-type associated with passed format
static String getDescription(String scope)
          Returns OpenSearch Servic Document as a string
static Document getDescriptionDoc(String scope)
          Returns the OpenSearch service document appropriate for given scope
static List<String> getFormats()
          Returns list of supported formats
static Document getResultsDoc(String format, String query, int totalResults, int start, int pageSize, DSpaceObject scope, DSpaceObject[] results, Map<String,String> labels)
          Returns a formatted set of search results as a document
static String getResultsString(String format, String query, int totalResults, int start, int pageSize, DSpaceObject scope, DSpaceObject[] results, Map<String,String> labels)
          Returns a formatted set of search results as a string
static DSpaceObject resolveScope(Context context, String scope)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OpenSearch

public OpenSearch()
Method Detail

getFormats

public static List<String> getFormats()
Returns list of supported formats

Returns:
list of format names - 'rss', 'atom' or 'html'

getContentType

public static String getContentType(String format)
Returns a mime-type associated with passed format

Parameters:
format - the results document format (rss, atom, html)
Returns:
content-type mime-type

getDescriptionDoc

public static Document getDescriptionDoc(String scope)
                                  throws IOException
Returns the OpenSearch service document appropriate for given scope

Parameters:
scope - - null for entire repository, or handle or community or collection
Returns:
document the service document
Throws:
IOException

getDescription

public static String getDescription(String scope)
Returns OpenSearch Servic Document as a string

Parameters:
scope - - null for entire repository, or handle or community or collection
Returns:
service document as a string

getResultsString

public static String getResultsString(String format,
                                      String query,
                                      int totalResults,
                                      int start,
                                      int pageSize,
                                      DSpaceObject scope,
                                      DSpaceObject[] results,
                                      Map<String,String> labels)
                               throws IOException
Returns a formatted set of search results as a string

Parameters:
format - results format - html, rss or atom
query - - the search query
totalResults - - the hit count
start - - start result index
pageSize - - page size
scope - - search scope, null or community/collection handle
results - the retreived DSpace objects satisfying search
labels - labels to apply - format specific
Returns:
formatted search results
Throws:
IOException

getResultsDoc

public static Document getResultsDoc(String format,
                                     String query,
                                     int totalResults,
                                     int start,
                                     int pageSize,
                                     DSpaceObject scope,
                                     DSpaceObject[] results,
                                     Map<String,String> labels)
                              throws IOException
Returns a formatted set of search results as a document

Parameters:
format - results format - html, rss or atom
query - - the search query
totalResults - - the hit count
start - - start result index
pageSize - - page size
scope - - search scope, null or community/collection handle
results - the retreived DSpace objects satisfying search
labels - labels to apply - format specific
Returns:
formatted search results
Throws:
IOException

resolveScope

public static DSpaceObject resolveScope(Context context,
                                        String scope)
                                 throws SQLException
Throws:
SQLException


Copyright © 2012 DuraSpace. All Rights Reserved.