1 22 23 package org.objectweb.petals.tools.jbicommon.util; 24 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import java.util.StringTokenizer ; 28 29 34 public final class StringHelper { 35 36 private StringHelper() { 37 super(); 38 } 39 40 48 public static boolean equal(final String a, final String b) { 49 boolean result; 50 if (a == null) { 51 result = b == null; 52 } else { 53 result = a.equals(b); 54 } 55 return result; 56 } 57 58 65 public static boolean equalIgnoreCase(final String a, final String b) { 66 boolean result; 67 if (a == null) { 68 result = b == null; 69 } else { 70 result = a.equalsIgnoreCase(b); 71 } 72 return result; 73 } 74 75 91 public static String extractValueForAttribute(final String string, 92 final String attribute, final String separator) { 93 String result = null; 94 95 if (!isNullOrEmpty(string) && !isNullOrEmpty(attribute)) { 97 int start = string.indexOf(attribute); 99 100 if (start >= 0 && start < string.length()) { 101 start += attribute.length() + 1; 102 103 if (start < string.length()) { 104 int end = 0; 106 107 if (isNullOrEmpty(separator)) { 108 end = string.length(); 110 } else { 111 end = string.indexOf(separator, start); 113 114 if (end < 0) { 115 end = string.length(); 116 } 117 } 118 result = string.substring(start, end); 119 } 120 } 121 } 122 return result; 123 } 124 125 131 public static boolean isNullOrEmpty(final String s) { 132 return (s == null) || s.trim().equals(""); 133 } 134 135 147 public static List <String > splitPathElements(final String path) { 148 List <String > pathElements = new ArrayList <String >(); 149 150 if (!isNullOrEmpty(path)) { 151 StringTokenizer tokenizer = new StringTokenizer (path, "/"); 152 153 while (tokenizer.hasMoreTokens()) { 154 pathElements.add(tokenizer.nextToken()); 155 } 156 } 157 return pathElements; 158 } 159 } 160 | Popular Tags |