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:
013: package org.tmatesoft.svn.core;
014:
015: /**
016: * The <b>SVNProperty</b> class is a representation class for both versioned
017: * properties (user-managed svn specials) and for metaproperties (untweakable)
018: * supported by Subversion. This class holds string constants that are property
019: * names, and gives some useful methods to operate with properties (in particular).
020: *
021: * @version 1.1.1
022: * @author TMate Software Ltd.
023: */
024: public class SVNProperty {
025: /**
026: * An <span class="javastring">"svn:"</span> prefix.
027: */
028: public static final String SVN_PREFIX = "svn:";
029: /**
030: * An <span class="javastring">"svn:wc:"</span> prefix.
031: */
032: public static final String SVN_WC_PREFIX = "svn:wc:";
033:
034: /**
035: * A special property used in a commit transaction.
036: */
037: public static final String TXN_CHECK_LOCKS = SVN_PREFIX
038: + "check-locks";
039:
040: /**
041: * A special property used in a commit transaction.
042: */
043: public static final String TXN_CHECK_OUT_OF_DATENESS = SVN_PREFIX
044: + "check-ood";
045:
046: /**
047: * An <span class="javastring">"svn:entry:"</span> prefix.
048: */
049: public static final String SVN_ENTRY_PREFIX = "svn:entry:";
050: /**
051: * An <span class="javastring">"svn:eol-style"</span> SVN special property.
052: */
053: public static final String EOL_STYLE = SVN_PREFIX + "eol-style";
054: /**
055: * An <span class="javastring">"svn:ignore"</span> SVN special property.
056: */
057: public static final String IGNORE = SVN_PREFIX + "ignore";
058: /**
059: * An <span class="javastring">"svn:mime-type"</span> SVN special property.
060: */
061: public static final String MIME_TYPE = SVN_PREFIX + "mime-type";
062: /**
063: * An <span class="javastring">"svn:keywords"</span> SVN special property.
064: */
065: public static final String KEYWORDS = SVN_PREFIX + "keywords";
066: /**
067: * An <span class="javastring">"svn:executable"</span> SVN special property.
068: */
069: public static final String EXECUTABLE = SVN_PREFIX + "executable";
070: /**
071: * An <span class="javastring">"svn:externals"</span> SVN special property.
072: */
073: public static final String EXTERNALS = SVN_PREFIX + "externals";
074: /**
075: * An <span class="javastring">"svn:special"</span> SVN special property.
076: */
077: public static final String SPECIAL = SVN_PREFIX + "special";
078: /**
079: * An <span class="javastring">"svn:entry:revision"</span> SVN untweakable metaproperty.
080: */
081: public static final String REVISION = SVN_ENTRY_PREFIX + "revision";
082: /**
083: * An <span class="javastring">"svn:entry:committed-rev"</span> SVN untweakable metaproperty.
084: */
085: public static final String COMMITTED_REVISION = SVN_ENTRY_PREFIX
086: + "committed-rev";
087: /**
088: * An <span class="javastring">"svn:entry:committed-date"</span> SVN untweakable metaproperty.
089: */
090: public static final String COMMITTED_DATE = SVN_ENTRY_PREFIX
091: + "committed-date";
092:
093: /**
094: * <span class="javastring">"has-props"</span> SVN untweakable metaproperty.
095: * @since 1.1, new in Subversion 1.4
096: */
097: public static final String HAS_PROPS = "has-props";
098:
099: /**
100: * <span class="javastring">"has-prop-mods"</span> SVN untweakable metaproperty.
101: * @since 1.1, new in Subversion 1.4
102: */
103: public static final String HAS_PROP_MODS = "has-prop-mods";
104:
105: /**
106: * <span class="javastring">"cachable-props"</span> SVN untweakable metaproperty.
107: * @since 1.1, new in Subversion 1.4
108: */
109: public static final String CACHABLE_PROPS = "cachable-props";
110:
111: /**
112: * <span class="javastring">"present-props"</span> SVN untweakable metaproperty.
113: * @since 1.1, new in Subversion 1.4
114: */
115: public static final String PRESENT_PROPS = "present-props";
116:
117: /**
118: * An <span class="javastring">"svn:entry:checksum"</span> SVN untweakable metaproperty.
119: */
120: public static final String CHECKSUM = SVN_ENTRY_PREFIX + "checksum";
121: /**
122: * An <span class="javastring">"svn:entry:url"</span> SVN untweakable metaproperty.
123: */
124: public static final String URL = SVN_ENTRY_PREFIX + "url";
125: /**
126: * An <span class="javastring">"svn:entry:copyfrom-url"</span> SVN untweakable metaproperty.
127: */
128: public static final String COPYFROM_URL = SVN_ENTRY_PREFIX
129: + "copyfrom-url";
130: /**
131: * An <span class="javastring">"svn:entry:copyfrom-rev"</span> SVN untweakable metaproperty.
132: */
133: public static final String COPYFROM_REVISION = SVN_ENTRY_PREFIX
134: + "copyfrom-rev";
135: /**
136: * An <span class="javastring">"svn:entry:schedule"</span> SVN untweakable metaproperty.
137: */
138: public static final String SCHEDULE = SVN_ENTRY_PREFIX + "schedule";
139: /**
140: * An <span class="javastring">"svn:entry:copied"</span> SVN untweakable metaproperty.
141: */
142: public static final String COPIED = SVN_ENTRY_PREFIX + "copied";
143: /**
144: * An <span class="javastring">"svn:entry:last-author"</span> SVN untweakable metaproperty.
145: */
146: public static final String LAST_AUTHOR = SVN_ENTRY_PREFIX
147: + "last-author";
148: /**
149: * An <span class="javastring">"svn:entry:uuid"</span> SVN untweakable metaproperty.
150: */
151: public static final String UUID = SVN_ENTRY_PREFIX + "uuid";
152: /**
153: * An <span class="javastring">"svn:entry:repos"</span> SVN untweakable metaproperty.
154: */
155: public static final String REPOS = SVN_ENTRY_PREFIX + "repos";
156: /**
157: * An <span class="javastring">"svn:entry:prop-time"</span> SVN untweakable metaproperty.
158: */
159: public static final String PROP_TIME = SVN_ENTRY_PREFIX
160: + "prop-time";
161: /**
162: * An <span class="javastring">"svn:entry:text-time"</span> SVN untweakable metaproperty.
163: */
164: public static final String TEXT_TIME = SVN_ENTRY_PREFIX
165: + "text-time";
166: /**
167: * An <span class="javastring">"svn:entry:name"</span> SVN untweakable metaproperty.
168: */
169: public static final String NAME = SVN_ENTRY_PREFIX + "name";
170: /**
171: * An <span class="javastring">"svn:entry:kind"</span> SVN untweakable metaproperty.
172: */
173: public static final String KIND = SVN_ENTRY_PREFIX + "kind";
174: /**
175: * An <span class="javastring">"svn:entry:conflict-old"</span> SVN untweakable metaproperty.
176: */
177: public static final String CONFLICT_OLD = SVN_ENTRY_PREFIX
178: + "conflict-old";
179: /**
180: * An <span class="javastring">"svn:entry:conflict-new"</span> SVN untweakable metaproperty.
181: */
182: public static final String CONFLICT_NEW = SVN_ENTRY_PREFIX
183: + "conflict-new";
184: /**
185: * An <span class="javastring">"svn:entry:conflict-wrk"</span> SVN untweakable metaproperty.
186: */
187: public static final String CONFLICT_WRK = SVN_ENTRY_PREFIX
188: + "conflict-wrk";
189: /**
190: * An <span class="javastring">"svn:entry:prop-reject-file"</span> SVN untweakable metaproperty.
191: */
192: public static final String PROP_REJECT_FILE = SVN_ENTRY_PREFIX
193: + "prop-reject-file";
194: /**
195: * An <span class="javastring">"svn:entry:deleted"</span> SVN untweakable metaproperty.
196: */
197: public static final String DELETED = SVN_ENTRY_PREFIX + "deleted";
198: /**
199: * An <span class="javastring">"svn:entry:absent"</span> SVN untweakable metaproperty.
200: */
201: public static final String ABSENT = SVN_ENTRY_PREFIX + "absent";
202: /**
203: * An <span class="javastring">"svn:entry:incomplete"</span> SVN untweakable metaproperty.
204: */
205: public static final String INCOMPLETE = SVN_ENTRY_PREFIX
206: + "incomplete";
207: /**
208: * An <span class="javastring">"svn:entry:corrupted"</span> SVN untweakable metaproperty.
209: */
210: public static final String CORRUPTED = SVN_ENTRY_PREFIX
211: + "corrupted";
212: /**
213: * An <span class="javastring">"svn:wc:ra_dav:version-url"</span> SVN untweakable metaproperty.
214: */
215: public static final String WC_URL = SVN_WC_PREFIX
216: + "ra_dav:version-url";
217: /**
218: * An <span class="javastring">"svn:entry:lock-token"</span> SVN untweakable metaproperty.
219: */
220: public static final String LOCK_TOKEN = SVN_ENTRY_PREFIX
221: + "lock-token";
222: /**
223: * An <span class="javastring">"svn:entry:lock-comment"</span> SVN untweakable metaproperty.
224: */
225: public static final String LOCK_COMMENT = SVN_ENTRY_PREFIX
226: + "lock-comment";
227: /**
228: * An <span class="javastring">"svn:entry:lock-owner"</span> SVN untweakable metaproperty.
229: */
230: public static final String LOCK_OWNER = SVN_ENTRY_PREFIX
231: + "lock-owner";
232: /**
233: * An <span class="javastring">"svn:entry:lock-creation-date"</span> SVN untweakable metaproperty.
234: */
235: public static final String LOCK_CREATION_DATE = SVN_ENTRY_PREFIX
236: + "lock-creation-date";
237: /**
238: * An <span class="javastring">"svn:needs-lock"</span> SVN special property.
239: */
240: public static final String NEEDS_LOCK = SVN_PREFIX + "needs-lock";
241: /**
242: * One of the two possible values of the {@link #KIND} property -
243: * <span class="javastring">"dir"</span>
244: */
245: public static final String KIND_DIR = "dir";
246: /**
247: * One of the two possible values of the {@link #KIND} property -
248: * <span class="javastring">"file"</span>
249: */
250: public static final String KIND_FILE = "file";
251: /**
252: * One of the four possible values of the {@link #EOL_STYLE} property -
253: * <span class="javastring">"LF"</span> (line feed)
254: */
255: public static final String EOL_STYLE_LF = "LF";
256: /**
257: * One of the four possible values of the {@link #EOL_STYLE} property -
258: * <span class="javastring">"CR"</span> (linefeed)
259: */
260: public static final String EOL_STYLE_CR = "CR";
261: /**
262: * One of the four possible values of the {@link #EOL_STYLE} property -
263: * <span class="javastring">"CRLF"</span>
264: */
265: public static final String EOL_STYLE_CRLF = "CRLF";
266: /**
267: * One of the four possible values of the {@link #EOL_STYLE} property -
268: * <span class="javastring">"native"</span>
269: */
270: public static final String EOL_STYLE_NATIVE = "native";
271: /**
272: * One of the three possible values of the {@link #SCHEDULE} property -
273: * <span class="javastring">"add"</span>
274: */
275: public static final String SCHEDULE_ADD = "add";
276: /**
277: * One of the three possible values of the {@link #SCHEDULE} property -
278: * <span class="javastring">"delete"</span>
279: */
280: public static final String SCHEDULE_DELETE = "delete";
281: /**
282: * One of the three possible values of the {@link #SCHEDULE} property -
283: * <span class="javastring">"replace"</span>
284: */
285: public static final String SCHEDULE_REPLACE = "replace";
286:
287: private static final byte[] EOL_LF_BYTES = { '\n' };
288: private static final byte[] EOL_CRLF_BYTES = { '\r', '\n' };
289: private static final byte[] EOL_CR_BYTES = { '\r' };
290: private static final byte[] EOL_NATIVE_BYTES = System.getProperty(
291: "line.separator").getBytes();
292:
293: /**
294: * Says if the given property name starts with the {@link #SVN_WC_PREFIX}
295: * prefix.
296: *
297: * @param name a property name to check
298: * @return <span class="javakeyword">true</span> if <code>name</code> is
299: * not <span class="javakeyword">null</span> and starts with
300: * the {@link #SVN_WC_PREFIX} prefix, otherwise <span class="javakeyword">false</span>
301: */
302: public static boolean isWorkingCopyProperty(String name) {
303: return name != null && name.startsWith(SVN_WC_PREFIX);
304: }
305:
306: /**
307: * Says if the given property name starts with the {@link #SVN_ENTRY_PREFIX}
308: * prefix.
309: *
310: * @param name a property name to check
311: * @return <span class="javakeyword">true</span> if <code>name</code> is
312: * not <span class="javakeyword">null</span> and starts with
313: * the {@link #SVN_ENTRY_PREFIX} prefix, otherwise <span class="javakeyword">false</span>
314: */
315: public static boolean isEntryProperty(String name) {
316: return name != null && name.startsWith(SVN_ENTRY_PREFIX);
317: }
318:
319: /**
320: * Says if the given property name starts with the {@link #SVN_PREFIX}
321: * prefix.
322: *
323: * @param name a property name to check
324: * @return <span class="javakeyword">true</span> if <code>name</code> is
325: * not <span class="javakeyword">null</span> and starts with
326: * the {@link #SVN_PREFIX} prefix, otherwise <span class="javakeyword">false</span>
327: */
328: public static boolean isSVNProperty(String name) {
329: return name != null && name.startsWith(SVN_PREFIX);
330: }
331:
332: /**
333: * Checks if a property is regular. Regular are some <span class="javastring">"svn:"</span>
334: * properties and all user props, i.e. ones stored in the repository filesystem.
335: *
336: * @param name a property name
337: * @return <span class="javakeyword">true</span> if regular, otherwise
338: * <span class="javakeyword">false</span>
339: */
340: public static boolean isRegularProperty(String name) {
341: if (name == null) {
342: return false;
343: } else if (name.startsWith(SVN_WC_PREFIX)
344: || name.startsWith(SVN_ENTRY_PREFIX)) {
345: return false;
346: } else {
347: return true;
348: }
349: }
350:
351: /**
352: * Says if the given MIME-type corresponds to a text type.
353: *
354: * @param mimeType a value of a file {@link #MIME_TYPE} property
355: * @return <span class="javakeyword">true</span> if <code>mimeType</code>
356: * is either <span class="javakeyword">null</span> or is a text
357: * type (starts with <span class="javastring">"text/"</span>)
358: * @see #isBinaryMimeType(String)
359: */
360: public static boolean isTextMimeType(String mimeType) {
361: return mimeType == null || mimeType.startsWith("text/");
362: }
363:
364: /**
365: * Says if the given MIME-type corresponds to a binary (non-textual) type.
366: *
367: * @param mimeType a value of a file {@link #MIME_TYPE} property
368: * @return <span class="javakeyword">true</span> if <code>mimeType</code>
369: * is not a text type
370: * @see #isTextMimeType(String)
371: */
372: public static boolean isBinaryMimeType(String mimeType) {
373: return !isTextMimeType(mimeType);
374: }
375:
376: /**
377: * Returns eol-marker bytes according to the given eol type.
378: *
379: * @param eolType a requested eol-marker type (platform specific)
380: * @return <span class="javakeyword">null</span> if <code>eolType</code> is
381: * <span class="javakeyword">null</span>, or an array of bytes
382: * for one of the four possible eol types
383: * @see #EOL_STYLE_CR
384: * @see #EOL_STYLE_CRLF
385: * @see #EOL_STYLE_LF
386: * @see #EOL_STYLE_NATIVE
387: */
388: public static byte[] getEOLBytes(String eolType) {
389: if (eolType == null) {
390: return null;
391: } else if (SVNProperty.EOL_STYLE_NATIVE.equals(eolType)) {
392: return EOL_NATIVE_BYTES;
393: } else if (SVNProperty.EOL_STYLE_CR.equals(eolType)) {
394: return EOL_CR_BYTES;
395: } else if (SVNProperty.EOL_STYLE_CRLF.equals(eolType)) {
396: return EOL_CRLF_BYTES;
397: }
398: return EOL_LF_BYTES;
399: }
400:
401: /**
402: * Converts a string representation of a boolean value to boolean.
403: * Useful to convert values of the {@link #COPIED} property.
404: *
405: * @param text a string to convert to a boolean value
406: * @return <span class="javakeyword">true</span> if and only if
407: * <code>text</code> is not <span class="javakeyword">null</span>
408: * and is equal, ignoring case, to the string
409: * <span class="javastring">"true"</span>
410: */
411: public static boolean booleanValue(String text) {
412: return text == null ? false : Boolean.valueOf(text.trim())
413: .booleanValue();
414: }
415:
416: /**
417: * Converts a string representation of a numeric value to a long value.
418: * Useful to convert revision numbers.
419: *
420: * @param text a string to convert to a long value
421: * @return a long representation of the given string;
422: * -1 is returned if the string can not be parsed
423: */
424: public static long longValue(String text) {
425: if (text != null) {
426: try {
427: return Long.parseLong(text);
428: } catch (NumberFormatException e) {
429: }
430: }
431: return -1;
432: }
433:
434: /**
435: * Converts a boolean value to a string representation.
436: * Useful to convert values of the {@link #COPIED} property.
437: *
438: * @param b a boolean value
439: * @return a string representation of <code>b</code>
440: */
441: public static String toString(boolean b) {
442: return Boolean.toString(b);
443: }
444:
445: /**
446: * Converts a long value to a string representation.
447: * Useful to convert revision numbers.
448: *
449: * @param i a long value
450: * @return a string representation of <code>i</code>
451: */
452: public static String toString(long i) {
453: return Long.toString(i);
454: }
455:
456: /**
457: * Returns a short name for the given property name - that is
458: * a name without any prefixes.
459: *
460: * @param longName a property name
461: * @return a property short name
462: */
463: public static String shortPropertyName(String longName) {
464: if (longName == null) {
465: return null;
466: }
467: if (longName.startsWith(SVNProperty.SVN_ENTRY_PREFIX)) {
468: return longName.substring(SVNProperty.SVN_ENTRY_PREFIX
469: .length());
470: } else if (longName.startsWith(SVNProperty.SVN_WC_PREFIX)) {
471: return longName.substring(SVNProperty.SVN_WC_PREFIX
472: .length());
473: } else if (longName.startsWith(SVNProperty.SVN_PREFIX)) {
474: return longName.substring(SVNProperty.SVN_PREFIX.length());
475: }
476: return longName;
477: }
478:
479: /**
480: * Returns the value for such boolean properties as
481: * <span class="javastring">"svn:executable"</span>, <span class="javastring">"svn:needs-lock"</span>
482: * and <span class="javastring">"svn:special"</span>.
483: * Used by internals.
484: *
485: * @param propName a property name
486: * @return the property value <span class="javastring">"*"</span>, or
487: * <span class="javakeyword">null</span> if the property is not boolean
488: * @see #isBooleanProperty(String)
489: * @since 1.1
490: */
491: public static String getValueOfBooleanProperty(String propName) {
492: if (SVNProperty.EXECUTABLE.equals(propName)
493: || SVNProperty.NEEDS_LOCK.equals(propName)
494: || SVNProperty.SPECIAL.equals(propName)) {
495: return "*";
496: }
497: return null;
498: }
499:
500: /**
501: * Checks whether the property is boolean.
502: *
503: * @param propName a property name
504: * @return <span class="javakeyword">true</span> if boolean,
505: * otherwise <span class="javakeyword">false</span>
506: * @since 1.1
507: */
508: public static boolean isBooleanProperty(String propName) {
509: return SVNProperty.EXECUTABLE.equals(propName)
510: || SVNProperty.SPECIAL.equals(propName)
511: || SVNProperty.NEEDS_LOCK.equals(propName);
512: }
513: }
|