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:com.googlecode.jsfFlex.myFaces.LocaleUtils.java

/**
 * Convert locale string used by converter tags to locale.
 *
 * @param name name of the locale/*from  w ww.  jav a  2 s  . c om*/
 * @return locale specified by the given String
 *
 * @see org.apache.myfaces.taglib.core.ConvertDateTimeTag#setConverterLocale
 * @see org.apache.myfaces.taglib.core.ConvertNumberTag#setConverterLocale
 */
public static Locale converterTagLocaleFromString(String name) {
    try {
        Locale locale;
        StringTokenizer st = new StringTokenizer(name, "_");
        String language = st.nextToken();

        if (st.hasMoreTokens()) {
            String country = st.nextToken();

            if (st.hasMoreTokens()) {
                String variant = st.nextToken();
                locale = new Locale(language, country, variant);
            } else {
                locale = new Locale(language, country);
            }
        } else {
            locale = new Locale(language);
        }

        return locale;
    } catch (Exception e) {
        throw new IllegalArgumentException(
                "Locale parsing exception - " + "invalid string representation '" + name + "'");
    }
}

From source file:org.sonar.server.charts.deprecated.PieChart.java

private void configureColors(String colors) {
    try {//from  ww w.  j  a v  a 2 s .  c o m
        if (colors != null && colors.length() > 0) {
            StringTokenizer stringTokenizer = new StringTokenizer(colors, ",");
            int i = 0;
            while (stringTokenizer.hasMoreTokens()) {
                ((PiePlot) jfreechart.getPlot()).setSectionPaint(Integer.toString(i),
                        Color.decode("0x" + stringTokenizer.nextToken()));
                i++;
            }
        } else {
            configureDefaultColors();
        }
    } catch (Exception e) {
        configureDefaultColors();
    }
}

From source file:at.tuwien.minimee.migration.parser.TIME_Parser.java

/**
 * The line is supposed to look like that: 
 * pCpu:0%,sys:0.00,user:0.00,real:1.00,exit:0
 * @param line//  w  w  w  .j a  v a 2s.c  o m
 */
private void parseLine(String line) {

    StringTokenizer tokenizer = new StringTokenizer(line, ",");

    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();

        int colon = token.indexOf(':');
        if (colon == -1) {
            continue;
        }

        if ("pCpu".compareTo(token.substring(0, colon)) == 0) {

            int pSign = token.indexOf('%');
            if (pSign == -1) {
                continue;
            }

            pCpu = (new Double(token.substring(colon + 1, pSign)));
        } else if ("sys".compareTo(token.substring(0, colon)) == 0) {

            sys = (new Double(token.substring(colon + 1)));

        } else if ("user".compareTo(token.substring(0, colon)) == 0) {

            user = (new Double(token.substring(colon + 1)));

        } else if ("real".compareTo(token.substring(0, colon)) == 0) {

            real = (new Double(token.substring(colon + 1)));

        } else if ("exit".compareTo(token.substring(0, colon)) == 0) {

            exitCode = (new Integer(token.substring(colon + 1)));
        }
    }
}

From source file:org.ambraproject.queue.PMCResponseConsumer.java

/**
 * Message handler method. Message comes in articleId|result|errorMessage format.
 *
 * @param body Message body.//from   w w w . j a  va  2s  . c  o m
 * @throws ApplicationException If operation fails, URISyntaxException if
 *                              <code>updateSyndication</code> method fails to create the Syndication's unique Id.
 * @throws Exception in operation failed.
 */
@Handler
public void handleResponse(@Body String body) throws Exception {

    if (body == null) {
        throw new ApplicationException("PMC response message is null");
    }

    log.info("Received syndication response: " + body);

    StringTokenizer tokenizer = new StringTokenizer(body, SEPARATOR);

    String doi;
    String result;
    String errorMessage = null;

    if (tokenizer.hasMoreTokens()) {
        doi = tokenizer.nextToken();
    } else {
        throw new ApplicationException("Invalid PMC response message received: " + body);
    }

    if (tokenizer.hasMoreTokens()) {
        result = tokenizer.nextToken();
    } else {
        throw new ApplicationException("Invalid PMC response message received: " + body);
    }

    if (tokenizer.hasMoreTokens()) {
        errorMessage = tokenizer.nextToken();
    }

    if (doi == null || doi.equalsIgnoreCase(UNKNOWN)) {
        log.error("Received " + result + " response for unknow DOI. Error message: " + errorMessage);
    } else {
        syndicationService.updateSyndication(doi, "PMC",
                OK.equalsIgnoreCase(result) ? Syndication.STATUS_SUCCESS : Syndication.STATUS_FAILURE,
                errorMessage);
    }
}

