Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
PETALS - PETALS Services Platform. Copyright (c) 2005-2006 EBM WebSourcing, http://www.ebmwebsourcing.com/ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------------------- $Id: SourceHelper.java 94 2006-03-26 17:11:05Z alouis $ -------------------------------------------------------------------------
 
 
 package org.ow2.petals.component.framework.util;
 
 import java.util.List;
Initial developer(s): Adrien LOUIS

Author(s):
alouis - EBM Websourcing
ofabre - EBM Websourcing
Since:
1.0
 
 public final class StringHelper {
 
     private StringHelper() {
         super();
     }

    
Test the equality of the specified strings. test is : ( (a==b==null) || a.equals(b) )

Parameters:
a
b
Returns:
 
     public static boolean equal(final String afinal String b) {
         boolean result;
         if (a == null) {
             result = b == null;
         } else {
             result = a.equals(b);
         }
         return result;
     }

    
Same as equal, with ignoreCase

Parameters:
a
b
Returns:
 
     public static boolean equalIgnoreCase(final String afinal String b) {
         boolean result;
         if (a == null) {
             result = b == null;
         } else {
             result = a.equalsIgnoreCase(b);
         }
         return result;
     }

    
TODO use Tokenizer Extract in the given String the value corresponding to the given attribute: ".......<ATTRIBUTE>=VALUE<SEPARATOR>......". - not case sensitive - return the first value for the first matching attribute - the separator between ATT and VALUE must be : "="

Parameters:
string can be null or empty (return null)
attribute can be null or empty (return null)
separator (";"," ","&"...) can be null or empty. in this case, take the end of the String : "ATT=<VALUE etc etc>"
Returns:
the found attribute value, null otherwise
 
     public static String extractValueForAttribute(final String stringfinal String attribute,
             final String separator) {
         String result = null;
 
         // check string and att are not empty
         if (!isNullOrEmpty(string) && !isNullOrEmpty(attribute)) {
             // find start index
            int start = string.indexOf(attribute);
            if (start >= 0 && start < string.length()) {
                start += attribute.length() + 1;
                if (start < string.length()) {
                    // find end index
                    int end = 0;
                    if (isNullOrEmpty(separator)) {
                        // no separator, end = end of string
                        end = string.length();
                    } else {
                        // a separator is specified, find end index
                        end = string.indexOf(separatorstart);
                        if (end < 0) {
                            end = string.length();
                        }
                    }
                    result = string.substring(startend);
                }
            }
        }
        return result;
    }

    
Return true if the String is null or its size is 0.

Parameters:
s
Returns:
    public static boolean isNullOrEmpty(final String s) {
        return (s == null) || s.trim().equals("");
    }

    
Split the given String path into String path elements. For example, the following path "/foo/bar" will be split into two parts "foo" and "bar", returned in List. If the given path includes empty path elements (Ex: "/foo//bar//"), the returned List doesn't contain these elements (for this exemple result will be "foo","bar").

Parameters:
path the String path to split, can be null or empty (return an empty ArrayList)
Returns:
a List of String path elements, cannot be null, can be empty
    public static List<StringsplitPathElements(final String path) {
        List<StringpathElements = new ArrayList<String>();
        if (!isNullOrEmpty(path)) {
            StringTokenizer tokenizer = new StringTokenizer(path"/");
            while (tokenizer.hasMoreTokens()) {
                pathElements.add(tokenizer.nextToken());
            }
        }
        return pathElements;
    }

    
Replace an old character by a new one in the given string

Parameters:
line the String to modify
oldChar the character to be replaced
newChar the replacement character
Returns:
the new String with character replaced
    public static String replace(String linechar oldCharchar newChar) {
        String result = "";
        if (line != null) {
            for (int j = 0; j < line.length(); j++) {
                if (line.charAt(j) == oldChar) {
                    result += newChar;
                } else {
                    result += line.charAt(j);
                }
            }
        }
        return result;
    }
New to GrepCode? Check out our FAQ X