org.openrdf.elmo.scutter
Class Util

java.lang.Object
  extended by org.openrdf.elmo.scutter.Util

public class Util
extends Object


Field Summary
protected static Logger _logger
           
static String CONTEXT_PASSWORD_PARAMETER
           
static String CONTEXT_REPOSITORY_PARAMETER
           
static String CONTEXT_SERVER_PARAMETER
           
static String CONTEXT_USERNAME_PARAMETER
           
static String REQUEST_REPOSITORY_ATTRIBUTE
           
static String SERVLET_PASSWORD_PARAMETER
           
static String SERVLET_REPOSITORY_PARAMETER
           
static String SERVLET_SERVER_PARAMETER
           
static String SERVLET_USERNAME_PARAMETER
           
 
Constructor Summary
Util()
           
 
Method Summary
static void copyRepositoryContent(Repository source, Repository target)
           
static
<T extends Resource>
List<T>
getAllInstances(ElmoManager manager, Class<T> cl)
          Get all instances of type T from a given repository
static int getContentLength(String url)
          Determine the value for the Content-Length header using a HEAD call
static InputStream getDocumentAsInputStream(String url)
          Retrieve a document from the given URL using HTTP GET
static String getDocumentAsString(String url)
          Retrieve a document from the given URL using HTTP GET.
static URI getType(Class c)
          Find the ontological type (rdfs:Class) for a Java Class
static ElmoManager initManager(Repository repository)
           
static Repository initRepository(HttpServletRequest request)
          Initialize an Elmo repository from servlet request.
static Repository initRepository(ServletConfig config)
          Initialize an Elmo repository from servlet initialization parameters and if that fails from the context initialization parameters.
static Repository initRepository(ServletConfig config, HttpServletRequest request)
          Initialize an Elmo repository from either servlet request parameters or servlet initialization parameters.
static Repository initRepository(String repositoryLocation, String repositoryName)
          Initialize a remote Elmo repository using the location and name
static Repository initRepository(String repositoryLocation, String repositoryName, String username, String password)
          Initialize a remote Elmo repository using (optional) username and password.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVLET_SERVER_PARAMETER

public static final String SERVLET_SERVER_PARAMETER
See Also:
Constant Field Values

SERVLET_REPOSITORY_PARAMETER

public static final String SERVLET_REPOSITORY_PARAMETER
See Also:
Constant Field Values

SERVLET_USERNAME_PARAMETER

public static final String SERVLET_USERNAME_PARAMETER
See Also:
Constant Field Values

SERVLET_PASSWORD_PARAMETER

public static final String SERVLET_PASSWORD_PARAMETER
See Also:
Constant Field Values

CONTEXT_SERVER_PARAMETER

public static final String CONTEXT_SERVER_PARAMETER
See Also:
Constant Field Values

CONTEXT_REPOSITORY_PARAMETER

public static final String CONTEXT_REPOSITORY_PARAMETER
See Also:
Constant Field Values

CONTEXT_USERNAME_PARAMETER

public static final String CONTEXT_USERNAME_PARAMETER
See Also:
Constant Field Values

CONTEXT_PASSWORD_PARAMETER

public static final String CONTEXT_PASSWORD_PARAMETER
See Also:
Constant Field Values

REQUEST_REPOSITORY_ATTRIBUTE

public static final String REQUEST_REPOSITORY_ATTRIBUTE
See Also:
Constant Field Values

_logger

protected static Logger _logger
Constructor Detail

Util

public Util()
Method Detail

getDocumentAsInputStream

public static InputStream getDocumentAsInputStream(String url)
                                            throws org.apache.commons.httpclient.HttpException,
                                                   IOException
Retrieve a document from the given URL using HTTP GET

Parameters:
url -
Returns:
Document as stream
Throws:
org.apache.commons.httpclient.HttpException
IOException
See Also:
GetMethod

getDocumentAsString

public static String getDocumentAsString(String url)
                                  throws org.apache.commons.httpclient.HttpException,
                                         IOException
Retrieve a document from the given URL using HTTP GET. The method getDocumentAsInputStream is preferred over this one, because reading a document requires to buffer a document of unknown size.

Parameters:
url -
Returns:
Document as String
Throws:
org.apache.commons.httpclient.HttpException
IOException
See Also:
getDocumentAsInputStream(java.lang.String)

