com.hlcl.rql.as
Class StringHelper

java.lang.Object
  extended by com.hlcl.rql.as.StringHelper

public class StringHelper
extends java.lang.Object

Utilities for String formatting, manipulation, and queries. More information about this class is available from ostermiller.org.

Since:
ostermillerutils 1.00.00
Author:
Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities

Constructor Summary
StringHelper()
           
 
Method Summary
static void buildFindAnyPattern(java.lang.String[] terms, java.lang.StringBuffer sb)
          Build a regular expression that is each of the terms or'd together.
static java.lang.String buildHtmlA(java.lang.String address, java.lang.String label, boolean shouldOpenInNewWindow)
          Creates the HTML source code for a anchor tag: ....
static java.lang.String buildHtmlMailto(java.lang.String address, java.lang.String label)
          Creates the HTML source code for a simple mailto: anchor tag: ....
static java.lang.String buildHtmlMailto(java.lang.String address, java.lang.String subject, java.lang.String label)
          Creates the HTML source code for a simple mailto: anchor tag: ....
static java.lang.String capitalize(java.lang.String s)
          Changes the first and only the first char of the string s to uppercase.
static java.util.List collectContainedText(java.lang.String s, java.lang.String findList, java.lang.String delimiter, boolean caseSensitive)
          Liefert eine liste aller find strings aus findList, die in s vorkommen.
static java.util.List collectContainedText(java.lang.String s, java.lang.String findList, java.lang.String delimiter, boolean caseSensitive, boolean htmlEncodeFindList)
          Liefert eine liste aller find strings aus findList, die in s vorkommen.
static boolean contains(java.lang.String s, java.lang.String find, boolean ignoreCase)
          Liefert true, wenn find in s enthalten ist.
static boolean contains(java.lang.String listOfPossibleSubstrings, java.lang.String delimiter, java.lang.String value)
          Liefert true, wenn in element (index egal) mindestens ein String aus list enthalten ist, sonst false.
static boolean contains(java.lang.String list, java.lang.String delimiter, java.lang.String element, boolean isCheckCaseSensitive)
          Liefert true, wenn gegebenes element ein Element von list ist, sonst false.
static java.lang.String convertAllHttpLinks(java.lang.String s)
          Convert in given string s all links starting with 'http:' to a HTML link (<a href...>...</a>).
static java.lang.String convertAllHttpLinks(java.lang.String s, boolean correctUppercase)
          Convert in given string s all links starting with 'http:' to a HTML link (<a href...>...</a>).
