001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.core.internal.wc.admin;
013:
014: import java.util.Iterator;
015: import java.util.Map;
016:
017: import org.tmatesoft.svn.core.SVNException;
018: import org.tmatesoft.svn.core.SVNNodeKind;
019: import org.tmatesoft.svn.core.SVNProperty;
020: import org.tmatesoft.svn.core.SVNURL;
021: import org.tmatesoft.svn.core.internal.util.SVNEncodingUtil;
022: import org.tmatesoft.svn.core.internal.util.SVNPathUtil;
023:
024: /**
025: * @version 1.1.1
026: * @author TMate Software Ltd.
027: */
028: public class SVNEntry implements Comparable {
029:
030: private Map myAttributes;
031: private SVNAdminArea myAdminArea;
032: private String myName;
033:
034: public SVNEntry(Map attributes, SVNAdminArea adminArea, String name) {
035: myAttributes = attributes;
036: myName = name;
037: myAdminArea = adminArea;
038: if (!myAttributes.containsKey(SVNProperty.NAME)) {
039: myAttributes.put(SVNProperty.NAME, name);
040: }
041: }
042:
043: public boolean equals(Object obj) {
044: if (obj == null || obj.getClass() != SVNEntry.class) {
045: return false;
046: }
047: SVNEntry entry = (SVNEntry) obj;
048: return entry.myAttributes == myAttributes
049: && entry.myName.equals(myName);
050: }
051:
052: public int hashCode() {
053: return myAttributes.hashCode() + 17 * myName.hashCode();
054: }
055:
056: public int compareTo(Object obj) {
057: if (obj == this ) {
058: return 0;
059: }
060: if (obj == null || obj.getClass() != SVNEntry.class) {
061: return 1;
062: }
063: if (isThisDir()) {
064: return -1;
065: }
066: SVNEntry entry = (SVNEntry) obj;
067: return myName.toLowerCase().compareTo(
068: entry.myName.toLowerCase());
069: }
070:
071: public boolean isThisDir() {
072: return "".equals(getName());
073: }
074:
075: public String getURL() {
076: String url = (String) myAttributes.get(SVNProperty.URL);
077: if (url == null && myAdminArea != null
078: && !myAdminArea.getThisDirName().equals(myName)) {
079: SVNEntry rootEntry = null;
080: try {
081: rootEntry = myAdminArea.getEntry(myAdminArea
082: .getThisDirName(), true);
083: } catch (SVNException svne) {
084: return url;
085: }
086: url = rootEntry.getURL();
087: url = SVNPathUtil.append(url, SVNEncodingUtil
088: .uriEncode(myName));
089: }
090: return url;
091: }
092:
093: public SVNURL getSVNURL() throws SVNException {
094: String url = getURL();
095: if (url != null) {
096: return SVNURL.parseURIEncoded(url);
097: }
098: return null;
099: }
100:
101: public String getName() {
102: return myName;
103: }
104:
105: public boolean isDirectory() {
106: return SVNProperty.KIND_DIR.equals(myAttributes
107: .get(SVNProperty.KIND));
108: }
109:
110: public long getRevision() {
111: String revStr = (String) myAttributes.get(SVNProperty.REVISION);
112: if (revStr == null && myAdminArea != null
113: && !myAdminArea.getThisDirName().equals(myName)) {
114: SVNEntry rootEntry = null;
115: try {
116: rootEntry = myAdminArea.getEntry(myAdminArea
117: .getThisDirName(), true);
118: } catch (SVNException svne) {
119: return -1;
120: }
121: return rootEntry.getRevision();
122: }
123: return revStr != null ? Long.parseLong(revStr) : -1;
124: }
125:
126: public boolean isScheduledForAddition() {
127: return SVNProperty.SCHEDULE_ADD.equals(myAttributes
128: .get(SVNProperty.SCHEDULE));
129: }
130:
131: public boolean isScheduledForDeletion() {
132: return SVNProperty.SCHEDULE_DELETE.equals(myAttributes
133: .get(SVNProperty.SCHEDULE));
134: }
135:
136: public boolean isScheduledForReplacement() {
137: return SVNProperty.SCHEDULE_REPLACE.equals(myAttributes
138: .get(SVNProperty.SCHEDULE));
139: }
140:
141: public boolean isHidden() {
142: return (isDeleted() || isAbsent()) && !isScheduledForAddition()
143: && !isScheduledForReplacement();
144: }
145:
146: public boolean isFile() {
147: return SVNProperty.KIND_FILE.equals(myAttributes
148: .get(SVNProperty.KIND));
149: }
150:
151: public String getLockToken() {
152: return (String) myAttributes.get(SVNProperty.LOCK_TOKEN);
153: }
154:
155: public boolean isDeleted() {
156: return Boolean.TRUE.toString().equals(
157: myAttributes.get(SVNProperty.DELETED));
158: }
159:
160: public boolean isAbsent() {
161: return Boolean.TRUE.toString().equals(
162: myAttributes.get(SVNProperty.ABSENT));
163: }
164:
165: public String toString() {
166: return myName;
167: }
168:
169: private boolean setAttributeValue(String name, String value) {
170: if (value == null) {
171: return myAttributes.remove(name) != null;
172: }
173: Object oldValue = myAttributes.put(name, value);
174: return !value.equals(oldValue);
175: }
176:
177: public boolean setRevision(long revision) {
178: return setAttributeValue(SVNProperty.REVISION, Long
179: .toString(revision));
180: }
181:
182: public boolean setURL(String url) {
183: return setAttributeValue(SVNProperty.URL, url);
184: }
185:
186: public void setIncomplete(boolean incomplete) {
187: setAttributeValue(SVNProperty.INCOMPLETE,
188: incomplete ? Boolean.TRUE.toString() : null);
189: }
190:
191: public boolean isIncomplete() {
192: return Boolean.TRUE.toString().equals(
193: myAttributes.get(SVNProperty.INCOMPLETE));
194: }
195:
196: public String getConflictOld() {
197: return (String) myAttributes.get(SVNProperty.CONFLICT_OLD);
198: }
199:
200: public void setConflictOld(String name) {
201: setAttributeValue(SVNProperty.CONFLICT_OLD, name);
202: }
203:
204: public String getConflictNew() {
205: return (String) myAttributes.get(SVNProperty.CONFLICT_NEW);
206: }
207:
208: public void setConflictNew(String name) {
209: setAttributeValue(SVNProperty.CONFLICT_NEW, name);
210: }
211:
212: public String getConflictWorking() {
213: return (String) myAttributes.get(SVNProperty.CONFLICT_WRK);
214: }
215:
216: public void setConflictWorking(String name) {
217: setAttributeValue(SVNProperty.CONFLICT_WRK, name);
218: }
219:
220: public String getPropRejectFile() {
221: return (String) myAttributes.get(SVNProperty.PROP_REJECT_FILE);
222: }
223:
224: public void setPropRejectFile(String name) {
225: setAttributeValue(SVNProperty.PROP_REJECT_FILE, name);
226: }
227:
228: public String getAuthor() {
229: return (String) myAttributes.get(SVNProperty.LAST_AUTHOR);
230: }
231:
232: public String getCommittedDate() {
233: return (String) myAttributes.get(SVNProperty.COMMITTED_DATE);
234: }
235:
236: public long getCommittedRevision() {
237: String rev = (String) myAttributes
238: .get(SVNProperty.COMMITTED_REVISION);
239: if (rev == null) {
240: return -1;
241: }
242: return Long.parseLong(rev);
243: }
244:
245: public void setTextTime(String time) {
246: setAttributeValue(SVNProperty.TEXT_TIME, time);
247: }
248:
249: public void setKind(SVNNodeKind kind) {
250: String kindStr = kind == SVNNodeKind.DIR ? SVNProperty.KIND_DIR
251: : (kind == SVNNodeKind.FILE ? SVNProperty.KIND_FILE
252: : null);
253: setAttributeValue(SVNProperty.KIND, kindStr);
254: }
255:
256: public void setAbsent(boolean absent) {
257: setAttributeValue(SVNProperty.ABSENT, absent ? Boolean.TRUE
258: .toString() : null);
259: }
260:
261: public void setDeleted(boolean deleted) {
262: setAttributeValue(SVNProperty.DELETED, deleted ? Boolean.TRUE
263: .toString() : null);
264: }
265:
266: public SVNNodeKind getKind() {
267: String kind = (String) myAttributes.get(SVNProperty.KIND);
268: if (SVNProperty.KIND_DIR.equals(kind)) {
269: return SVNNodeKind.DIR;
270: } else if (SVNProperty.KIND_FILE.equals(kind)) {
271: return SVNNodeKind.FILE;
272: }
273: return SVNNodeKind.UNKNOWN;
274: }
275:
276: public String getTextTime() {
277: return (String) myAttributes.get(SVNProperty.TEXT_TIME);
278: }
279:
280: public String getChecksum() {
281: return (String) myAttributes.get(SVNProperty.CHECKSUM);
282: }
283:
284: public void setLockComment(String comment) {
285: myAttributes.put(SVNProperty.LOCK_COMMENT, comment);
286: }
287:
288: public void setLockOwner(String owner) {
289: setAttributeValue(SVNProperty.LOCK_OWNER, owner);
290: }
291:
292: public void setLockCreationDate(String date) {
293: setAttributeValue(SVNProperty.LOCK_CREATION_DATE, date);
294: }
295:
296: public void setLockToken(String token) {
297: setAttributeValue(SVNProperty.LOCK_TOKEN, token);
298: }
299:
300: public void setUUID(String uuid) {
301: setAttributeValue(SVNProperty.UUID, uuid);
302: }
303:
304: public void unschedule() {
305: setAttributeValue(SVNProperty.SCHEDULE, null);
306: }
307:
308: public void scheduleForAddition() {
309: setAttributeValue(SVNProperty.SCHEDULE,
310: SVNProperty.SCHEDULE_ADD);
311: }
312:
313: public void scheduleForDeletion() {
314: setAttributeValue(SVNProperty.SCHEDULE,
315: SVNProperty.SCHEDULE_DELETE);
316: }
317:
318: public void scheduleForReplacement() {
319: setAttributeValue(SVNProperty.SCHEDULE,
320: SVNProperty.SCHEDULE_REPLACE);
321: }
322:
323: public void setSchedule(String schedule) {
324: setAttributeValue(SVNProperty.SCHEDULE, schedule);
325: }
326:
327: public void setCopyFromRevision(long revision) {
328: setAttributeValue(SVNProperty.COPYFROM_REVISION,
329: revision >= 0 ? Long.toString(revision) : null);
330: }
331:
332: public boolean setCopyFromURL(String url) {
333: return setAttributeValue(SVNProperty.COPYFROM_URL, url);
334: }
335:
336: public void setCopied(boolean copied) {
337: setAttributeValue(SVNProperty.COPIED, copied ? Boolean.TRUE
338: .toString() : null);
339: }
340:
341: public String getCopyFromURL() {
342: return (String) myAttributes.get(SVNProperty.COPYFROM_URL);
343: }
344:
345: public SVNURL getCopyFromSVNURL() throws SVNException {
346: String url = getCopyFromURL();
347: if (url != null) {
348: return SVNURL.parseURIEncoded(url);
349: }
350: return null;
351: }
352:
353: public long getCopyFromRevision() {
354: String rev = (String) myAttributes
355: .get(SVNProperty.COPYFROM_REVISION);
356: if (rev == null) {
357: return -1;
358: }
359: return Long.parseLong(rev);
360: }
361:
362: public String getPropTime() {
363: return (String) myAttributes.get(SVNProperty.PROP_TIME);
364: }
365:
366: public void setPropTime(String time) {
367: setAttributeValue(SVNProperty.PROP_TIME, time);
368: }
369:
370: public boolean isCopied() {
371: return Boolean.TRUE.toString().equals(
372: myAttributes.get(SVNProperty.COPIED));
373: }
374:
375: public String getUUID() {
376: return (String) myAttributes.get(SVNProperty.UUID);
377: }
378:
379: public String getRepositoryRoot() {
380: return (String) myAttributes.get(SVNProperty.REPOS);
381: }
382:
383: public SVNURL getRepositoryRootURL() throws SVNException {
384: String url = getRepositoryRoot();
385: if (url != null) {
386: return SVNURL.parseURIEncoded(url);
387: }
388: return null;
389: }
390:
391: public boolean setRepositoryRoot(String url) {
392: return setAttributeValue(SVNProperty.REPOS, url);
393: }
394:
395: public boolean setRepositoryRootURL(SVNURL url) {
396: return setRepositoryRoot(url == null ? null : url.toString());
397: }
398:
399: public void loadProperties(Map entryProps) {
400: if (entryProps == null) {
401: return;
402: }
403: for (Iterator propNames = entryProps.keySet().iterator(); propNames
404: .hasNext();) {
405: String propName = (String) propNames.next();
406: setAttributeValue(propName, (String) entryProps
407: .get(propName));
408: }
409: }
410:
411: public String getLockOwner() {
412: return (String) myAttributes.get(SVNProperty.LOCK_OWNER);
413: }
414:
415: public String getLockComment() {
416: return (String) myAttributes.get(SVNProperty.LOCK_COMMENT);
417: }
418:
419: public String getLockCreationDate() {
420: return (String) myAttributes
421: .get(SVNProperty.LOCK_CREATION_DATE);
422: }
423:
424: public String getSchedule() {
425: return (String) myAttributes.get(SVNProperty.SCHEDULE);
426: }
427:
428: public void setCachableProperties(String[] cachableProps) {
429: if (cachableProps != null) {
430: myAttributes.put(SVNProperty.CACHABLE_PROPS, cachableProps);
431: } else {
432: myAttributes.remove(SVNProperty.CACHABLE_PROPS);
433: }
434: }
435:
436: public String[] getCachableProperties() {
437: return (String[]) myAttributes.get(SVNProperty.CACHABLE_PROPS);
438: }
439:
440: public String[] getPresentProperties() {
441: return (String[]) myAttributes.get(SVNProperty.PRESENT_PROPS);
442: }
443:
444: public Map asMap() {
445: return myAttributes;
446: }
447:
448: public SVNEntry copy() {
449: return new SVNEntry(myAttributes, null, myName);
450: }
451: }
|