From source file:de.tor.tribes.util.parser.TroopsParser70.java

@Override
public boolean parse(String pData) {
    StringTokenizer lineTokenizer = new StringTokenizer(pData, "\n\r");
    List<String> lineList = new LinkedList<>();

    while (lineTokenizer.hasMoreElements()) {
        String line = lineTokenizer.nextToken();
        //"cheap snob rebuild linebreak"-hack
        if (line.trim().endsWith("+")) {
            line += lineTokenizer.nextToken();
        }/*from w w  w  . ja v a  2s .c om*/
        debug("Push line to stack: " + line);
        lineList.add(line);
    }

    // used to update group on the fly, if not "all" selected
    String groupName = null;
    // groups could be multiple lines, detection is easiest for first line (starts with "Gruppen:")
    boolean groupLines = false;
    // store visited villages, so we can add em to selected group
    List<Village> villages = new LinkedList<>();

    int foundTroops = 0;
    TroopsManager.getSingleton().invalidate();
    while (!lineList.isEmpty()) {
        String currentLine = lineList.remove(0);
        Village v = null;
        try {
            v = VillageParser.parseSingleLine(currentLine);
        } catch (Exception e) {
            //no village in line
        }
        if (v != null) {
            if (processEntry(v, currentLine, lineList)) {
                foundTroops++;
                // add village to list of villages in selected group
                if (groupName != null)
                    villages.add(v);
                groupLines = false; //should already be false. set to false again, to avoid searching for group name in garbage if user copied nonsense
            }
        } else {
            // Check if current line is first group line. In case it is, store selected group
            if (currentLine.trim().startsWith(getVariable("overview.groups")))
                groupLines = true;
            // Check if current line contains active group. In case it does, store group name and stop searching
            if (groupLines && currentLine.matches(".*>.*?<.*")) {
                groupLines = false;
                groupName = StringUtils.substringBetween(currentLine, ">", "<"); // = line.replaceAll(".*>|<.*",""); if we stop using Apache Commons   
                debug("Found selected group in line '" + currentLine + "'");
                debug("Selected group '" + groupName + "'");
            } else
                debug("Dropping line '" + currentLine + "'");
        }
    }
    boolean retValue = (foundTroops != 0);
    if (retValue) {
        try {
            DSWorkbenchMainFrame.getSingleton()
                    .showSuccess("DS Workbench hat Truppeninformationen zu " + foundTroops
                            + ((foundTroops == 1) ? " Dorf " : " Drfern ")
                            + " in die Truppenbersicht eingetragen.");
        } catch (Exception e) {
            NotifierFrame.doNotification("DS Workbench hat Truppeninformationen zu " + foundTroops
                    + ((foundTroops == 1) ? " Dorf " : " Drfern ") + " in die Truppenbersicht eingetragen.",
                    NotifierFrame.NOTIFY_INFO);
        }
    }
    TroopsManager.getSingleton().revalidate(retValue);

    //update selected group, if any
    if (groupName != null && !groupName.equals(getVariable("groups.all"))) {
        HashMap<String, List<Village>> groupTable = new HashMap<>();
        groupTable.put(groupName, villages);
        DSWorkbenchMainFrame.getSingleton().fireGroupParserEvent(groupTable);
    }

    return retValue;
}

From source file:com.smartmarmot.common.Configurator.java

private static Query[] getQueries(String parameter, Properties _propsq) throws Exception {
    try {/*ww  w .  j  a v  a  2  s  .  c  o  m*/
        StringTokenizer stq = new StringTokenizer(_propsq.getProperty(parameter), Constants.DELIMITER);
        String[] QueryLists = new String[stq.countTokens()];
        int count = 0;
        while (stq.hasMoreTokens()) {
            String token = stq.nextToken().toString().trim();
            QueryLists[count] = token;
            count++;
        }

        Collection<Query> Queries = new ArrayList<Query>();
        for (int i = 0; i < QueryLists.length; i++) {
            try {
                Query q = getQueryProperties(_propsq, QueryLists[i]);
                Queries.add(q);
            } catch (Exception e1) {
                SmartLogger.logThis(Level.ERROR,
                        "Error on Configurator on reading query " + QueryLists[i] + e1);
                SmartLogger.logThis(Level.INFO, "Query " + QueryLists[i] + " skipped due to error " + e1);
            }
        }
        Query[] queries = (Query[]) Queries.toArray(new Query[0]);
        return queries;
    } catch (Exception ex) {

        SmartLogger.logThis(Level.ERROR,
                "Error on Configurator on reading properties file " + _propsq.toString() + " getQueries("
                        + parameter + "," + _propsq.toString() + ") " + ex.getMessage());
        return null;
    }

}

