You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rave.apache.org by un...@apache.org on 2012/06/05 09:46:42 UTC
svn commit: r1346271 - in /rave/sandbox/content-services: demo-portal/
rave-jcr-config/ rave-jcr-config/src/main/java/org/apache/jackrabbit/
rave-jcr-config/src/main/java/org/apache/jackrabbit/core/
rave-jcr-config/src/main/java/org/apache/rave/jcr/ ra...
Author: unico
Date: Tue Jun 5 07:46:40 2012
New Revision: 1346271
URL: http://svn.apache.org/viewvc?rev=1346271&view=rev
Log:
RAVE-603 implement content bootstrap as a phase during construction of a jackrabbit repository in order to prevent availability of repository before proper initialization has been done and in order to pass on system session to respective helper classes; preparations for ability to import content and resources to specific workspace; add tck rave repository stub to be able to run tests on a bootstrapped custom repository
Added:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/jackrabbit/
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/jackrabbit/core/
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/jackrabbit/core/AccessibleRepositoryImpl.java
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/SessionProvider.java
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/jackrabbit/
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/jackrabbit/RaveRepositoryImpl.java
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/jackrabbit/
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/jackrabbit/RaveRepositoryStub.java
rave/sandbox/content-services/rave-jcr-integration/test/src/test/java/org/apache/rave/jcr/RaveRepositoryTest.java
Removed:
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/RaveSystem.java
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/System.java
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/SystemContext.java
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/servlet/
rave/sandbox/content-services/rave-jcr-integration/test/src/test/java/org/apache/rave/jcr/RaveSystemTest.java
Modified:
rave/sandbox/content-services/demo-portal/ (props changed)
rave/sandbox/content-services/rave-jcr-config/pom.xml
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/Module.java
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleImporter.java
rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleRegistry.java
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java
rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/importing/ResourceImporterTest.java
rave/sandbox/content-services/rave-jcr-integration/ (props changed)
rave/sandbox/content-services/rave-jcr-integration/module1/ (props changed)
rave/sandbox/content-services/rave-jcr-integration/module2/ (props changed)
rave/sandbox/content-services/rave-jcr-integration/test/ (props changed)
rave/sandbox/content-services/rave-jcr-integration/test/pom.xml
rave/sandbox/content-services/rave-jcr-integration/test/src/test/resources/repositoryStubImpl.properties
rave/sandbox/content-services/rave-jcr-service/src/main/java/org/apache/rave/jcr/servlet/jackrabbit/JackrabbitRepositoryServlet.java
rave/sandbox/content-services/rave-jcr/src/main/resources/log4j.xml
Propchange: rave/sandbox/content-services/demo-portal/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jun 5 07:46:40 2012
@@ -1,3 +1,4 @@
+derby.log
.settings
.classpath
.project
Modified: rave/sandbox/content-services/rave-jcr-config/pom.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/pom.xml?rev=1346271&r1=1346270&r2=1346271&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/pom.xml (original)
+++ rave/sandbox/content-services/rave-jcr-config/pom.xml Tue Jun 5 07:46:40 2012
@@ -61,20 +61,13 @@
<artifactId>jackrabbit-spi-commons</artifactId>
<version>${apache.jackrabbit.version}</version>
</dependency>
-
- <!-- Test -->
- <dependency>
- <groupId>org.apache.jackrabbit</groupId>
- <artifactId>jackrabbit-jcr-tests</artifactId>
- <version>${apache.jackrabbit.version}</version>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
<version>${apache.jackrabbit.version}</version>
- <scope>test</scope>
</dependency>
+
+ <!-- Test -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
@@ -83,6 +76,12 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-jcr-tests</artifactId>
+ <version>${apache.jackrabbit.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
@@ -125,6 +124,17 @@
</systemProperties>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
Added: rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/jackrabbit/core/AccessibleRepositoryImpl.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/jackrabbit/core/AccessibleRepositoryImpl.java?rev=1346271&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/jackrabbit/core/AccessibleRepositoryImpl.java (added)
+++ rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/jackrabbit/core/AccessibleRepositoryImpl.java Tue Jun 5 07:46:40 2012
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.jackrabbit.core;
+
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+
+/**
+ * The purpose of this class is purely to open up the Jackrabbit repository implementation
+ * for extending classes.
+ */
+public class AccessibleRepositoryImpl extends RepositoryImpl {
+
+ protected AccessibleRepositoryImpl(RepositoryConfig repConfig) throws RepositoryException {
+ super(repConfig);
+ }
+
+ @Override
+ protected SystemSession getSystemSession(String workspaceName) throws RepositoryException {
+ return super.getSystemSession(workspaceName);
+ }
+
+ @Override
+ protected RepositoryContext getRepositoryContext() {
+ return super.getRepositoryContext();
+ }
+
+}
Modified: rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/Module.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/Module.java?rev=1346271&r1=1346270&r2=1346271&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/Module.java (original)
+++ rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/Module.java Tue Jun 5 07:46:40 2012
@@ -39,7 +39,7 @@ import org.apache.rave.jcr.importing.Imp
* <p>A module descriptor may specify a list of modules it depends on.
* Items in those modules will be loaded before items of the same type in this module.
* This is for instance necessary when a cnd declares a node type that extends a node type
- * that is defined by a cnd in another module, or when a content item want to import content
+ * that is defined by a cnd in another module, or when a content item wants to import content
* to a node that is imported by another module.
* </p>
*
Modified: rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleImporter.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleImporter.java?rev=1346271&r1=1346270&r2=1346271&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleImporter.java (original)
+++ rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleImporter.java Tue Jun 5 07:46:40 2012
@@ -52,7 +52,7 @@ public final class ModuleImporter {
private static final Logger log = LoggerFactory.getLogger(ModuleImporter.class);
- private final Session session;
+ private final SessionProvider sessionProvider;
private final ModuleRegistry moduleRegistry;
private final Collection<Module> modules;
private final boolean reload;
@@ -63,14 +63,22 @@ public final class ModuleImporter {
private final List<Module.Content> contents = new ArrayList<Module.Content>();
private final List<Module.Resource> resources = new ArrayList<Module.Resource>();
- public ModuleImporter(Session session, ModuleRegistry moduleRegistry, Collection<Module> modules, boolean reload, MimeTypeResolver mimeTypeResolver) {
- this.session = session;
+ public ModuleImporter(SessionProvider sessionProvider, ModuleRegistry moduleRegistry, Collection<Module> modules, boolean reload, MimeTypeResolver mimeTypeResolver) {
+ this.sessionProvider = sessionProvider;
this.moduleRegistry = moduleRegistry;
this.modules = modules;
this.reload = reload;
this.mimeTypeResolver = mimeTypeResolver;
}
+ /**
+ * Collects and sorts the module items that are to be processed during {@link #execute()}
+ * <p>
+ * After this method finishes these module items are available from the {@link #getNamespaces()}, {@link #getCnds()},
+ * {@link #getContents()} and {@link #getResources()} methods
+ * </p>
+ * @throws RepositoryException
+ */
public void prepare() throws RepositoryException {
log.info("Preparing for import");
@@ -162,6 +170,10 @@ public final class ModuleImporter {
return contents;
}
+ public List<Module.Resource> getResources() {
+ return resources;
+ }
+
private Collection<Module.Content> getDownstreamContentItems(final Module.Content content, final Collection<Module> allModules) {
final Collection<Module.Content> downstreamContentItems = new ArrayList<Module.Content>();
for (final Module module : allModules) {
@@ -179,6 +191,7 @@ public final class ModuleImporter {
log.info("No namespaces to register");
return;
}
+ final Session session = sessionProvider.getSession(null);
final NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry();
for (Module.Namespace namespace : namespaces) {
final Module module = namespace.getModule();
@@ -209,11 +222,12 @@ public final class ModuleImporter {
}
}
- private void registerNodeTypes() {
+ private void registerNodeTypes() throws RepositoryException {
if (cnds.isEmpty()) {
log.info("No node types to register");
return;
}
+ final Session session = sessionProvider.getSession(null);
for (Module.Cnd cnd : cnds) {
final Module module = cnd.getModule();
final boolean reregister = cnd.getStatus() != Module.Status.NEW;
@@ -239,8 +253,9 @@ public final class ModuleImporter {
log.info("No content to import");
return;
}
- final ContentImporter contentImporter = new ContentImporter(session);
for (Module.Content content : contents) {
+ final Session session = sessionProvider.getSession(null);
+ final ContentImporter contentImporter = new ContentImporter(session);
final Module module = content.getModule();
if (!session.nodeExists(content.getParent())) {
log.error("Cannot import content from " + content.getFile() + " in module " + module.getName()
@@ -277,8 +292,9 @@ public final class ModuleImporter {
log.info("No resources to import");
return;
}
- final ResourceImporter resourceImporter = new ResourceImporter(session, mimeTypeResolver);
for (Module.Resource resource : resources) {
+ final Session session = sessionProvider.getSession(null);
+ final ResourceImporter resourceImporter = new ResourceImporter(session, mimeTypeResolver);
final Module module = resource.getModule();
if (!session.nodeExists(resource.getParent())) {
log.error("Cannot import resources " + resource.getName() + " in module " + module.getName() +
Modified: rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleRegistry.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleRegistry.java?rev=1346271&r1=1346270&r2=1346271&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleRegistry.java (original)
+++ rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/ModuleRegistry.java Tue Jun 5 07:46:40 2012
@@ -204,19 +204,19 @@ public final class ModuleRegistry {
log.info("Registering new module '" + module.getName() + "'");
final Node modulesNode = session.getNode(modulesPath);
- final Node node = getOrCreateNode(modulesNode, module.getName());
+ final Node moduleNode = getOrCreateNode(modulesNode, module.getName());
try {
- node.setProperty(VERSION, module.getVersion());
- node.setProperty(BASEURL, module.getBaseUrl());
- node.setProperty(STATUS, Module.Status.NEW.toString());
+ moduleNode.setProperty(VERSION, module.getVersion());
+ moduleNode.setProperty(BASEURL, module.getBaseUrl());
+ moduleNode.setProperty(STATUS, Module.Status.NEW.toString());
if (!module.getDependencies().isEmpty()) {
- setDependencies(node, module);
+ setDependencies(moduleNode, module);
}
if (!module.getNamespaces().isEmpty()) {
- final Node namespacesNode = getOrCreateNode(node, NAMESPACES);
+ final Node namespacesNode = getOrCreateNode(moduleNode, NAMESPACES);
for (Module.Namespace namespace : module.getNamespaces()) {
if (!namespacesNode.hasNode(namespace.getName())) {
final Node namespaceNode = namespacesNode.addNode(namespace.getName());
@@ -228,7 +228,7 @@ public final class ModuleRegistry {
}
if (!module.getCnds().isEmpty()) {
- final Node cndsNode = getOrCreateNode(node, CNDS);
+ final Node cndsNode = getOrCreateNode(moduleNode, CNDS);
for (Module.Cnd cnd : module.getCnds()) {
Node cndNode = getOrCreateNode(cndsNode, cnd.getName());
setCndProperties(cndNode, cnd);
@@ -238,7 +238,7 @@ public final class ModuleRegistry {
}
if (!module.getContents().isEmpty()) {
- final Node contentsNode = getOrCreateNode(node, CONTENTS);
+ final Node contentsNode = getOrCreateNode(moduleNode, CONTENTS);
for (Module.Content content : module.getContents()) {
final Node contentNode = getOrCreateNode(contentsNode, content.getName());
setContentProperties(contentNode, content);
@@ -248,7 +248,7 @@ public final class ModuleRegistry {
}
if (!module.getResources().isEmpty()) {
- final Node resourcesNode = getOrCreateNode(node, RESOURCES);
+ final Node resourcesNode = getOrCreateNode(moduleNode, RESOURCES);
for (Module.Resource resource : module.getResources()) {
final Node resourceNode = getOrCreateNode(resourcesNode, resource.getName());
setResourceProperties(resourceNode, resource);
Added: rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/SessionProvider.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/SessionProvider.java?rev=1346271&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/SessionProvider.java (added)
+++ rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/bootstrapping/SessionProvider.java Tue Jun 5 07:46:40 2012
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.jcr.bootstrapping;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+public interface SessionProvider {
+
+ Session getSession(String workspaceName) throws RepositoryException;
+
+}
Added: rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/jackrabbit/RaveRepositoryImpl.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/jackrabbit/RaveRepositoryImpl.java?rev=1346271&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/jackrabbit/RaveRepositoryImpl.java (added)
+++ rave/sandbox/content-services/rave-jcr-config/src/main/java/org/apache/rave/jcr/jackrabbit/RaveRepositoryImpl.java Tue Jun 5 07:46:40 2012
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.rave.jcr.jackrabbit;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.ServletContext;
+
+import org.apache.jackrabbit.core.AccessibleRepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.rave.jcr.bootstrapping.BootstrapException;
+import org.apache.rave.jcr.bootstrapping.Module;
+import org.apache.rave.jcr.bootstrapping.ModuleImporter;
+import org.apache.rave.jcr.bootstrapping.ModuleRegistry;
+import org.apache.rave.jcr.bootstrapping.ModuleScanner;
+import org.apache.rave.jcr.bootstrapping.SessionProvider;
+import org.apache.rave.jcr.importing.MimeTypeResolver;
+
+public class RaveRepositoryImpl extends AccessibleRepositoryImpl {
+
+ private final ServletContext servletContext;
+
+ public RaveRepositoryImpl(RepositoryConfig repConfig, ServletContext servletContext) throws RepositoryException, BootstrapException {
+ super(repConfig);
+ this.servletContext = servletContext;
+ initializeSystem();
+ updateModules();
+ }
+
+ private void initializeSystem() throws RepositoryException {
+ if (!hasWorkspace(getSystemWorkspaceName())) {
+ createWorkspace(getSystemWorkspaceName());
+ }
+
+ final Session session = getSystemSession(getSystemWorkspaceName());
+ try {
+ try {
+ session.getWorkspace().getNamespaceRegistry().registerNamespace(getSystemNamespacePrefix(), getSystemNamespaceUri());
+ } catch (NamespaceException ignore) {}
+ Node system;
+ if (!session.nodeExists("/" + getSystemNamespacePrefix() + ":system")) {
+ system = session.getRootNode().addNode(getSystemNamespacePrefix() + ":system");
+ } else {
+ system = session.getNode("/" + getSystemNamespacePrefix() + ":system");
+ }
+ if (!system.hasNode("modules")) {
+ system.addNode("modules");
+ session.save();
+ }
+ } finally {
+ session.refresh(false);
+ }
+ }
+
+ private void updateModules() throws RepositoryException, BootstrapException {
+ final Session session = getSystemSession(getSystemWorkspaceName());
+ try {
+ final ModuleScanner moduleScanner = new ModuleScanner(getSystemNamespacePrefix());
+ final ModuleRegistry moduleRegistry = new ModuleRegistry(session, "/" + getSystemNamespacePrefix() + ":system");
+ final Map<String, Module> current = moduleScanner.scan();
+
+ final Map<String, Module> previous = moduleRegistry.readModules();
+
+ final Collection<Module> added = getAddedModules(current, previous);
+ for (Module module : added) {
+ moduleRegistry.writeModule(module);
+ }
+
+ final Map<Module, Module> modified = getModifiedModules(current, previous);
+ for (Map.Entry<Module, Module> entry : modified.entrySet()) {
+ moduleRegistry.updateModule(entry.getKey(), entry.getValue());
+ }
+ } finally {
+ session.refresh(false);
+ }
+
+ }
+
+ public void bootstrap(final boolean reload) throws RepositoryException, BootstrapException {
+ final Session session = getSystemSession(getSystemWorkspaceName());
+ try {
+ final ModuleRegistry moduleRegistry = new ModuleRegistry(session, "/" + getSystemNamespacePrefix() + ":system");
+ final Map<String, Module> moduleMap = moduleRegistry.readModules();
+ final ModuleImporter importer = new ModuleImporter(new SessionProvider() {
+ @Override
+ public Session getSession(String workspaceName) throws RepositoryException {
+ if (workspaceName == null) {
+ workspaceName = "default";
+ }
+ return getSystemSession(workspaceName);
+ }
+ }, moduleRegistry, moduleMap.values(), reload, new MimeTypeResolver() {
+ @Override
+ public String getMimeType(final String file) {
+ return servletContext.getMimeType(file);
+ }
+ });
+ importer.prepare();
+ importer.execute();
+ } finally {
+ session.refresh(false);
+ }
+ }
+
+ protected String getSystemNamespacePrefix() {
+ return "rave";
+ }
+
+ protected String getSystemNamespaceUri() {
+ return "http://rave.apache.org/jcr/1.0";
+ }
+
+ protected String getSystemWorkspaceName() {
+ return "default";
+ }
+
+ private boolean hasWorkspace(String workspaceName) {
+ for (String name : getWorkspaceNames()) {
+ if (name.equals(workspaceName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private Collection<Module> getAddedModules(Map<String, Module> current, Map<String, Module> previous) {
+ Collection<Module> added = new ArrayList<Module>();
+ for (String moduleName : current.keySet()) {
+ if (!previous.containsKey(moduleName)) {
+ added.add(current.get(moduleName));
+ }
+ }
+ return added;
+ }
+
+ private Map<Module, Module> getModifiedModules(Map<String, Module> current, Map<String, Module> previous) {
+ Map<Module, Module> modified = new LinkedHashMap<Module, Module>();
+ for (Map.Entry<String, Module> entry : current.entrySet()) {
+ final String moduleName = entry.getKey();
+ final Module currentModule = entry.getValue();
+ if (previous.containsKey(moduleName) && !currentModule.equals(previous.get(moduleName))) {
+ modified.put(currentModule, previous.get(moduleName));
+ }
+ }
+ return modified;
+ }
+
+}
Modified: rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java?rev=1346271&r1=1346270&r2=1346271&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java (original)
+++ rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/bootstrapping/ModuleRegistryTest.java Tue Jun 5 07:46:40 2012
@@ -18,11 +18,15 @@
*/
package org.apache.rave.jcr.bootstrapping;
+import java.net.URL;
+import java.util.Enumeration;
+
+import javax.jcr.NamespaceException;
import javax.jcr.Node;
+import javax.jcr.NodeIterator;
import javax.jcr.Session;
import org.apache.jackrabbit.test.AbstractJCRTest;
-import org.apache.rave.jcr.RaveSystem;
public class ModuleRegistryTest extends AbstractJCRTest {
@@ -31,21 +35,38 @@ public class ModuleRegistryTest extends
@Override
public void setUp() throws Exception {
super.setUp();
- new RaveSystem(getHelper().getRepository(), null).initialize();
+
+ // initialize rave:system
+ final Session session = getHelper().getSuperuserSession();
+ try {
+ try {
+ session.getWorkspace().getNamespaceRegistry().registerNamespace("rave", "http://rave.apache.org/jcr/1.0");
+ } catch (NamespaceException ignore) {}
+ Node system = session.getRootNode().addNode("rave:system");
+ system.addNode("modules");
+ session.save();
+ } finally {
+ session.logout();
+ }
+
this.session = getHelper().getReadWriteSession();
+
}
@Override
public void tearDown() throws Exception {
- super.tearDown();
+ session.getRootNode().getNode("rave:system").remove();
+ session.save();
session.refresh(false);
session.logout();
+ super.tearDown();
}
public void testWriteModule() throws Exception {
final ModuleRegistry moduleRegistry = new ModuleRegistry(session, "/rave:system");
final ModuleScanner moduleScanner = new ModuleScanner("rave");
- final Module module = moduleScanner.parse(getClass().getResource("/META-INF/rave/module.json"));
+ final URL resource = getClass().getResource("/META-INF/rave/module.json");
+ final Module module = moduleScanner.parse(resource);
moduleRegistry.writeModule(module);
assertTrue(session.nodeExists("/rave:system/modules/foo"));
Modified: rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/importing/ResourceImporterTest.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/importing/ResourceImporterTest.java?rev=1346271&r1=1346270&r2=1346271&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/importing/ResourceImporterTest.java (original)
+++ rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/importing/ResourceImporterTest.java Tue Jun 5 07:46:40 2012
@@ -40,6 +40,7 @@ public class ResourceImporterTest extend
public void tearDown() throws Exception {
session.refresh(false);
session.logout();
+ super.tearDown();
}
public void testImportResource() throws Exception {
Added: rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/jackrabbit/RaveRepositoryStub.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/jackrabbit/RaveRepositoryStub.java?rev=1346271&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/jackrabbit/RaveRepositoryStub.java (added)
+++ rave/sandbox/content-services/rave-jcr-config/src/test/java/org/apache/rave/jcr/jackrabbit/RaveRepositoryStub.java Tue Jun 5 07:46:40 2012
@@ -0,0 +1,183 @@
+package org.apache.rave.jcr.jackrabbit;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.jcr.Repository;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.jackrabbit.core.JackrabbitRepositoryStub;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+
+public class RaveRepositoryStub extends JackrabbitRepositoryStub {
+
+ /**
+ * Constructor as required by the JCR TCK.
+ *
+ * @param settings repository settings
+ */
+ public RaveRepositoryStub(Properties settings) {
+ super(settings);
+ }
+
+ @Override
+ protected Repository createRepository(final String dir, final String xml) throws Exception {
+ new File(dir).mkdirs();
+
+ if (!new File(xml).exists()) {
+ InputStream input = getResource("repository.xml");
+ try {
+ OutputStream output = new FileOutputStream(xml);
+ try {
+ IOUtils.copy(input, output);
+ } finally {
+ output.close();
+ }
+ } finally {
+ input.close();
+ }
+ }
+
+ RepositoryConfig config = RepositoryConfig.create(xml, dir);
+ return new RaveRepositoryImpl(config, new MockServletContext());
+ }
+
+ private static InputStream getResource(String name) {
+ return RaveRepositoryStub.class.getResourceAsStream(name);
+ }
+
+ private static class MockServletContext implements ServletContext {
+
+ @Override
+ public String getContextPath() {
+ return null;
+ }
+
+ @Override
+ public ServletContext getContext(final String s) {
+ return null;
+ }
+
+ @Override
+ public int getMajorVersion() {
+ return 0;
+ }
+
+ @Override
+ public int getMinorVersion() {
+ return 0;
+ }
+
+ @Override
+ public String getMimeType(final String file) {
+ return null;
+ }
+
+ @Override
+ public Set getResourcePaths(final String s) {
+ return null;
+ }
+
+ @Override
+ public URL getResource(final String s) throws MalformedURLException {
+ return null;
+ }
+
+ @Override
+ public InputStream getResourceAsStream(final String s) {
+ return null;
+ }
+
+ @Override
+ public RequestDispatcher getRequestDispatcher(final String s) {
+ return null;
+ }
+
+ @Override
+ public RequestDispatcher getNamedDispatcher(final String s) {
+ return null;
+ }
+
+ @Override
+ public Servlet getServlet(final String s) throws ServletException {
+ return null;
+ }
+
+ @Override
+ public Enumeration getServlets() {
+ return null;
+ }
+
+ @Override
+ public Enumeration getServletNames() {
+ return null;
+ }
+
+ @Override
+ public void log(final String s) {
+ }
+
+ @Override
+ public void log(final Exception e, final String s) {
+ }
+
+ @Override
+ public void log(final String s, final Throwable throwable) {
+ }
+
+ @Override
+ public String getRealPath(final String s) {
+ return null;
+ }
+
+ @Override
+ public String getServerInfo() {
+ return null;
+ }
+
+ @Override
+ public String getInitParameter(final String s) {
+ return null;
+ }
+
+ @Override
+ public Enumeration getInitParameterNames() {
+ return null;
+ }
+
+ @Override
+ public Object getAttribute(final String s) {
+ return null;
+ }
+
+ @Override
+ public Enumeration getAttributeNames() {
+ return null;
+ }
+
+ @Override
+ public void setAttribute(final String s, final Object o) {
+ }
+
+ @Override
+ public void removeAttribute(final String s) {
+ }
+
+ @Override
+ public String getServletContextName() {
+ return null;
+ }
+
+ }
+}
Propchange: rave/sandbox/content-services/rave-jcr-integration/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jun 5 07:46:40 2012
@@ -1,3 +1,4 @@
+*.iml
.settings
.project
target
Propchange: rave/sandbox/content-services/rave-jcr-integration/module1/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jun 5 07:46:40 2012
@@ -1,3 +1,4 @@
+*.iml
.settings
target
.classpath
Propchange: rave/sandbox/content-services/rave-jcr-integration/module2/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jun 5 07:46:40 2012
@@ -1,3 +1,4 @@
+*.iml
.settings
target
.classpath
Propchange: rave/sandbox/content-services/rave-jcr-integration/test/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Jun 5 07:46:40 2012
@@ -1,3 +1,4 @@
+*.iml
.settings
target
.classpath
Modified: rave/sandbox/content-services/rave-jcr-integration/test/pom.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/test/pom.xml?rev=1346271&r1=1346270&r2=1346271&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/test/pom.xml (original)
+++ rave/sandbox/content-services/rave-jcr-integration/test/pom.xml Tue Jun 5 07:46:40 2012
@@ -49,6 +49,13 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.rave.sandbox.jcr</groupId>
+ <artifactId>rave-jcr-config</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
Added: rave/sandbox/content-services/rave-jcr-integration/test/src/test/java/org/apache/rave/jcr/RaveRepositoryTest.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/test/src/test/java/org/apache/rave/jcr/RaveRepositoryTest.java?rev=1346271&view=auto
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/test/src/test/java/org/apache/rave/jcr/RaveRepositoryTest.java (added)
+++ rave/sandbox/content-services/rave-jcr-integration/test/src/test/java/org/apache/rave/jcr/RaveRepositoryTest.java Tue Jun 5 07:46:40 2012
@@ -0,0 +1,39 @@
+package org.apache.rave.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+import org.apache.rave.jcr.jackrabbit.RaveRepositoryImpl;
+
+public class RaveRepositoryTest extends AbstractJCRTest {
+
+ public void testBootstrap() throws Exception {
+ final Session session = getHelper().getSuperuserSession();
+ ((RaveRepositoryImpl) session.getRepository()).bootstrap(false);
+
+ assertTrue(session.nodeExists("/testroot/foo"));
+ final Node foo = session.getNode("/testroot/foo");
+ assertTrue(foo.isNodeType("foo:foo"));
+
+ assertTrue(foo.hasProperty("qux"));
+ final Property qux = foo.getProperty("qux");
+ assertTrue(qux.isMultiple());
+ assertEquals(2, qux.getValues().length);
+
+ assertTrue(foo.hasNode("bar"));
+ final Node bar = foo.getNode("bar");
+ assertTrue(bar.isNodeType("bar:bar"));
+
+ assertTrue(session.nodeExists("/testroot/images"));
+ final Node images = session.getNode("/testroot/images");
+ assertTrue(images.isNodeType("nt:folder"));
+
+ assertTrue(session.nodeExists("/testroot/images/blank.gif"));
+ final Node gif = session.getNode("/testroot/images/blank.gif");
+ assertTrue(gif.isNodeType("nt:file"));
+
+ }
+
+}
Modified: rave/sandbox/content-services/rave-jcr-integration/test/src/test/resources/repositoryStubImpl.properties
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-integration/test/src/test/resources/repositoryStubImpl.properties?rev=1346271&r1=1346270&r2=1346271&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-integration/test/src/test/resources/repositoryStubImpl.properties (original)
+++ rave/sandbox/content-services/rave-jcr-integration/test/src/test/resources/repositoryStubImpl.properties Tue Jun 5 07:46:40 2012
@@ -14,4 +14,4 @@
# limitations under the License.
# Stub implementation class
-javax.jcr.tck.repository_stub_impl=org.apache.jackrabbit.core.JackrabbitRepositoryStub
+javax.jcr.tck.repository_stub_impl=org.apache.rave.jcr.jackrabbit.RaveRepositoryStub
Modified: rave/sandbox/content-services/rave-jcr-service/src/main/java/org/apache/rave/jcr/servlet/jackrabbit/JackrabbitRepositoryServlet.java
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr-service/src/main/java/org/apache/rave/jcr/servlet/jackrabbit/JackrabbitRepositoryServlet.java?rev=1346271&r1=1346270&r2=1346271&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr-service/src/main/java/org/apache/rave/jcr/servlet/jackrabbit/JackrabbitRepositoryServlet.java (original)
+++ rave/sandbox/content-services/rave-jcr-service/src/main/java/org/apache/rave/jcr/servlet/jackrabbit/JackrabbitRepositoryServlet.java Tue Jun 5 07:46:40 2012
@@ -19,20 +19,55 @@
package org.apache.rave.jcr.servlet.jackrabbit;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
+import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
-import org.apache.rave.jcr.RaveSystem;
+import org.apache.jackrabbit.core.RepositoryImpl;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.jackrabbit.servlet.AbstractRepositoryServlet;
import org.apache.rave.jcr.bootstrapping.BootstrapException;
-import org.apache.rave.jcr.servlet.ServletSystemContext;
+import org.apache.rave.jcr.jackrabbit.RaveRepositoryImpl;
+
/**
- * Extended version of the JackrabbitRepositoryServlet to allow overriding of the
- * <code>repository.home</code> and <code>repository.config</code> location init parameters through system properties.
+ * Servlet that makes a Jackrabbit repository available as a servlet context
+ * attribute. The repository is started during servlet initialization and
+ * shut down when the servlet is destroyed.
+ * <p>
+ * The supported initialization parameters of this servlet are:
+ * <dl>
+ * <dt>javax.jcr.Repository</dt>
+ * <dd>
+ * Name of the servlet context attribute to put the repository in.
+ * The default value is "<code>javax.jcr.Repository</code>".
+ * </dd>
+ * <dt>repository.home</dt>
+ * <dd>
+ * Path of the repository home directory. The home directory is
+ * automatically created during servlet initialization if it does
+ * not already exist.
+ * </dd>
+ * <dt>repository.config</dt>
+ * <dd>
+ * Path of the repository configuration file. The default value is
+ * "<code>repository.xml</code>" within the configured repository home
+ * directory. A standard configuration file is automatically copied to
+ * the configured location during servlet initialization if the file
+ * does not already exist.
+ * </dd>
+ * </dl>
+ * <p>
+ * The values of the repository.home and repository.config parameters can be overriden:
+ * </p>
* <p>
* First a context specific system property will be evaluated using a postfix
* of the context path without leading /, separated by a . (dot).<br/>
@@ -53,10 +88,13 @@ import org.apache.rave.jcr.servlet.Servl
* <li><code>repository.home: WEB-INF/storage</code></li>
* </ul>
* </p>
- *
+
+ * The repository servlet can also be mapped to the URL space. See
+ * {@link AbstractRepositoryServlet} for the details.
+ *
* @version $Id$
*/
-public class JackrabbitRepositoryServlet extends org.apache.jackrabbit.servlet.jackrabbit.JackrabbitRepositoryServlet {
+public class JackrabbitRepositoryServlet extends AbstractRepositoryServlet {
private static final long serialVersionUID = 1L;
@@ -69,13 +107,66 @@ public class JackrabbitRepositoryServlet
/** Default repository storage directory */
public static final String DEFAULT_REPOSITORY_DIRECTORY = "WEB-INF/storage";
+ private RaveRepositoryImpl raveRepository;
+
private String repositoryDirectory;
private String repositoryConfig;
-
- protected boolean isEmpty(String value) {
- return value == null || value.isEmpty();
+
+ @Override
+ public void init(ServletConfig config) throws ServletException {
+ repositoryDirectory = getLocationParam(config, REPOSITORY_DIRECTORY_PARAM, DEFAULT_REPOSITORY_DIRECTORY);
+ repositoryConfig = getLocationParam(config, REPOSITORY_CONFIG_PARAM, null);
+ super.init(config);
+ }
+
+ @Override
+ public void init() throws ServletException {
+ try {
+ final File home = new File(getInitParameter(REPOSITORY_DIRECTORY_PARAM, DEFAULT_REPOSITORY_DIRECTORY));
+ if (!home.exists()) {
+ log("Creating repository home directory: " + home);
+ home.mkdirs();
+ }
+
+ final File config = new File(getInitParameter(REPOSITORY_CONFIG_PARAM, new File(home, "repository.xml").getPath()));
+ if (!config.exists()) {
+ log("Creating default repository configuration: " + config);
+ createDefaultConfiguration(config);
+ }
+
+ raveRepository = new RaveRepositoryImpl(RepositoryConfig.create(config.toURI(), home.getPath()), getServletContext());
+ raveRepository.bootstrap(true);
+
+ } catch (RepositoryException e) {
+ throw new ServletException("Failed to start Jackrabbit", e);
+ } catch (BootstrapException e) {
+ throw new ServletException("Failed to start Jackrabbit", e);
+ }
+
+ super.init();
+ }
+
+ public void destroy() {
+ super.destroy();
+ raveRepository.shutdown();
}
-
+
+ @Override
+ protected Repository getRepository() throws RepositoryException {
+ return raveRepository;
+ }
+
+ @Override
+ protected String getInitParameter(String name, String def) {
+ if (REPOSITORY_DIRECTORY_PARAM.equals(name) && !isEmpty(repositoryDirectory)) {
+ return repositoryDirectory;
+ }
+ else if (REPOSITORY_CONFIG_PARAM.equals(name) && !isEmpty(repositoryConfig)) {
+ return repositoryConfig;
+ }
+ return super.getInitParameter(name, def);
+ }
+
protected String getLocationParam(ServletConfig config, String parameterName, String defaultValue) throws ServletException {
// build context path name postfix for system property lookup
String contextPath = config.getServletContext().getContextPath();
@@ -122,43 +213,45 @@ public class JackrabbitRepositoryServlet
throw new ServletException("Cannot determine parameter "+parameterName+" location "+ location);
}
location = result;
- }
+ }
}
return location;
}
-
- @Override
- protected String getInitParameter(String name, String def) {
- if (REPOSITORY_DIRECTORY_PARAM.equals(name) && !isEmpty(repositoryDirectory)) {
- return repositoryDirectory;
- }
- else if (REPOSITORY_CONFIG_PARAM.equals(name) && !isEmpty(repositoryConfig)) {
- return repositoryConfig;
- }
- return super.getInitParameter(name, def);
- }
-
- @Override
- public void init(ServletConfig config) throws ServletException {
- repositoryDirectory = getLocationParam(config, REPOSITORY_DIRECTORY_PARAM, DEFAULT_REPOSITORY_DIRECTORY);
- repositoryConfig = getLocationParam(config, REPOSITORY_CONFIG_PARAM, null);
- super.init(config);
+
+ private boolean isEmpty(String value) {
+ return value == null || value.isEmpty();
}
- @Override
- public void init() throws ServletException {
- super.init();
+ /**
+ * Copies the default repository configuration file to the given location.
+ *
+ * @param config path of the configuration file
+ * @throws ServletException if the configuration file could not be copied
+ */
+ private void createDefaultConfiguration(File config)
+ throws ServletException {
try {
- // FIXME: when super.init finishes the repository is already available for clients, but then the system
- // is not yet initialized and bootstrapped
- final RaveSystem raveSystem = new RaveSystem(getRepository(), new ServletSystemContext(getServletConfig()));
- raveSystem.initialize();
- raveSystem.update();
- raveSystem.bootstrap(true);
- } catch (BootstrapException e) {
- throw new ServletException(e.getMessage(), e);
- } catch (RepositoryException e) {
- throw new ServletException(e.getMessage(), e);
+ OutputStream output = new FileOutputStream(config);
+ try {
+ InputStream input =
+ RepositoryImpl.class.getResourceAsStream("repository.xml");
+ try {
+ byte[] buffer = new byte[8192];
+ int n = input.read(buffer);
+ while (n != -1) {
+ output.write(buffer, 0, n);
+ n = input.read(buffer);
+ }
+ } finally {
+ input.close();
+ }
+ } finally {
+ output.close();
+ }
+ } catch (IOException e) {
+ throw new ServletException(
+ "Failed to copy default configuration: " + config, e);
}
}
+
}
Modified: rave/sandbox/content-services/rave-jcr/src/main/resources/log4j.xml
URL: http://svn.apache.org/viewvc/rave/sandbox/content-services/rave-jcr/src/main/resources/log4j.xml?rev=1346271&r1=1346270&r2=1346271&view=diff
==============================================================================
--- rave/sandbox/content-services/rave-jcr/src/main/resources/log4j.xml (original)
+++ rave/sandbox/content-services/rave-jcr/src/main/resources/log4j.xml Tue Jun 5 07:46:40 2012
@@ -30,14 +30,18 @@
</layout>
</appender>
- <logger name="org.jackrabbit">
- <level value="warn" />
+ <logger name="org.apache.rave.jcr.bootstrapping">
+ <level value="info" />
</logger>
<logger name="org.apache.rave">
<level value="warn" />
</logger>
+ <logger name="org.apache.jackrabbit">
+ <level value="warn" />
+ </logger>
+
<!-- Root Logger -->
<root>
<priority value="warn" />