Search in sources :

Example 1 with JNDIRepositoryFactory

use of org.apache.jackrabbit.commons.repository.JNDIRepositoryFactory in project jackrabbit by apache.

the class JNDIRepositoryServlet method getRepository.

/**
     * Returns a JNDI repository based on the configured init parameters.
     *
     * @return JNDI repository
     */
protected Repository getRepository() throws RepositoryException {
    try {
        String location = Repository.class.getName().replace('.', '/');
        Hashtable environment = new Hashtable();
        Enumeration names = getInitParameterNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            if (name.equals("location")) {
                location = getInitParameter(name);
            } else if (!name.equals(Repository.class.getName())) {
                environment.put(name, getInitParameter(name));
            }
        }
        return new JNDIRepositoryFactory(new InitialContext(environment), location).getRepository();
    } catch (NamingException e) {
        throw new RepositoryException("Repository not found: Invalid JNDI context", e);
    }
}
Also used : Repository(javax.jcr.Repository) Enumeration(java.util.Enumeration) Hashtable(java.util.Hashtable) JNDIRepositoryFactory(org.apache.jackrabbit.commons.repository.JNDIRepositoryFactory) NamingException(javax.naming.NamingException) RepositoryException(javax.jcr.RepositoryException) InitialContext(javax.naming.InitialContext)

Aggregations

Enumeration (java.util.Enumeration)1 Hashtable (java.util.Hashtable)1 Repository (javax.jcr.Repository)1 RepositoryException (javax.jcr.RepositoryException)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 JNDIRepositoryFactory (org.apache.jackrabbit.commons.repository.JNDIRepositoryFactory)1