static java.lang.String convertAllMailLinks(java.lang.String s)
          Convert in given string s all mail links (containing a '@' to a HTML link (<a href...>...</a>).
static java.lang.String convertAllMailLinks(java.lang.String s, boolean correctUppercase)
          Convert in given string s all mail links (containing a '@' to a HTML link (<a href...>...</a>).
static java.lang.String convertCamelCase2words(java.lang.String s, java.lang.String separator)
          Converts the camelcase string s (SanFranciscoBay) into a words (=San Francisco Bay) separated by given separator.
static java.lang.String convertFormattedText2Plain(java.lang.String htmlCode)
          Converts a HTML text editor source code to normal text fitting into a StandardField Text.
static java.lang.String convertTo01(boolean aBoolean)
          Liefert den String '0', falls aBoolean false ist oder '1', falls aBoolean true ist.
static boolean convertToBoolean(java.lang.String trueOrFalseString)
          Liefert boolean true, if and only if the given String is 'true'.
static java.util.Map convertToMap(java.lang.String values, java.lang.String pairSeparator, java.lang.String keyValueSeparator)
          Konvertiert eine Liste von Key-Value Paaren in eine Map.
static java.lang.String convertToPageLink(java.lang.String s, java.lang.String start, java.lang.String end, Page page)
          Konvertiert s zu einem HTML quelltext, wobei ein Seitenlink zwischen start und end zur gegebenen Seite erstellt wird.
static java.lang.String convertToString(boolean trueOrFalse)
          Liefert string "true", if and only if the given boolean is true.
static java.lang.String convertToYesNo(boolean aBoolean)
          Liefert den String 'yes', falls aBoolean true ist, sonst 'no'.
static java.lang.String correctUppercase(java.lang.String s)
          Converts the String s to lowercase, but only if s is all uppercase.
static java.lang.String deleteTrail(java.lang.String s, java.lang.String trail)
          Löscht von s den eventuell vorhandenen String trail am Ende.
static java.lang.String encodeHtml(java.lang.String s)
          Encodes given string s into the html entities.
static java.lang.String encodeMailTexts(java.lang.String subjectOrBodyText)
          Encode mail subject and body texts.
static boolean endsWithOneOf(java.lang.String name, java.util.List<java.lang.String> suffixes)
          Liefert true, wenn der gegebene name auf mindestens einen der gegebenen suffixe endet.
static boolean endsWithOneOf(java.lang.String name, java.lang.String[] suffixes)
          Liefert true, wenn der gegebene name auf mindestens einen der gegebenen suffixe endet.
static boolean endsWithOneOf(java.lang.String name, java.lang.String listOfSuffixes, java.lang.String delimiter)
          Liefert true, wenn der gegebene name auf mindestens einen der gegebenen suffixe endet.
static java.lang.String ensureLength(java.lang.String s, int maxLength)
          Returns s unchanged if length is <= maxLength, otherwise s is cutted to maxLength.
static java.lang.String escapeHTML(java.lang.String s)
          Replaces characters that may be confused by a HTML parser with their equivalent character entity references.
static java.lang.String escapeJavaLiteral(java.lang.String s)
          Replaces characters that are not allowed in a Java style string literal with their escape characters.
static java.lang.String escapeRegularExpressionLiteral(java.lang.String s)
          Escapes characters that have special meaning to regular expressions
static java.lang.String escapeSQL(java.lang.String s)
          Replaces characters that may be confused by an SQL parser with their equivalent escape characters.
static java.lang.String getAttributeValue(java.lang.String markupTag, java.lang.String attributeName)
          Returns the value of attribute (first occurence!) in markupTag or null if not found.
static java.lang.String getFirstLetter(java.lang.String s)
          Returns the first letter of the given string or null, if length = 0.
static java.lang.String getFirstWord(java.lang.String s)
          Liefert das erste Wort (bis zum ersten blank) oder den gesamten string, falls kein blank enthalten.
static java.lang.String getMaxLengthHint(java.lang.String s, int maxLength, int trailLength)
          Liefert den Text aus s trailLength Zeichen vor der maximalen Länge maxLength.
static java.lang.String getStartTag(java.lang.String markup, java.lang.String find)
          Returns the tag from the markup (html, xml) which contains find or null if not found at all in markup.
static java.lang.String getTag(java.lang.String source, java.lang.String tagName)
          Liefert den Text aus source (inkl.
static java.lang.String getTextBetween(java.lang.String s, java.lang.String start, java.lang.String end)
          Liefert den Text aus s zwischen den beiden markern, falls start gefunden wurde, sonst null.
static java.lang.String getTextBetween(java.lang.String s, java.lang.String start, java.lang.String end, java.lang.String notFoundValue)
          Liefert den Text aus s zwischen den beiden markern, falls start gefunden wurde, sonst den notFoundValue.
static java.lang.String getTextBetweenTag(java.lang.String source, java.lang.String tagName)
          Liefert den Text aus sourceCode zwischen dem ersten gefundenen Tag mit dem Namen tagName.
static boolean hasListAtLeastOneValue(java.util.List list)
          Liefert true, wenn in der gegebenen Liste von Strings mindestens ein Wert (nach trim()) enthalten ist, sonst false.
static int indexOfIgnoreCase(java.lang.String s, java.lang.String find)
          Returns the index of the substring find in s ignoring case.
static boolean matches(java.lang.String s, java.lang.String pattern)
          Liefert true, falls der gegebenen String s dem pattern entspricht.
static java.lang.String midpad(java.lang.String s, int length)
          Pad the beginning and end of the given String with spaces until the String is of the given length.
static java.lang.String midpad(java.lang.String s, int length, char c)
          Pad the beginning and end of the given String with the given character until the result is the desired length.
static java.util.List<java.lang.String> orderElements(java.util.Set<java.lang.String> elements, java.lang.String elementOrder, java.lang.String delimiter)
          Order the given set of elements by the delimiter separated list of elements in elementOrder.
static java.util.List posSplit(java.lang.String positionsStr, java.lang.String separator, java.lang.String line)
          Splits the line using fixed positions and collect into an list of strings.
static java.lang.String postpad(java.lang.String s, int length)
          Pad the end of the given String with spaces until the String is of the given length.
static java.lang.String postpad(java.lang.String s, int length, char c)
          Append the given character to the String until the result is the desired length.
static java.lang.String prepad(java.lang.String s, int length)
          Pad the beginning of the given String with spaces until the String is of the given length.
static java.lang.String prepad(java.lang.String s, int length, char c)
          Pre-pend the given character to the String until the result is the desired length.
static java.lang.String removePrefix(java.lang.String s, java.lang.String prefix)
          Try to removes prefix from s.
static java.lang.String removeSuffix(java.lang.String s, java.lang.String suffix)
          Try to emoves suffix from s.
static java.lang.String replace(java.lang.String s, java.lang.String find, java.lang.String replace)
          Replace occurrences of a substring.
static java.lang.String replaceListValues(java.lang.String s, java.lang.String findList, java.lang.String delimiter, java.lang.String replace)
          Ersetzt alle werte aus der liste findList (getrennt duch delimiter) mit replace.
static java.lang.String replaceTagValue(java.lang.String s, java.lang.String tagName, java.lang.String with)
          Ersetzt den Text aus s zwischen dem Tag und , falls beide gefunden wurden, durch with.\n Die Tags bleiben beide erhalten, sie werden nicht entfernt.\n
static java.lang.String replaceText(java.lang.String s, java.lang.String start, java.lang.String end, java.lang.String with)
          Ersetzt den Text aus s von start bis end, falls start gefunden wurde, durch with.\n Die beiden Marker start und end werden dabei entfernt.\n Falls start oder end nicht gefunden wird, bleibt s unverändert.
static java.lang.String replaceTextBetween(java.lang.String s, java.lang.String start, java.lang.String end, java.lang.String with)
          Ersetzt den Text aus s zwischen den beiden markern start und end, falls start gefunden wurde durch with.\n Die beiden Marker start und end bleiben erhalten.\n Falls start oder end nicht gefunden wird, bleibt s unverändert.
static java.lang.String right(java.lang.String s, int fromRight)
          Returns the length character from the right of the given string s.
static java.lang.String shorten(java.lang.String s, int targetLength)
          Shorten the given text to max length targetLength.
static java.util.List<java.lang.String> split(java.lang.String list, char separator)
          Diese Methode spaltet einen String am gegebenen separator auf.
static java.lang.String[] split(java.lang.String s, java.lang.String delimiter)
          Split the given String into tokens.
static java.lang.String[] splitAt1stOccurenceFromLeft(java.lang.String s, java.lang.String delimiter)
          Teilt den gegebenen String s am ersten von links gefundenen Auftreten von delimiter.
static boolean startsWithOneOf(java.lang.String name, java.lang.String listOfPrefixes, java.lang.String delimiter)
          Liefert true, wenn der gegebene name mit mindestens einem der gegebenen prefixe beginnt.
static java.lang.String surroundTag(java.lang.String source, java.lang.String tagName)
          Umgibt den gegebenen source mit einem Tag mit dem gegegenen Namen.
static java.lang.String toString(java.util.List list, java.lang.String delimiter)
          Converts the given list into a String separated by the given delimiter.
static java.lang.String trim(java.lang.String s, java.lang.String c)
          Trim any of the characters contained in the second string from the beginning and end of the first.
static java.lang.String unescapeHTML(java.lang.String s)
          Turn any HTML escape entities in the string into characters and return the resulting string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringHelper

public StringHelper()
Method Detail

buildFindAnyPattern

public static void buildFindAnyPattern(java.lang.String[] terms,
                                       java.lang.StringBuffer sb)
Build a regular expression that is each of the terms or'd together.

Parameters:
terms - a list of search terms.
sb - place to build the regular expression.
Throws:
java.lang.IllegalArgumentException - if the length of terms is zero.
Since:
ostermillerutils 1.02.25

buildHtmlA

public static java.lang.String buildHtmlA(java.lang.String address,
                                          java.lang.String label,
                                          boolean shouldOpenInNewWindow)
Creates the HTML source code for a anchor tag: ....

Parameters:
address - the value of the href attribute
label - the clickable text of the link
shouldOpenInNewWindow - adds a target="_blank" attribut, if true

buildHtmlMailto

public static java.lang.String buildHtmlMailto(java.lang.String address,
                                               java.lang.String label)
Creates the HTML source code for a simple mailto: anchor tag: ....

Parameters:
address - the mail address
label - the clickable text of the link

buildHtmlMailto

public static java.lang.String buildHtmlMailto(java.lang.String address,
                                               java.lang.String subject,
                                               java.lang.String label)
Creates the HTML source code for a simple mailto: anchor tag: ....

Parameters:
address - the mail address
subject - the subject information
label - the clickable text of the link

capitalize

public static java.lang.String capitalize(java.lang.String s)
Changes the first and only the first char of the string s to uppercase. All other letters are converted to lowercase.


collectContainedText

public static java.util.List collectContainedText(java.lang.String s,
                                                  java.lang.String findList,
                                                  java.lang.String delimiter,
                                                  boolean caseSensitive)
Liefert eine liste aller find strings aus findList, die in s vorkommen. Ist die zurückgegebene Liste leer, wurde nichts in s gefunden.

Checked case sensitive with indexOf().

Parameters:
s - the string to search
findList - the list with strings to check for; for instance HLCL,Container Line,Container Linie
delimiter - the ,
caseSensitive - case sensitive search or not; to ignore case set to false
Returns:
a list of elements of findList

collectContainedText

public static java.util.List collectContainedText(java.lang.String s,
                                                  java.lang.String findList,
                                                  java.lang.String delimiter,
                                                  boolean caseSensitive,
                                                  boolean htmlEncodeFindList)
Liefert eine liste aller find strings aus findList, die in s vorkommen. Ist die zurückgegebene Liste leer, wurde nichts in s gefunden.

Checked case sensitive with indexOf().

Parameters:
s - the string to search
findList - the list with strings to check for; for instance HLCL,Container Line,Container Linie
delimiter - the ,
caseSensitive - case sensitive search or not; to ignore case set to false
htmlEncodeFindList - =true, try a HTML encode find text search in addition
Returns:
a list of elements of findList

contains

public static boolean contains(java.lang.String s,
                               java.lang.String find,
                               boolean ignoreCase)
Liefert true, wenn find in s enthalten ist. Dabei wird Groß- und Kleinschreibung beachtet, ja nach gegebenem ignoreCase.


contains

public static boolean contains(java.lang.String listOfPossibleSubstrings,
                               java.lang.String delimiter,
                               java.lang.String value)
Liefert true, wenn in element (index egal) mindestens ein String aus list enthalten ist, sonst false.

Checked with indexOf().

Parameters:
listOfPossibleSubstrings - the list; for instance e1,e2,e3
delimiter - the ,
value - is this String contained in at least one element of the given list

contains

public static boolean contains(java.lang.String list,
                               java.lang.String delimiter,
                               java.lang.String element,
                               boolean isCheckCaseSensitive)
Liefert true, wenn gegebenes element ein Element von list ist, sonst false.

Checked with one of equals().

Parameters:
list - the list; for instance e1,e2,e3
delimiter - the ,
element - is this element an element of the given list
isCheckCaseSensitive - =true check with equals =false check with equalsIgnoreCase

convertAllHttpLinks

public static java.lang.String convertAllHttpLinks(java.lang.String s)
Convert in given string s all links starting with 'http:' to a HTML link (<a href...>...</a>). All text starting with http: until the next blank or tag '<' is converted.

Parameters:
s - the string to convert

convertAllHttpLinks

public static java.lang.String convertAllHttpLinks(java.lang.String s,
                                                   boolean correctUppercase)
Convert in given string s all links starting with 'http:' to a HTML link (<a href...>...</a>). All text starting with http: until the next blank or tag '<' is converted.

Parameters:
s - the string to convert
correctUppercase - converts the visible mail address to lowercase

convertAllMailLinks

public static java.lang.String convertAllMailLinks(java.lang.String s)
Convert in given string s all mail links (containing a '@' to a HTML link (<a href...>...</a>). Start and end is found by next blank or tag '< or >'.

Parameters:
s - the string to convert

convertAllMailLinks

public static java.lang.String convertAllMailLinks(java.lang.String s,
                                                   boolean correctUppercase)
Convert in given string s all mail links (containing a '@' to a HTML link (<a href...>...</a>). Start and end is found by next blank or tag '< or >'.

Parameters:
s - the string to convert
correctUppercase - converts the visible mail address to lowercase

convertTo01

public static java.lang.String convertTo01(boolean aBoolean)
Liefert den String '0', falls aBoolean false ist oder '1', falls aBoolean true ist.


convertToYesNo

public static java.lang.String convertToYesNo(boolean aBoolean)
Liefert den String 'yes', falls aBoolean true ist, sonst 'no'.


convertToBoolean

public static boolean convertToBoolean(java.lang.String trueOrFalseString)
Liefert boolean true, if and only if the given String is 'true'.


convertToString

public static java.lang.String convertToString(boolean trueOrFalse)
Liefert string "true", if and only if the given boolean is true.


convertToMap

public static java.util.Map convertToMap(java.lang.String values,
                                         java.lang.String pairSeparator,
                                         java.lang.String keyValueSeparator)
Konvertiert eine Liste von Key-Value Paaren in eine Map.

Parameters:
values - e.g. SUBJECT=Subject,VESSEL=Vessel,VOY-I=Voyage I
pairSeparator - the ,
keyValueSeparator - the =

convertToPageLink

public static java.lang.String convertToPageLink(java.lang.String s,
                                                 java.lang.String start,
                                                 java.lang.String end,
                                                 Page page)
Konvertiert s zu einem HTML quelltext, wobei ein Seitenlink zwischen start und end zur gegebenen Seite erstellt wird. Die beiden Marker start und end werden dabei entfernt.\n Falls start oder end nicht gefunden wird, bleibt s unverändert.


correctUppercase

public static java.lang.String correctUppercase(java.lang.String s)
Converts the String s to lowercase, but only if s is all uppercase. Example: 'ABC' is converted to 'abc', but 'Abc' is returned unchanged


convertFormattedText2Plain

public static java.lang.String convertFormattedText2Plain(java.lang.String htmlCode)
Converts a HTML text editor source code to normal text fitting into a StandardField Text.

Replaces:   to blank,

Removes:
,

,


deleteTrail

public static java.lang.String deleteTrail(java.lang.String s,
                                           java.lang.String trail)
Löscht von s den eventuell vorhandenen String trail am Ende.


encodeHtml

public static java.lang.String encodeHtml(java.lang.String s)
Encodes given string s into the html entities.

Parameters:
s - String to be encoded

encodeMailTexts

public static java.lang.String encodeMailTexts(java.lang.String subjectOrBodyText)
Encode mail subject and body texts. Use URLEncoder, but replace the + with space again.

Parameters:
subjectOrBodyText - text to convert

endsWithOneOf

public static boolean endsWithOneOf(java.lang.String name,
                                    java.lang.String[] suffixes)
Liefert true, wenn der gegebene name auf mindestens einen der gegebenen suffixe endet.

Parameters:
suffixes - list of possible suffixes
name - string to check

startsWithOneOf

public static boolean startsWithOneOf(java.lang.String name,
                                      java.lang.String listOfPrefixes,
                                      java.lang.String delimiter)
Liefert true, wenn der gegebene name mit mindestens einem der gegebenen prefixe beginnt.


endsWithOneOf

public static boolean endsWithOneOf(java.lang.String name,
                                    java.util.List<java.lang.String> suffixes)
Liefert true, wenn der gegebene name auf mindestens einen der gegebenen suffixe endet.

Parameters:
suffixes - list of possible suffixes
name - string to check

endsWithOneOf

public static boolean endsWithOneOf(java.lang.String name,
                                    java.lang.String listOfSuffixes,
                                    java.lang.String delimiter)
Liefert true, wenn der gegebene name auf mindestens einen der gegebenen suffixe endet.

Parameters:
listOfSuffixes - list of possible suffixes
name - string to check

escapeHTML

public static java.lang.String escapeHTML(java.lang.String s)
Replaces characters that may be confused by a HTML parser with their equivalent character entity references.

Any data that will appear as text on a web page should be be escaped. This is especially important for data that comes from untrusted sources such as Internet users. A common mistake in CGI programming is to ask a user for data and then put that data on a web page. For example:

 Server: What is your name?
 User: <b>Joe<b>
 Server: Hello <b>Joe</b>, Welcome
 
If the name is put on the page without checking that it doesn't contain HTML code or without sanitizing that HTML code, the user could reformat the page, insert scripts, and control the the content on your web server.

This method will replace HTML characters such as > with their HTML entity reference (&gt;) so that the html parser will be sure to interpret them as plain text rather than HTML or script.

This method should be used for both data to be displayed in text in the html document, and data put in form elements. For example:
<html><body>This in not a &lt;tag&gt; in HTML</body></html>
and
<form><input type="hidden" name="date" value="This data could be &quot;malicious&quot;"></form>
In the second example, the form data would be properly be resubmitted to your cgi script in the URLEncoded format:
This data could be %22malicious%22

Parameters:
s - String to be escaped
Returns:
escaped String
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

escapeJavaLiteral

public static java.lang.String escapeJavaLiteral(java.lang.String s)
Replaces characters that are not allowed in a Java style string literal with their escape characters. Specifically quote ("), single quote ('), new line (\n), carriage return (\r), and backslash (\), and tab (\t) are escaped.

Parameters:
s - String to be escaped
Returns:
escaped String
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

escapeRegularExpressionLiteral

public static java.lang.String escapeRegularExpressionLiteral(java.lang.String s)
Escapes characters that have special meaning to regular expressions

Parameters:
s - String to be escaped
Returns:
escaped String
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.02.25

escapeSQL

public static java.lang.String escapeSQL(java.lang.String s)
Replaces characters that may be confused by an SQL parser with their equivalent escape characters.

Any data that will be put in an SQL query should be be escaped. This is especially important for data that comes from untrusted sources such as Internet users.

For example if you had the following SQL query:
"SELECT * FROM addresses WHERE name='" + name + "' AND private='N'"
Without this function a user could give " OR 1=1 OR ''='" as their name causing the query to be:
"SELECT * FROM addresses WHERE name='' OR 1=1 OR ''='' AND private='N'"
which will give all addresses, including private ones.
Correct usage would be:
"SELECT * FROM addresses WHERE name='" + StringHelper.escapeSQL(name) + "' AND private='N'"

Another way to avoid this problem is to use a PreparedStatement with appropriate placeholders.

Parameters:
s - String to be escaped
Returns:
escaped String
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

getAttributeValue

public static java.lang.String getAttributeValue(java.lang.String markupTag,
                                                 java.lang.String attributeName)
Returns the value of attribute (first occurence!) in markupTag or null if not found. Case ignored.


getFirstLetter

public static java.lang.String getFirstLetter(java.lang.String s)
Returns the first letter of the given string or null, if length = 0.


getFirstWord

public static java.lang.String getFirstWord(java.lang.String s)
Liefert das erste Wort (bis zum ersten blank) oder den gesamten string, falls kein blank enthalten.


getMaxLengthHint

public static java.lang.String getMaxLengthHint(java.lang.String s,
                                                int maxLength,
                                                int trailLength)
Liefert den Text aus s trailLength Zeichen vor der maximalen Länge maxLength.

Liefert einen Leerstring, falls maxLength > s.length() and s, falls trailLength >= maxLength.


getStartTag

public static java.lang.String getStartTag(java.lang.String markup,
                                           java.lang.String find)
Returns the tag from the markup (html, xml) which contains find or null if not found at all in markup. Case ignored.


getTextBetween

public static java.lang.String getTextBetween(java.lang.String s,
                                              java.lang.String start,
                                              java.lang.String end)
Liefert den Text aus s zwischen den beiden markern, falls start gefunden wurde, sonst null.


getTextBetween

public static java.lang.String getTextBetween(java.lang.String s,
                                              java.lang.String start,
                                              java.lang.String end,
                                              java.lang.String notFoundValue)
Liefert den Text aus s zwischen den beiden markern, falls start gefunden wurde, sonst den notFoundValue.


getTag

public static java.lang.String getTag(java.lang.String source,
                                      java.lang.String tagName)
Liefert den Text aus source (inkl. des tags) des ersten gefundenen Tags mit dem Namen tagName. Liefert null, falls das Tag gar nicht vorkommt.


surroundTag

public static java.lang.String surroundTag(java.lang.String source,
                                           java.lang.String tagName)
Umgibt den gegebenen source mit einem Tag mit dem gegegenen Namen.


getTextBetweenTag

public static java.lang.String getTextBetweenTag(java.lang.String source,
                                                 java.lang.String tagName)
Liefert den Text aus sourceCode zwischen dem ersten gefundenen Tag mit dem Namen tagName. Liefert null, falls das Tag gar nicht vorkommt.


hasListAtLeastOneValue

public static boolean hasListAtLeastOneValue(java.util.List list)
Liefert true, wenn in der gegebenen Liste von Strings mindestens ein Wert (nach trim()) enthalten ist, sonst false.

Parameters:
list - list of strings

indexOfIgnoreCase

public static int indexOfIgnoreCase(java.lang.String s,
                                    java.lang.String find)
Returns the index of the substring find in s ignoring case.


matches

public static boolean matches(java.lang.String s,
                              java.lang.String pattern)
Liefert true, falls der gegebenen String s dem pattern entspricht.

Parameters:
s - String to check
pattern - ein String, der genau einen wildcard * enthält; alle checks sind case sensitive!

midpad

public static java.lang.String midpad(java.lang.String s,
                                      int length)
Pad the beginning and end of the given String with spaces until the String is of the given length. The result is that the original String is centered in the middle of the new string.

If the number of characters to pad is even, then the padding will be split evenly between the beginning and end, otherwise, the extra character will be added to the end.

If a String is longer than the desired length, it will not be truncated, however no padding will be added.

Parameters:
s - String to be padded.
length - desired length of result.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

midpad

public static java.lang.String midpad(java.lang.String s,
                                      int length,
                                      char c)
Pad the beginning and end of the given String with the given character until the result is the desired length. The result is that the original String is centered in the middle of the new string.

If the number of characters to pad is even, then the padding will be split evenly between the beginning and end, otherwise, the extra character will be added to the end.

If a String is longer than the desired length, it will not be truncated, however no padding will be added.

Parameters:
s - String to be padded.
length - desired length of result.
c - padding character.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

posSplit

public static java.util.List posSplit(java.lang.String positionsStr,
                                      java.lang.String separator,
                                      java.lang.String line)
Splits the line using fixed positions and collect into an list of strings.

Parameters:
positionsStr - separated list of start positions of each field e.g. 0,8,12,20
separator - the one size string separating field positions in positions
line - string to split
Returns:
list of trimmed strings; length same as given in positions

postpad

public static java.lang.String postpad(java.lang.String s,
                                       int length)
Pad the end of the given String with spaces until the String is of the given length.

If a String is longer than the desired length, it will not be truncated, however no padding will be added.

Parameters:
s - String to be padded.
length - desired length of result.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

postpad

public static java.lang.String postpad(java.lang.String s,
                                       int length,
                                       char c)
Append the given character to the String until the result is the desired length.

If a String is longer than the desired length, it will not be truncated, however no padding will be added.

Parameters:
s - String to be padded.
length - desired length of result.
c - padding character.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

prepad

public static java.lang.String prepad(java.lang.String s,
                                      int length)
Pad the beginning of the given String with spaces until the String is of the given length.

If a String is longer than the desired length, it will not be truncated, however no padding will be added.

Parameters:
s - String to be padded.
length - desired length of result.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

prepad

public static java.lang.String prepad(java.lang.String s,
                                      int length,
                                      char c)
Pre-pend the given character to the String until the result is the desired length.

If a String is longer than the desired length, it will not be truncated, however no padding will be added.

Parameters:
s - String to be padded.
length - desired length of result.
c - padding character.
Returns:
padded String.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

replace

public static java.lang.String replace(java.lang.String s,
                                       java.lang.String find,
                                       java.lang.String replace)
Replace occurrences of a substring. StringHelper.replace("1-2-3", "-", "|");
result: "1|2|3"
StringHelper.replace("-1--2-", "-", "|");
result: "|1||2|"
StringHelper.replace("123", "", "|");
result: "123"
StringHelper.replace("1-2---3----4", "--", "|");
result: "1-2|-3||4"
StringHelper.replace("1-2---3----4", "--", "---");
result: "1-2----3------4"

Parameters:
s - String to be modified.
find - String to find.
replace - String to replace.
Returns:
a string with all the occurrences of the string to find replaced.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

replaceTagValue

public static java.lang.String replaceTagValue(java.lang.String s,
                                               java.lang.String tagName,
                                               java.lang.String with)
Ersetzt den Text aus s zwischen dem Tag und , falls beide gefunden wurden, durch with.\n Die Tags bleiben beide erhalten, sie werden nicht entfernt.\n


replaceListValues

public static java.lang.String replaceListValues(java.lang.String s,
                                                 java.lang.String findList,
                                                 java.lang.String delimiter,
                                                 java.lang.String replace)
Ersetzt alle werte aus der liste findList (getrennt duch delimiter) mit replace.


replaceText

public static java.lang.String replaceText(java.lang.String s,
                                           java.lang.String start,
                                           java.lang.String end,
                                           java.lang.String with)
Ersetzt den Text aus s von start bis end, falls start gefunden wurde, durch with.\n Die beiden Marker start und end werden dabei entfernt.\n Falls start oder end nicht gefunden wird, bleibt s unverändert.


replaceTextBetween

public static java.lang.String replaceTextBetween(java.lang.String s,
                                                  java.lang.String start,
                                                  java.lang.String end,
                                                  java.lang.String with)
Ersetzt den Text aus s zwischen den beiden markern start und end, falls start gefunden wurde durch with.\n Die beiden Marker start und end bleiben erhalten.\n Falls start oder end nicht gefunden wird, bleibt s unverändert.


right

public static java.lang.String right(java.lang.String s,
                                     int fromRight)
Returns the length character from the right of the given string s.


removePrefix

public static java.lang.String removePrefix(java.lang.String s,
                                            java.lang.String prefix)
Try to removes prefix from s. If s doen't starts with prefix return s unchanged.


removeSuffix

public static java.lang.String removeSuffix(java.lang.String s,
                                            java.lang.String suffix)
Try to emoves suffix from s. If s doen't ends with suffix return s unchanged.


ensureLength

public static java.lang.String ensureLength(java.lang.String s,
                                            int maxLength)
Returns s unchanged if length is <= maxLength, otherwise s is cutted to maxLength.


convertCamelCase2words

public static java.lang.String convertCamelCase2words(java.lang.String s,
                                                      java.lang.String separator)
Converts the camelcase string s (SanFranciscoBay) into a words (=San Francisco Bay) separated by given separator.


shorten

public static java.lang.String shorten(java.lang.String s,
                                       int targetLength)
Shorten the given text to max length targetLength. The ... are inserted in the middle.


split

public static java.util.List<java.lang.String> split(java.lang.String list,
                                                     char separator)
Diese Methode spaltet einen String am gegebenen separator auf.

Parameters:
list - string which needs to be splitted
separator - delimiter of items
Returns:
List

split

public static java.lang.String[] split(java.lang.String s,
                                       java.lang.String delimiter)
Split the given String into tokens.

This method is meant to be similar to the split function in other programming languages but it does not use regular expressions. Rather the String is split on a single String literal.

Unlike java.util.StringTokenizer which accepts multiple character tokens as delimiters, the delimiter here is a single String literal.

Each null token is returned as an empty String. Delimiters are never returned as tokens.

If there is no delimiter because it is either empty or null, the only element in the result is the original String.

StringHelper.split("1-2-3", "-");
result: {"1", "2", "3"}
StringHelper.split("-1--2-", "-");
result: {"", "1", ,"", "2", ""}
StringHelper.split("123", "");
result: {"123"}
StringHelper.split("1-2---3----4", "--");
result: {"1-2", "-3", "", "4"}

Parameters:
s - String to be split.
delimiter - String literal on which to split.
Returns:
an array of tokens.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

splitAt1stOccurenceFromLeft

public static java.lang.String[] splitAt1stOccurenceFromLeft(java.lang.String s,
                                                             java.lang.String delimiter)
Teilt den gegebenen String s am ersten von links gefundenen Auftreten von delimiter. Der delimiter selbst wird nicht zurückgegeben. Liefert ein Array zurück:

[0] - links des String delimiter (oder empty String, falls delimiter nicht in s) [1] - rechts von delimiter (oder der gesamte Strings, falls delimiter nicht in s)


toString

public static java.lang.String toString(java.util.List list,
                                        java.lang.String delimiter)
Converts the given list into a String separated by the given delimiter.


orderElements

public static java.util.List<java.lang.String> orderElements(java.util.Set<java.lang.String> elements,
                                                             java.lang.String elementOrder,
                                                             java.lang.String delimiter)
Order the given set of elements by the delimiter separated list of elements in elementOrder.

Returns only elements contained in elementOrder!


trim

public static java.lang.String trim(java.lang.String s,
                                    java.lang.String c)
Trim any of the characters contained in the second string from the beginning and end of the first.

Parameters:
s - String to be trimmed.
c - list of characters to trim from s.
Returns:
trimmed String.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00

unescapeHTML

public static java.lang.String unescapeHTML(java.lang.String s)
Turn any HTML escape entities in the string into characters and return the resulting string.

Parameters:
s - String to be unescaped.
Returns:
unescaped String.
Throws:
java.lang.NullPointerException - if s is null.
Since:
ostermillerutils 1.00.00