Author: norman
Date: Mon Mar  8 16:08:24 2010
New Revision: 920375

URL: http://svn.apache.org/viewvc?rev=920375&view=rev
Log:
Start to work on JCR implementation for imap (IMAP-93)

Added:
    james/imap/trunk/jcr/
    james/imap/trunk/jcr/LICENSE.txt
    james/imap/trunk/jcr/NOTICE.txt
    james/imap/trunk/jcr/pom.xml
    james/imap/trunk/jcr/src/
    james/imap/trunk/jcr/src/main/
    james/imap/trunk/jcr/src/main/java/
    james/imap/trunk/jcr/src/main/java/org/
    james/imap/trunk/jcr/src/main/java/org/apache/
    james/imap/trunk/jcr/src/main/java/org/apache/james/
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/
    
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/
    
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/
    
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/JCRSubscription.java
    
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/NonTransactionalMapper.java
Modified:
    
james/imap/trunk/maildir/src/main/java/org/apache/james/imap/maildir/mail/MaildirMailboxMapper.java
    james/imap/trunk/parent/pom.xml
    james/imap/trunk/pom.xml
    
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/user/SubscriptionMapper.java

Added: james/imap/trunk/jcr/LICENSE.txt
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/jcr/LICENSE.txt?rev=920375&view=auto
==============================================================================
--- james/imap/trunk/jcr/LICENSE.txt (added)
+++ james/imap/trunk/jcr/LICENSE.txt Mon Mar  8 16:08:24 2010
@@ -0,0 +1,176 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
\ No newline at end of file

Added: james/imap/trunk/jcr/NOTICE.txt
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/jcr/NOTICE.txt?rev=920375&view=auto
==============================================================================
--- james/imap/trunk/jcr/NOTICE.txt (added)
+++ james/imap/trunk/jcr/NOTICE.txt Mon Mar  8 16:08:24 2010
@@ -0,0 +1,11 @@
+
+=========================================================================
+==      NOTICE file for use with the Apache License, Version 2.0,      ==
+=========================================================================
+
+Apache JAMES 
+Copyright 2007-2008 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+            
\ No newline at end of file

Added: james/imap/trunk/jcr/pom.xml
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/jcr/pom.xml?rev=920375&view=auto
==============================================================================
--- james/imap/trunk/jcr/pom.xml (added)
+++ james/imap/trunk/jcr/pom.xml Mon Mar  8 16:08:24 2010
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="ISO-8859-15"?>
+<!--
+  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.    
+-->
+<project>
+  <parent>
+    <artifactId>apache-james-imap-parent</artifactId>
+    <groupId>org.apache.james</groupId>
+    <version>0.1-SNAPSHOT</version>
+    <relativePath>../parent/pom.xml</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.james</groupId>
+  <artifactId>apache-james-imap-jcr</artifactId>
+  <name>Apache James IMAP JCR Mailbox Manager</name>
+  <dependencies>
+    <dependency>
+      <groupId>${javax.mail.groupId}</groupId>
+      <artifactId>${javax.mail.artifactId}</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>${javax.activation.groupId}</groupId>
+      <artifactId>${javax.activation.artifactId}</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-mailbox</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-james-imap-store</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.apache.james</groupId>
+      <artifactId>apache-mime4j</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>javax.jcr</groupId>
+      <artifactId>jcr</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>jackrabbit-jcr-commons</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Added: 
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java?rev=920375&view=auto
==============================================================================
--- 
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
 (added)
+++ 
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
 Mon Mar  8 16:08:24 2010
