jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r776310 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
Date Tue, 19 May 2009 13:29:06 GMT
Author: jukka
Date: Tue May 19 13:29:06 2009
New Revision: 776310

URL: http://svn.apache.org/viewvc?rev=776310&view=rev
Log:
JCR-2119: Method to create default RepositoryConfig from just the repository directory

Added the following methods:

    RepositoryConfig.install(File dir);
    RepostiroyConfig.install(File xml, File dir);
    RepositoryConfig.create(File dir);
    RepositoryConfig.create(File xml, File dir);

The install() methods will automatically create the repository directory and configuration
file if they do not already exist. The create() methods will fail with an exception in the
same situation.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java?rev=776310&r1=776309&r2=776310&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/config/RepositoryConfig.java
Tue May 19 13:29:06 2009
@@ -16,7 +16,8 @@
  */
 package org.apache.jackrabbit.core.config;
 
-import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.IOUtils; 
+import org.apache.jackrabbit.core.RepositoryImpl;
 import org.apache.jackrabbit.core.data.DataStore;
 import org.apache.jackrabbit.core.data.DataStoreFactory;
 import org.apache.jackrabbit.core.fs.FileSystem;
@@ -41,10 +42,12 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.StringWriter;
@@ -71,10 +74,116 @@
     /** the default logger */
     private static Logger log = LoggerFactory.getLogger(RepositoryConfig.class);
 
+    /** Name of the default repository configuration file. */
+    private static final String REPOSITORY_XML = "repository.xml";
+
     /** Name of the workspace configuration file. */
     private static final String WORKSPACE_XML = "workspace.xml";
 
     /**
+     * Returns the configuration of a repository in a given repository
+     * directory. The repository configuration is read from a "repository.xml"
+     * file inside the repository directory.
+     * <p>
+     * The directory is created if it does not exist. If the repository
+     * configuration file does not exist, then it is created using the
+     * default Jackrabbit configuration settings.
+     *
+     * @since Apache Jackrabbit 1.6
+     * @param dir repository home directory
+     * @return repository configuration
+     * @throws ConfigurationException on configuration errors
+     */
+    public static RepositoryConfig install(File dir)
+            throws IOException, ConfigurationException {
+        return install(new File(dir, REPOSITORY_XML), dir);
+    }
+
+    /**
+     * Returns the configuration of a repository with the given configuration
+     * file and repository home directory.
+     * <p>
+     * The directory is created if it does not exist. If the repository
+     * configuration file does not exist, then it is created using the
+     * default Jackrabbit configuration settings.
+     *
+     * @since Apache Jackrabbit 1.6
+     * @param dir repository home directory
+     * @return repository configuration
+     * @throws ConfigurationException on configuration errors
+     */
+    public static RepositoryConfig install(File xml, File dir)
+            throws IOException, ConfigurationException {
+        if (!dir.exists()) {
+            log.info("Creating repository directory {}", dir);
+            dir.mkdirs();
+        }
+
+        if (!xml.exists()) {
+            log.info("Installing default repository configuration to {}", xml);
+            OutputStream output = new FileOutputStream(xml);
+            try {
+                InputStream input =
+                    RepositoryImpl.class.getResourceAsStream(REPOSITORY_XML);
+                try {
+                    IOUtils.copy(input, output);
+                } finally {
+                   input.close();
+                }
+            } finally {
+                output.close();
+            }
+        }
+
+        return create(xml, dir);
+    }
+
+    /**
+     * Returns the configuration of a repository in a given repository
+     * directory. The repository configuration is read from a "repository.xml"
+     * file inside the repository directory.
+     * <p>
+     * An exception is thrown if the directory does not exist or if
+     * the repository configuration file can not be read. 
+     *
+     * @since Apache Jackrabbit 1.6
+     * @param dir repository home directory
+     * @return repository configuration
+     * @throws ConfigurationException on configuration errors
+     */
+    public static RepositoryConfig create(File dir)
+            throws ConfigurationException {
+        return create(new File(dir, REPOSITORY_XML), dir);
+    }
+
+    /**
+     * Returns the configuration of a repository with the given configuration
+     * file and repository home directory.
+     * <p>
+     * An exception is thrown if the directory does not exist or if
+     * the repository configuration file can not be read. 
+     *
+     * @since Apache Jackrabbit 1.6
+     * @param dir repository home directory
+     * @return repository configuration
+     * @throws ConfigurationException on configuration errors
+     */
+    public static RepositoryConfig create(File xml, File dir)
+            throws ConfigurationException {
+        if (!dir.isDirectory()) {
+            throw new ConfigurationException(
+                    "Repository directory " + dir + " does not exist");
+        }
+
+        if (!xml.isFile()) {
+            throw new ConfigurationException(
+                    "Repository configuration file " + xml + " does not exist");
+        }
+
+        return create(new InputSource(xml.toURI().toString()), dir.getPath());
+    }
+
+    /**
      * Convenience method that wraps the configuration file name into an
      * {@link InputSource} and invokes the
      * {@link #create(InputSource, String)} method.



Mime
View raw message