Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 45884 invoked from network); 19 May 2009 13:29:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 May 2009 13:29:38 -0000 Received: (qmail 75167 invoked by uid 500); 19 May 2009 13:29:38 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 75124 invoked by uid 500); 19 May 2009 13:29:38 -0000 Mailing-List: contact commits-help@jackrabbit.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jackrabbit.apache.org Delivered-To: mailing list commits@jackrabbit.apache.org Received: (qmail 75115 invoked by uid 99); 19 May 2009 13:29:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 May 2009 13:29:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 19 May 2009 13:29:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 1FA962388866; Tue, 19 May 2009 13:29:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090519132907.1FA962388866@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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. + *

+ * 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. + *

+ * 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. + *

+ * 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. + *

+ * 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.