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 StringALPHABETstatic StringALPHABET_UPPER_CASEstatic StringALPHANUMstatic StringBASIC_CHARstatic StringDEFAULT_LIST_SEPARATORstatic StringDEFAULT_SEPARATORstatic String[]EMPTY_STRING_ARRAYprotected static Loggerloggercreate a static logger.static StringNUMERICstatic PatternRANGE_MATCHER_BETWEENstatic PatternRANGE_MATCHER_GREATERstatic PatternRANGE_MATCHER_LOWERstatic StringREQUEST_KEY_FORM_VALIDstatic SimpleDateFormatRFC822DATEFORMATstatic StringRFC822DATEPATTERNstatic StringSOMETHINGstatic StringspecialCharstatic longTIMED_TOKEN_DIVIDERstatic String[][]TXT2HTMLstatic StringURLOK_CHAR
-
Constructor Summary
Constructors Constructor Description StringHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringaddSufixToFileName(String fileName, String sufix)static StringarrayToString(Object[] array)static StringarrayToString(Object[] array, String inSep)static StringasBase32(byte value)generate a base 32 string with a intstatic StringasBase32(byte[] bytes)generate a base 32 string.static StringasBase32(int value)generate a base 32 string with a intstatic StringasBase64(byte[] bytes)generate a base 64 string.static StringasBase64(int value)generate a base 64 string with a intstatic StringasBase64(long value)generate a base 64 string with a longstatic StringcamelToSnake(String camelStr)static StringchangeFileExtension(String inFileName, String newExt)change the file extension of the pathstatic StringcleanPath(String path)clean path, remove double "/" and replace "\" by "/"StringcleanString(String text)static <T extends IStringSeralizable>
StringcollectionStringSeralizableToString(Collection<T> col, String sep)static StringcollectionToString(String... values)static StringcollectionToString(Collection<?> col)static StringcollectionToString(Collection<?> col, String inSep)static StringcollectionToText(Collection<?> col)convert a collection to text.static StringcollectionToTextarea(Collection<?> col)convert a collection to text.static StringcolorToHexString(Color color)static StringcolorToHexStringNotNull(Color color)static booleancompare(String str1, String str2)static booleancontainsAny(String source, String... texts)static booleancontainsNoCase(String text, String token)static booleancontainsOne(String source, String... texts)static booleancontainsUppercase(String text)check if a text contains uppercase char. test > false, Test > true, TEST > truestatic StringconvertString(String pattern1, String pattern2, String text)convert a string to another string if math pattern1 and convert to pattern2.static voidcopyInClipbaord(String content)static intcountChar(String str, char c)static StringCR2BR(String text)replace CR withstatic StringcreateASCIIString(String text)static StringcreateComparableString(String text)static StringcreateFileName(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 StringcreateI18NURL(String value)static StringcreateKey(int length, Set<String> keys)create a new unic key.static StringCRtoSpace(String text)replace CR with a spacestatic StringcutEndXHTML(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 StringdecodeNoChar(String data, String noChars)insert char from a Sting (encoded with encodeNoChar)static StringdoubleQutotes(String text)static StringencodeAsStructuredCommunicationMod97(String code)transform a string of number (length 10) to a structured communication, last number is the mod 97 of the first numberstatic StringencodeCDATA(String value)encode a string to a CDATA sequence.static StringencodeNoChar(String data, String noChars)remove char from a Stingstatic StringencryptPassword(String plaintext)static StringencryptPasswordSHA256(String plaintext)static StringescapeHTML(String html)static StringescapeProperty(String theString, boolean escapeSpace, boolean escapeUnicode)Method copied from the private method java.util.Properties#saveConvert(...)static StringescapeSpecialRegexChars(String str)static StringescapeString(String field, boolean escapeDoubleQuotes)static StringescapeWordChar(String text)static StringexpandSystemProperties(String str)static StringextractHost(String inUrl)static StringextractHostAndProtocol(String inUrl)static List<String>extractItem(String text, String prefix, String suffix)extract a subtext from a text.static LongextractLong(String text)extract only number of a alpha numeric stringstatic IntegerextractNumber(String text)extract only number of a alpha numeric stringstatic StringextractNumberAsString(String text)extract only number of a alpha numeric stringstatic FloatextractPrice(String text, String inCurrency, String sep)static StringfirstLetterLower(String string)static StringfirstLetterUpper(String string)static StringframeTokenCaseUnsensitive(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 StringgetColName(int colIndex)static intgetColNum(String colName)static longgetCRC32(String text)static StringgetDateRandomId()return a ID contruct on with the current date : sample : 20101223-4687static StringgetDateRandomIdWithCheck()return a ID contruct on with the current date : sample : 20101223-4687static intgetDigitMod9(String value)static StringgetDirNameFromPath(String path)static StringgetFileExtension(String inFileName)retreive the file extension.static StringgetFileNameFromPath(String path)retreive the file extension.static StringgetFileNameWithoutExtension(String inFileName)retreive the file extension.static StringgetFileSize(String filePath)return a formated size in a String.static StringgetFirstNotNull(String value1, String value2)static StringgetItem(String text, String sep, int i, String defaultValue)get the item from a string with separator. sample : text1,text2,text3 getItem(sample,",",1) = text1static StringgetLanguageFromFileName(String filename)static StringgetLargeRandomIdBase64()generate a id in a String.static StringgetNewToken()static StringgetNumberAsAlphabetic(int number)static StringgetPathType(String path, String prefix)return the type of a path (video, image...)static IntegergetPixelValue(String pxSize)transform a string with size in pixel in integer.static StringgetPropertieskey(String key)static StringgetRandomId()static StringgetRandomIdBase10()generate a id in a String.static StringgetRandomIdBase64()generate a id in a String.static StringgetRandomString(int lenght)static StringgetRandomString(int lenght, String acceptedChars)static StringgetShortRandomId()return a short id (length 10 chars).static Stringhex(byte[] array)static Stringhtml2txt(String html)static inthtmlSize(String str)retreive the size of a String with html code. sample: "aaa´" = 4.static StringindentScss(String scss)static StringindentText(String text, char tokenOpen, char tokenClose, char escapeChar, String alignStr)static booleanisAllEmpty(Object... values)static booleanisAlpha(String str)check if stirng contains only digital numberstatic booleanisCharset(byte[] b, String inCharset)static booleanisContains(String src, String token)static booleanisDigit(char c)static booleanisDigit(String str)check if stirng contains only digital numberstatic booleanisDoc(String fileName)return true if the filename in a document (sp. : word, libreoffice...).static booleanisEditable(String fileName)return true if the filename in a image for wcms (sp. : tif or psd in not a image).static booleanisEditableExtension(String fileExtension)static booleanisEmpty(Object value)static booleanisExcelFile(String fileName)return true if the filename in a image for wcms (sp. : tif or psd in not a image).static booleanisFloat(String str)static booleanisHTML(String fileName)return true if the filename in a html image).static booleanisHTMLStatic(String fileName)static booleanisHTMLText(String text)static booleanisImage(String fileName)return true if the filename in a image for wcms (sp. : tif or psd in not a image).static booleanisImageExtension(String fileExtension)return true if the file extension is an image for wcms (sp. : tif or psd is not an image).static booleanisJpeg(String fileName)return true if the filename in a image for wcms (sp. : tif or psd in not a image).static booleanisJpgExtension(String fileExtension)return true if the file extension is an image for wcms (sp. : tif or psd is not an image).static booleanisLetter(char c)static booleanisLikeNumber(String str)check if string contains somthing similar to digital numberstatic booleanisMail(String email)static booleanisMailURL(String url)static booleanisOneEmpty(Object... values)static booleanisPasswordMath(String pwdData, String userInput, boolean crypted)static booleanisPDF(String fileName)return true if the filename in a PDF file.static booleanisPhoneNumber(String phone)static booleanisProperties(String fileName)static booleanisSound(String fileName)return true if the filename in a sound file image.static booleanisTrue(Object inBool)static booleanisTrue(Object inBool, boolean defaultValue)static booleanisTrue(String bool, boolean defaultValue)static booleanisURL(String url)static booleanisURLFile(String fileName)return true if the filename in a url file).static booleanisVAT(String vat)static booleanisVideo(String fileName)return true if the filename in a video file image).static booleanlistContainsItem(String list, String sep, String item)static voidmain(String[] args)static StringmapToString(Map<String,String> maps)static StringmapToText(Map<String,String> map, String sep)static booleanmatchQuestionPattern(String str, String pattern)Test if a string match with a pattern using '?'.static booleanmatchSimplePattern(String str, String pattern, boolean ignoreCase)Test if a string match with a pattern using '?'static booleanmatchStarPattern(String str, String pattern)Test if a string match with a pattern using stars (*).static Stringmd5(String message)static Stringmd5Hex(String message)static StringmergeString(String sep, String... parts)merge string with 'sep' betweenstatic StringneverEmpty(String inStr, String replaceWith)transform a string empty to a other stringstatic StringneverNull(Object inStr)transform a string null in a empty String.static StringneverNull(Object inStr, String replaceWith)transform a string null in a empty String.static StringneverNullOrEmpty(Object inStr, String replaceWith)static StringnoRepeatChar(String text, char chr)static StringnormalizePhoneNumber(String phone, String countryPrefix)format number to number like : +32486123456static StringonlyAlphaNumeric(String data, boolean stopOnBadChar)static ColorparseColor(String color)parse error without fault, return null if color is unidentified.static DateparseDate(String inDate)static DateparseDate(String inDate, char sep)static DateparseDate(String inDate, String pattern)static DateparseDateOrTime(String inDate)static DateparseDateTime(String inDate, char sep)static DateparseExcelDate(String inDate)static DateparseFileTime(String fileTime)static DateparseInputDate(String inDate)static DateparseInputDateAndTime(String inDate)static LocalDateparseInputLocalDate(String inDate)static LocalTimeparseInputLocalTime(String inTime)static IntegerparseInt(String txt)parse txt, if is'nt integer return 0static intparseInt(String value, int defaultValue)null save parse int.static IntegerparseInt(String txt, Integer defaultValue)parse int, if txt is'nt integer return default value.static DateparseIso8601(String input)static LocalDateparseLocalDate(String inDate, String pattern)static LocalDateTimeparseLocalDateTime(String inDate, String pattern)static LocalTimeparseLocalTime(String inDate, String pattern)static Date[]parseRangeDate(String date)static DateparseSecondFileTime(String fileTime)static DateparseSortableDate(String date)static LocalDateparseSortableLocalDate(String date)static DateparseSortableTime(String date)static DateparseTime(String inDate)static DateparseTimeOnly(String inDate)static StringpropertiesToString(Properties p)static Stringquote(String string)static booleanrangeMatches(String range, Integer value)Test if the value is included in the range.static String[]readLines(String text)static StringremoveAccents(String textWithAccent)static StringremoveCR(String text)remove CR from a Stringstatic StringremoveDuplicateToken(String text, String token)static StringremoveFirstChar(String txt, char c)static StringremoveNumber(String text)static StringremoveQuote(String text)remote " on the start and the end of text, if quote was found.static StringremoveRepeatedChar(String str)static StringremoveRepeatedChar(String str, char c)remove repeated char inside string. sample : "javlo--love" "-" = "javlo-love".static StringremoveSequence(String text, String prefix, String sufix)remove sequence from a string. sample : removeSequence ("slkqfj #dlskj# sdljf", "#", "#") -> slkqfj sdljf.static StringremoveSpecialChars(char c)static StringremoveSpecialChars(String text)static StringremoveTag(String text)remove tag. sample: link -> linkstatic StringrenderDate(LocalDate date)static StringrenderDate(LocalDate date, String pattern)static StringrenderDate(LocalDateTime date, String pattern)static StringrenderDate(LocalTime time, String pattern)static StringrenderDate(Date date)static StringrenderDate(Date date, String pattern)static StringrenderDate(Locale locale, Date date, String pattern)static StringrenderDateAndTime(LocalDateTime date)static StringrenderDateAsRFC822String(LocalDate date)static StringrenderDateAsRFC822String(LocalDateTime date)static StringrenderDateAsRFC822String(ZonedDateTime date)static StringrenderDateAsRFC822String(Date date)static StringrenderDateWithDefaultValue(Date date, String defaultValue)static StringrenderDay(Date date, String lang)static StringrenderDouble(double value, int precision)static StringrenderDouble(double value, int precision, char sep)static StringrenderDouble(double value, Locale locale)static StringrenderDoubleAsPercentage(double value)static StringrenderFileTime(Date date)static StringrenderFullDate(ContentContext ctx, Date date)static StringrenderInputDate(LocalDate inDate)static StringrenderInputDate(Date inDate)static StringrenderLightDate(Date date)static StringrenderMediumDate(ContentContext ctx, Date date)static StringrenderMonthDate(ContentContext ctx, Date date)static StringrenderNumber(int n, int size)static StringrenderNumber(long n, int size)static StringrenderOnlyTime(Date date)static StringrenderPrice(double price, String currency)static StringrenderSecondFileTime(Date date)static StringrenderShortDate(ContentContext ctx, Date date)render a date, search the format in I18n files.static StringrenderShortDateWidthDay(ContentContext ctx, Date date)static StringrenderShortTime(ContentContext ctx, Date date)static StringrenderSize(long size)return a formated size in a String.static StringrenderSortableDate(Date date)static StringrenderSortableTime(Date date)static StringrenderTime(LocalTime time)static StringrenderTime(Date date)static StringrenderTime(ContentContext ctx, Date date)static StringrenderTimeInSecond(long time)static StringrenderTimeOnly(Date date)static StringrenderTimeOnlyShort(Date date)static StringrenderTimeShort(Date date)static StringrenderUserFriendlyDate(Date date)static StringrenderUserFriendlyDate(Locale locale, Date date)static StringrenderUserFriendlyDate(ContentContext ctx, Date date)render a date, search the format in I18n files.static StringrenderUserFriendlyTime(Date date)static StringreplaceBloc(String content, String newBloc, String prefix, String suffix, int insidePosition)replace a bloc, between two prefix and suffix and with char pos inside.static StringreplaceCR(String text, String separator)static StringreplaceFileExtension(String file, String ext)static StringreplaceItem(String text, String newItem, String prefix, String suffix)replace text in larger textstatic DoublesafeParseDouble(String string, Double defaultValue)static IntegersafeParseInt(String string, Integer defaultValue)static LongsafeParseLong(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 StringsetLineSeparator(String text, int maxSize, String lineSeparator)static DatesmartParseDate(String inDate)static DatesmartParseDate(String inDate, String lang)static DatesmartParseDateTime(String inDate)static LocalTimesmartParseTime(String inTime)static StringsnakeToCamel(String str)static StringsortText(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 intstringInArray(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 StringstringToFileName(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 StringstringWithoutSpecialChar(String inStr)static List<String>textToList(String text)static StringtextToList(GlobalContext globalContext, String text, String sep, String layout, boolean autoLink)static StringtextToList(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 StringtimedTokenGenerate(String data, long timeInMillis)static booleantimedTokenValidate(String tokenData, String orignalData, int validityRangeInMinutes, long timeInMillis)static String[]toArrayString(Object[] objArray)static StringtoHTMLAttribute(String value)transform a free value to a attribute xml valuestatic StringtoJsonValue(String data)static StringtoJSString(String inStr)transform a String to insert in a JavaScript.static StringtoLatin(String text)convert to latin alphabetstatic StringtoMaxSize(String str, int size, String sufix)transform a String to a max size. sample: "Welcome in the new wave party" --> "Welcome in the..."static StringtoXMLAttribute(String value)transform a free value to a attribute xml valuestatic Stringtrim(String text)static Stringtrim(String text, char trimChar)replace trimChar at the start and the end of text string. sample : --test-, - >>> teststatic StringtrimAndNullify(String str)static StringtrimInternal(String str)replace all space repeatition with one spacestatic StringtrimLineReturn(String string)static List<String>trimList(Collection<String> list)trim all items of the list.static StringtrimOn(String inText, String token)static StringtrimSpaceAndUnderscore(String inText)static Stringtxt2html(String text)static Stringtxt2htmlCR(String text)replace CR with
and replace special char to html codestatic Map<String,String>uriParamToMap(String uri)static booleanvalidUTF8(byte[] input)static StringwriteLines(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:
FileNotFoundExceptionIOException
-
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:
IOExceptionFileNotFoundException
-
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:
FileNotFoundExceptionIOException
-
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:
IOExceptionFileNotFoundException
-
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:
trueis the value is in the rangefalseotherwise
-
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:
MalformedURLExceptionException
-
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
-
-