Lines 25-102
Link Here
|
25 |
* |
25 |
* |
26 |
* @since Ant 1.5.2 |
26 |
* @since Ant 1.5.2 |
27 |
*/ |
27 |
*/ |
28 |
public class Resource implements Cloneable, Comparable { |
28 |
public abstract class Resource implements Cloneable, Comparable { |
|
|
29 |
protected String name = null; |
30 |
|
29 |
/** Constant unknown size */ |
31 |
/** Constant unknown size */ |
30 |
public static final long UNKNOWN_SIZE = -1; |
32 |
public static final long UNKNOWN_SIZE = -1; |
31 |
|
33 |
|
32 |
private String name = null; |
|
|
33 |
private boolean exists = true; |
34 |
private long lastmodified = 0; |
35 |
private boolean directory = false; |
36 |
private long size = UNKNOWN_SIZE; |
37 |
|
38 |
/** |
34 |
/** |
39 |
* Default constructor. |
35 |
* Default constructor. |
40 |
*/ |
36 |
*/ |
41 |
public Resource() { |
37 |
protected Resource() { |
42 |
} |
|
|
43 |
|
44 |
/** |
45 |
* Only sets the name. |
46 |
* |
47 |
* <p>This is a dummy, used for not existing resources.</p> |
48 |
* |
49 |
* @param name relative path of the resource. Expects |
50 |
* "/" to be used as the directory separator. |
51 |
*/ |
52 |
public Resource(String name) { |
53 |
this(name, false, 0, false); |
54 |
} |
55 |
|
56 |
/** |
57 |
* Sets the name, lastmodified flag, and exists flag. |
58 |
* |
59 |
* @param name relative path of the resource. Expects |
60 |
* "/" to be used as the directory separator. |
61 |
* @param exists if true, this resource exists. |
62 |
* @param lastmodified the last modification time of this resource. |
63 |
*/ |
64 |
public Resource(String name, boolean exists, long lastmodified) { |
65 |
this(name, exists, lastmodified, false); |
66 |
} |
67 |
|
68 |
/** |
69 |
* Sets the name, lastmodified flag, exists flag, and directory flag. |
70 |
* |
71 |
* @param name relative path of the resource. Expects |
72 |
* "/" to be used as the directory separator. |
73 |
* @param exists if true the resource exists |
74 |
* @param lastmodified the last modification time of the resource |
75 |
* @param directory if true, this resource is a directory |
76 |
*/ |
77 |
public Resource(String name, boolean exists, long lastmodified, |
78 |
boolean directory) { |
79 |
this(name, exists, lastmodified, directory, UNKNOWN_SIZE); |
80 |
} |
81 |
|
82 |
/** |
83 |
* Sets the name, lastmodified flag, exists flag, directory flag, and size. |
84 |
* |
85 |
* @param name relative path of the resource. Expects |
86 |
* "/" to be used as the directory separator. |
87 |
* @param exists if true the resource exists |
88 |
* @param lastmodified the last modification time of the resource |
89 |
* @param directory if true, this resource is a directory |
90 |
* @param size the size of this resource. |
91 |
*/ |
92 |
public Resource(String name, boolean exists, long lastmodified, |
93 |
boolean directory, long size) { |
94 |
this.name = name; |
95 |
setName(name); |
96 |
setExists(exists); |
97 |
setLastModified(lastmodified); |
98 |
setDirectory(directory); |
99 |
setSize(size); |
100 |
} |
38 |
} |
101 |
|
39 |
|
102 |
/** |
40 |
/** |
Lines 128-144
Link Here
|
128 |
* The exists attribute tells whether a file exists. |
66 |
* The exists attribute tells whether a file exists. |
129 |
* @return true if this resource exists. |
67 |
* @return true if this resource exists. |
130 |
*/ |
68 |
*/ |
131 |
public boolean isExists() { |
69 |
public abstract boolean isExists(); |
132 |
return exists; |
|
|
133 |
} |
134 |
|
70 |
|
135 |
/** |
71 |
/** |
136 |
* Set the exists attribute. |
72 |
* Set the exists attribute. |
137 |
* @param exists if true, this resource exists. |
73 |
* @param exists if true, this resource exists. |
138 |
*/ |
74 |
*/ |
139 |
public void setExists(boolean exists) { |
75 |
public abstract void setExists(boolean exists); |
140 |
this.exists = exists; |
|
|
141 |
} |
142 |
|
76 |
|
143 |
/** |
77 |
/** |
144 |
* Tells the modification time in milliseconds since 01.01.1970 . |
78 |
* Tells the modification time in milliseconds since 01.01.1970 . |
Lines 146-187
Link Here
|
146 |
* @return 0 if the resource does not exist to mirror the behavior |
80 |
* @return 0 if the resource does not exist to mirror the behavior |
147 |
* of {@link java.io.File File}. |
81 |
* of {@link java.io.File File}. |
148 |
*/ |
82 |
*/ |
149 |
public long getLastModified() { |
83 |
public abstract long getLastModified(); |
150 |
return !exists || lastmodified < 0 ? 0L : lastmodified; |
|
|
151 |
} |
152 |
|
84 |
|
153 |
/** |
85 |
/** |
154 |
* Set the last modification attribute. |
86 |
* Set the last modification attribute. |
155 |
* @param lastmodified the modification time in milliseconds since 01.01.1970. |
87 |
* @param lastmodified the modification time in milliseconds since 01.01.1970. |
156 |
*/ |
88 |
*/ |
157 |
public void setLastModified(long lastmodified) { |
89 |
public abstract void setLastModified(long lastmodified); |
158 |
this.lastmodified = lastmodified; |
|
|
159 |
} |
160 |
|
90 |
|
161 |
/** |
91 |
/** |
162 |
* Tells if the resource is a directory. |
92 |
* Tells if the resource is a directory. |
163 |
* @return boolean flag indicating if the resource is a directory. |
93 |
* @return boolean flag indicating if the resource is a directory. |
164 |
*/ |
94 |
*/ |
165 |
public boolean isDirectory() { |
95 |
public abstract boolean isDirectory(); |
166 |
return directory; |
|
|
167 |
} |
168 |
|
96 |
|
169 |
/** |
97 |
/** |
170 |
* Set the directory attribute. |
98 |
* Set the directory attribute. |
171 |
* @param directory if true, this resource is a directory. |
99 |
* @param directory if true, this resource is a directory. |
172 |
*/ |
100 |
*/ |
173 |
public void setDirectory(boolean directory) { |
101 |
public abstract void setDirectory(boolean directory); |
174 |
this.directory = directory; |
|
|
175 |
} |
176 |
|
102 |
|
177 |
/** |
103 |
/** |
178 |
* Set the size of this Resource. |
104 |
* Set the size of this Resource. |
179 |
* @param size the size, as a long. |
105 |
* @param size the size, as a long. |
180 |
* @since Ant 1.6.3 |
106 |
* @since Ant 1.6.3 |
181 |
*/ |
107 |
*/ |
182 |
public void setSize(long size) { |
108 |
public abstract void setSize(long size); |
183 |
this.size = (size > UNKNOWN_SIZE) ? size : UNKNOWN_SIZE; |
|
|
184 |
} |
185 |
|
109 |
|
186 |
/** |
110 |
/** |
187 |
* Get the size of this Resource. |
111 |
* Get the size of this Resource. |
Lines 189-197
Link Here
|
189 |
* compatibility with java.io.File), or UNKNOWN_SIZE if not known. |
113 |
* compatibility with java.io.File), or UNKNOWN_SIZE if not known. |
190 |
* @since Ant 1.6.3 |
114 |
* @since Ant 1.6.3 |
191 |
*/ |
115 |
*/ |
192 |
public long getSize() { |
116 |
public abstract long getSize(); |
193 |
return (exists) ? size : 0L; |
|
|
194 |
} |
195 |
|
117 |
|
196 |
/** |
118 |
/** |
197 |
* Clone this Resource. |
119 |
* Clone this Resource. |