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.tamnd.core.util.ZConfig.java

private void _init() {
    //~~~~~~~~~~ init configs from files ~~~~~~~~~~
    String appName = ZSystemProp.GetAppName();//check if zappname is exist
    String appProf = ZSystemProp.GetAppProf();
    String configDir = ZSystemProp.GetConfDir();
    String prePath;//from   ww w . j  a  v  a2s.  c  o m
    if (configDir.endsWith("/")) {
        prePath = configDir + appProf + ".";
    } else {
        prePath = configDir + "/" + appProf + ".";
    }
    String configFiles = ZSystemProp.GetProp("zconffiles", "config.ini");
    if (configFiles != null && !configFiles.isEmpty()) {
        StringTokenizer strTok = new StringTokenizer(configFiles, ",");
        while (strTok.hasMoreTokens()) {
            String fileName = strTok.nextToken();
            String path = prePath + fileName;
            try {
                ConfigToMap(_configMap, LoadFromFile(path), false);
            } catch (Exception ex) {
                System.err.println(ex);
            }
        }
    } else {
        System.out.println("No configuration file is specified");
    }
}

From source file:com.chinamobile.bcbsp.partition.RecordParseDefault.java

/**
 * This method is used to parse a record and obtain VertexID .
 * @param key The key of the vertex record
 * @return the vertex id//w  ww.  ja v a  2  s  .  c  o  m
 */
@Override
public Text getVertexID(Text key) {
    try {
        StringTokenizer str = new StringTokenizer(key.toString(), Constants.SPLIT_FLAG);
        if (str.countTokens() != 2) {
            return null;
        }
        return new Text(str.nextToken());
    } catch (Exception e) {
        return null;
    }
}

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

public static IntegrationKeys getIntegrationKeys(String configvalue, String delimiter) throws Exception {
    if (configvalue == null)
        return new IntegrationKeys();
    StringTokenizer st = new StringTokenizer(configvalue, delimiter);
    int i = 1;//from w ww . ja v a2 s.c  om
    int j = 1;
    IntegrationKeys keys = new IntegrationKeys();
    while (st.hasMoreTokens()) {
        String value = st.nextToken();

        if (i == 1) {
            // decrypt
            keys.setUserid(value);
        } else if (i == 2) {
            // decrypt
            keys.setPassword(value);
        } else if (i == 3) {
            // decrypt
            keys.setTransactionKey(value);
        } else {
            if (j == 1) {
                keys.setKey1(value);
            } else if (j == 2) {
                keys.setKey2(value);
            } else if (j == 3) {
                keys.setKey3(value);
            }
            j++;
        }
        i++;
    }
    return keys;
}

From source file:com.icesoft.faces.component.ext.taglib.Util.java

/**
 * Gets the comma separated list of visibility user roles from the given
 * component and checks if current user is in one of these roles.
 *
 * @param component a user role aware component
 * @return true if no user roles are defined for this component or user is
 *         in one of these roles, false otherwise
 *//*  ww  w.  jav  a2  s  . c o m*/
public static boolean isRenderedOnUserRole(UIComponent component) {
    if (ignoreUserRoleAttributes()) {
        return true;
    }
    String userRole;
    if (component instanceof IceExtended) {
        userRole = ((IceExtended) component).getRenderedOnUserRole();
    } else {
        userRole = (String) component.getAttributes().get(IceExtended.RENDERED_ON_USER_ROLE_ATTR);
    }

    if (log.isTraceEnabled()) {
        log.trace("userRole in " + getRoot(component) + " is " + userRole);

    }

    //there is no restriction
    if (userRole == null) {
        return true;
    }

    FacesContext facesContext = FacesContext.getCurrentInstance();
    StringTokenizer st = new StringTokenizer(userRole, ",");
    while (st.hasMoreTokens()) {
        if (facesContext.getExternalContext().isUserInRole(st.nextToken().trim())) {
            return true;
        }
    }
    return false;
}

From source file:de.mg.stock.server.update.StockUpdateFromYahooInstant.java

public InstantPrice get(String symbol) {

    LocalDateTime fetchTime = dateTimeProvider.now();

    /*/* w w  w .  jav a  2 s. c  o m*/
    b2=ask (real time)
    b3=bid (real time)
    a=ask
    b=bid
    g=day min
    h=day max
    d1=last trade date
    t1=last trade time
     */
    String response = httpUtil.get("http://download.finance.yahoo.com/d/quotes.csv?f=b2b3abghd1t1&s=" + symbol);
    if (isEmpty(response)) {
        logger.warning("nothing received for " + symbol);
        return null;
    }

    String[] lines = response.split(System.getProperty("line.separator"));
    if (lines.length != 1) {
        logger.warning("received " + lines.length + " for " + symbol);
        return null;
    }

    InstantPrice result = new InstantPrice();

    StringTokenizer tok = new StringTokenizer(lines[0], ",");

    Long askReal = toLong(tok.nextToken());
    Long bidReal = toLong(tok.nextToken());
    Long ask = toLong(tok.nextToken());
    Long bid = toLong(tok.nextToken());
    Long dayMin = toLong(tok.nextToken());
    Long dayMax = toLong(tok.nextToken());

    String dateTimeStr = tok.nextToken() + " " + tok.nextToken();
    dateTimeStr = dateTimeStr.replaceAll("\"", "");
    LocalDateTime tradeTime = DateConverters.toLocalDateTime(dateTimeStr, "MM/dd/yyyy hh:mma", Locale.ENGLISH);
    if (tradeTime == null) {
        logger.warning("invalid date + time for " + symbol + ": " + dateTimeStr);
        return null;
    }

    result.setTime(tradeTime);
    result.setFetchedAt(fetchTime);
    result.setAsk(askReal != null ? askReal : ask);
    result.setBid(bidReal != null ? bidReal : bid);
    result.setDayMax(dayMax);
    result.setDayMin(dayMin);

    if (result.getAsk() == null && result.getBid() == null && result.getDayMax() == null
            && result.getDayMin() == null) {
        logger.info("no meaningful values for " + symbol + ": " + response);
        return null;
    }

    // only for debugging
    if (false)
        logger.info("retrieved: " + response + "\nparsed: " + result.toString());

    return result;
}

