X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=server%2Fruntime%2Forg.argeo.server.jackrabbit%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fserver%2Fjackrabbit%2FJackrabbitContainer.java;h=ef96b3595d153ba10aaa877704c5277074ceb9de;hb=73121781a9ee5c08891beaf4ab714cd728e586b2;hp=21209b51120065e564853ac3a4d167393606d188;hpb=1f8e265227896228ced3d39285abaee99bb97e5e;p=lgpl%2Fargeo-commons.git diff --git a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/JackrabbitContainer.java b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/JackrabbitContainer.java index 21209b511..ef96b3595 100644 --- a/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/JackrabbitContainer.java +++ b/server/runtime/org.argeo.server.jackrabbit/src/main/java/org/argeo/server/jackrabbit/JackrabbitContainer.java @@ -1,3 +1,19 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.argeo.server.jackrabbit; import java.io.File; @@ -9,9 +25,12 @@ import javax.jcr.NoSuchWorkspaceException; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; +import javax.jcr.Value; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.jackrabbit.core.RepositoryImpl; import org.apache.jackrabbit.core.TransientRepository; import org.apache.jackrabbit.core.config.RepositoryConfig; @@ -19,8 +38,14 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.Resource; +/** + * Wrapper around a Jackrabbit repository which allows to configure it in Spring + * and expose it as a {@link Repository}. + */ public class JackrabbitContainer implements InitializingBean, DisposableBean, Repository { + private Log log = LogFactory.getLog(JackrabbitContainer.class); + private Resource configuration; private File homeDirectory; @@ -29,11 +54,16 @@ public class JackrabbitContainer implements InitializingBean, DisposableBean, private Repository repository; public void afterPropertiesSet() throws Exception { + if (inMemory && homeDirectory.exists()) { + FileUtils.deleteDirectory(homeDirectory); + log.warn("Deleted Jackrabbit home directory " + homeDirectory); + } + RepositoryConfig config; InputStream in = configuration.getInputStream(); try { - config = RepositoryConfig.create(in, homeDirectory - .getCanonicalPath()); + config = RepositoryConfig.create(in, + homeDirectory.getCanonicalPath()); } catch (Exception e) { throw new RuntimeException("Cannot read configuration", e); } finally { @@ -44,6 +74,9 @@ public class JackrabbitContainer implements InitializingBean, DisposableBean, repository = new TransientRepository(config); else repository = RepositoryImpl.create(config); + + log.info("Initialized Jackrabbit repository " + repository + " in " + + homeDirectory + " with config " + configuration); } public void destroy() throws Exception { @@ -55,8 +88,14 @@ public class JackrabbitContainer implements InitializingBean, DisposableBean, } if (inMemory) - if (homeDirectory.exists()) + if (homeDirectory.exists()) { FileUtils.deleteDirectory(homeDirectory); + if (log.isDebugEnabled()) + log.debug("Deleted Jackrabbit home directory " + + homeDirectory); + } + log.info("Destroyed Jackrabbit repository " + repository + " in " + + homeDirectory + " with config " + configuration); } // JCR REPOSITORY (delegated) @@ -88,6 +127,22 @@ public class JackrabbitContainer implements InitializingBean, DisposableBean, return repository.login(workspaceName); } + public boolean isStandardDescriptor(String key) { + return repository.isStandardDescriptor(key); + } + + public boolean isSingleValueDescriptor(String key) { + return repository.isSingleValueDescriptor(key); + } + + public Value getDescriptorValue(String key) { + return repository.getDescriptorValue(key); + } + + public Value[] getDescriptorValues(String key) { + return repository.getDescriptorValues(key); + } + // BEANS METHODS public void setHomeDirectory(File homeDirectory) { this.homeDirectory = homeDirectory; @@ -97,4 +152,8 @@ public class JackrabbitContainer implements InitializingBean, DisposableBean, this.configuration = configuration; } + public void setInMemory(Boolean inMemory) { + this.inMemory = inMemory; + } + }