rename MailboxTree -> MailTree
[org.ibex.mail.git] / src / org / ibex / mail / MailTree.java
1 // Copyright 2007 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package org.ibex.mail;
6 import org.ibex.mail.*;
7 import org.ibex.util.*;
8 import org.ibex.mail.*;
9 import org.ibex.js.*;
10 import java.io.*;
11 import java.net.*;
12 import java.util.*;
13 import java.text.*;
14
15 /** a node on the "mailbox tree" */
16 public interface MailTree {
17
18     public MailTree     slash(String name, boolean create);
19     public String[]     children();
20     public void         rmdir(String subdir);
21     public void         rename(String subdir, MailTree newParent, String newName);
22     public Mailbox      getMailbox();
23
24     public static class Wrapper implements MailTree {
25         protected MailTree mt;
26         public Wrapper(MailTree mt) { this.mt = mt; }
27         public MailTree     slash(String name, boolean create) { return mt.slash(name, create); }
28         public String[]     children() { return mt.children(); }
29         public void         rmdir(String subdir) { mt.rmdir(subdir); }
30         public void         rename(String subdir, MailTree newParent, String newName) { mt.rename(subdir, newParent, newName); }
31         public Mailbox      getMailbox() { return mt.getMailbox(); }
32     }
33
34     /** applies an Acl to a directory; requires directions on how to Acl-ize subdirectories */
35     public static abstract class AclWrapper extends Wrapper {
36         protected Acl.Entry acl;
37         public AclWrapper(MailTree mt, Acl.Entry acl) { super(mt); this.acl = acl; }
38         public Mailbox      getMailbox() { return new Mailbox.AclWrapper(mt.getMailbox(), acl); }
39         public void rmdir(String subdir) {
40             if (!acl.delete) throw new Acl.PermissionDenied();
41             super.rmdir(subdir);
42         }
43         public void rename(String subdir, MailTree newParent, String newName) {
44             if (!acl.delete) throw new Acl.PermissionDenied();
45             super.rename(subdir, newParent, newName);
46         }
47         public abstract MailTree slash(String name, boolean create);
48     }
49
50     /** applies the Acl recursively to the entire subtree */
51     public static class RecursiveAclWrapper extends AclWrapper {
52         public RecursiveAclWrapper(MailTree mt, Acl.Entry acl) { super(mt, acl); }
53         public MailTree slash(String name, boolean create) {
54             if (!acl.list) throw new Acl.PermissionDenied();
55             if (!acl.mkdirs) create = false;
56             return new RecursiveAclWrapper(super.slash(name, create), acl);
57         }
58     }
59 }