From source file:com.salesmanager.core.module.impl.application.shipping.CalculateBoxPackingModule.java

public PackageDetail getConfigurationOptions(MerchantConfiguration config, String currency) throws Exception {

    if (config == null || config.getConfigurationValue1() == null) {
        return null;
    }/* w  w  w . ja v  a 2  s.  com*/

    PackageDetail details = new PackageDetail();
    StringTokenizer st = new StringTokenizer(config.getConfigurationValue1(), "|");

    Map parseTokens = new HashMap();

    int i = 1;
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        if (i == 1) {

            details.setShippingWidth(new BigDecimal(token).doubleValue());

        } else if (i == 2) {
            details.setShippingHeight(new BigDecimal(token).doubleValue());

        } else if (i == 3) {
            details.setShippingLength(new BigDecimal(token).doubleValue());

        } else if (i == 4) {
            details.setShippingWeight(new BigDecimal(token).doubleValue());

        } else if (i == 5) {
            details.setShippingMaxWeight(new BigDecimal(token).doubleValue());

        } else if (i == 6) {
            details.setTreshold(Integer.parseInt(token));

        }
        i++;
    }
    details.setCurrency(currency);
    return details;

}

From source file:com.floreantpos.util.StringUtils.java

/**
 * <p>/*  ww  w.j  a v a  2 s.  c  om*/
 * Remove underscores from a string and replaces first
 * letters with capitals.  Other letters are changed to lower case.
 * </p>
 *
 * <p>
 * For example <code>foo_bar</code> becomes <code>FooBar</code>
 * but <code>foo_barBar</code> becomes <code>FooBarbar</code>.
 * </p>
 *
 * @param data string to remove underscores from.
 * @return String
 * @deprecated Use the org.apache.commons.util.StringUtils class
 * instead.  Using its firstLetterCaps() method in conjunction
 * with a StringTokenizer will achieve the same result.
 */
static public String removeUnderScores(String data) {
    String temp = null;
    StringBuilder out = new StringBuilder();
    temp = data;

    StringTokenizer st = new StringTokenizer(temp, "_");

    while (st.hasMoreTokens()) {
        String element = (String) st.nextElement();
        out.append(firstLetterCaps(element));
    }

    return out.toString();
}

From source file:it.unipd.dei.ims.falcon.CmdLine.java

private static int[] parseIntArray(String s) {
    StringTokenizer t = new StringTokenizer(s, ",");
    int[] ia = new int[t.countTokens()];
    int ti = 0;//from w  w  w .  j  a va2s. c  om
    while (t.hasMoreTokens())
        ia[ti] = Integer.parseInt(t.nextToken());
    return ia;
}

From source file:bboss.org.apache.velocity.util.StringUtils.java

/**
 * <p>/*from  w w w .j  ava 2s.  c  om*/
 * Remove underscores from a string and replaces first
 * letters with capitals.  Other letters are changed to lower case.
 * </p>
 *
 * <p>
 * For example <code>foo_bar</code> becomes <code>FooBar</code>
 * but <code>foo_barBar</code> becomes <code>FooBarbar</code>.
 * </p>
 *
 * @param data string to remove underscores from.
 * @return String
 * @deprecated Use the org.apache.commons.util.StringUtils class
 * instead.  Using its firstLetterCaps() method in conjunction
 * with a StringTokenizer will achieve the same result.
 */
static public String removeUnderScores(String data) {
    String temp = null;
    StringBuffer out = new StringBuffer();
    temp = data;

    StringTokenizer st = new StringTokenizer(temp, "_");

    while (st.hasMoreTokens()) {
        String element = (String) st.nextElement();
        out.append(firstLetterCaps(element));
    }

    return out.toString();
}