KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > mail > MailboxURL


1 /*
2  * MailboxURL.java
3  *
4  * Copyright (C) 2002 Peter Graves
5  * $Id: MailboxURL.java,v 1.1.1.1 2002/09/24 16:09:53 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j.mail;
23
24 import java.net.MalformedURLException JavaDoc;
25 import org.armedbear.j.Log;
26
27 public abstract class MailboxURL
28 {
29     private String JavaDoc baseName;
30     private String JavaDoc limitPattern;
31
32     protected String JavaDoc user;
33     protected String JavaDoc host;
34     protected int port;
35
36     public final String JavaDoc getBaseName()
37     {
38         return baseName;
39     }
40
41     public final void setBaseName(String JavaDoc baseName)
42     {
43         this.baseName = baseName;
44     }
45
46     public final String JavaDoc getLimitPattern()
47     {
48         return limitPattern;
49     }
50
51     public final void setLimitPattern(String JavaDoc limitPattern)
52     {
53         this.limitPattern = limitPattern;
54     }
55
56     public final String JavaDoc getUser()
57     {
58         return user;
59     }
60
61     public final void setUser(String JavaDoc user)
62     {
63         this.user = user;
64     }
65
66     public final String JavaDoc getHost()
67     {
68         return host;
69     }
70
71     public final int getPort()
72     {
73         return port;
74     }
75
76     public static MailboxURL parse(String JavaDoc input)
77     {
78         if (input == null)
79             return null;
80         input = input.trim();
81         if (input.length() == 0)
82             return null;
83         String JavaDoc baseName;
84         String JavaDoc limitPattern = null;
85         if (input.charAt(0) == '"') {
86             int index = input.indexOf('"', 1);
87             if (index < 0)
88                 return null;
89             baseName = input.substring(1, index);
90             if (index < input.length()-1)
91                 limitPattern = input.substring(index+1).trim();
92         } else {
93             int index = input.indexOf(' ');
94             if (index >= 0) {
95                 baseName = input.substring(0, index);
96                 limitPattern = input.substring(index).trim();
97             } else
98                 baseName = input;
99         }
100         if (baseName.length() == 0)
101             return null;
102         MailboxURL url = null;
103         try {
104             if (baseName.charAt(0) == '{') {
105                 // IMAP.
106
url = new ImapURL(baseName);
107             } else if (baseName.startsWith("pop://")) {
108                 // POP.
109
url = new PopURL(baseName);
110             } else {
111                 // Local.
112
url = new LocalMailboxURL(baseName);
113             }
114         }
115         catch (MalformedURLException JavaDoc e) {
116             Log.error(e);
117         }
118         if (url != null) {
119             url.setBaseName(baseName);
120             url.setLimitPattern(limitPattern);
121         }
122         return url;
123     }
124
125     public abstract String JavaDoc getCanonicalName();
126 }
127
Popular Tags