@@ -0,0 +1,124 @@
+/****************************************************************
+ * 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.james.imap.jcr.mail;
+
+import java.util.List;
+
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.mailbox.MailboxNotFoundException;
+import org.apache.james.imap.mailbox.StorageException;
+import org.apache.james.imap.store.mail.MailboxMapper;
+import org.apache.james.imap.store.mail.NonTransactionalMapper;
+import org.apache.james.imap.store.mail.model.Mailbox;
+
+/**
+ * JCR implementation of a MailboxMapper
+ * 
+ *
+ */
+public class JCRMailboxMapper extends NonTransactionalMapper implements 
MailboxMapper{
+
+       private final static String WILDCARD = "*";
+       private final Session session;
+       private final String PATH = "mailboxes";
+
+       public JCRMailboxMapper(Session session) {
+               this.session = session;
+       }
+       @Override
+       public long countMailboxesWithName(String name) throws StorageException 
{
+               // TODO Auto-generated method stub
+               return 0;
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see 
org.apache.james.imap.store.mail.MailboxMapper#delete(org.apache.james.imap.store.mail.model.Mailbox)
+        */
+       public void delete(Mailbox mailbox) throws StorageException {
+               try {
+                       session.getRootNode().getNode(PATH + "/" 
+mailbox.getName()).remove();
+               } catch (PathNotFoundException e) {
+                       // mailbox does not exists.. 
+               } catch (RepositoryException e) {
+                       throw new 
StorageException(HumanReadableText.DELETED_FAILED, e);
+               }               
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.apache.james.imap.store.mail.MailboxMapper#deleteAll()
+        */
+       public void deleteAll() throws StorageException {
+               try {
+                       session.getRootNode().getNode(PATH).remove();
+                       session.save();
+
+               } catch (PathNotFoundException e) {
+                       // nothing todo
+               } catch (RepositoryException e) {
+                       throw new 
StorageException(HumanReadableText.DELETED_FAILED, e);
+               }
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see 
org.apache.james.imap.store.mail.MailboxMapper#existsMailboxStartingWith(java.lang.String)
+        */
+       public boolean existsMailboxStartingWith(String mailboxName)
+                       throws StorageException {
+               try {
+                       return session.getRootNode().getNodes(PATH + "/" + 
mailboxName + WILDCARD).hasNext();
+               } catch (RepositoryException e) {
+                       throw new 
StorageException(HumanReadableText.SEARCH_FAILED, e);
+               }
+       }
+
+       @Override
+       public Mailbox findMailboxById(long mailboxId) throws StorageException,
+                       MailboxNotFoundException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public Mailbox findMailboxByName(String name) throws StorageException,
+                       MailboxNotFoundException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public List<Mailbox> findMailboxWithNameLike(String name)
+                       throws StorageException {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void save(Mailbox mailbox) throws StorageException {
+               // TODO Auto-generated method stub
+               
+       }
+
+}

Added: 
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java?rev=920375&view=auto
==============================================================================
--- 
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java
 (added)
+++ 
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java
 Mon Mar  8 16:08:24 2010
@@ -0,0 +1,143 @@
+/****************************************************************
+ * 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.james.imap.jcr.user;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.jcr.user.model.JCRSubscription;
+import org.apache.james.imap.mailbox.SubscriptionException;
+import org.apache.james.imap.store.user.SubscriptionMapper;
+import org.apache.james.imap.store.user.model.Subscription;
+
+/**
+ * JCR implementation of a SubscriptionManager. Just be aware, this 
SubscriptionManager doesn't
+ * support transactions. So very call on a method ends in a "real" action
+  *
+ */
+public class JCRSubscriptionMapper implements SubscriptionMapper{
+
+       private final Session session;
+       private final static String PATH = "subscriptions";
+       
+       public JCRSubscriptionMapper(Session session) {
+               this.session = session;
+       }
+       
+       /**
+        * Transactions are not supported by most JCR implementations. So do 
nothing
+        */
+       public void begin() throws SubscriptionException {
+               // Nothing todo
+               
+       }
+
+       /**
+        * Transactions are not supported by most JCR implementations. So do 
nothing
+        */
+       public void commit() throws SubscriptionException {
+               // Nothing todo
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see 
org.apache.james.imap.store.user.SubscriptionMapper#delete(org.apache.james.imap.store.user.model.Subscription)
+        */
+       public void delete(Subscription subscription) throws 
SubscriptionException {
+               try {
+                       Node node = session.getRootNode().getNode(PATH + "/" + 
subscription.getUser() + "/" + subscription.getMailbox());
+                       node.remove();
+                       session.save();
+               } catch (PathNotFoundException e) {
+                       // do nothing
+               } catch (RepositoryException e) {
+                       throw new 
SubscriptionException(HumanReadableText.DELETED_FAILED,e);
+               }
+
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see 
org.apache.james.imap.store.user.SubscriptionMapper#findFindMailboxSubscriptionForUser(java.lang.String,
 java.lang.String)
+        */
+       public Subscription findFindMailboxSubscriptionForUser(String user,
+                       String mailbox) throws SubscriptionException {
+               try {
+                       Node node = session.getRootNode().getNode(PATH + "/" + 
user + "/" + mailbox);
+                       return JCRSubscription.from(node);
+               } catch (PathNotFoundException e) {
+                       return null;
+               } catch (RepositoryException e) {
+            throw new SubscriptionException(HumanReadableText.SEARCH_FAILED, 
e);
+               }
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see 
org.apache.james.imap.store.user.SubscriptionMapper#findSubscriptionsForUser(java.lang.String)
+        */
+       public List<Subscription> findSubscriptionsForUser(String user)
+                       throws SubscriptionException {
+               List<Subscription> subList = new ArrayList<Subscription>();
+               try {
+                       Node node = session.getRootNode().getNode(PATH + "/" + 
user);
+                       NodeIterator nodeIt = node.getNodes("*");
+                       while(nodeIt.hasNext()) {
+                               
subList.add(JCRSubscription.from(nodeIt.nextNode()));
+                       }
+               } catch (PathNotFoundException e) {
+                       // Do nothing just return the empty list later
+               } catch (RepositoryException e) {
+                       throw new 
SubscriptionException(HumanReadableText.SEARCH_FAILED,e);
+               }
+               return subList;
+
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see 
org.apache.james.imap.store.user.SubscriptionMapper#save(org.apache.james.imap.store.user.model.Subscription)
+        */
+       public void save(Subscription subscription) throws 
SubscriptionException {
+               String username = subscription.getUser();
+               String mailbox = subscription.getMailbox();
+               String nodename = username + "/" + mailbox;
+               try {
+                       Node node = session.getRootNode().getNode(PATH);
+                       Node subNode;
+                       if (node.hasNode(nodename )) {
+                               subNode = node.getNode(nodename);
+                       } else {
+                               subNode = node.addNode(nodename);
+                       }
+                       JCRSubscription.copy(subscription, subNode);
+                       session.save();
+               } catch (RepositoryException e) {
+            throw new SubscriptionException(HumanReadableText.SAVE_FAILED, e);
+               }               
+       }
+
+}

Added: 
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/JCRSubscription.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/JCRSubscription.java?rev=920375&view=auto
==============================================================================
--- 
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/JCRSubscription.java
 (added)
+++ 
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/model/JCRSubscription.java
 Mon Mar  8 16:08:24 2010
@@ -0,0 +1,102 @@
+/****************************************************************
+ * 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.james.imap.jcr.user.model;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
+import javax.jcr.ValueFormatException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.version.VersionException;
+
+import org.apache.james.imap.store.user.model.Subscription;
+
+
+/**
+ * JCR implementation of a Subscription
+ *
+ */
+public class JCRSubscription implements Subscription{
+
+       private final String mailbox;
+
+       private final String username;
+
+       public final static String USERNAME_PROPERTY = "username";
+       public final static String MAILBOX_PROPERTY = "mailbox";
+
+       public JCRSubscription(String username, String mailbox) {
+               this.username = username;
+               this.mailbox = mailbox;
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.apache.james.imap.store.user.model.Subscription#getMailbox()
+        */
+       public String getMailbox() {
+               return mailbox;
+       }
+
+       /*
+        * (non-Javadoc)
+        * @see org.apache.james.imap.store.user.model.Subscription#getUser()
+        */
+       public String getUser() {
+               return username;
+       }
+       
+       /**
+        * Return the JCRSubscription for the given node
+        * 
+        * @param node 
+        * @return subscription
+        * @throws ValueFormatException
+        * @throws PathNotFoundException
+        * @throws RepositoryException
+        */
+       public static JCRSubscription from(Node node) throws 
ValueFormatException, PathNotFoundException, RepositoryException {
+               String username = 
node.getProperty(USERNAME_PROPERTY).getString();;
+               String mailbox = node.getProperty(MAILBOX_PROPERTY).getString();
+               
+               return new JCRSubscription(username, mailbox);
+       }
+       
+       
+       /**
+        * Copy all needed properties to the given node for the given 
subscription
+        * 
+        * @param subscription
+        * @param node
+        * @return node
+        * @throws ValueFormatException
+        * @throws VersionException
+        * @throws LockException
+        * @throws ConstraintViolationException
+        * @throws RepositoryException
+        */
+       public static Node copy(Subscription subscription, Node node) throws 
ValueFormatException, VersionException, LockException, 
ConstraintViolationException, RepositoryException {
+               node.setProperty(USERNAME_PROPERTY, subscription.getUser());
+               node.setProperty(MAILBOX_PROPERTY, subscription.getMailbox());
+               return node;
+               
+       }
+}

Modified: 
james/imap/trunk/maildir/src/main/java/org/apache/james/imap/maildir/mail/MaildirMailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/maildir/src/main/java/org/apache/james/imap/maildir/mail/MaildirMailboxMapper.java?rev=920375&r1=920374&r2=920375&view=diff
==============================================================================
--- 
james/imap/trunk/maildir/src/main/java/org/apache/james/imap/maildir/mail/MaildirMailboxMapper.java
 (original)
+++ 
james/imap/trunk/maildir/src/main/java/org/apache/james/imap/maildir/mail/MaildirMailboxMapper.java
 Mon Mar  8 16:08:24 2010
@@ -1,62 +1,30 @@
-/****************************************************************
- * 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.james.imap.maildir.mail;
 
-import java.io.IOException;
 import java.util.List;
-import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.transaction.file.TxFileResourceManager;
 import org.apache.commons.transaction.file.FileResourceManager.FileResource;
 import org.apache.commons.transaction.resource.ResourceException;
 import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxNotFoundException;
 import org.apache.james.imap.mailbox.StorageException;
-import org.apache.james.imap.maildir.mail.model.MaildirMailbox;
 import org.apache.james.imap.store.mail.MailboxMapper;
 import org.apache.james.imap.store.mail.model.Mailbox;
 
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.DomDriver;
-
-/**
- * MailboxMapper which use Maildir layout
- * 
- * 
- */
-public class MaildirMailboxMapper extends MaildirTransactionalMapper implements
-               MailboxMapper {
+public class MaildirMailboxMapper implements MailboxMapper{
 
-       private final static String PREFIX = "james-imap";
-       private final XStream xstream = new XStream(new DomDriver());
+       private TxFileResourceManager manager;
 
-       public MaildirMailboxMapper(final TxFileResourceManager manager) {
-               super(manager);
+       public MaildirMailboxMapper(TxFileResourceManager manager) {
+               this.manager = manager;
        }
-
+       
+       
        /*
         * (non-Javadoc)
-        * 
-        * @see
-        * org.apache.james.imap.store.mail.MailboxMapper#countMailboxesWithName
-        * (java.lang.String)
+        * @see 
org.apache.james.imap.store.mail.MailboxMapper#countMailboxesWithName(java.lang.String)
         */
        public long countMailboxesWithName(String name) throws StorageException 
{
                try {
@@ -66,39 +34,32 @@
                        }
                        return 0;
                } catch (ResourceException e) {
-                       throw new 
StorageException(HumanReadableText.COUNT_FAILED, e);
+            throw new StorageException(HumanReadableText.COUNT_FAILED, e);
                }
        }
 
        /*
         * (non-Javadoc)
-        * 
-        * @see
-        * 
org.apache.james.imap.store.mail.MailboxMapper#delete(org.apache.james
-        * .imap.store.mail.model.Mailbox)
+        * @see 
org.apache.james.imap.store.mail.MailboxMapper#delete(org.apache.james.imap.store.mail.model.Mailbox)
         */
        public void delete(Mailbox mailbox) throws StorageException {
                try {
                        
manager.getResource(getPathForMailbox(mailbox)).delete();
-                       deleteMailboxId(mailbox.getMailboxId());
-               } catch (Exception e) {
+               } catch (ResourceException e) {
                        throw new 
StorageException(HumanReadableText.DELETED_FAILED, e);
                }
        }
 
        /*
         * (non-Javadoc)
-        * 
         * @see org.apache.james.imap.store.mail.MailboxMapper#deleteAll()
         */
        public void deleteAll() throws StorageException {
                try {
-                       List<? extends FileResource> mailboxes = 
manager.getResource(
-                                       manager.getRootPath()).getChildren();
-                       for (int i = 0; i < mailboxes.size(); i++) {
+                       List<? extends FileResource> mailboxes = 
manager.getResource(manager.getRootPath()).getChildren();
+                       for(int i = 0 ; i < mailboxes.size(); i++) {
                                mailboxes.get(i).delete();
                        }
-                       
manager.getResource(manager.getRootPath()).getChild(PREFIX + 
"-ids.properties").delete();
                } catch (ResourceException e) {
                        throw new 
StorageException(HumanReadableText.DELETED_FAILED, e);
                }
@@ -106,10 +67,7 @@
 
        /*
         * (non-Javadoc)
-        * 
-        * @see
-        * 
org.apache.james.imap.store.mail.MailboxMapper#existsMailboxStartingWith
-        * (java.lang.String)
+        * @see 
org.apache.james.imap.store.mail.MailboxMapper#existsMailboxStartingWith(java.lang.String)
         */
        public boolean existsMailboxStartingWith(String mailboxName)
                        throws StorageException {
@@ -119,104 +77,38 @@
                                return true;
                        }
                        return false;
-
+                       
                } catch (ResourceException e) {
                        throw new 
StorageException(HumanReadableText.SEARCH_FAILED, e);
                }
        }
 
-       /**
-        * Convert the give name to the right path
-        * 
-        * @param name
-        * @return path
-        */
        private String convertToPath(String name) {
                return name.substring("#mail".length()).replaceAll("\\.", "/");
        }
-
-       /*
-        * (non-Javadoc)
-        * @see 
org.apache.james.imap.store.mail.MailboxMapper#findMailboxById(long)
-        */
+       
+       
        public Mailbox findMailboxById(long mailboxId) throws StorageException,
                        MailboxNotFoundException {
-
-               try {
-                       String name = convertToPath(getMailboxName(mailboxId));
-                       MaildirMailbox mailbox = (MaildirMailbox) 
xstream.fromXML(manager
-                                       .getResource(name).getChild(PREFIX + 
"-metadata.xml")
-                                       .readStream());
-                       return mailbox;
-               } catch (Exception e) {
-                       throw new 
StorageException(HumanReadableText.SEARCH_FAILED, e);
-               }
+               // TODO Auto-generated method stub
+               return null;
        }
 
-       /*
-        * (non-Javadoc)
-        * @see 
org.apache.james.imap.store.mail.MailboxMapper#findMailboxByName(java.lang.String)
-        */
        public Mailbox findMailboxByName(String name) throws StorageException,
                        MailboxNotFoundException {
-               try {
-
-                       FileResource fr = 
manager.getResource(convertToPath(name));
-                       if (fr.exists()) {
-                               return (MaildirMailbox) 
xstream.fromXML(fr.getChild(
-                                               PREFIX + 
"-metadata.xml").readStream());
-
-                       }
-               } catch (ResourceException e) {
-                       throw new 
StorageException(HumanReadableText.SEARCH_FAILED, e);
-               }
-               throw new MailboxNotFoundException(name);
+               // TODO Auto-generated method stub
+               return null;
        }
 
-       /*
-        * (non-Javadoc)
-        * @see 
org.apache.james.imap.store.mail.MailboxMapper#findMailboxWithNameLike(java.lang.String)
-        */
        public List<Mailbox> findMailboxWithNameLike(String name)
                        throws StorageException {
                // TODO Auto-generated method stub
                return null;
        }
 
-       private String getMailboxName(long id) throws IOException,
-                       ResourceException {
-               Properties props = new Properties();
-               props.load(manager.getResource(manager.getRootPath()).getChild(
-                               PREFIX + "-ids.properties").readStream());
-               return (String) props.get(id);
-       }
-
-       private void deleteMailboxId(long id) throws IOException, 
ResourceException {
-               FileResource fr = 
manager.getResource(manager.getRootPath()).getChild(
-                               PREFIX + "-ids.properties");
-               Properties props = new Properties();
-               props.load(fr.readStream());
-               props.remove(id);
-               props.store(manager.getResource(manager.getRootPath()).getChild(
-                               PREFIX + "-ids.properties").writeStream(true), 
"");
-       }
-       
-       private void saveMailboxIdMapping(long id, String name) throws 
IOException, ResourceException {
-               FileResource fr = 
manager.getResource(manager.getRootPath()).getChild(
-                               PREFIX + "-ids.properties");
-               Properties props = new Properties();
-               props.load(fr.readStream());
-               props.put(id,name);
-               props.store(manager.getResource(manager.getRootPath()).getChild(
-                               PREFIX + "-ids.properties").writeStream(true), 
"");
-       }
-
        /*
         * (non-Javadoc)
-        * 
-        * @see
-        * org.apache.james.imap.store.mail.MailboxMapper#save(org.apache.james.
-        * imap.store.mail.model.Mailbox)
+        * @see 
org.apache.james.imap.store.mail.MailboxMapper#save(org.apache.james.imap.store.mail.model.Mailbox)
         */
        public void save(Mailbox mailbox) throws StorageException {
                try {
@@ -224,48 +116,45 @@
                        fr.getChild("new").createAsDirectory();
                        fr.getChild("cur").createAsDirectory();
                        fr.getChild("tmp").createAsDirectory();
-                       saveMailboxIdMapping(mailbox.getMailboxId(), 
mailbox.getName());
-                       xstream.toXML(mailbox,fr.getChild(PREFIX + 
"-metadata.xml").writeStream(true));
-                               
-               } catch (Exception e) {
+               } catch (ResourceException e) {
                        throw new 
StorageException(HumanReadableText.SAVE_FAILED, e);
                }
        }
 
-       /**
-        * Return the path for the given mailbox
-        * 
-        * @param mailbox
-        * @return path
-        */
        private String getPathForMailbox(Mailbox mailbox) {
-               String path = "";
+               String path ="";
                String name = mailbox.getName();
                String parts[] = name.split("\\.");
                String userParts[] = parts[1].split("@");
-
-               // reverse order to domain, user
-               path += constructPath(new String[] { userParts[1], userParts[2] 
}, 0);
-               path += "/Maildir";
+               
+               path += constructPath(userParts, 0);
                path += constructPath(parts, 2);
 
                return path;
        }
-
-       /**
-        * Construct path for the given array, starting from start index.
-        * 
-        * @param parts
-        * @param start
-        * @return path
-        */
+       
        private String constructPath(String[] parts, int start) {
                String path = "";
                for (int i = start; i < parts.length; i++) {
-                       // suffix with "."
-                       path += "/." + parts[i];
+                       path += "/" + parts[i];
                }
                return path;
        }
+       
+       /*
+        * (non-Javadoc)
+        * @see 
org.apache.james.imap.store.mail.TransactionalMapper#execute(org.apache.james.imap.store.mail.TransactionalMapper.Transaction)
+        */
+       public void execute(Transaction transaction) throws MailboxException {
+               manager.startTransaction(60, TimeUnit.SECONDS);
+               
+               try {
+                       transaction.run();
+                       manager.commitTransaction();
+               } catch (MailboxException e) {
+                       manager.rollbackTransaction();
+                       throw e;
+               }
+       }
 
 }

Modified: james/imap/trunk/parent/pom.xml
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/parent/pom.xml?rev=920375&r1=920374&r2=920375&view=diff
==============================================================================
--- james/imap/trunk/parent/pom.xml (original)
+++ james/imap/trunk/parent/pom.xml Mon Mar  8 16:08:24 2010
@@ -522,6 +522,25 @@
       <!-- 
         END Maildir
       -->
+      
+      <!-- 
+        START JCR
+      -->
+      <dependency>
+        <groupId>javax.jcr</groupId>
+        <artifactId>jcr</artifactId>
+        <version>1.0</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.jackrabbit</groupId>
+        <artifactId>jackrabbit-jcr-commons</artifactId>
+        <version>2.0.0</version>
+      </dependency>
+      
+      <!-- 
+        END JCR
+      -->
+      
     </dependencies>
   </dependencyManagement>
 

Modified: james/imap/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/pom.xml?rev=920375&r1=920374&r2=920375&view=diff
==============================================================================
--- james/imap/trunk/pom.xml (original)
+++ james/imap/trunk/pom.xml Mon Mar  8 16:08:24 2010
@@ -43,6 +43,7 @@
     <module>processor</module>
     <module>torque</module>
     <module>jpa</module>
+    <module>jcr</module>
     <module>memory</module>
     <module>seda</module>
     <module>deployment</module>

Added: 
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/NonTransactionalMapper.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/NonTransactionalMapper.java?rev=920375&view=auto
==============================================================================
--- 
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/NonTransactionalMapper.java
 (added)
+++ 
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/NonTransactionalMapper.java
 Mon Mar  8 16:08:24 2010
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.james.imap.store.mail;
+
+import org.apache.james.imap.mailbox.MailboxException;
+
+/**
+ * Mapper which not do any real transaction handling. It just execute the 
execute() method
+ *  of the Transaction object without any special handling.
+ *  
+ *  This class is mostly usefull for Mapper implementations which not support 
Transactions
+ *
+ */
+public class NonTransactionalMapper implements TransactionalMapper {
+
+       /**
+        * Just execute the Transaction object without any transaction support.
+        */
+       public void execute(Transaction transaction) throws MailboxException {
+               transaction.run();
+       }
+
+}

Modified: 
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/user/SubscriptionMapper.java
URL: 
http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/user/SubscriptionMapper.java?rev=920375&r1=920374&r2=920375&view=diff
==============================================================================
--- 
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/user/SubscriptionMapper.java
 (original)
+++ 
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/user/SubscriptionMapper.java
 Mon Mar  8 16:08:24 2010
@@ -23,10 +23,24 @@
 import org.apache.james.imap.mailbox.SubscriptionException;
 import org.apache.james.imap.store.user.model.Subscription;
 
+/**
+ * 
+ *
+ */
 public interface SubscriptionMapper {
 
+       /**
+        * Begin transaction 
+        * 
+        * @throws SubscriptionException
+        */
     public abstract void begin() throws SubscriptionException;
 
+    /**
+     * Commit transaction
+     * 
+     * @throws SubscriptionException
+     */
     public abstract void commit() throws SubscriptionException;
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to