Package com.atlassian.bamboo.util
Class BambooStringUtils
java.lang.Object
com.atlassian.bamboo.util.BambooStringUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass represent efficient way of filtering a set of strings with respect to a prefix or suffix. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charstatic final charstatic final charstatic final charstatic final charstatic final char[]static final String -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable StringcapitalizeFirstLetter(@Nullable String input) Capitalizes the first letter of the input string and converts the rest to lowercase.static booleancontainsRelatedCharacters(@Nullable String string, @org.jetbrains.annotations.NotNull char[] characters) Deprecated.static booleancontainsRelaxedXssRelatedCharacters(@Nullable String string) static booleancontainsShellInjectionRelatedCharacters(@Nullable String string) static booleancontainsXssRelatedCharacters(@Nullable String string) Returns true if the supplied string contains characters that could be used to deface a page or trigger an XSS exploit (characters: "&'<>\).static @NotNull StringChanges Dos-style line endings to Unix style line endingsstatic StringencodeHtmlWithTagWhiteList(String string) Escapes string but preserves few defined tags.static StringenumSetToString(@NotNull Set<? extends Enum> enumSet) Converts collection of enums to comma delimited stringstatic @Nullable StringfirstNotBlank(String... strings) Returns firstStringfrom the array which is not blank (so it is neither whitespace, empty nor null).static @NotNull StringforceAlphaNumeric(@Nullable String str) static @NotNull StringforceValidHtmlId(@NotNull String id) According to the HTML standard, ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").static StringformatTemplate(String urlTemplate, Map<String, String> variableValues) Expands variable references inurlTemplatewithvariableValues.static @NotNull StringgetFirstRelatedCharacter(@Nullable String string, @org.jetbrains.annotations.NotNull char[] characters) static @NotNull StringgetFirstRelaxedXssRelatedCharacter(@Nullable String string) static StringgetFirstShellInjectionRelatedCharacters(@Nullable String string) static @NotNull StringgetFirstXssRelatedCharacter(@Nullable String string) Retrieves first unsafe character from supplied stringstatic booleanstatic intReturns n-th occurence of string (index is 0-based)static intindexOfRegex(String haystack, String needle, int occurence) Returns n-th occurence of regex (index is 0-based)static booleanisMixedCase(@NotNull String value) Returns true if the passed String contains both uppercase and lowercase characters.lineIterator(String string) lineStream(String input) static @Nullable StringnullIfBlank(@Nullable String string) static StringpreventInlining(String constant) Deprecated.since 6.3 useBambooConstantUtils.preventInlining(Object)static @NotNull StringRemoves a character at specified index from stringreplaceAll(String regex, String replacement) replaceAll(Pattern pattern, String replacement) static booleansmartContains(@Nullable String haystack, @Nullable String needle) Checks if needle exists in the haystack.static booleanstartsWithAny(String string, Collection<String> searchStrings) static StringstripFullyEnclosingQuotes(String input) static StringtoCamelCase(@NotNull String string, char separator) Returns the string in camel case.static StringtoCommandLineString(@NotNull Iterable<String> commandArgs) Joins supplied argument into a valid command line, wrapping arguments in single quotes if needed.static @Nullable StringtruncateAndAddEllipsis(@Nullable String string, int maxLength) Truncates a string to specified length.static @Nullable StringtruncateAndAddEllipsisToLengthInBytes(@Nullable String string, int maxBytes) static @NotNull StringRemoves quotes from variable using shell rules.
-
Field Details
-
CHAR_NONE
public static final char CHAR_NONE- See Also:
-
CHAR_APOSTROPHE
public static final char CHAR_APOSTROPHE- See Also:
-
CHAR_BACKSLASH
public static final char CHAR_BACKSLASH- See Also:
-
CHAR_DOUBLE_QUOTE
public static final char CHAR_DOUBLE_QUOTE- See Also:
-
CHAR_ELLIPSIS
public static final char CHAR_ELLIPSIS- See Also:
-
XSS_RELATED_CHARACTERS
public static final char[] XSS_RELATED_CHARACTERS -
XSS_RELATED_CHARACTERS_FIND_STR
- See Also:
-
-
Method Details
-
forceAlphaNumeric
-
containsXssRelatedCharacters
Returns true if the supplied string contains characters that could be used to deface a page or trigger an XSS exploit (characters: "&'<>\). Should be used in addition to normal escaping of output, not instead of it.- Parameters:
string- string to check- Returns:
- true if string contains unsafe characters, false otherwise
-
getFirstXssRelatedCharacter
@NotNull public static @NotNull String getFirstXssRelatedCharacter(@Nullable @Nullable String string) Retrieves first unsafe character from supplied string- Parameters:
string- the string to check- Returns:
- string with the first encountered unsafe character.
-
containsRelaxedXssRelatedCharacters
-
getFirstRelaxedXssRelatedCharacter
-
containsShellInjectionRelatedCharacters
-
getFirstShellInjectionRelatedCharacters
-
containsRelatedCharacters
@Deprecated public static boolean containsRelatedCharacters(@Nullable @Nullable String string, @NotNull @org.jetbrains.annotations.NotNull char[] characters) Deprecated.since 5.15 please useBambooStringUtils.containsRelatedCharacters(java.lang.String, char[]) -
getFirstRelatedCharacter
-
forceValidHtmlId
According to the HTML standard, ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). This method replaces all invalid characters in the supplied id with an underscore. It does not enforce the "must begin with a letter" rule. There are two functions that do it, one in FreeMarker functions.ftl and one in BambooStringUtils. They MUST be kept in sync. -
lineIterator
- Returns:
- an iterable that makes it possible to iterate over lines with Windows or Unix endings
-
lineStream
- Returns:
- an iterable that makes it possible to iterate over lines with Windows or Unix endings
-
indexOf
Returns n-th occurence of string (index is 0-based)- Parameters:
haystack- search hereneedle- search forn- n-the cocurence to return- Returns:
- -1 if not found, else the index
-
indexOfRegex
Returns n-th occurence of regex (index is 0-based)- Parameters:
haystack- search hereneedle- search foroccurence- n-the occurence to return- Returns:
- -1 if not found, else the index
-
startsWithAny
- See Also:
-
StringUtils.startsWithAny(CharSequence, CharSequence...)
-
nullIfBlank
-
encodeHtmlWithTagWhiteList
Escapes string but preserves few defined tags. Allows some html formatting inside strings while preventing XSS. Allowed tags are: <br /> <i> <b> <p> <div> <a> <strong> . Properties are not allowed except 'href' in anchor tag.- Parameters:
string-- Returns:
- html escaped string with white listed tags preserved
-
unquote
@NotNull public static @NotNull String unquote(@NotNull @NotNull String quotedVarValue, boolean processBackslashes) Removes quotes from variable using shell rules.- Parameters:
quotedVarValue-processBackslashes- whether backslash should be treated as a special character or not- Returns:
-
in
-
remove
Removes a character at specified index from string- Parameters:
quotedVarValue-index-- Returns:
-
truncateAndAddEllipsis
@Nullable public static @Nullable String truncateAndAddEllipsis(@Nullable @Nullable String string, int maxLength) Truncates a string to specified length. If truncation causes actual information loss an ellipsis is appended to the end of the string.- Parameters:
string- stringmaxLength- maximum length of the string- Returns:
- truncated string
-
truncateAndAddEllipsisToLengthInBytes
-
stripFullyEnclosingQuotes
-
replaceAll
-
replaceAll
-
capitalizeFirstLetter
Capitalizes the first letter of the input string and converts the rest to lowercase. If the input string is null or empty, it returns the input string as is.- Parameters:
input- the string to be capitalized- Returns:
- the string with the first letter capitalized and the rest in lowercase
-
dos2unix
Changes Dos-style line endings to Unix style line endings -
toCamelCase
Returns the string in camel case. Com.atlassian.bamboo.somePlugin becomes comAtlassianBambooSomePlugin- Parameters:
string-separator-- Returns:
-
toCommandLineString
Joins supplied argument into a valid command line, wrapping arguments in single quotes if needed. -
formatTemplate
Expands variable references inurlTemplatewithvariableValues.The variable references look like "${foo}" and will be replaced with the value matching the that key from
variableValues. The names may not contain '}' characters but are otherwise unconstrained. Variables which do not have associated values in the request are unmodified.- Parameters:
urlTemplate- the template to expand.variableValues- the variable values to use when expanding the template- Returns:
- the template expanded as detailed above.
-
enumSetToString
Converts collection of enums to comma delimited string -
preventInlining
Deprecated.since 6.3 useBambooConstantUtils.preventInlining(Object)This is to prevent inlining. Please see https://hello.atlassian.net/wiki/x/XoctDQ for details.- Parameters:
constant- The constant to return.- Returns:
- the given constant.
-
firstNotBlank
Returns firstStringfrom the array which is not blank (so it is neither whitespace, empty nor null). If all strings are blank, null is returned.- Parameters:
strings- array of strings- Returns:
- the first not blank string from the array or null, if all strings are blank
-
isMixedCase
Returns true if the passed String contains both uppercase and lowercase characters.Character.isUpperCase(int)andCharacter.isLowerCase(int)methods are used to determine character case.- Parameters:
value- a string to test- Returns:
- true if the passed string is mixed case (has both uppercase and lowercase characters)
-
smartContains
public static boolean smartContains(@Nullable @Nullable String haystack, @Nullable @Nullable String needle) Checks if needle exists in the haystack. If needle is lowercase, ignores case, otherwise it's case sensitive.
-
BambooStringUtils.containsRelatedCharacters(java.lang.String, char[])