diff options
Diffstat (limited to 'moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/StringUtils.java')
-rw-r--r-- | moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/StringUtils.java | 159 |
1 files changed, 78 insertions, 81 deletions
diff --git a/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/StringUtils.java b/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/StringUtils.java index 695be18..4c22340 100644 --- a/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/StringUtils.java +++ b/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/StringUtils.java @@ -21,59 +21,59 @@ * that you distribute must include a readable copy of the "NOTICE" text file. */ - package at.gv.egovernment.moaspss.util; import java.util.StringTokenizer; /** * Utitility functions for string manipulations. - * + * * @author Harald Bratko */ public class StringUtils { /** * Removes all blanks and tabs from the given string. - * + * * @param s The string to remove all blanks and tabs from. - * @return The input string with all blanks and tabs removed from. + * @return The input string with all blanks and tabs removed from. */ public static String removeBlanks(String s) { - StringTokenizer st = new StringTokenizer(s); - StringBuffer sb = new StringBuffer(s.length()); + final StringTokenizer st = new StringTokenizer(s); + final StringBuffer sb = new StringBuffer(s.length()); while (st.hasMoreTokens()) { sb.append(st.nextToken()); } return sb.toString(); } - + /** * Removes all occurences of the specified token from the the given string. - * + * * @param s The string to remove all occurences of the specified token from. - * @return The input string with all occurences of the specified token removed from. + * @return The input string with all occurences of the specified token removed + * from. */ public static String removeToken(String s, String token) { - StringTokenizer st = new StringTokenizer(s, token); - StringBuffer sb = new StringBuffer(s.length()); + final StringTokenizer st = new StringTokenizer(s, token); + final StringBuffer sb = new StringBuffer(s.length()); while (st.hasMoreTokens()) { sb.append(st.nextToken()); } return sb.toString(); } - + /** * Removes all leading zeros from the input string. - * - * @param s The string remove the leading zeros from. - * @return The input string with the leading zeros removed from. + * + * @param s The string remove the leading zeros from. + * @return The input string with the leading zeros removed from. */ public static String deleteLeadingZeros(String s) { - StringBuffer sb = new StringBuffer(s); - int l = sb.length(); + final StringBuffer sb = new StringBuffer(s); + final int l = sb.length(); int j = 0; - for (int i=0; i<l; i++) { + for (int i = 0; i < l; i++) { if (sb.charAt(i) == '0') { j++; } else { @@ -82,97 +82,94 @@ public class StringUtils { } return sb.substring(j, l); } - + /** * Replaces each substring of string <code>s</code> that matches the given * <code>search</code> string by the given <code>replace</code> string. - * - * @param s The string where the replacement should take place. - * @param search The pattern that should be replaced. - * @param replace The string that should replace all each <code>search</code> - * string within <code>s</code>. - * @return A string where all occurrence of <code>search</code> are - * replaced with <code>replace</code>. + * + * @param s The string where the replacement should take place. + * @param search The pattern that should be replaced. + * @param replace The string that should replace all each <code>search</code> + * string within <code>s</code>. + * @return A string where all occurrence of <code>search</code> are replaced + * with <code>replace</code>. */ - public static String replaceAll (String s, String search, String replace) - { - StringBuffer sb = new StringBuffer(); - int i = 0, j = 0; - int len = search.length(); - while (j > -1) - { - j = s.indexOf(search, i); + public static String replaceAll(String s, String search, String replace) { + final StringBuffer sb = new StringBuffer(); + int i = 0, j = 0; + final int len = search.length(); + while (j > -1) { + j = s.indexOf(search, i); + + if (j > -1) { + sb.append(s.substring(i, j)); + sb.append(replace); + i = j + len; + } + } - if (j > -1) - { - sb.append(s.substring(i,j)); - sb.append(replace); - i = j + len; - } - } - - sb.append(s.substring(i, s.length())); + sb.append(s.substring(i, s.length())); - return sb.toString(); + return sb.toString(); } - + /** - * Changes the SecurityLayer version in the given string. - * This method usually takes as input an XML structure represented in a string - * format and changes the SecurityLayer namespaces prefixes and URIs from - * one SecurityLayer version to another. - * e.g.: code>sl10</code> to <code>sl</code> and - * <code>http://www.buergerkarte.at/namespaces/securitylayer/20020225#</code> - * to - * <code>http://www.buergerkarte.at/namespaces/securitylayer/1.2#</code> - * - * @param s The string (usally an XML structure) where the - * SecurityLayer version should be changed. - * @param slPrefixOld The SecurityLayer namespace prefix that should be - * replaced by the new one. - * @param slPrefixNew The new SecurityLayer namespace prefix that should - * replace the old one. - * @param slNSUriOld The SecurityLayer namespace URI that should be - * replaced by the new one. - * @param slNSUriNew The new SecurityLayer namespace URI that should - * replace the old one. - * @return A string where the SecurityLayer namespace prefixes - * and URIs are replaced by new ones. + * Changes the SecurityLayer version in the given string. This method usually + * takes as input an XML structure represented in a string format and changes + * the SecurityLayer namespaces prefixes and URIs from one SecurityLayer version + * to another. e.g.: code>sl10</code> to <code>sl</code> and + * <code>http://www.buergerkarte.at/namespaces/securitylayer/20020225#</code> to + * <code>http://www.buergerkarte.at/namespaces/securitylayer/1.2#</code> + * + * @param s The string (usally an XML structure) where the + * SecurityLayer version should be changed. + * @param slPrefixOld The SecurityLayer namespace prefix that should be replaced + * by the new one. + * @param slPrefixNew The new SecurityLayer namespace prefix that should replace + * the old one. + * @param slNSUriOld The SecurityLayer namespace URI that should be replaced by + * the new one. + * @param slNSUriNew The new SecurityLayer namespace URI that should replace + * the old one. + * @return A string where the SecurityLayer namespace prefixes and URIs are + * replaced by new ones. */ - public static String changeSLVersion(String s, String slPrefixOld, String slPrefixNew, String slNSUriOld, String slNSUriNew) { + public static String changeSLVersion(String s, String slPrefixOld, String slPrefixNew, String slNSUriOld, + String slNSUriNew) { String retString = replaceAll(s, slPrefixOld, slPrefixNew); retString = replaceAll(retString, slNSUriOld, slNSUriNew); - return retString ; + return retString; } - + /** * Removes the XML declaration from an XML expression. - * + * * @param xmlString XML expression as String - * + * * @return XML expression, XML declaration removed */ public static String removeXMLDeclaration(String xmlString) { - if (xmlString!=null && xmlString.startsWith("<?xml")) { - int firstElement = xmlString.indexOf("<", 1); + if (xmlString != null && xmlString.startsWith("<?xml")) { + final int firstElement = xmlString.indexOf("<", 1); return xmlString.substring(firstElement); } else { return xmlString; } } - + /** * Checks if String is empty + * * @param s String to be checked if empty * @return True if String is empty, false otherwise */ public static boolean isEmpty(String s) { - if (s == null || s.length() == 0) - return true; - else - return false; - + if (s == null || s.length() == 0) { + return true; + } else { + return false; + } + } - - + } |