getContentLength

public static int getContentLength(String url)
                            throws org.apache.commons.httpclient.HttpException,
                                   IOException
Determine the value for the Content-Length header using a HEAD call

Parameters:
url -
Returns:
Throws:
org.apache.commons.httpclient.HttpException
IOException

initManager

public static ElmoManager initManager(Repository repository)

initRepository

public static Repository initRepository(String repositoryLocation,
                                        String repositoryName)
                                 throws Exception
Initialize a remote Elmo repository using the location and name

Parameters:
repositoryLocation - String containing a URL
repositoryName - Repository name
Returns:
Repository
Throws:
Exception - if parameter is missing, invalid or initilization failed
See Also:
elmo.repository.ElmoRepository

initRepository

public static Repository initRepository(String repositoryLocation,
                                        String repositoryName,
                                        String username,
                                        String password)
                                 throws Exception
Initialize a remote Elmo repository using (optional) username and password. Performs some sanity checks on the repository location and name.

Parameters:
repositoryLocation - URL of the server
repositoryName - Repository name
username - Optional username
password - Optional password
Returns:
Repository
Throws:
Exception - if parameter is missing, invalid or initilization failed

initRepository

public static Repository initRepository(HttpServletRequest request)
                                 throws ServletException
Initialize an Elmo repository from servlet request. First try to find a SesameRepository as a request attribute , if fails try to initialize one using request parameter. The attribute and init parameter names to specified are defined as constants in this class.

Parameters:
request - Request with parameters
Returns:
Repository
Throws:
ServletException - if parameters are missing or repository failed to initialize
See Also:
REQUEST_REPOSITORY_ATTRIBUTE, SERVLET_SERVER_PARAMETER, SERVLET_REPOSITORY_PARAMETER, SERVLET_USERNAME_PARAMETER, SERVLET_USERNAME_PARAMETER

initRepository

public static Repository initRepository(ServletConfig config)
                                 throws ServletException
Initialize an Elmo repository from servlet initialization parameters and if that fails from the context initialization parameters. The init parameter names to specified are defined as constants in this class.

Parameters:
config - ServletConfig instance
Returns:
Repository
Throws:
ServletException - if parameters are missing or repository failed to initialize
See Also:
SERVLET_SERVER_PARAMETER, SERVLET_REPOSITORY_PARAMETER, SERVLET_USERNAME_PARAMETER, SERVLET_PASSWORD_PARAMETER, CONTEXT_SERVER_PARAMETER, CONTEXT_REPOSITORY_PARAMETER, CONTEXT_USERNAME_PARAMETER, CONTEXT_PASSWORD_PARAMETER

initRepository

public static Repository initRepository(ServletConfig config,
                                        HttpServletRequest request)
                                 throws ServletException
Initialize an Elmo repository from either servlet request parameters or servlet initialization parameters. First try to find a ElmoRepository object in the request. If not present, try to initialize one based on request parameters. If this also fails, try to use servlet init parameters and lastly the context initialization paratemers. The attribute, request and init parameter names to specified are defined as constants in this class.

Parameters:
servlet - Servlet instance
request - Request with parameters
Returns:
Repository
Throws:
ServletException - if parameters are missing or repository failed to initialize
See Also:
REQUEST_REPOSITORY_ATTRIBUTE, SERVLET_SERVER_PARAMETER, SERVLET_REPOSITORY_PARAMETER, SERVLET_USERNAME_PARAMETER, SERVLET_USERNAME_PARAMETER, CONTEXT_SERVER_PARAMETER, CONTEXT_REPOSITORY_PARAMETER, CONTEXT_USERNAME_PARAMETER, CONTEXT_USERNAME_PARAMETER

copyRepositoryContent

public static void copyRepositoryContent(Repository source,
                                         Repository target)
                                  throws OpenRDFException,
                                         IOException
Throws:
OpenRDFException
IOException

getType

public static URI getType(Class c)
Find the ontological type (rdfs:Class) for a Java Class

Parameters:
c -
Returns:
URI of the class

getAllInstances

public static <T extends Resource> List<T> getAllInstances(ElmoManager manager,
                                                           Class<T> cl)
Get all instances of type T from a given repository

Type Parameters:
T -
Parameters:
rep -
cl -
Returns:


Copyright © 2004-2008 Aduna. All Rights Reserved.