Example usage for java.util StringTokenizer hasMoreTokens

List of usage examples for java.util StringTokenizer hasMoreTokens

Introduction

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

Prototype

public boolean hasMoreTokens() 

Source Link

Document

Tests if there are more tokens available from this tokenizer's string.

Usage

From source file:com.processpuzzle.internalization.domain.ProcessPuzzleLocale.java

public static ProcessPuzzleLocale parse(String localeSpecifier) {
    if (localeSpecifier == null)
        throw new LocaleParseException(localeSpecifier);
    String language = null;//from   ww  w  .  j a v  a 2 s. co m
    String country = null;
    String variant = null;

    StringTokenizer tokenizer = new StringTokenizer(localeSpecifier, SPECIFIER_DELIMITERS);
    int index = 0;
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if (index == 0)
            language = token.trim();
        if (index == 1)
            country = token.trim();
        if (index == 2)
            variant = token.trim();
        index++;
    }

    ProcessPuzzleLocale locale = null;
    try {
        if (country == null)
            locale = new ProcessPuzzleLocale(language);
        else if (variant == null)
            locale = new ProcessPuzzleLocale(language, country);
        else
            locale = new ProcessPuzzleLocale(language, country, variant);
    } catch (UnsupportedLocaleException e) {
        throw new LocaleParseException(localeSpecifier);
    }
    return locale;
}

From source file:com.silverpeas.jcrutil.BetterRepositoryFactoryBean.java

protected static void prepareContext(InitialContext ic, String jndiName) throws NamingException {
    Context currentContext = ic;/*from w  w w . j  a  v a 2  s. c o  m*/
    StringTokenizer tokenizer = new StringTokenizer(jndiName, "/", false);
    while (tokenizer.hasMoreTokens()) {
        String name = tokenizer.nextToken();
        if (tokenizer.hasMoreTokens()) {
            try {
                currentContext = (Context) currentContext.lookup(name);
            } catch (javax.naming.NameNotFoundException nnfex) {
                currentContext = currentContext.createSubcontext(name);
            }
        }
    }
}

From source file:de.kapsi.net.daap.DaapUtil.java

/**
 * Splits a query String ("key1=value1&key2=value2...") and
 * stores the data in a Map/*from ww w. j  a va 2  s . c  om*/
 * 
 * @param queryString a query String
 * @return the splitten query String as Map
 */
public static final Map parseQuery(String queryString) {

    Map map = new HashMap();

    if (queryString != null && queryString.length() != 0) {
        StringTokenizer tok = new StringTokenizer(queryString, "&");
        while (tok.hasMoreTokens()) {
            String token = tok.nextToken();

            int q = token.indexOf('=');
            if (q != -1 && q != token.length()) {
                String key = token.substring(0, q);
                String value = token.substring(++q);
                map.put(key, value);
            }
        }
    }

    return map;
}

From source file:modula.parser.io.ModelUpdater.java

/**
 * transition//from   www  .j a  v a  2s  .  c  o  m
 */
private static void updateTransition(final SimpleTransition transition,
        final Map<String, TransitionTarget> targets) throws ModelException {
    String next = transition.getNext();
    if (next == null) { // stay transition
        return;
    }
    Set<TransitionTarget> tts = transition.getTargets();
    if (tts.isEmpty()) {
        // 'next' is a space separated list of transition target IDs
        StringTokenizer ids = new StringTokenizer(next);
        while (ids.hasMoreTokens()) {
            String id = ids.nextToken();
            TransitionTarget tt = targets.get(id);
            if (tt == null) {
                logAndThrowModelError(ERR_TARGET_NOT_FOUND, new Object[] { id });
            }
            tts.add(tt);
        }
        if (tts.size() > 1) {
            boolean legal = verifyTransitionTargets(tts);
            if (!legal) {
                logAndThrowModelError(ERR_ILLEGAL_TARGETS, new Object[] { next });
            }
        }
    }
}

From source file:RequestUtil.java

/**
 * Delete a cookie except the designated variable name from CookieString
 * //w ww.  jav  a 2  s  .  com
 * @param cookieString
 * @param paramName
 * @return
 */
public static String removeCookieParam(String cookieString, Set<String> paramNames) {
    StringTokenizer tok = new StringTokenizer(cookieString, ";", false);
    String resultCookieString = "";

    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        int i = token.indexOf("=");
        if (i > -1) {
            for (String paramName : paramNames) {
                String name = token.substring(0, i).trim();
                if (paramName.equalsIgnoreCase(name)) {
                    if (resultCookieString.length() > 0)
                        resultCookieString += ";";
                    resultCookieString += token;
                }
            }
        } else {
            // we have a bad cookie.... just let it go
        }
        if (paramNames.isEmpty()) {
            if (resultCookieString.length() > 0)
                resultCookieString += ";";
            resultCookieString += token;
        }
    }
    return resultCookieString.trim();
}

