Package org.javlo.helper
Class StringHelper
- java.lang.Object
-
- org.javlo.helper.StringHelper
-
public class StringHelper extends Object
- Author:
- pvandermaesen
-
-
Field Summary
Fields Modifier and Type Field Description static String
ALPHABET
static String
ALPHABET_UPPER_CASE
static String
ALPHANUM
static String
BASIC_CHAR
static String
DEFAULT_LIST_SEPARATOR
static String
DEFAULT_SEPARATOR
static String[]
EMPTY_STRING_ARRAY
protected static Logger
logger
create a static logger.static String
NUMERIC
static Pattern
RANGE_MATCHER_BETWEEN
static Pattern
RANGE_MATCHER_GREATER
static Pattern
RANGE_MATCHER_LOWER
static String
REQUEST_KEY_FORM_VALID
static SimpleDateFormat
RFC822DATEFORMAT
static String
RFC822DATEPATTERN
static String
SOMETHING
static String
specialChar
static long
TIMED_TOKEN_DIVIDER
static String[][]
TXT2HTML
static String
URLOK_CHAR
-
Constructor Summary
Constructors Constructor Description StringHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static String
addSufixToFileName(String fileName, String sufix)
static String
arrayToString(Object[] array)
static String
arrayToString(Object[] array, String inSep)
static String
asBase32(byte value)
generate a base 32 string with a intstatic String
asBase32(byte[] bytes)
generate a base 32 string.static String
asBase32(int value)
generate a base 32 string with a intstatic String
asBase64(byte[] bytes)
generate a base 64 string.static String
asBase64(int value)
generate a base 64 string with a intstatic String
asBase64(long value)
generate a base 64 string with a longstatic String
camelToSnake(String camelStr)
static String
changeFileExtension(String inFileName, String newExt)
change the file extension of the pathstatic String
cleanPath(String path)
clean path, remove double "/" and replace "\" by "/"String
cleanString(String text)
static <T extends IStringSeralizable>
StringcollectionStringSeralizableToString(Collection<T> col, String sep)
static String
collectionToString(String... values)
static String
collectionToString(Collection<?> col)
static String
collectionToString(Collection<?> col, String inSep)
static String
collectionToText(Collection<?> col)
convert a collection to text.static String
collectionToTextarea(Collection<?> col)
convert a collection to text.static String
colorToHexString(Color color)
static String
colorToHexStringNotNull(Color color)
static boolean
compare(String str1, String str2)
static boolean
containsAny(String source, String... texts)
static boolean
containsNoCase(String text, String token)
static boolean
containsOne(String source, String... texts)
static boolean
containsUppercase(String text)
check if a text contains uppercase char. test > false, Test > true, TEST > truestatic String
convertString(String pattern1, String pattern2, String text)
convert a string to another string if math pattern1 and convert to pattern2.static void
copyInClipbaord(String content)
static int
countChar(String str, char c)
static String
CR2BR(String text)
replace CR withstatic String
createASCIIString(String text)
static String
createComparableString(String text)
static String
createFileName(String fileName)
convert a file name with space, accent and other bad character to a acceptable name. sample: "l'éléphant rose.odt" -> "l_elephant_rose.odt"static String
createI18NURL(String value)
static String
createKey(int length, Set<String> keys)
create a new unic key.static String
CRtoSpace(String text)
replace CR with a spacestatic String
cutEndXHTML(String str, int cut)
cut the end of a xhtml code. sample: "aaa´coucou", 5 = "aaa´c"static byte[]
decodeBase64(String data)
generate a base 64 string.static String
decodeNoChar(String data, String noChars)
insert char from a Sting (encoded with encodeNoChar)static String
doubleQutotes(String text)
static String
encodeAsStructuredCommunicationMod97(String code)
transform a string of number (length 10) to a structured communication, last number is the mod 97 of the first numberstatic String
encodeCDATA(String value)
encode a string to a CDATA sequence.static String
encodeNoChar(String data, String noChars)
remove char from a Stingstatic String
encryptPassword(String plaintext)
static String
encryptPasswordSHA256(String plaintext)
static String
escapeHTML(String html)
static String
escapeProperty(String theString, boolean escapeSpace, boolean escapeUnicode)
Method copied from the private method java.util.Properties#saveConvert(...)static String
escapeSpecialRegexChars(String str)
static String
escapeString(String field, boolean escapeDoubleQuotes)
static String
escapeWordChar(String text)
static String
expandSystemProperties(String str)
static String
extractHost(String inUrl)
static String
extractHostAndProtocol(String inUrl)
static List<String>
extractItem(String text, String prefix, String suffix)
extract a subtext from a text.static Long
extractLong(String text)
extract only number of a alpha numeric stringstatic Integer
extractNumber(String text)
extract only number of a alpha numeric stringstatic String
extractNumberAsString(String text)
extract only number of a alpha numeric stringstatic Float
extractPrice(String text, String inCurrency, String sep)
static String
firstLetterLower(String string)
static String
firstLetterUpper(String string)
static String
frameTokenCaseUnsensitive(String str, String token, String prefix, String sufix)
split a String, if there are no character between two token this method place a empty String ( !static String
getColName(int colIndex)
static int
getColNum(String colName)
static long
getCRC32(String text)
static String
getDateRandomId()
return a ID contruct on with the current date : sample : 20101223-4687static String
getDateRandomIdWithCheck()
return a ID contruct on with the current date : sample : 20101223-4687static int
getDigitMod9(String value)
static String
getDirNameFromPath(String path)
static String
getFileExtension(String inFileName)
retreive the file extension.static String
getFileNameFromPath(String path)
retreive the file extension.static String
getFileNameWithoutExtension(String inFileName)
retreive the file extension.static String
getFileSize(String filePath)
return a formated size in a String.static String
getFirstNotNull(String value1, String value2)
static String
getItem(String text, String sep, int i, String defaultValue)
get the item from a string with separator. sample : text1,text2,text3 getItem(sample,",",1) = text1static String
getLanguageFromFileName(String filename)
static String
getLargeRandomIdBase64()
generate a id in a String.static String
getNewToken()
static String
getNumberAsAlphabetic(int number)
static String
getPathType(String path, String prefix)
return the type of a path (video, image...)static Integer
getPixelValue(String pxSize)
transform a string with size in pixel in integer.static String
getPropertieskey(String key)
static String
getRandomId()
static String
getRandomIdBase10()
generate a id in a String.static String
getRandomIdBase64()
generate a id in a String.static String
getRandomString(int lenght)
static String
getRandomString(int lenght, String acceptedChars)
static String
getShortRandomId()
return a short id (length 10 chars).static String
hex(byte[] array)
static String
html2txt(String html)
static int
htmlSize(String str)
retreive the size of a String with html code. sample: "aaa´" = 4.static String
indentScss(String scss)
static String
indentText(String text, char tokenOpen, char tokenClose, char escapeChar, String alignStr)
static boolean
isAllEmpty(Object... values)
static boolean
isAlpha(String str)
check if stirng contains only digital numberstatic boolean
isCharset(byte[] b, String inCharset)
static boolean
isContains(String src, String token)
static boolean
isDigit(char c)
static boolean
isDigit(String str)
check if stirng contains only digital numberstatic boolean
isDoc(String fileName)
return true if the filename in a document (sp. : word, libreoffice...).static boolean
isEditable(String fileName)
return true if the filename in a image for wcms (sp. : tif or psd in not a image).static boolean
isEditableExtension(String fileExtension)
static boolean
isEmpty(Object value)
static boolean
isExcelFile(String fileName)
return true if the filename in a image for wcms (sp. : tif or psd in not a image).static boolean
isFloat(String str)
static boolean
isHTML(String fileName)
return true if the filename in a html image).static boolean
isHTMLStatic(String fileName)
static boolean
isHTMLText(String text)
static boolean
isImage(String fileName)
return true if the filename in a image for wcms (sp. : tif or psd in not a image).static boolean
isImageExtension(String fileExtension)
return true if the file extension is an image for wcms (sp. : tif or psd is not an image).static boolean
isJpeg(String fileName)
return true if the filename in a image for wcms (sp. : tif or psd in not a image).static boolean
isJpgExtension(String fileExtension)
return true if the file extension is an image for wcms (sp. : tif or psd is not an image).static boolean
isLetter(char c)
static boolean
isLikeNumber(String str)
check if string contains somthing similar to digital numberstatic boolean
isMail(String email)
static boolean
isMailURL(String url)
static boolean
isOneEmpty(Object... values)
static boolean
isPasswordMath(String pwdData, String userInput, boolean crypted)
static boolean
isPDF(String fileName)
return true if the filename in a PDF file.static boolean
isPhoneNumber(String phone)
static boolean
isProperties(String fileName)
static boolean
isSound(String fileName)
return true if the filename in a sound file image.static boolean
isTrue(Object inBool)
static boolean
isTrue(Object inBool, boolean defaultValue)
static boolean
isTrue(String bool, boolean defaultValue)
static boolean
isURL(String url)
static boolean
isURLFile(String fileName)
return true if the filename in a url file).static boolean
isVAT(String vat)
static boolean
isVideo(String fileName)
return true if the filename in a video file image).static boolean
listContainsItem(String list, String sep, String item)
static void
main(String[] args)
static String
mapToString(Map<String,String> maps)
static String
mapToText(Map<String,String> map, String sep)
static boolean
matchQuestionPattern(String str, String pattern)
Test if a string match with a pattern using '?'.static boolean
matchSimplePattern(String str, String pattern, boolean ignoreCase)
Test if a string match with a pattern using '?'static boolean
matchStarPattern(String str, String pattern)
Test if a string match with a pattern using stars (*).static String
md5(String message)
static String
md5Hex(String message)
static String
mergeString(String sep, String... parts)
merge string with 'sep' betweenstatic String
neverEmpty(String inStr, String replaceWith)
transform a string empty to a other stringstatic String
neverNull(Object inStr)
transform a string null in a empty String.static String
neverNull(Object inStr, String replaceWith)
transform a string null in a empty String.static String
neverNullOrEmpty(Object inStr, String replaceWith)
static String
noRepeatChar(String text, char chr)
static String
normalizePhoneNumber(String phone, String countryPrefix)
format number to number like : +32486123456static String
onlyAlphaNumeric(String data, boolean stopOnBadChar)
static Color
parseColor(String color)
parse error without fault, return null if color is unidentified.static Date
parseDate(String inDate)
static Date
parseDate(String inDate, char sep)
static Date
parseDate(String inDate, String pattern)
static Date
parseDateOrTime(String inDate)
static Date
parseDateTime(String inDate, char sep)
static Date
parseExcelDate(String inDate)
static Date
parseFileTime(String fileTime)
static Date
parseInputDate(String inDate)
static Date
parseInputDateAndTime(String inDate)
static LocalDate
parseInputLocalDate(String inDate)
static LocalTime
parseInputLocalTime(String inTime)
static Integer
parseInt(String txt)
parse txt, if is'nt integer return 0static int
parseInt(String value, int defaultValue)
null save parse int.static Integer
parseInt(String txt, Integer defaultValue)
parse int, if txt is'nt integer return default value.static Date
parseIso8601(String input)
static LocalDate
parseLocalDate(String inDate, String pattern)
static LocalDateTime
parseLocalDateTime(String inDate, String pattern)
static LocalTime
parseLocalTime(String inDate, String pattern)
static Date[]
parseRangeDate(String date)
static Date
parseSecondFileTime(String fileTime)
static Date
parseSortableDate(String date)
static LocalDate
parseSortableLocalDate(String date)
static Date
parseSortableTime(String date)
static Date
parseTime(String inDate)
static Date
parseTimeOnly(String inDate)
static String
propertiesToString(Properties p)
static String
quote(String string)
static boolean
rangeMatches(String range, Integer value)
Test if the value is included in the range.static String[]
readLines(String text)
static String
removeAccents(String textWithAccent)
static String
removeCR(String text)
remove CR from a Stringstatic String
removeDuplicateToken(String text, String token)
static String
removeFirstChar(String txt, char c)
static String
removeNumber(String text)
static String
removeQuote(String text)
remote " on the start and the end of text, if quote was found.static String
removeRepeatedChar(String str)
static String
removeRepeatedChar(String str, char c)
remove repeated char inside string. sample : "javlo--love" "-" = "javlo-love".static String
removeSequence(String text, String prefix, String sufix)
remove sequence from a string. sample : removeSequence ("slkqfj #dlskj# sdljf", "#", "#") -> slkqfj sdljf.static String
removeSpecialChars(char c)
static String
removeSpecialChars(String text)
static String
removeTag(String text)
remove tag. sample: link -> linkstatic String
renderDate(LocalDate date)
static String
renderDate(LocalDate date, String pattern)
static String
renderDate(LocalDateTime date, String pattern)
static String
renderDate(LocalTime time, String pattern)
static String
renderDate(Date date)
static String
renderDate(Date date, String pattern)
static String
renderDate(Locale locale, Date date, String pattern)
static String
renderDateAndTime(LocalDateTime date)
static String
renderDateAsRFC822String(LocalDate date)
static String
renderDateAsRFC822String(LocalDateTime date)
static String
renderDateAsRFC822String(ZonedDateTime date)
static String
renderDateAsRFC822String(Date date)
static String
renderDateWithDefaultValue(Date date, String defaultValue)
static String
renderDay(Date date, String lang)
static String
renderDouble(double value, int precision)
static String
renderDouble(double value, int precision, char sep)
static String
renderDouble(double value, Locale locale)
static String
renderDoubleAsPercentage(double value)
static String
renderFileTime(Date date)
static String
renderFullDate(ContentContext ctx, Date date)
static String
renderInputDate(LocalDate inDate)
static String
renderInputDate(Date inDate)
static String
renderLightDate(Date date)
static String
renderMediumDate(ContentContext ctx, Date date)
static String
renderMonthDate(ContentContext ctx, Date date)
static String
renderNumber(int n, int size)
static String
renderNumber(long n, int size)
static String
renderOnlyTime(Date date)
static String
renderPrice(double price, String currency)
static String
renderSecondFileTime(Date date)
static String
renderShortDate(ContentContext ctx, Date date)
render a date, search the format in I18n files.static String
renderShortDateWidthDay(ContentContext ctx, Date date)
static String
renderShortTime(ContentContext ctx, Date date)
static String
renderSize(long size)
return a formated size in a String.static String
renderSortableDate(Date date)
static String
renderSortableTime(Date date)
static String
renderTime(LocalTime time)
static String
renderTime(Date date)
static String
renderTime(ContentContext ctx, Date date)
static String
renderTimeInSecond(long time)
static String
renderTimeOnly(Date date)
static String
renderTimeOnlyShort(Date date)
static String
renderTimeShort(Date date)
static String
renderUserFriendlyDate(Date date)
static String
renderUserFriendlyDate(Locale locale, Date date)
static String
renderUserFriendlyDate(ContentContext ctx, Date date)
render a date, search the format in I18n files.static String
renderUserFriendlyTime(Date date)
static String
replaceBloc(String content, String newBloc, String prefix, String suffix, int insidePosition)
replace a bloc, between two prefix and suffix and with char pos inside.static String
replaceCR(String text, String separator)
static String
replaceFileExtension(String file, String ext)
static String
replaceItem(String text, String newItem, String prefix, String suffix)
replace text in larger textstatic Double
safeParseDouble(String string, Double defaultValue)
static Integer
safeParseInt(String string, Integer defaultValue)
static Long
safeParseLong(String string, Long defaultValue)
static Collection<String>
searchEmail(String text)
extract email from a free textstatic List<URL>
searchLinks(String text)
extract external link from a free textstatic Collection<javax.mail.internet.InternetAddress>
searchStructuredEmail(String text)
extract email from a free textstatic String
setLineSeparator(String text, int maxSize, String lineSeparator)
static Date
smartParseDate(String inDate)
static Date
smartParseDate(String inDate, String lang)
static Date
smartParseDateTime(String inDate)
static LocalTime
smartParseTime(String inTime)
static String
snakeToCamel(String str)
static String
sortText(String text)
sort line of a textstatic String[]
split(String str, String token)
split a String, if there are no character between two token this method place a empty String ( !static String[]
splitAddress(String address)
static String[]
splitStaySeparator(String str, char token)
split a String, if there are no character between two token this method place a empty String ( !static String[]
splitStaySeparator(String str, String token)
split a String, if there are no character between two token this method place a empty String ( !static int
stringInArray(String[] array, String token)
static String[]
stringToArray(String str)
static String[]
stringToArray(String str, String token)
static String[]
stringToArrayRemoveEmpty(String str)
static List<String>
stringToCollection(String str)
static List<String>
stringToCollection(String str, String token)
static List<String>
stringToCollection(String str, String token, boolean trim)
static Collection<? extends String>
stringToCollectionRemoveEmpty(String addRolesAsRaw)
static List<String>
stringToCollectionTrim(String str)
static List<String>
stringToCollectionTrim(String str, String token)
static String
stringToFileName(String inStr)
static Map<String,String>
stringToMap(String encodedMap)
static Set<String>
stringToSet(String str)
static Set<String>
stringToSet(String str, String sep)
static <T extends IStringSeralizable>
List<T>stringToStringSeralizableCollection(String data, String sep, Class c)
static String
stringWithoutSpecialChar(String inStr)
static List<String>
textToList(String text)
static String
textToList(GlobalContext globalContext, String text, String sep, String layout, boolean autoLink)
static String
textToList(GlobalContext globalContext, String text, String sep, String layout, boolean autoLink, String ulClass)
static Map<String,String>
textToMap(String encodedMap)
static Map<String,String>
textToMap(String encodedMap, String sep)
static String
timedTokenGenerate(String data, long timeInMillis)
static boolean
timedTokenValidate(String tokenData, String orignalData, int validityRangeInMinutes, long timeInMillis)
static String[]
toArrayString(Object[] objArray)
static String
toHTMLAttribute(String value)
transform a free value to a attribute xml valuestatic String
toJsonValue(String data)
static String
toJSString(String inStr)
transform a String to insert in a JavaScript.static String
toLatin(String text)
convert to latin alphabetstatic String
toMaxSize(String str, int size, String sufix)
transform a String to a max size. sample: "Welcome in the new wave party" --> "Welcome in the..."static String
toXMLAttribute(String value)
transform a free value to a attribute xml valuestatic String
trim(String text)
static String
trim(String text, char trimChar)
replace trimChar at the start and the end of text string. sample : --test-, - >>> teststatic String
trimAndNullify(String str)
static String
trimInternal(String str)
replace all space repeatition with one spacestatic String
trimLineReturn(String string)
static List<String>
trimList(Collection<String> list)
trim all items of the list.static String
trimOn(String inText, String token)
static String
trimSpaceAndUnderscore(String inText)
static String
txt2html(String text)
static String
txt2htmlCR(String text)
replace CR with
and replace special char to html codestatic Map<String,String>
uriParamToMap(String uri)
static boolean
validUTF8(byte[] input)
static String
writeLines(String... text)
-
-
-
Field Detail
-
logger
protected static Logger logger
create a static logger.
-
SOMETHING
public static final String SOMETHING
- See Also:
- Constant Field Values
-
REQUEST_KEY_FORM_VALID
public static final String REQUEST_KEY_FORM_VALID
- See Also:
- Constant Field Values
-
ALPHABET
public static final String ALPHABET
- See Also:
- Constant Field Values
-
ALPHABET_UPPER_CASE
public static final String ALPHABET_UPPER_CASE
-
NUMERIC
public static final String NUMERIC
- See Also:
- Constant Field Values
-
BASIC_CHAR
public static final String BASIC_CHAR
-
URLOK_CHAR
public static final String URLOK_CHAR
-
ALPHANUM
public static final String ALPHANUM
- See Also:
- Constant Field Values
-
specialChar
public static String specialChar
-
DEFAULT_SEPARATOR
public static String DEFAULT_SEPARATOR
-
TXT2HTML
public static final String[][] TXT2HTML
-
RFC822DATEPATTERN
public static final String RFC822DATEPATTERN
- See Also:
- Constant Field Values
-
RFC822DATEFORMAT
public static SimpleDateFormat RFC822DATEFORMAT
-
DEFAULT_LIST_SEPARATOR
public static final String DEFAULT_LIST_SEPARATOR
- See Also:
- Constant Field Values
-
EMPTY_STRING_ARRAY
public static final String[] EMPTY_STRING_ARRAY
-
RANGE_MATCHER_LOWER
public static final Pattern RANGE_MATCHER_LOWER
-
RANGE_MATCHER_BETWEEN
public static final Pattern RANGE_MATCHER_BETWEEN
-
RANGE_MATCHER_GREATER
public static final Pattern RANGE_MATCHER_GREATER
-
TIMED_TOKEN_DIVIDER
public static final long TIMED_TOKEN_DIVIDER
- See Also:
- Constant Field Values
-
-
Method Detail
-
asBase64
public static String asBase64(byte[] bytes)
generate a base 64 string.- Returns:
- a unique id.
-
asBase32
public static String asBase32(int value)
generate a base 32 string with a int- Returns:
- a unique id.
-
asBase32
public static String asBase32(byte value)
generate a base 32 string with a int- Returns:
- a unique id.
-
asBase32
public static String asBase32(byte[] bytes)
generate a base 32 string.- Returns:
- a unique id.
-
asBase64
public static String asBase64(int value)
generate a base 64 string with a int- Returns:
- a unique id.
-
asBase64
public static String asBase64(long value)
generate a base 64 string with a long- Returns:
- a unique id.
-
changeFileExtension
public static String changeFileExtension(String inFileName, String newExt)
change the file extension of the path- Parameters:
inFileName
- a path or a url to a file.newExt
- the new extension of the file.- Returns:
- the same path with the new extension.
-
collectionToString
public static String collectionToString(Collection<?> col)
-
collectionStringSeralizableToString
public static <T extends IStringSeralizable> String collectionStringSeralizableToString(Collection<T> col, String sep)
-
stringToStringSeralizableCollection
public static <T extends IStringSeralizable> List<T> stringToStringSeralizableCollection(String data, String sep, Class c) throws InstantiationException, IllegalAccessException
-
collectionToText
public static String collectionToText(Collection<?> col)
convert a collection to text. Each item of the collection will be a line if the text.- Parameters:
col
-- Returns:
-
collectionToTextarea
public static String collectionToTextarea(Collection<?> col)
convert a collection to text. Each item of the collection will be a line if the text.- Parameters:
col
-- Returns:
-
collectionToString
public static String collectionToString(Collection<?> col, String inSep)
-
mergeString
public static String mergeString(String sep, String... parts)
merge string with 'sep' between- Parameters:
sep
-part
-- Returns:
-
convertString
public static String convertString(String pattern1, String pattern2, String text)
convert a string to another string if math pattern1 and convert to pattern2. pattern is a String with one '*' for any characters. sample : /*, /test/*, /view/fr --> /test/view/fr- Parameters:
pattern1
- a pattern with one '*'pattern2
- a pattern with one '*'text
-- Returns:
-
countChar
public static int countChar(String str, char c)
-
CR2BR
public static String CR2BR(String text)
replace CR with- Parameters:
text
- a simple text- Returns:
- XHTML code
-
removeSpecialChars
public static String removeSpecialChars(char c)
-
createFileName
public static String createFileName(String fileName)
convert a file name with space, accent and other bad character to a acceptable name. sample: "l'éléphant rose.odt" -> "l_elephant_rose.odt"- Parameters:
fileName
- a bad file name- Returns:
- a correct file name
-
trim
public static String trim(String text, char trimChar)
replace trimChar at the start and the end of text string. sample : --test-, - >>> test- Parameters:
text
-trimChar
-- Returns:
-
trimInternal
public static String trimInternal(String str)
replace all space repeatition with one space
-
CRtoSpace
public static String CRtoSpace(String text)
replace CR with a space- Parameters:
text
- a simple text- Returns:
- one line text
-
cutEndXHTML
public static String cutEndXHTML(String str, int cut)
cut the end of a xhtml code. sample: "aaa´coucou", 5 = "aaa´c"- Parameters:
str
- the stringcut
- the end charaster must be removed.- Returns:
- a trunced XHTML String
-
decodeBase64
public static byte[] decodeBase64(String data) throws IOException
generate a base 64 string.- Returns:
- a unique id.
- Throws:
IOException
-
decodeNoChar
public static String decodeNoChar(String data, String noChars)
insert char from a Sting (encoded with encodeNoChar)- Parameters:
data
- string to be encodednoChars
- list of vorbiden char- Returns:
-
encodeCDATA
public static String encodeCDATA(String value)
encode a string to a CDATA sequence.- Parameters:
value
-- Returns:
-
encodeNoChar
public static String encodeNoChar(String data, String noChars)
remove char from a Sting- Parameters:
data
- string to be encodednoChars
- list of vorbiden char- Returns:
-
frameTokenCaseUnsensitive
public static String frameTokenCaseUnsensitive(String str, String token, String prefix, String sufix)
split a String, if there are no character between two token this method place a empty String ( != String.split )- Parameters:
str
- a standard strtoken
- a token ( not pattern !!! )- Returns:
- a array of String without the token
-
getDateRandomId
public static String getDateRandomId()
return a ID contruct on with the current date : sample : 20101223-4687- Returns:
-
getDateRandomIdWithCheck
public static String getDateRandomIdWithCheck()
return a ID contruct on with the current date : sample : 20101223-4687- Returns:
-
getDigitMod9
public static int getDigitMod9(String value)
-
extractNumber
public static Integer extractNumber(String text)
extract only number of a alpha numeric string- Parameters:
text
-- Returns:
- 23 from "23px", null from "animal".
-
extractLong
public static Long extractLong(String text)
extract only number of a alpha numeric string- Parameters:
text
-- Returns:
- 23 from "23px", null from "animal".
-
extractNumberAsString
public static String extractNumberAsString(String text)
extract only number of a alpha numeric string- Parameters:
text
-- Returns:
- 23 from "23px", null from "animal".
-
getFileExtension
public static String getFileExtension(String inFileName)
retreive the file extension.- Parameters:
inFileName
- a file name- Returns:
- a file extension without dot ( pdf, zip, ... )
-
getFileNameFromPath
public static String getFileNameFromPath(String path)
retreive the file extension.- Parameters:
inFileName
- a file name- Returns:
- a file name
-
getFileNameWithoutExtension
public static String getFileNameWithoutExtension(String inFileName)
retreive the file extension.- Parameters:
inFileName
- a file name- Returns:
- a file extension without dot ( pdf, zip, ... )
-
getFileSize
public static final String getFileSize(String filePath)
return a formated size in a String.- Parameters:
filePath
- a path to a file- Returns:
- a string represent a size (sample : 45KB)
-
getRandomId
public static String getRandomId()
-
getShortRandomId
public static String getShortRandomId()
return a short id (length 10 chars).- Returns:
-
encodeAsStructuredCommunicationMod97
public static String encodeAsStructuredCommunicationMod97(String code)
transform a string of number (length 10) to a structured communication, last number is the mod 97 of the first number- Parameters:
code
- a string of length 10 with only number- Returns:
- a string on length 12 with the the last number is the mod 97
-
getRandomIdBase10
public static String getRandomIdBase10()
generate a id in a String.- Returns:
- a unique id.
-
getLargeRandomIdBase64
public static String getLargeRandomIdBase64()
generate a id in a String.- Returns:
- a unique id.
-
getRandomIdBase64
public static String getRandomIdBase64()
generate a id in a String.- Returns:
- a unique id.
-
getRandomString
public static String getRandomString(int lenght)
-
htmlSize
public static int htmlSize(String str)
retreive the size of a String with html code. sample: "aaa´" = 4.- Parameters:
str
- the string- Returns:
- the size of the String;
-
isCharset
public static boolean isCharset(byte[] b, String inCharset)
-
isDigit
public static boolean isDigit(char c)
-
isLetter
public static boolean isLetter(char c)
-
isLikeNumber
public static boolean isLikeNumber(String str)
check if string contains somthing similar to digital number- Parameters:
str
-- Returns:
-
isDigit
public static boolean isDigit(String str)
check if stirng contains only digital number- Parameters:
str
-- Returns:
-
isAlpha
public static boolean isAlpha(String str)
check if stirng contains only digital number- Parameters:
str
-- Returns:
-
isFloat
public static boolean isFloat(String str)
-
isHTMLText
public static boolean isHTMLText(String text)
-
isHTML
public static final boolean isHTML(String fileName)
return true if the filename in a html image).- Parameters:
fileName
- file name with extension- Returns:
- true if file name is a image
-
isHTMLStatic
public static final boolean isHTMLStatic(String fileName)
-
isProperties
public static final boolean isProperties(String fileName)
-
isImage
public static final boolean isImage(String fileName)
return true if the filename in a image for wcms (sp. : tif or psd in not a image).- Parameters:
fileName
- file name with extension- Returns:
- true if file name is a image
-
isEditable
public static final boolean isEditable(String fileName)
return true if the filename in a image for wcms (sp. : tif or psd in not a image).- Parameters:
fileName
- file name with extension- Returns:
- true if file name is a image
-
isJpeg
public static final boolean isJpeg(String fileName)
return true if the filename in a image for wcms (sp. : tif or psd in not a image).- Parameters:
fileName
- file name with extension- Returns:
- true if file name is a image
-
isExcelFile
public static final boolean isExcelFile(String fileName)
return true if the filename in a image for wcms (sp. : tif or psd in not a image).- Parameters:
fileName
- file name with extension- Returns:
- true if file name is a image
-
isImageExtension
public static final boolean isImageExtension(String fileExtension)
return true if the file extension is an image for wcms (sp. : tif or psd is not an image).- Parameters:
fileExtension
- file extension- Returns:
- true if file name is a image
- See Also:
getFileExtension(String)
-
isEditableExtension
public static final boolean isEditableExtension(String fileExtension)
-
isJpgExtension
public static final boolean isJpgExtension(String fileExtension)
return true if the file extension is an image for wcms (sp. : tif or psd is not an image).- Parameters:
fileExtension
- file extension- Returns:
- true if file name is a image
- See Also:
getFileExtension(String)
-
isDoc
public static final boolean isDoc(String fileName)
return true if the filename in a document (sp. : word, libreoffice...).- Parameters:
fileName
- file name with extension- Returns:
- true if file name is a image
-
isPDF
public static final boolean isPDF(String fileName)
return true if the filename in a PDF file.- Parameters:
fileName
- file name with extension- Returns:
- true if file name is a image
-
isMail
public static boolean isMail(String email)
-
isMailURL
public static boolean isMailURL(String url)
-
isPasswordMath
public static final boolean isPasswordMath(String pwdData, String userInput, boolean crypted)
-
isPhoneNumber
public static boolean isPhoneNumber(String phone)
-
isSound
public static final boolean isSound(String fileName)
return true if the filename in a sound file image.- Parameters:
fileName
- file name with extension- Returns:
- true if file name is a sound
-
isTrue
public static boolean isTrue(Object inBool)
-
isTrue
public static boolean isTrue(Object inBool, boolean defaultValue)
-
isTrue
public static boolean isTrue(String bool, boolean defaultValue)
-
isURL
public static boolean isURL(String url)
-
isURLFile
public static final boolean isURLFile(String fileName)
return true if the filename in a url file).- Parameters:
fileName
- file name with extension- Returns:
- true if file name is a url file
-
isVideo
public static final boolean isVideo(String fileName)
return true if the filename in a video file image).- Parameters:
fileName
- file name with extension- Returns:
- true if file name is a video
-
matchStarPattern
public static boolean matchStarPattern(String str, String pattern)
Test if a string match with a pattern using stars (*).
assert matchStarPattern("eeA", "ee*");
assert !matchStarPattern("eeA", "ee");
assert matchStarPattern("Aee", "*ee");
assert !matchStarPattern("Aee", "ee");
assert matchStarPattern("eAe", "e*e");
assert !matchStarPattern("eAe", "ee");
assert matchStarPattern("ee", "ee");- Parameters:
str
-pattern
-- Returns:
-
matchQuestionPattern
public static boolean matchQuestionPattern(String str, String pattern)
Test if a string match with a pattern using '?'.- Parameters:
str
-pattern
-- Returns:
-
matchSimplePattern
public static boolean matchSimplePattern(String str, String pattern, boolean ignoreCase)
Test if a string match with a pattern using '?' and '*'.- Parameters:
str
-pattern
-- Returns:
-
neverEmpty
public static String neverEmpty(String inStr, String replaceWith)
transform a string empty to a other string- Parameters:
inStr
- a string can be nullreplaceWith
- replace with this if null.- Returns:
- never null ( empty string if input is null)
-
neverNull
public static String neverNull(Object inStr)
transform a string null in a empty String.- Parameters:
inStr
- a string can be null- Returns:
- never null ( empty string if input is null)
-
neverNull
public static String neverNull(Object inStr, String replaceWith)
transform a string null in a empty String.- Parameters:
inStr
- a string can be nullreplaceWith
- replace with this if null.- Returns:
- never null ( empty string if input is null)
-
parseDate
public static Date parseDate(String inDate) throws ParseException
- Throws:
ParseException
-
parseExcelDate
public static Date parseExcelDate(String inDate) throws ParseException
- Throws:
ParseException
-
parseInputDate
public static Date parseInputDate(String inDate) throws ParseException
- Throws:
ParseException
-
parseInputDateAndTime
public static Date parseInputDateAndTime(String inDate) throws ParseException
- Throws:
ParseException
-
renderInputDate
public static String renderInputDate(Date inDate) throws ParseException
- Throws:
ParseException
-
renderInputDate
public static String renderInputDate(LocalDate inDate) throws ParseException
- Throws:
ParseException
-
parseInt
public static int parseInt(String value, int defaultValue)
null save parse int.- Parameters:
value
- a string with a int insidedefaultValue
- the value if string value is null- Returns:
-
parseRangeDate
public static Date[] parseRangeDate(String date) throws ParseException
- Throws:
ParseException
-
parseDate
public static Date parseDate(String inDate, char sep) throws ParseException
- Throws:
ParseException
-
parseDateTime
public static Date parseDateTime(String inDate, char sep) throws ParseException
- Throws:
ParseException
-
parseDate
public static Date parseDate(String inDate, String pattern) throws ParseException
- Throws:
ParseException
-
parseLocalDateTime
public static LocalDateTime parseLocalDateTime(String inDate, String pattern)
-
parseDateOrTime
public static Date parseDateOrTime(String inDate) throws ParseException
- Throws:
ParseException
-
parseFileTime
public static Date parseFileTime(String fileTime) throws ParseException
- Throws:
ParseException
-
parseSecondFileTime
public static Date parseSecondFileTime(String fileTime) throws ParseException
- Throws:
ParseException
-
parseSortableTime
public static Date parseSortableTime(String date) throws ParseException
- Throws:
ParseException
-
parseSortableDate
public static Date parseSortableDate(String date) throws ParseException
- Throws:
ParseException
-
parseSortableLocalDate
public static LocalDate parseSortableLocalDate(String date) throws ParseException
- Throws:
ParseException
-
parseTime
public static Date parseTime(String inDate) throws ParseException
- Throws:
ParseException
-
parseTimeOnly
public static Date parseTimeOnly(String inDate) throws ParseException
- Throws:
ParseException
-
removeCR
public static String removeCR(String text)
remove CR from a String- Parameters:
text
- a simple String- Returns:
- a string without CR.
-
removeRepeatedChar
public static String removeRepeatedChar(String str, char c)
remove repeated char inside string. sample : "javlo--love" "-" = "javlo-love".- Parameters:
str
-c
-- Returns:
-
removeSequence
public static final String removeSequence(String text, String prefix, String sufix)
remove sequence from a string. sample : removeSequence ("slkqfj #dlskj# sdljf", "#", "#") -> slkqfj sdljf.- Parameters:
text
- a simple textprefix
- the prefix for identify the sequencesufix
- the sufix for identify the sequence- Returns:
-
removeTag
public static String removeTag(String text)
remove tag. sample: link -> link- Parameters:
text
- XHTML Code- Returns:
- simple text
-
renderShortTime
public static String renderShortTime(ContentContext ctx, Date date) throws FileNotFoundException, IOException
- Throws:
FileNotFoundException
IOException
-
renderShortDate
public static String renderShortDate(ContentContext ctx, Date date) throws FileNotFoundException, IOException
render a date, search the format in I18n files.- Parameters:
session
-locale
-date
-- Returns:
- Throws:
IOException
FileNotFoundException
-
renderDate
public static String renderDate(LocalDateTime date, String pattern)
-
parseIso8601
public static Date parseIso8601(String input) throws ParseException
- Throws:
ParseException
-
renderDateAsRFC822String
public static String renderDateAsRFC822String(LocalDateTime date)
-
renderDateAsRFC822String
public static String renderDateAsRFC822String(ZonedDateTime date)
-
renderDateWithDefaultValue
public static String renderDateWithDefaultValue(Date date, String defaultValue)
-
renderTimeInSecond
public static final String renderTimeInSecond(long time)
-
renderDouble
public static String renderDouble(double value, int precision)
-
renderDouble
public static String renderDouble(double value, int precision, char sep)
-
renderDoubleAsPercentage
public static String renderDoubleAsPercentage(double value)
-
renderMediumDate
public static String renderMediumDate(ContentContext ctx, Date date)
-
renderFullDate
public static String renderFullDate(ContentContext ctx, Date date)
-
renderMonthDate
public static String renderMonthDate(ContentContext ctx, Date date)
-
renderNumber
public static String renderNumber(int n, int size)
-
renderNumber
public static String renderNumber(long n, int size)
-
renderShortDateWidthDay
public static String renderShortDateWidthDay(ContentContext ctx, Date date)
-
renderSize
public static final String renderSize(long size)
return a formated size in a String.- Parameters:
filePath
- a path to a file- Returns:
- a string represent a size (sample : 45KB)
-
renderTime
public static String renderTime(ContentContext ctx, Date date) throws FileNotFoundException, IOException
- Throws:
FileNotFoundException
IOException
-
renderDateAndTime
public static String renderDateAndTime(LocalDateTime date)
-
renderUserFriendlyDate
public static String renderUserFriendlyDate(ContentContext ctx, Date date) throws FileNotFoundException, IOException
render a date, search the format in I18n files.- Parameters:
session
-locale
-date
-- Returns:
- Throws:
IOException
FileNotFoundException
-
searchStructuredEmail
public static Collection<javax.mail.internet.InternetAddress> searchStructuredEmail(String text)
extract email from a free text- Parameters:
text
- a free text- Returns:
- a collection of email address
-
searchEmail
public static Collection<String> searchEmail(String text)
extract email from a free text- Parameters:
text
- a free text- Returns:
- a collection of email address
-
searchLinks
public static List<URL> searchLinks(String text)
extract external link from a free text- Parameters:
text
- a free text, can be html- Returns:
- a collection of URL
-
split
public static String[] split(String str, String token)
split a String, if there are no character between two token this method place a empty String ( != String.split )- Parameters:
str
- a standard strtoken
- a token ( not pattern !!! )- Returns:
- a array of String without the separator
-
splitStaySeparator
public static String[] splitStaySeparator(String str, char token)
split a String, if there are no character between two token this method place a empty String ( != String.split )- Parameters:
str
- a standard strtoken
- a token ( not pattern !!! )- Returns:
- a array of String with the separator
-
splitStaySeparator
public static String[] splitStaySeparator(String str, String token)
split a String, if there are no character between two token this method place a empty String ( != String.split )- Parameters:
str
- a standard strtoken
- a token ( not pattern !!! )- Returns:
- a array of String with the separator
-
stringToCollection
public static List<String> stringToCollection(String str, String token, boolean trim)
-
textToList
public static String textToList(GlobalContext globalContext, String text, String sep, String layout, boolean autoLink)
-
textToList
public static String textToList(GlobalContext globalContext, String text, String sep, String layout, boolean autoLink, String ulClass)
- Parameters:
sep
- separation between title and text. sample "1.2 great section" sep=" " -> "1.2" is title and "great section" is text.layout
- the layout of the list : ("ul-ul", "ol-ol", "ul-ol", "ol-ul") the first element is the first level and the next is all the next level.- Returns:
- a xhtml list.
-
toJSString
public static String toJSString(String inStr)
transform a String to insert in a JavaScript.- Parameters:
inStr
- a Simple String- Returns:
- a String with replacement for insert into a javascript.
-
toMaxSize
public static String toMaxSize(String str, int size, String sufix)
transform a String to a max size. sample: "Welcome in the new wave party" --> "Welcome in the..."- Parameters:
str
- the string must be cut.size
- the max size of the final string.sufix
- the sufix of new String if cutted (sp. ... ).- Returns:
-
toXMLAttribute
public static String toXMLAttribute(String value)
transform a free value to a attribute xml value- Parameters:
value
-- Returns:
-
toHTMLAttribute
public static String toHTMLAttribute(String value)
transform a free value to a attribute xml value- Parameters:
value
-- Returns:
-
txt2htmlCR
public static String txt2htmlCR(String text)
replace CR with
and replace special char to html code- Parameters:
text
- a simple text- Returns:
- XHTML code
-
getPathType
public static String getPathType(String path, String prefix)
return the type of a path (video, image...)- Parameters:
path
-prefix
-- Returns:
-
isEmpty
public static boolean isEmpty(Object value)
-
isAllEmpty
public static boolean isAllEmpty(Object... values)
-
isOneEmpty
public static boolean isOneEmpty(Object... values)
-
extractItem
public static List<String> extractItem(String text, String prefix, String suffix)
extract a subtext from a text.- Parameters:
text
-prefix
-suffix
-- Returns:
-
replaceBloc
public static String replaceBloc(String content, String newBloc, String prefix, String suffix, int insidePosition)
replace a bloc, between two prefix and suffix and with char pos inside.- Parameters:
content
-newBloc
-prefix
-suffix
-insidePosition
-- Returns:
-
replaceItem
public static String replaceItem(String text, String newItem, String prefix, String suffix)
replace text in larger text- Parameters:
text
- the original textnewItem
- the new text partprefix
- the prefix before the replacementsuffix
- the suffix afther the replacement- Returns:
-
stringToCollectionRemoveEmpty
public static Collection<? extends String> stringToCollectionRemoveEmpty(String addRolesAsRaw)
-
createKey
public static String createKey(int length, Set<String> keys)
create a new unic key.- Parameters:
length
- the length of the key.keys
- set of keys allready exist- Returns:
- null if all keys are in keys set
-
cleanPath
public static String cleanPath(String path)
clean path, remove double "/" and replace "\" by "/"- Parameters:
path
-- Returns:
- "//web/path" >> "/web/path"
-
containsUppercase
public static boolean containsUppercase(String text)
check if a text contains uppercase char. test > false, Test > true, TEST > true- Parameters:
text
-- Returns:
-
escapeProperty
public static String escapeProperty(String theString, boolean escapeSpace, boolean escapeUnicode)
Method copied from the private method java.util.Properties#saveConvert(...)- Parameters:
theString
-escapeSpace
-escapeUnicode
-- Returns:
-
validUTF8
public static boolean validUTF8(byte[] input)
-
getNewToken
public static String getNewToken()
-
getNumberAsAlphabetic
public static String getNumberAsAlphabetic(int number)
-
parseColor
public static Color parseColor(String color)
parse error without fault, return null if color is unidentified.- Parameters:
color
-- Returns:
-
trimList
public static List<String> trimList(Collection<String> list)
trim all items of the list.- Parameters:
list
-- Returns:
-
getItem
public static String getItem(String text, String sep, int i, String defaultValue)
get the item from a string with separator. sample : text1,text2,text3 getItem(sample,",",1) = text1- Parameters:
text
-sep
-i
-defaultValue
- default value if item not found- Returns:
-
getPixelValue
public static Integer getPixelValue(String pxSize)
transform a string with size in pixel in integer.- Parameters:
pxSize
- a size in px (sp. '12px').- Returns:
- null if bad param (sp. 12%, tralala, null) and the value in pixel if corrent param (12px, 0px, 23 px).
-
hex
public static String hex(byte[] array)
-
getCRC32
public static long getCRC32(String text)
-
textToMap
public static Map<String,String> textToMap(String encodedMap) throws IOException
- Throws:
IOException
-
textToMap
public static Map<String,String> textToMap(String encodedMap, String sep) throws IOException
- Throws:
IOException
-
mapToText
public static String mapToText(Map<String,String> map, String sep) throws IOException
- Throws:
IOException
-
rangeMatches
public static boolean rangeMatches(String range, Integer value)
Test if the value is included in the range.- Parameters:
range
- Range values are like -25,25-30,31-35,35+value
- the integer to test- Returns:
true
is the value is in the rangefalse
otherwise
-
getColNum
public static int getColNum(String colName)
-
getColName
public static String getColName(int colIndex)
-
timedTokenValidate
public static boolean timedTokenValidate(String tokenData, String orignalData, int validityRangeInMinutes, long timeInMillis)
-
toLatin
public static String toLatin(String text)
convert to latin alphabet- Parameters:
text
-- Returns:
-
removeQuote
public static String removeQuote(String text)
remote " on the start and the end of text, if quote was found.- Parameters:
text
-- Returns:
-
normalizePhoneNumber
public static String normalizePhoneNumber(String phone, String countryPrefix)
format number to number like : +32486123456- Parameters:
phone
-countryPrefix
-- Returns:
-
isVAT
public static boolean isVAT(String vat) throws MalformedURLException, Exception
- Throws:
MalformedURLException
Exception
-
propertiesToString
public static String propertiesToString(Properties p)
-
parseInt
public static Integer parseInt(String txt)
parse txt, if is'nt integer return 0- Parameters:
txt
-- Returns:
-
parseInt
public static Integer parseInt(String txt, Integer defaultValue)
parse int, if txt is'nt integer return default value.- Parameters:
txt
-defaultValue
-- Returns:
-
setLineSeparator
public static String setLineSeparator(String text, int maxSize, String lineSeparator)
-
indentText
public static String indentText(String text, char tokenOpen, char tokenClose, char escapeChar, String alignStr)
-
copyInClipbaord
public static void copyInClipbaord(String content)
-
main
public static void main(String[] args) throws IOException
- Throws:
IOException
-
-