public void setRuntimes(String sRuntimes){ this.runtimes = StringUtil.splitString(sRuntimes, ','); } public boolean hasRuntime(String runtime) {
/** * Breaks a string into an array of substrings, with the delimeter removed. * The delimeter character passed as aparanmeter. Note that * <CODE>java.util.StringTokenizer</CODE> offers similar functionality. * This method differs by the fact that it returns all of the tokens at once, * using a String array, and does not require the explicit creation of a tokenizer * object. This function also returns empty strings when delimiters are concatened, * which is not the case of <CODE>java.util.StringTokenizer</CODE>. Finally, * the delimiter is unique and passed as a char, which makes the method much faster.<BR> * The returned strings are *not* trimmed. * @param s the string to split * @param c the delimeter * @return the substrings of s * @ibm-api */ public static final String[] splitString(String s, char sep) { return splitString(s,sep,false); }
/** * Breaks a string into an array of substrings, with the delimeter removed. * The delimeter character passed as aparanmeter. Note that * <CODE>java.util.StringTokenizer</CODE> offers similar functionality. * This method differs by the fact that it returns all of the tokens at once, * using a String array, and does not require the explicit creation of a tokenizer * object. This function also returns empty strings when delimiters are concatened, * which is not the case of <CODE>java.util.StringTokenizer</CODE>. Finally, * the delimiter is unique and passed as a char, which makes the method much faster.<BR> * The returned strings are *not* trimmed. * @param s the string to split * @param c the delimeter * @return the substrings of s * @ibm-api */ public static final String[] splitString(String s, char sep) { return splitString(s,sep,false); }
/** * Breaks a string into an array of substrings, with the delimeter removed. * The delimeter character passed as aparanmeter. Note that * <CODE>java.util.StringTokenizer</CODE> offers similar functionality. * This method differs by the fact that it returns all of the tokens at once, * using a String array, and does not require the explicit creation of a tokenizer * object. This function also returns empty strings when delimiters are concatened, * which is not the case of <CODE>java.util.StringTokenizer</CODE>. Finally, * the delimiter is unique and passed as a char, which makes the method much faster.<BR> * @param s the string to split * @param c the delimeter * @param trim indicates if the strings returned should be trimmed * @return the substrings of s * @ibm-api */ public static String[] splitString( String s, char sep, boolean trim ) { if( s==null ) { return EMPTY_STRING_ARRAY; } return splitString( null, 0, s, 0, sep, trim ); } private static String[] splitString( String[] result, int count, String s, int pos, char sep, boolean trim ) {
/** * Breaks a string into an array of substrings, with the delimeter removed. * The delimeter character passed as aparanmeter. Note that * <CODE>java.util.StringTokenizer</CODE> offers similar functionality. * This method differs by the fact that it returns all of the tokens at once, * using a String array, and does not require the explicit creation of a tokenizer * object. This function also returns empty strings when delimiters are concatened, * which is not the case of <CODE>java.util.StringTokenizer</CODE>. Finally, * the delimiter is unique and passed as a char, which makes the method much faster.<BR> * @param s the string to split * @param c the delimeter * @param trim indicates if the strings returned should be trimmed * @return the substrings of s * @ibm-api */ public static String[] splitString( String s, char sep, boolean trim ) { if( s==null ) { return EMPTY_STRING_ARRAY; } return splitString( null, 0, s, 0, sep, trim ); } private static String[] splitString( String[] result, int count, String s, int pos, char sep, boolean trim ) {
protected static String[] decodeCookieNameAndPath(String encoded) throws ServletException { try { String s = URLDecoder.decode(encoded, "UTF-8"); return StringUtil.splitString(s, ';'); } catch (UnsupportedEncodingException e) { return null; } }
/** * Gets the specified part out of a parameter of format * name=xxx[|value=xxx][|label=xxx][|idHelpSnippet=snippet_id][|required] * * If a part is followed by '=' then the part after '=' is returned, else it just returns the part. * Here the parameter is already split into name=value sections. * @param parts The parameter split into name=value pieces. * @param part The part to be retrieved. * @return */ public static String getParameterPart(String[] parts, String part){ for(int i = 0; i < parts.length; i++){ String[] splitParts = StringUtil.splitString(parts[i], '='); if(splitParts[0].equals(part)){ if(splitParts.length == 1){ return splitParts[0]; } else{ return splitParts[1]; } } } return null; }
private static String[] splitString( String[] result, int count, String s, int pos, String sep, boolean trim ) { int newPos = s.indexOf(sep,pos); if( newPos>=0 ) { result = splitString( null, count+1, s, newPos+sep.length(), sep, trim ); result[count] = s.substring( pos, newPos ); } else { result = new String[count+1]; result[count] = s.substring( pos ); } if(trim) { result[count] = result[count].trim(); } return result; }
private static String[] splitString( String[] result, int count, String s, int pos, char sep, boolean trim ) { int newPos = s.indexOf(sep,pos); if( newPos>=0 ) { result = splitString( null, count+1, s, newPos+1, sep, trim ); result[count] = s.substring( pos, newPos ); } else { result = new String[count+1]; result[count] = s.substring( pos ); } if(trim) { result[count] = result[count].trim(); } return result; } public static String[] splitString( String s, String sep, boolean trim ) {
private static String[] splitString( String[] result, int count, String s, int pos, char sep, boolean trim ) { int newPos = s.indexOf(sep,pos); if( newPos>=0 ) { result = splitString( null, count+1, s, newPos+1, sep, trim ); result[count] = s.substring( pos, newPos ); } else { result = new String[count+1]; result[count] = s.substring( pos ); } if(trim) { result[count] = result[count].trim(); } return result; } public static String[] splitString( String s, String sep, boolean trim ) {
private static String[] splitString( String[] result, int count, String s, int pos, String sep, boolean trim ) { int newPos = s.indexOf(sep,pos); if( newPos>=0 ) { result = splitString( null, count+1, s, newPos+sep.length(), sep, trim ); result[count] = s.substring( pos, newPos ); } else { result = new String[count+1]; result[count] = s.substring( pos ); } if(trim) { result[count] = result[count].trim(); } return result; }
protected String normalizeVersion(String version) { if (StringUtil.isEmpty(version)) { return ""; } String[] split = StringUtil.splitString(version, '.'); StringBuilder sb = new StringBuilder(); for (String part : split) { sb.append(String.format("%4s", part)); } return sb.toString(); }
/** * Splits the parameter into sections and returns the value of part. * @param parameter * @param part * @return */ public static String getParameterPart(String parameter, String part){ if(!parameter.contains("|") && !parameter.contains("=")){ return parameter; } String[] parts = StringUtil.splitString(parameter, '|'); return getParameterPart(parts, part); }
public static String[] splitString( String s, String sep, boolean trim ) { if( s==null ) { return EMPTY_STRING_ARRAY; } if( isEmpty(sep) ){ // Handling this like the JavaScript split method, // if the separator is omitted, the entire string is returned. // Different to the Java String split method, which returns // an array full with entries for each character. return new String[]{s}; } return splitString( null, 0, s, 0, sep, trim ); } private static String[] splitString( String[] result, int count, String s, int pos, String sep, boolean trim ) {
public static String[] splitString( String s, String sep, boolean trim ) { if( s==null ) { return EMPTY_STRING_ARRAY; } if( isEmpty(sep) ){ // Handling this like the JavaScript split method, // if the separator is omitted, the entire string is returned. // Different to the Java String split method, which returns // an array full with entries for each character. return new String[]{s}; } return splitString( null, 0, s, 0, sep, trim ); } private static String[] splitString( String[] result, int count, String s, int pos, String sep, boolean trim ) {
public String getRawCookieValue(javax.servlet.http.Cookie cookie, HttpServletRequest request) { try { String header = request.getHeader("cookie"); String[] headerParts = StringUtil.splitString(header, "; ", false); String name = cookie.getName(); for (int i=0; i<headerParts.length; i++) { String cookieHeader = headerParts[i]; if (cookieHeader.startsWith(name)) { String value = cookieHeader.substring(name.length()+1); return value; } } } catch (Exception e) { if (logger.isLoggable(Level.INFO)) { logger.log(Level.INFO, "Unable to parse cookie header", e); } } return cookie.getValue(); }
public static DefaultHttpClient wrapHttpClient(DefaultHttpClient client,String httpProxy){ if(StringUtil.isEmpty(httpProxy)) { return client; } String[] parts = StringUtil.splitString(httpProxy, ':'); String host = parts[0]; int port = DEFAULT_PORT; if (parts.length > 1) { try { port = Integer.parseInt(parts[1]); } catch (NumberFormatException nfe) { // TODO add logging return client; } } return wrapHttpClient(client,host,port); }
/** * */ public static final int getJavaVersion() { if( javaVersion<0 ) { try { javaVersion=0; String[] v = StringUtil.splitString(System.getProperty("java.version"),'.',true);//NORES //$NON-NLS-1$ if( v.length>=1 ) { int major = parseInt(v[0]); int minor = v.length>=2 ? parseInt(v[1]) : 0; int minor2 = v.length>=3 ? parseInt(v[2]) : 0; javaVersion = major*100 + minor*10 + minor2; } } catch( Exception e ) { // If we cannot get the version for any reason, // simply assume java2 javaVersion = 120; } } return javaVersion; } private static final int parseInt( String s ) {
/** * Parse a list of endpoints from a comma delimited string and create an array if non empty. * @param sEndpoints * @return Endpoint * @throws IOException */ public static Endpoint[] parseEndpoints(String sEndpoints) { if(StringUtil.isNotEmpty(sEndpoints)) { String[] a = StringUtil.splitString(sEndpoints, ','); if(a.length>0) { Endpoint[] endpoints = new Endpoint[a.length]; for(int i=0; i<a.length; i++) { Endpoint ep = endpoints[i] = new Endpoint(); // name[:alias] String s = a[i]; int pos = s.indexOf(':'); if(pos>=0) { ep.setName(s.substring(0,pos).trim()); ep.setAlias(s.substring(pos+1).trim()); } else { ep.setName(s); } } return endpoints; } } return null; }
/** * */ public static final int getJavaVersion() { if( javaVersion<0 ) { try { javaVersion=0; String[] v = StringUtil.splitString(System.getProperty("java.version"),'.',true);//NORES //$NON-NLS-1$ if( v.length>=1 ) { int major = parseInt(v[0]); int minor = v.length>=2 ? parseInt(v[1]) : 0; int minor2 = v.length>=3 ? parseInt(v[2]) : 0; javaVersion = major*100 + minor*10 + minor2; } } catch( Exception e ) { // If we cannot get the version for any reason, // simply assume java2 javaVersion = 120; } } return javaVersion; } private static final int parseInt( String s ) {