org.tmatesoft.svn.core.SVNProperty Maven / Gradle / Ivy
The newest version!
/*
* ====================================================================
* Copyright (c) 2004-2006 TMate Software Ltd. All rights reserved.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://svnkit.com/license.html
* If newer versions of this license are posted there, you may use a
* newer version instead, at your option.
* ====================================================================
*/
package org.tmatesoft.svn.core;
/**
* The SVNProperty class is a representation class for both versioned
* properties (user-managed svn specials) and for metaproperties (untweakable)
* supported by Subversion. This class holds string constants that are property
* names, and gives some useful methods to operate with properties (in particular).
*
* @version 1.1.0
* @author TMate Software Ltd.
*/
public class SVNProperty {
/**
* An "svn:" prefix.
*/
public static final String SVN_PREFIX = "svn:";
/**
* An "svn:wc:" prefix.
*/
public static final String SVN_WC_PREFIX = "svn:wc:";
/**
* A special property used in a commit transaction.
*/
public static final String TXN_CHECK_LOCKS = SVN_PREFIX + "check-locks";
/**
* A special property used in a commit transaction.
*/
public static final String TXN_CHECK_OUT_OF_DATENESS = SVN_PREFIX + "check-ood";
/**
* An "svn:entry:" prefix.
*/
public static final String SVN_ENTRY_PREFIX = "svn:entry:";
/**
* An "svn:eol-style" SVN special property.
*/
public static final String EOL_STYLE = SVN_PREFIX + "eol-style";
/**
* An "svn:ignore" SVN special property.
*/
public static final String IGNORE = SVN_PREFIX + "ignore";
/**
* An "svn:mime-type" SVN special property.
*/
public static final String MIME_TYPE = SVN_PREFIX + "mime-type";
/**
* An "svn:keywords" SVN special property.
*/
public static final String KEYWORDS = SVN_PREFIX + "keywords";
/**
* An "svn:executable" SVN special property.
*/
public static final String EXECUTABLE = SVN_PREFIX + "executable";
/**
* An "svn:externals" SVN special property.
*/
public static final String EXTERNALS = SVN_PREFIX + "externals";
/**
* An "svn:special" SVN special property.
*/
public static final String SPECIAL = SVN_PREFIX + "special";
/**
* An "svn:entry:revision" SVN untweakable metaproperty.
*/
public static final String REVISION = SVN_ENTRY_PREFIX + "revision";
/**
* An "svn:entry:committed-rev" SVN untweakable metaproperty.
*/
public static final String COMMITTED_REVISION = SVN_ENTRY_PREFIX
+ "committed-rev";
/**
* An "svn:entry:committed-date" SVN untweakable metaproperty.
*/
public static final String COMMITTED_DATE = SVN_ENTRY_PREFIX
+ "committed-date";
/**
* "has-props" SVN untweakable metaproperty.
* @since 1.1, new in Subversion 1.4
*/
public static final String HAS_PROPS = "has-props";
/**
* "has-prop-mods" SVN untweakable metaproperty.
* @since 1.1, new in Subversion 1.4
*/
public static final String HAS_PROP_MODS = "has-prop-mods";
/**
* "cachable-props" SVN untweakable metaproperty.
* @since 1.1, new in Subversion 1.4
*/
public static final String CACHABLE_PROPS = "cachable-props";
/**
* "present-props" SVN untweakable metaproperty.
* @since 1.1, new in Subversion 1.4
*/
public static final String PRESENT_PROPS = "present-props";
/**
* An "svn:entry:checksum" SVN untweakable metaproperty.
*/
public static final String CHECKSUM = SVN_ENTRY_PREFIX + "checksum";
/**
* An "svn:entry:url" SVN untweakable metaproperty.
*/
public static final String URL = SVN_ENTRY_PREFIX + "url";
/**
* An "svn:entry:copyfrom-url" SVN untweakable metaproperty.
*/
public static final String COPYFROM_URL = SVN_ENTRY_PREFIX + "copyfrom-url";
/**
* An "svn:entry:copyfrom-rev" SVN untweakable metaproperty.
*/
public static final String COPYFROM_REVISION = SVN_ENTRY_PREFIX
+ "copyfrom-rev";
/**
* An "svn:entry:schedule" SVN untweakable metaproperty.
*/
public static final String SCHEDULE = SVN_ENTRY_PREFIX + "schedule";
/**
* An "svn:entry:copied" SVN untweakable metaproperty.
*/
public static final String COPIED = SVN_ENTRY_PREFIX + "copied";
/**
* An "svn:entry:last-author" SVN untweakable metaproperty.
*/
public static final String LAST_AUTHOR = SVN_ENTRY_PREFIX + "last-author";
/**
* An "svn:entry:uuid" SVN untweakable metaproperty.
*/
public static final String UUID = SVN_ENTRY_PREFIX + "uuid";
/**
* An "svn:entry:repos" SVN untweakable metaproperty.
*/
public static final String REPOS = SVN_ENTRY_PREFIX + "repos";
/**
* An "svn:entry:prop-time" SVN untweakable metaproperty.
*/
public static final String PROP_TIME = SVN_ENTRY_PREFIX + "prop-time";
/**
* An "svn:entry:text-time" SVN untweakable metaproperty.
*/
public static final String TEXT_TIME = SVN_ENTRY_PREFIX + "text-time";
/**
* An "svn:entry:name" SVN untweakable metaproperty.
*/
public static final String NAME = SVN_ENTRY_PREFIX + "name";
/**
* An "svn:entry:kind" SVN untweakable metaproperty.
*/
public static final String KIND = SVN_ENTRY_PREFIX + "kind";
/**
* An "svn:entry:conflict-old" SVN untweakable metaproperty.
*/
public static final String CONFLICT_OLD = SVN_ENTRY_PREFIX + "conflict-old";
/**
* An "svn:entry:conflict-new" SVN untweakable metaproperty.
*/
public static final String CONFLICT_NEW = SVN_ENTRY_PREFIX + "conflict-new";
/**
* An "svn:entry:conflict-wrk" SVN untweakable metaproperty.
*/
public static final String CONFLICT_WRK = SVN_ENTRY_PREFIX + "conflict-wrk";
/**
* An "svn:entry:prop-reject-file" SVN untweakable metaproperty.
*/
public static final String PROP_REJECT_FILE = SVN_ENTRY_PREFIX
+ "prop-reject-file";
/**
* An "svn:entry:deleted" SVN untweakable metaproperty.
*/
public static final String DELETED = SVN_ENTRY_PREFIX + "deleted";
/**
* An "svn:entry:absent" SVN untweakable metaproperty.
*/
public static final String ABSENT = SVN_ENTRY_PREFIX + "absent";
/**
* An "svn:entry:incomplete" SVN untweakable metaproperty.
*/
public static final String INCOMPLETE = SVN_ENTRY_PREFIX + "incomplete";
/**
* An "svn:entry:corrupted" SVN untweakable metaproperty.
*/
public static final String CORRUPTED = SVN_ENTRY_PREFIX + "corrupted";
/**
* An "svn:wc:ra_dav:version-url" SVN untweakable metaproperty.
*/
public static final String WC_URL = SVN_WC_PREFIX + "ra_dav:version-url";
/**
* An "svn:entry:lock-token" SVN untweakable metaproperty.
*/
public static final String LOCK_TOKEN = SVN_ENTRY_PREFIX + "lock-token";
/**
* An "svn:entry:lock-comment" SVN untweakable metaproperty.
*/
public static final String LOCK_COMMENT = SVN_ENTRY_PREFIX + "lock-comment";
/**
* An "svn:entry:lock-owner" SVN untweakable metaproperty.
*/
public static final String LOCK_OWNER = SVN_ENTRY_PREFIX + "lock-owner";
/**
* An "svn:entry:lock-creation-date" SVN untweakable metaproperty.
*/
public static final String LOCK_CREATION_DATE = SVN_ENTRY_PREFIX
+ "lock-creation-date";
/**
* An "svn:needs-lock" SVN special property.
*/
public static final String NEEDS_LOCK = SVN_PREFIX + "needs-lock";
/**
* One of the two possible values of the {@link #KIND} property -
* "dir"
*/
public static final String KIND_DIR = "dir";
/**
* One of the two possible values of the {@link #KIND} property -
* "file"
*/
public static final String KIND_FILE = "file";
/**
* One of the four possible values of the {@link #EOL_STYLE} property -
* "LF" (line feed)
*/
public static final String EOL_STYLE_LF = "LF";
/**
* One of the four possible values of the {@link #EOL_STYLE} property -
* "CR" (linefeed)
*/
public static final String EOL_STYLE_CR = "CR";
/**
* One of the four possible values of the {@link #EOL_STYLE} property -
* "CRLF"
*/
public static final String EOL_STYLE_CRLF = "CRLF";
/**
* One of the four possible values of the {@link #EOL_STYLE} property -
* "native"
*/
public static final String EOL_STYLE_NATIVE = "native";
/**
* One of the three possible values of the {@link #SCHEDULE} property -
* "add"
*/
public static final String SCHEDULE_ADD = "add";
/**
* One of the three possible values of the {@link #SCHEDULE} property -
* "delete"
*/
public static final String SCHEDULE_DELETE = "delete";
/**
* One of the three possible values of the {@link #SCHEDULE} property -
* "replace"
*/
public static final String SCHEDULE_REPLACE = "replace";
private static final byte[] EOL_LF_BYTES = { '\n' };
private static final byte[] EOL_CRLF_BYTES = { '\r', '\n' };
private static final byte[] EOL_CR_BYTES = { '\r' };
private static final byte[] EOL_NATIVE_BYTES = System.getProperty(
"line.separator").getBytes();
/**
* Says if the given property name starts with the {@link #SVN_WC_PREFIX}
* prefix.
*
* @param name a property name to check
* @return true if name
is
* not null and starts with
* the {@link #SVN_WC_PREFIX} prefix, otherwise false
*/
public static boolean isWorkingCopyProperty(String name) {
return name != null && name.startsWith(SVN_WC_PREFIX);
}
/**
* Says if the given property name starts with the {@link #SVN_ENTRY_PREFIX}
* prefix.
*
* @param name a property name to check
* @return true if name
is
* not null and starts with
* the {@link #SVN_ENTRY_PREFIX} prefix, otherwise false
*/
public static boolean isEntryProperty(String name) {
return name != null && name.startsWith(SVN_ENTRY_PREFIX);
}
/**
* Says if the given property name starts with the {@link #SVN_PREFIX}
* prefix.
*
* @param name a property name to check
* @return true if name
is
* not null and starts with
* the {@link #SVN_PREFIX} prefix, otherwise false
*/
public static boolean isSVNProperty(String name) {
return name != null && name.startsWith(SVN_PREFIX);
}
/**
* Checks if a property is regular. Regular are some "svn:"
* properties and all user props, i.e. ones stored in the repository filesystem.
*
* @param name a property name
* @return true if regular, otherwise
* false
*/
public static boolean isRegularProperty(String name){
if(name == null){
return false;
}else if(name.startsWith(SVN_WC_PREFIX) || name.startsWith(SVN_ENTRY_PREFIX)){
return false;
}else{
return true;
}
}
/**
* Says if the given MIME-type corresponds to a text type.
*
* @param mimeType a value of a file {@link #MIME_TYPE} property
* @return true if mimeType
* is either null or is a text
* type (starts with "text/")
* @see #isBinaryMimeType(String)
*/
public static boolean isTextMimeType(String mimeType) {
return mimeType == null || mimeType.startsWith("text/");
}
/**
* Says if the given MIME-type corresponds to a binary (non-textual) type.
*
* @param mimeType a value of a file {@link #MIME_TYPE} property
* @return true if mimeType
* is not a text type
* @see #isTextMimeType(String)
*/
public static boolean isBinaryMimeType(String mimeType) {
return !isTextMimeType(mimeType);
}
/**
* Returns eol-marker bytes according to the given eol type.
*
* @param eolType a requested eol-marker type (platform specific)
* @return null if eolType
is
* null, or an array of bytes
* for one of the four possible eol types
* @see #EOL_STYLE_CR
* @see #EOL_STYLE_CRLF
* @see #EOL_STYLE_LF
* @see #EOL_STYLE_NATIVE
*/
public static byte[] getEOLBytes(String eolType) {
if (eolType == null) {
return null;
} else if (SVNProperty.EOL_STYLE_NATIVE.equals(eolType)) {
return EOL_NATIVE_BYTES;
} else if (SVNProperty.EOL_STYLE_CR.equals(eolType)) {
return EOL_CR_BYTES;
} else if (SVNProperty.EOL_STYLE_CRLF.equals(eolType)) {
return EOL_CRLF_BYTES;
}
return EOL_LF_BYTES;
}
/**
* Converts a string representation of a boolean value to boolean.
* Useful to convert values of the {@link #COPIED} property.
*
* @param text a string to convert to a boolean value
* @return true if and only if
* text
is not null
* and is equal, ignoring case, to the string
* "true"
*/
public static boolean booleanValue(String text) {
return text == null ? false : Boolean.valueOf(text.trim())
.booleanValue();
}
/**
* Converts a string representation of a numeric value to a long value.
* Useful to convert revision numbers.
*
* @param text a string to convert to a long value
* @return a long representation of the given string;
* -1 is returned if the string can not be parsed
*/
public static long longValue(String text) {
if (text != null) {
try {
return Long.parseLong(text);
} catch (NumberFormatException e) {
}
}
return -1;
}
/**
* Converts a boolean value to a string representation.
* Useful to convert values of the {@link #COPIED} property.
*
* @param b a boolean value
* @return a string representation of b
*/
public static String toString(boolean b) {
return Boolean.toString(b);
}
/**
* Converts a long value to a string representation.
* Useful to convert revision numbers.
*
* @param i a long value
* @return a string representation of i
*/
public static String toString(long i) {
return Long.toString(i);
}
/**
* Returns a short name for the given property name - that is
* a name without any prefixes.
*
* @param longName a property name
* @return a property short name
*/
public static String shortPropertyName(String longName) {
if (longName == null) {
return null;
}
if (longName.startsWith(SVNProperty.SVN_ENTRY_PREFIX)) {
return longName.substring(SVNProperty.SVN_ENTRY_PREFIX.length());
} else if (longName.startsWith(SVNProperty.SVN_WC_PREFIX)) {
return longName.substring(SVNProperty.SVN_WC_PREFIX.length());
} else if (longName.startsWith(SVNProperty.SVN_PREFIX)) {
return longName.substring(SVNProperty.SVN_PREFIX.length());
}
return longName;
}
/**
* Returns the value for such boolean properties as
* "svn:executable", "svn:needs-lock"
* and "svn:special".
* Used by internals.
*
* @param propName a property name
* @return the property value "*", or
* null if the property is not boolean
* @see #isBooleanProperty(String)
* @since 1.1
*/
public static String getValueOfBooleanProperty(String propName) {
if (SVNProperty.EXECUTABLE.equals(propName) || SVNProperty.NEEDS_LOCK.equals(propName) || SVNProperty.SPECIAL.equals(propName)) {
return "*";
}
return null;
}
/**
* Checks whether the property is boolean.
*
* @param propName a property name
* @return true if boolean,
* otherwise false
* @since 1.1
*/
public static boolean isBooleanProperty(String propName) {
return SVNProperty.EXECUTABLE.equals(propName) || SVNProperty.SPECIAL.equals(propName) || SVNProperty.NEEDS_LOCK.equals(propName);
}
}