package org.argeo;
+/** Argeo Commons specific exception. */
public class ArgeoException extends RuntimeException {
private static final long serialVersionUID = 1L;
+ /** Creates an exception with a message. */
public ArgeoException(String message) {
super(message);
}
- public ArgeoException(Throwable cause) {
- super(cause);
+ /** Creates an exception with a message and a root cause. */
+ public ArgeoException(String message, Throwable e) {
+ super(message, e);
}
- public ArgeoException(String message, Throwable cause) {
- super(message, cause);
+ /** @deprecated use {@link #ArgeoException(String, Throwable)} instead. */
+ @Deprecated
+ public ArgeoException(Throwable cause) {
+ super(cause);
}
}
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.argeo.commons.security</groupId>
</dependency>
<dependency>
- <!--
- Force inclusion of commons.lang to prevent v2.1.0 to be taken by
- Spring Security
- -->
+ <!-- Force inclusion of commons.lang to prevent v2.1.0 to be taken by
+ Spring Security -->
<groupId>org.apache.commons</groupId>
<artifactId>com.springsource.org.apache.commons.lang</artifactId>
</dependency>
<!-- Spring -->
<dependency>
- <groupId>org.argeo.dep.osgi</groupId>
- <artifactId>org.argeo.dep.osgi.springframework.ldap</artifactId>
+ <groupId>org.argeo.dep.osgi</groupId>
+ <artifactId>org.argeo.dep.osgi.springframework.ldap</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>com.springsource.slf4j.log4j</artifactId>
</dependency>
- <!-- JSON -->
+ <!-- JSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>com.springsource.org.codehaus.jackson.mapper</artifactId>
import java.io.File;
import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
import javax.jcr.Credentials;
import javax.jcr.LoginException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jackrabbit.commons.NamespaceHelper;
import org.apache.jackrabbit.core.RepositoryImpl;
import org.apache.jackrabbit.core.TransientRepository;
import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.argeo.ArgeoException;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
private Repository repository;
+ /** Namespaces to register: key is prefix, value namespace */
+ private Map<String, String> namespaces = new HashMap<String, String>();
+
public void afterPropertiesSet() throws Exception {
if (inMemory && homeDirectory.exists()) {
FileUtils.deleteDirectory(homeDirectory);
}
public Session login() throws LoginException, RepositoryException {
- return repository.login();
+ Session session = repository.login();
+ processNewSession(session);
+ return session;
}
public Session login(Credentials credentials, String workspaceName)
throws LoginException, NoSuchWorkspaceException,
RepositoryException {
- return repository.login(credentials, workspaceName);
+ Session session = repository.login(credentials, workspaceName);
+ processNewSession(session);
+ return session;
}
public Session login(Credentials credentials) throws LoginException,
RepositoryException {
- return repository.login(credentials);
+ Session session = repository.login(credentials);
+ processNewSession(session);
+ return session;
}
public Session login(String workspaceName) throws LoginException,
NoSuchWorkspaceException, RepositoryException {
- return repository.login(workspaceName);
+ Session session = repository.login(workspaceName);
+ processNewSession(session);
+ return session;
+ }
+
+ protected void processNewSession(Session session) {
+ try {
+ NamespaceHelper namespaceHelper = new NamespaceHelper(session);
+ namespaceHelper.registerNamespaces(namespaces);
+ } catch (RepositoryException e) {
+ throw new ArgeoException("Cannot process new session", e);
+ }
}
public boolean isStandardDescriptor(String key) {
this.inMemory = inMemory;
}
+ public void setNamespaces(Map<String, String> namespaces) {
+ this.namespaces = namespaces;
+ }
+
}
return dateAsPath(cal, false);
}
- /** The provided data as a path ('/' at the end, not the beginning) */
+ /**
+ * The provided data as a path ('/' at the end, not the beginning)
+ *
+ * @param cal
+ * the date
+ * @param addHour
+ * whether to add hour as well
+ */
public static String dateAsPath(Calendar cal, Boolean addHour) {
StringBuffer buf = new StringBuffer(14);
buf.append('Y').append(cal.get(Calendar.YEAR));// 5
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
+/** Proxy JCR sessions and attach them to calling threads. */
public class ThreadBoundJcrSessionFactory implements FactoryBean,
DisposableBean {
private final static Log log = LogFactory
private boolean destroying = false;
private final Session proxiedSession;
+ private String defaultUsername = "demo";
+ private String defaultPassword = "demo";
+
public ThreadBoundJcrSessionFactory() {
Class<?>[] interfaces = { Session.class };
proxiedSession = (Session) Proxy.newProxyInstance(getClass()
protected Session login() {
try {
- SimpleCredentials sc = new SimpleCredentials("demo", "demo"
- .toCharArray());
+ SimpleCredentials sc = new SimpleCredentials(defaultUsername,
+ defaultPassword.toCharArray());
Session sess = repository.login(sc);
if (log.isTraceEnabled())
log.trace("Log in to JCR session " + sess + "; userId="
this.repository = repository;
}
+ public void setDefaultUsername(String defaultUsername) {
+ this.defaultUsername = defaultUsername;
+ }
+
+ public void setDefaultPassword(String defaultPassword) {
+ this.defaultPassword = defaultPassword;
+ }
+
}