From source file:fr.gouv.finances.dgfip.xemelios.utils.XmlUtils.java

/**
 * For the moment, this method can only transform very simple XPath, like <tt>/n:foo/b:bar/@a</tt>
 * @param xpath//www. ja  v  a  2s  . co m
 * @param ns
 * @return
 */
public static String normalizeNS(String xpath, NamespaceContext ns) {
    StringTokenizer tokenizer = new StringTokenizer(xpath, "/", true);
    StringBuilder sb = new StringBuilder();
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if (token.equals("/"))
            sb.append(token);
        else {
            boolean isAttribute = false;
            if (token.startsWith("@")) {
                token = token.substring(1);
                isAttribute = true;
            }
            int pos = token.indexOf(':');
            if (pos >= 0) {
                String prefix = token.substring(0, pos);
                String localName = token.substring(pos + 1);
                String newPrefix = ns.getPrefix(ns.getNamespaceURI(prefix));
                if (isAttribute && (newPrefix == null || newPrefix.length() == 0))
                    newPrefix = prefix;
                if (isAttribute)
                    sb.append("@");
                if (newPrefix.length() > 0)
                    sb.append(newPrefix).append(":");
                sb.append(localName);
            } else {
                if (!isAttribute) {
                    String localName = token;
                    if (XmlUtils.isValidNCName(localName)) {
                        String uri = ns.getNamespaceURI("");
                        if (uri != null) {
                            String newPrefix = ns.getPrefix(uri);
                            if (newPrefix.length() > 0)
                                sb.append(newPrefix).append(":");
                        }
                        sb.append(token);
                    } else {
                        sb.append(token);
                    }
                } else {
                    // attribute didn't had a namespace, let it like that
                    sb.append("@").append(token);
                }
            }
        }
    }
    return sb.toString();
}

From source file:ca.on.gov.jus.icon.common.util.JDBCUtils.java

/**
 * Checks a String for single-quote characters and escapes
 * them with another single-quote.  This is necessary for any
 * String used as a parameter in an SQL query.
 *
 * @param   parameter   The String checked for single-quote characters.
 * @return   The String with escaped single-quote characters.
 *///from   www .  ja  va 2  s .com
static public String toDBString(String parameter) {
    final String delimiter = "'";
    boolean returnDelims = true;
    StringBuffer buffer = null;
    StringTokenizer tokenizer = null;
    String dbString = null;

    if (parameter != null) {
        buffer = new StringBuffer();
        tokenizer = new StringTokenizer(parameter, delimiter, returnDelims);

        // Iterater through each occurance or a single-quote.
        while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken();
            buffer.append(token);

            // Check if the current token is the single-quote,
            // and escape it with another single-quote.
            if (token.equals(delimiter)) {
                buffer.append(delimiter);
            }
        }
        dbString = buffer.toString();
    }

    return dbString;
}

From source file:com.cloud.utils.UriUtils.java

private static List<NameValuePair> getUserDetails(String query) {
    List<NameValuePair> details = new ArrayList<NameValuePair>();
    if (query != null && !query.isEmpty()) {
        StringTokenizer allParams = new StringTokenizer(query, "&");
        while (allParams.hasMoreTokens()) {
            String param = allParams.nextToken();
            details.add(new BasicNameValuePair(param.substring(0, param.indexOf("=")),
                    param.substring(param.indexOf("=") + 1)));
        }//from  ww w .j av a  2s.  co  m
    }

    return details;
}

From source file:com.rabbitframework.commons.utils.StringUtils.java

public static List<String> tokenizeToArray(String str, String delimiters, boolean trimTokens,
        boolean ignoreEmptyTokens) {
    if (str == null) {
        return null;
    }//from   www. j  av a 2s .co  m
    StringTokenizer st = new StringTokenizer(str, delimiters);
    List<String> tokens = new ArrayList<String>();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (trimTokens) {
            token = token.trim();
        }
        if (!ignoreEmptyTokens || token.length() > 0) {
            tokens.add(token);
        }
    }
    return tokens;
}

From source file:io.datenwelt.cargo.rest.utils.Rfc2047.java

public static String encodeHeader(String input) {
    StringTokenizer tokenizer = new StringTokenizer(input, "\t ,;:-/=+#*", true);
    CharsetEncoder charsetEncoder = Charset.forName(CharEncoding.ISO_8859_1).newEncoder();
    QCodec qcodec = new QCodec(Charset.forName(CharEncoding.UTF_8));
    StringBuilder encoded = new StringBuilder();
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if (!charsetEncoder.canEncode(token)) {
            try {
                encoded.append(qcodec.encode(token));
            } catch (EncoderException ex) {
                LOG.debug("Skipping the Q encoding of header value for non ISO-8859-1 string: {}", input, ex);
                encoded.append(token);/*from w w  w  . j av  a 2s.c o  m*/
            }
        } else {
            encoded.append(token);
        }
    }
    return encoded.toString();
}