From source file:amqp.spring.camel.component.SpringAMQPConsumer.java

protected static Map<String, Object> parseKeyValues(String routingKey) {
    StringTokenizer tokenizer = new StringTokenizer(routingKey, "&|");
    Map<String, Object> pairs = new HashMap<String, Object>();
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        String[] keyValue = token.split("=");
        if (keyValue.length != 2)
            throw new IllegalArgumentException(
                    "Couldn't parse key/value pair [" + token + "] out of string: " + routingKey);

        pairs.put(keyValue[0], keyValue[1]);
    }/*from ww  w  .ja  va 2  s  . co  m*/

    return pairs;
}

From source file:net.sf.excelutils.tags.EachTag.java

public int[] parseTag(Object context, Workbook wb, Sheet sheet, Row curRow, Cell curCell)
        throws ExcelException {
    String expr = "";
    String each = curCell.getStringCellValue();

    LOG.debug("EachTag:" + each);

    StringTokenizer st = new StringTokenizer(each, " ");
    String widthstr = "";
    String onstr = "";
    int pos = 0;//from ww w  .  j a  v  a2  s .c  o  m
    while (st.hasMoreTokens()) {
        String str = st.nextToken();
        if (pos == 1) {
            expr = str;
        }
        if (pos == 2 && !"on".equals(str)) {
            widthstr = str;
        }
        if (pos == 3 && !"on".equals(str)) {
            onstr = str;
        }
        if (pos == 4) {
            onstr = str;
        }
        pos++;
    }

    int[] widths = new int[0];
    if (null != widthstr && !"".equals(widthstr)) {
        Object o = ExcelParser.parseStr(context, widthstr);
        if (null != o) {
            String[] s = o.toString().split(",");
            widths = new int[s.length];
            for (int i = 0; i < widths.length; i++) {
                widths[i] = Integer.parseInt(s[i]);
            }
        }
    }

    Object obj = ExcelParser.parseExpr(context, expr);
    if (null == obj)
        return new int[] { 0, 0, 0 };

    // by onstr get the property
    if (!"".equals(onstr)) {
        obj = ExcelParser.parseExpr(context, onstr);
        if (null == obj)
            return new int[] { 0, 0, 0 };
    }

    // iterator properties
    Iterator it = ExcelParser.getIterator(obj);
    if (null == it) {
        if (obj instanceof DynaBean) {
            it = ExcelParser.getIterator(ExcelParser.getBeanProperties(((DynaBean) obj).getDynaClass()));
        } else {
            it = ExcelParser.getIterator(ExcelParser.getBeanProperties(obj.getClass()));
        }
    }
    if (null == it) {
        return new int[] { 0, 0, 0 };
    }

    int index = 0;
    int arrayIndex = 0;
    int eachPos = curCell.getColumnIndex();
    String modelName = expr.substring(ExcelParser.VALUED_DELIM.length(),
            expr.length() - ExcelParser.VALUED_DELIM2.length());

    // restore the obj
    obj = ExcelParser.parseExpr(context, expr);
    while (it.hasNext()) {
        Object o = it.next();
        String property = "";
        if (o instanceof Field) {
            property = ((Field) o).getName();
        } else if (o instanceof Map.Entry) {
            property = ((Map.Entry) o).getKey().toString();
        } else if (o instanceof DynaProperty) {
            property = ((DynaProperty) o).getName();
        } else if (null != o) {
            property = o.toString();
        }

        // test the object is array/list or other
        if (obj.getClass().isArray() || obj instanceof Collection) {
            property = modelName + "[" + arrayIndex++ + "]";
        } else {
            property = modelName + "." + property;
        }

        Object value = ExcelParser.getValue(context, property);
        if (null == value)
            value = "";

        if (ExcelUtils.isCanShowType(value)) {

            // get cell merge count
            int width = 1;
            if (index < widths.length) {
                width = widths[index];
            } else if (1 == widths.length) {
                width = widths[0];
            }

            // get row merged of the curCell
            int rowMerged = 1;
            for (int i = 0; i < sheet.getNumMergedRegions(); i++) {
                CellRangeAddress r = sheet.getMergedRegion(i);
                if (r.getFirstRow() == curRow.getRowNum() && r.getFirstColumn() == curCell.getColumnIndex()
                        && r.getLastColumn() == curCell.getColumnIndex()) {
                    rowMerged = r.getLastRow() - r.getFirstRow() + 1;
                    break;
                }
            }

            Cell cell = WorkbookUtils.getCell(curRow, eachPos);

            // shift the after cell
            if (index > 0) {
                WorkbookUtils.shiftCell(sheet, curRow, cell, 1, rowMerged);
            }
            if (width > 1) {
                Cell nextCell = WorkbookUtils.getCell(curRow, eachPos + 1);
                WorkbookUtils.shiftCell(sheet, curRow, nextCell, width - 1, rowMerged);
            }

            // copy the style of curCell
            for (int rownum = curRow.getRowNum(); rownum < curRow.getRowNum() + rowMerged; rownum++) {
                for (int i = 0; i < width; i++) {
                    Row r = WorkbookUtils.getRow(rownum, sheet);
                    Cell c = WorkbookUtils.getCell(r, eachPos + i);
                    Cell cc = WorkbookUtils.getCell(r, curCell.getColumnIndex());
                    c.setCellStyle(cc.getCellStyle());
                }
            }

            // merge cells
            if (width > 1 || rowMerged > 1) {
                sheet.addMergedRegion(
                        new CellRangeAddress(curRow.getRowNum(), curRow.getRowNum() + rowMerged - 1,
                                cell.getColumnIndex(), cell.getColumnIndex() + width - 1));
            }

            cell.setCellValue("${" + property + "}");
            ExcelParser.parseCell(context, sheet, curRow, cell);

            eachPos += width;
            index++;
        }
    }

    return new int[] { 0, 0, 0 };
}

