Source code: dr/davmgr/protocol/DefaultUrls.java
1 package dr.davmgr.protocol;
2
3 import java.util.Hashtable;
4 import java.util.Vector;
5 import java.util.Enumeration;
6 import java.util.ListIterator;
7 import java.util.List;
8 import java.net.URL;
9
10 import dr.mime.MIMEType;
11
12 public class DefaultUrls implements Urls
13 {
14 protected Hashtable attributes = new Hashtable();
15
16 protected boolean collection = false;
17
18 protected boolean read = false;
19 protected boolean writeable = false;
20 protected boolean readable = false;
21 protected boolean locked = false;
22 protected boolean lockable = false;
23
24 protected Vector childUrls = null;
25 protected Urls parent = null;
26
27 protected ProtocolHandler protocolHandler = null;
28
29 protected boolean reading = true;
30
31 public URL getURL() { return (URL)getAttribute(A_URL); }
32
33 public String getFilename() {
34 return (String)getAttribute(A_FILENAME);
35 }
36
37 public long getLastModified() {
38 Long v;
39 if ((v=(Long)getAttribute(A_LASTMODIFIED))==null) return -1;
40 long vl;
41 try {
42 vl=((Long)v).longValue();
43 } catch (NumberFormatException nfe) {
44 return -1;
45 }
46 return vl;
47 }
48
49 public MIMEType getMIMEType() {
50 return (MIMEType)getAttribute(A_MIMETYPE);
51 }
52
53
54 public Hashtable getAttributes() { return attributes; }
55
56 public Object getAttribute(Object attribute) {
57 if ((attributes==null)||(attribute==null)) return null;
58 return attributes.get(attribute);
59 }
60 public void addAttribute(String attribute, Object value) {
61 if ((attribute==null)||(value==null)) return;
62 if (attributes==null) attributes=new Hashtable();
63 attributes.put(attribute, value);
64 }
65 public boolean isReadable() { return readable; }
66 public boolean isWriteable() { return writeable; }
67 public boolean isLockable() { return lockable; }
68 public boolean isLocked() { return locked; }
69
70 public boolean isCollection() { return collection; }
71 public boolean isLeaf() { return !isCollection(); }
72 public boolean isRead() { return read; }
73
74 public ProtocolHandler getProtocolHandler() {
75 return protocolHandler;
76 }
77
78 public void setUnread() {
79 if (childUrls!=null) {
80 DefaultUrls du;
81 for (Enumeration e = childUrls.elements(); e.hasMoreElements();) {
82 du = (DefaultUrls)e.nextElement();
83 du.setParent(null);
84 du.setUnread();
85 }
86 }
87 childUrls=null;
88 setRead(false);
89 }
90 public List getAll() { return childUrls; }
91 public List getCollections() {
92 if (childUrls==null) return null;
93 Vector c = new Vector();
94 for (Enumeration e=childUrls.elements(); e.hasMoreElements();) {
95 Urls urls = (Urls) e.nextElement();
96 if (urls.isCollection()) c.add(urls);
97 }
98 if (c.size()==0) return null;
99 return c;
100 }
101 public List getFiles() {
102 if (childUrls==null) return null;
103 Vector f = new Vector();
104 for (Enumeration e=childUrls.elements(); e.hasMoreElements();) {
105 Urls urls = (Urls) e.nextElement();
106 if (!urls.isCollection()) f.add(urls);
107 }
108 if (f.size()==0) return null;
109 return f;
110 }
111
112 public Urls getParent() {
113 return parent;
114 }
115
116 public boolean isReading() {
117 return reading;
118 }
119
120 public int compareTo(Object o) {
121 return toString().compareTo(o.toString());
122 }
123 public String toString() {
124 if (attributes==null) return super.toString();
125 if (attributes.get(A_FILENAME)!=null)
126 return (String)attributes.get(A_FILENAME);
127 else if (attributes.get(A_URL)!=null)
128 return ((URL)attributes.get(A_URL)).toString();
129 return super.toString();
130 }
131
132 // for convenience :
133 public void setURL(URL url) {
134 addAttribute(A_URL, url);
135 }
136
137 public void setFilename(String filename) {
138 addAttribute(A_FILENAME, filename);
139 }
140
141 public void setLastModified(long lastModified) {
142 addAttribute(A_LASTMODIFIED, new Long(lastModified));
143 }
144
145 public void setMIMEType(MIMEType mimeType) {
146 addAttribute(A_MIMETYPE, mimeType);
147 }
148
149 public void setCollection(boolean collection) {
150 this.collection=collection;
151 addAttribute(A_COLLECTION, new Boolean(collection));
152 }
153
154 public void setReadable(boolean readable) {
155 this.readable=readable;
156 addAttribute(A_READABLE, new Boolean(readable));
157 }
158
159 public void setWriteable(boolean writeable) {
160 this.writeable=writeable;
161 addAttribute(A_WRITEABLE, new Boolean(writeable));
162 }
163
164 public void setLockable(boolean lockable) {
165 this.lockable=lockable;
166 addAttribute(A_LOCKABLE, new Boolean(lockable));
167 }
168
169 public void setLocked(boolean locked) {
170 this.locked=locked;
171 addAttribute(A_LOCKED, new Boolean(locked));
172 }
173
174 public void setRead(boolean read) {
175 this.read=read;
176 addAttribute(A_READ, new Boolean(locked));
177 }
178
179 public void addChildUrls(Urls urls) {
180 if (childUrls==null) childUrls = new Vector();
181 childUrls.add(urls);
182 collection=true;
183 }
184 public boolean removeChildUrls(Urls urls) {
185 if ((childUrls==null)||(urls==null)) return false;
186 return childUrls.remove(urls);
187 }
188
189 public void setParent(Urls parent) { this.parent=parent; }
190
191 public void setProtocolHandler(ProtocolHandler protocolHandler) {
192 this.protocolHandler=protocolHandler;
193 }
194
195 public void setAttributes(Hashtable attributes) {
196 this.attributes=attributes;
197 }
198 public void setChildUrls(Vector childUrls) {
199 this.childUrls=childUrls;
200 }
201
202 public void setReading(boolean reading) {
203 this.reading=reading;
204 }
205 }