Example usage for java.util StringTokenizer StringTokenizer

List of usage examples for java.util StringTokenizer StringTokenizer

Introduction

In this page you can find the example usage for java.util StringTokenizer StringTokenizer.

Prototype

public StringTokenizer(String str, String delim) 

Source Link

Document

Constructs a string tokenizer for the specified string.

Usage

From source file:Main.java

/**
 * Calculates the level of a XML path name
 *
 * @param fullName The path name/*from ww  w  .j  a v a 2 s  .  c  o m*/
 * @return the level
 */
public static int getLevel(String fullName) {
    return (new StringTokenizer(fullName, ".")).countTokens();
}

From source file:StringUtil.java

/**
 * replaces all newlines in the given String 's' with the replacement
 * string 'r'. Each line is trimmed from leading and trailing whitespaces,
 * then the new line-delimiter is added.
 *
 * @param s the source string.//from   www.  jav a2 s .  c  o  m
 * @param r the new line delimiter
 * @return the resulting string.
 */
public static final String replaceNewLines(String s, String r) {
    StringBuilder result = new StringBuilder();

    StringTokenizer t = new StringTokenizer(s, "\n");
    while (t.hasMoreTokens()) {
        result.append(t.nextToken().trim()).append(r);
    }
    return result.toString();
}

From source file:Main.java

private static List<String> stringToArray(String str) {
    try {//w w w. java 2 s.  co  m
        List<String> arg = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(str, ",");
        while (st.hasMoreTokens()) {
            arg.add(st.nextToken());
        }
        return arg;
    } catch (Exception e) {
        return null;
    }
}

From source file:com.salesmanager.core.util.LanguageUtil.java

public static List parseLanguages(String langs) {
    List lst = new ArrayList();
    if (langs != null) {
        StringTokenizer st = new StringTokenizer(langs, ";");
        while (st != null && st.hasMoreTokens()) {
            String lang = st.nextToken();
            lst.add(lang);//from  w ww  .ja v  a  2s  . co  m
        }
    }
    return lst;
}

From source file:Main.java

public static String parseValue(Map<String, List<String>> responseHeader, String parentKey, String valueKey) {
    List<String> contentTypes = responseHeader.get(parentKey);
    if (contentTypes != null && contentTypes.size() > 0) {
        String contentType = contentTypes.get(0);
        StringTokenizer stringTokenizer = new StringTokenizer(contentType, ";");
        while (stringTokenizer.hasMoreTokens()) {
            String token = stringTokenizer.nextToken();
            if (token.contains(valueKey)) {
                String[] values = token.split("=");
                if (values.length > 1) {
                    return values[1];
                }/*from ww  w  . j a v a 2s .  c om*/
            }
        }
    }
    return null;
}

From source file:Main.java

protected static String[] split(final String str, final String delimiter) {
    if (str == null || str.trim().length() == 0) {
        return EMPTY_STRINGS;
    }//from w ww. j a  va 2s  . c  o m
    final List<String> list = new ArrayList<String>();
    final StringTokenizer st = new StringTokenizer(str, delimiter);
    while (st.hasMoreElements()) {
        list.add(st.nextToken());
    }
    return (String[]) list.toArray(new String[list.size()]);
}

From source file:Main.java

public static Node createNodeFromPath(Element modelElement, String path) {
    Document document = modelElement.getOwnerDocument();
    StringTokenizer st = new StringTokenizer(path, "/");
    while (st.hasMoreTokens()) {
        String t = st.nextToken();

        if (st.hasMoreTokens()) {
            if (t.equals("..")) {
                modelElement = (Element) modelElement.getParentNode();
            } else {
                Element elm = getFirstChildElement(modelElement, t);
                if (elm == null)
                    modelElement = (Element) modelElement.insertBefore(document.createElement(t),
                            getFirstChildElement(modelElement, t));
                else
                    modelElement = elm;/*from   w  w w. java  2s  . c  o  m*/
            }
        } else {
            modelElement = (Element) modelElement.insertBefore(document.createElement(t),
                    getFirstChildElement(modelElement, t));
        }
    }

    return modelElement;
}

From source file:Main.java

public static Vector<String> getSets(String setString) {
    StringTokenizer tokenizer = new StringTokenizer(setString, ";");
    Vector<String> sets = new Vector<String>();
    while (tokenizer.hasMoreTokens()) {
        sets.add(tokenizer.nextToken());
    }//from w  w w.  j  a  va 2s  .com
    if (sets.size() == 0)
        sets.add("");
    return sets;
}

From source file:Main.java

/**
 * Splits specified string at XML space character boundaries (<tt>'\t'</tt>,
 * <tt>'\r'</tt>, <tt>'\n'</tt>, <tt>' '</tt>). Returns list of
 * parts./*from w  ww . j  a v  a2s  .  co m*/
 * 
 * @param s string to be split
 * @return list of parts
 */
public static final String[] splitList(String s) {
    StringTokenizer tokens = new StringTokenizer(s, " \n\r\t");
    String[] split = new String[tokens.countTokens()];

    for (int i = 0; i < split.length; ++i)
        split[i] = tokens.nextToken();

    return split;
}

From source file:Main.java

public static QName getNamespace(Map<String, String> namespaces, String str, String defaultNamespace) {
    String prefix = null;//from   w  ww  . j a va2 s .  c o m
    String localName = null;

    StringTokenizer tokenizer = new StringTokenizer(str, ":");
    if (tokenizer.countTokens() == 2) {
        prefix = tokenizer.nextToken();
        localName = tokenizer.nextToken();
    } else if (tokenizer.countTokens() == 1) {
        localName = tokenizer.nextToken();
    }

    String namespceURI = defaultNamespace;
    if (prefix != null) {
        namespceURI = namespaces.get(prefix);
    }
    return new QName(namespceURI, localName);
}