From commits-return-4111-apmail-jackrabbit-commits-archive=jackrabbit.apache.org@jackrabbit.apache.org Sun Jun 03 21:44:16 2007 Return-Path: Delivered-To: apmail-jackrabbit-commits-archive@www.apache.org Received: (qmail 81456 invoked from network); 3 Jun 2007 21:44:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jun 2007 21:44:15 -0000 Received: (qmail 27315 invoked by uid 500); 3 Jun 2007 21:44:19 -0000 Delivered-To: apmail-jackrabbit-commits-archive@jackrabbit.apache.org Received: (qmail 27276 invoked by uid 500); 3 Jun 2007 21:44:19 -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 27267 invoked by uid 99); 3 Jun 2007 21:44:19 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 Jun 2007 14:44:19 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 Jun 2007 14:44:14 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 7E8B11A981A; Sun, 3 Jun 2007 14:43:54 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r543997 - in /jackrabbit/trunk/jackrabbit-core: pom.xml src/main/java/org/apache/jackrabbit/core/servlet/ src/main/java/org/apache/jackrabbit/core/servlet/JackrabbitRepositoryServlet.java Date: Sun, 03 Jun 2007 21:43:54 -0000 To: commits@jackrabbit.apache.org From: jukka@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070603214354.7E8B11A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jukka Date: Sun Jun 3 14:43:53 2007 New Revision: 543997 URL: http://svn.apache.org/viewvc?view=rev&rev=543997 Log: JCR-956: Added a Jackrabbit core repository servlet Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/servlet/ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/servlet/JackrabbitRepositoryServlet.java (with props) Modified: jackrabbit/trunk/jackrabbit-core/pom.xml Modified: jackrabbit/trunk/jackrabbit-core/pom.xml URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/pom.xml?view=diff&rev=543997&r1=543996&r2=543997 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/pom.xml (original) +++ jackrabbit/trunk/jackrabbit-core/pom.xml Sun Jun 3 14:43:53 2007 @@ -287,6 +287,10 @@ derby + javax.servlet + servlet-api + + junit junit test Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/servlet/JackrabbitRepositoryServlet.java URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/servlet/JackrabbitRepositoryServlet.java?view=auto&rev=543997 ============================================================================== --- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/servlet/JackrabbitRepositoryServlet.java (added) +++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/servlet/JackrabbitRepositoryServlet.java Sun Jun 3 14:43:53 2007 @@ -0,0 +1,161 @@ +/* + * 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.servlet; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.jcr.Repository; +import javax.jcr.RepositoryException; +import javax.servlet.ServletException; + +import org.apache.jackrabbit.api.JackrabbitRepository; +import org.apache.jackrabbit.commons.servlet.AbstractRepositoryServlet; +import org.apache.jackrabbit.core.RepositoryImpl; +import org.apache.jackrabbit.core.config.RepositoryConfig; + +/** + * 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. + *

+ * The supported initialization parameters of this servlet are: + *

+ *
javax.jcr.Repository
+ *
+ * Name of the servlet context attribute to put the repository in. + * The default value is "javax.jcr.Repository". + *
+ *
repository.home
+ *
+ * Path of the repository home directory. The default value is + * "jackrabbit-repository". The home directory is + * automatically created during servlet initialization if it does + * not already exist. + *
+ *
repository.config
+ *
+ * Path of the repository configuration file. The default value is + * "repository.xml" 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. + *
+ *
+ *

+ * The repository servlet can also be mapped to the URL space. See + * {@link AbstractRepositoryServlet} for the details. + * + * @since 1.4 + */ +public class JackrabbitRepositoryServlet extends AbstractRepositoryServlet { + + /** + * Serial version UID. + */ + private static final long serialVersionUID = 7102770011290708450L; + + /** + * Repository instance. + */ + private JackrabbitRepository repository; + + /** + * Starts the repository instance and makes it available in the + * servlet context. + * + * @throws ServletException if the repository can not be started + */ + public void init() throws ServletException { + try { + File home = new File(getInitParameter( + "repository.home", "jackrabbit-repository")); + if (!home.exists()) { + log("Creating repository home directory: " + home); + home.mkdirs(); + } + + File config = new File(getInitParameter( + "repository.config", + new File(home, "repository.xml").getPath())); + if (!config.exists()) { + log("Creating default repository configuration: " + config); + createDefaultConfiguration(config); + } + + repository = RepositoryImpl.create(RepositoryConfig.create( + config.toURI(), home.getPath())); + } catch (RepositoryException e) { + throw new ServletException("Failed to start Jackrabbit", e); + } + + super.init(); + } + + /** + * Removes the repository from the servlet context and shuts it down. + */ + public void destroy() { + super.destroy(); + repository.shutdown(); + } + + /** + * Returns the repository instance. + * + * @return repository instance + */ + protected Repository getRepository() { + return repository; + } + + /** + * 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 { + 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); + } + } + +} Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/servlet/JackrabbitRepositoryServlet.java ------------------------------------------------------------------------------ svn:eol-style = native