From source file:BitLottoVerify.java

public static Map<String, Long> getPaymentsBlockExplorer(String addr) throws Exception {
    URL u = new URL("http://blockexplorer.com/address/" + addr);
    Scanner scan = new Scanner(u.openStream());

    TreeMap<String, Long> map = new TreeMap<String, Long>();

    while (scan.hasNextLine()) {
        String line = scan.nextLine();
        StringTokenizer stok = new StringTokenizer(line, "\"#");
        while (stok.hasMoreTokens()) {
            String token = stok.nextToken();
            if (token.startsWith("/tx/")) {
                String tx = token.substring(4);
                line = scan.nextLine();//from   ww  w.  j a  va2 s  . com
                line = scan.nextLine();
                StringTokenizer stok2 = new StringTokenizer(line, "<>");
                stok2.nextToken();
                double amt = Double.parseDouble(stok2.nextToken());
                long amt_l = (long) Math.round(amt * 1e8);
                map.put(tx, amt_l);

            }
        }
    }
    return map;
}

From source file:Urls.java

/**
 * Returns the time when the document should be considered expired.
 * The time will be zero if the document always needs to be revalidated.
 * It will be <code>null</code> if no expiration time is specified.
 *//*from w ww .  j ava 2  s.  c o  m*/
public static Long getExpiration(URLConnection connection, long baseTime) {
    String cacheControl = connection.getHeaderField("Cache-Control");
    if (cacheControl != null) {
        StringTokenizer tok = new StringTokenizer(cacheControl, ",");
        while (tok.hasMoreTokens()) {
            String token = tok.nextToken().trim().toLowerCase();
            if ("must-revalidate".equals(token)) {
                return new Long(0);
            } else if (token.startsWith("max-age")) {
                int eqIdx = token.indexOf('=');
                if (eqIdx != -1) {
                    String value = token.substring(eqIdx + 1).trim();
                    int seconds;
                    try {
                        seconds = Integer.parseInt(value);
                        return new Long(baseTime + seconds * 1000);
                    } catch (NumberFormatException nfe) {
                        logger.warning("getExpiration(): Bad Cache-Control max-age value: " + value);
                        // ignore
                    }
                }
            }
        }
    }
    String expires = connection.getHeaderField("Expires");
    if (expires != null) {
        try {
            synchronized (PATTERN_RFC1123) {
                Date expDate = PATTERN_RFC1123.parse(expires);
                return new Long(expDate.getTime());
            }
        } catch (java.text.ParseException pe) {
            int seconds;
            try {
                seconds = Integer.parseInt(expires);
                return new Long(baseTime + seconds * 1000);
            } catch (NumberFormatException nfe) {
                logger.warning("getExpiration(): Bad Expires header value: " + expires);
            }
        }
    }
    return null;
}

From source file:com.zuoxiaolong.niubi.job.persistent.hibernate.HibernateNamingStrategy.java

private static String[] splitName(String someName) {
    StringTokenizer tokenizer = new StringTokenizer(someName, SEPARATOR);
    String[] tokens = new String[tokenizer.countTokens()];
    int i = 0;//from  w w  w . j  a  v  a2s  .c om
    while (tokenizer.hasMoreTokens()) {
        tokens[i] = tokenizer.nextToken();
        i++;
    }
    return tokens;
}