Package com.tridion.util
Class StringUtils
java.lang.Object
com.tridion.util.StringUtils
Some handy utils for string processing.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringstatic intdepthBelowCurrentPath(String basePath, String comparePath, String separator) Compares two paths (case-insensitive), and returns whether one path is a subdirectory or not, and if so, what depth this subdirectory is at.static StringgetFullURLString(String protocol, String domain, int port, String path) Takes all the component parts needed to generate a valid URL, and returns the valid URL.static booleanDeprecated.static booleanisNotEmpty(String... strings) Deprecated.static StringjoinHostStringAndPath(String hostString, String path) Joins the host part of a URL to a path part of a URL, ensuring that we don't have too many slashes.static StringjoinMetaPaths(String dataPath, String metaPath, String urlPath) Joins three strings to make something which could be the file location of a URL path.static StringnormalizeString(String string) Normalizes the specified string by removing leading and trailing whitespace characters.static Longstatic StringremoveCharAt(String s, int pos) static Stringstatic StringReplaces all occurrences of a character in a string and replaces them with a different string.static StringReplaces all occurrences of a particular substring in a string and replaces them with a different string.static StringsafeSubstring(String source, int beginIndex) static StringsafeSubstring(String source, int beginIndex, int endIndex) splitString(String input, String delimiter) Helper method to transform single string which contains multiple strings delimited with delimiter into set of strings.static booleanstringArrayContains(String[] array, String contains, boolean caseSensitive) static booleanstringEquals(String str1, String str2) static booleanstringEqualsIgnoreCase(String str1, String str2) static StringtrimIfNotNull(String string)
-
Field Details
-
PATH_SEPARATOR
Deprecated.useFile.separatorThe file (path) separator character for this platform (OS). -
NEWLINE_CHARACTER
The line separator character (new line) for this platform (OS).
-
-
Method Details
-
depthBelowCurrentPath
Compares two paths (case-insensitive), and returns whether one path is a subdirectory or not, and if so, what depth this subdirectory is at. For example,depthBelowCurrentPath("/root/", "/root/SG1/", "/")will return 1 ("/root/SG1/"is 1 directory below"/root/") For example,depthBelowCurrentPath("/root/SG1/", "/root/", "/")will return -1 ("/root/"is not below directory"/root/SG1/") Also,depthBelowCurrentPath("/root/", "/root/", "/")will return 0 ("/root/"the same as"/root/") AnddepthBelowCurrentPath("/root/", "/toor/", "/")will return -1 (the directories are not the same)- Parameters:
basePath- The path you want to comparecomparePath- The path you want to compare againstseparator- The path separator. Normally, this will be "/"- Returns:
- An int, representing either the depth below the current directory, or -1 if the directory is not a subdirectory, or the same directory
-
replace
Replaces all occurrences of a particular substring in a string and replaces them with a different string.- Parameters:
someString- The String to replace the occurrences in.matchString- The substring you want to replace.replacement- The String you want to replace the matchChar character with.- Returns:
- A String with all of the occurrences of the substring replaced.
-
replace
Replaces all occurrences of a character in a string and replaces them with a different string.- Parameters:
someString- The String to replace the occurrences in.matchChar- The character you want to replace.replacement- The String you want to replace the matchChar character with.- Returns:
- A String with all of the occurrences of the character replaced.
-
joinHostStringAndPath
Joins the host part of a URL to a path part of a URL, ensuring that we don't have too many slashes.- Parameters:
hostString- The host part of a URL, e.g. http://www.thiswebsite.com:8080path- The path part of a URL, e.g. /firstpath/- Returns:
- The full URL, eg. http://www.thiswebsite.com:8080/firstpath/
-
getFullURLString
Takes all the component parts needed to generate a valid URL, and returns the valid URL. So the callString hostString = StringUtils.getFullURLString("http", "www.mywebsite.com", 8080, "/pages")returnshttp://www.website.com:8080/pages.- Parameters:
protocol- The protocol to use. If no protocol is supplied, "http" is presumed.domain- The domain to use, may benull.port- The port to use. If port is 80 and protocol is "http", port is not included in the URL.path- The path to use, may benull.- Returns:
- A valid URL, or
nullif both domain and path arenull.
-
joinMetaPaths
Joins three strings to make something which could be the file location of a URL path.- Parameters:
dataPath- Location where metadata is storedmetaPath- Metadata string you want to inserturlPath- URL of item you want to append- Returns:
- A path which should represent the location of the URL metadata file for use by the findByURL methods.
-
normalizeString
Normalizes the specified string by removing leading and trailing whitespace characters. Anullis replaced with an empty string.- Parameters:
string- the string to normalize; may benull.- Returns:
- The normalized string.
-
isEmpty
Deprecated. -
isNotEmpty
Deprecated. -
stringEquals
-
stringEqualsIgnoreCase
-
trimIfNotNull
-
stringArrayContains
-
safeSubstring
- Throws:
ParseException
-
safeSubstring
public static String safeSubstring(String source, int beginIndex, int endIndex) throws ParseException - Throws:
ParseException
-
removeCharAt
-
removeQuotations
-
addQuotations
-
parseLong
-
splitString
Helper method to transform single string which contains multiple strings delimited with delimiter into set of strings.- Parameters:
input- The String which contains multiple string valuesdelimiter- The delimiter used to split the strings- Returns:
- Resolved
Setof strings
-
File.separator