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:Main.java

/**
 * Find an element using XPath-quotation expressions. Path must not including
 * the context element, path elements can be separated by / or .,
 * and namespace is NOT supported.//from   w  w w.  j av  a2  s . com
 * @param context Element to start the search from, cannot be null.
 * @param path XPath-quotation expression, cannot be null.
 * @param create if true, new elements are created if necessary.
 * @return the first matched element if there are matches, otherwise
 * return null.
 */
public static Element getElementByPath(Element context, String path, boolean create) {
    Element cur = context;
    StringTokenizer tokens = new StringTokenizer(path, "/");

    while (tokens.hasMoreTokens()) {
        String name = tokens.nextToken();
        Element parent = cur;
        cur = getChildElement(cur, name);
        if (cur == null) {
            if (create) {
                // create the element
                Element newElement = context.getOwnerDocument().createElement(name);
                //context.appendChild(newElement);
                parent.appendChild(newElement);
                cur = newElement;
            } else {
                return null;
            }
        }
    }
    return cur;
}

From source file:com.joliciel.talismane.utils.DaoUtils.java

public static List<String> getSelectArray(String selectString, String alias) {
    List<String> selectArray = new ArrayList<String>();
    StringTokenizer st = new StringTokenizer(selectString, ",", false);
    boolean haveAlias = alias != null && alias.length() > 0;
    while (st.hasMoreTokens()) {
        String column = st.nextToken().trim();
        if (haveAlias)
            selectArray.add(alias + "." + column + " as " + alias + "_" + column);
        else//w w  w .  ja  v  a  2 s. c o m
            selectArray.add(column);

    }
    return selectArray;
}

From source file:de.otto.mongodb.profiler.web.ConnectionController.java

private static void parseHosts(final String input, final ProfiledConnectionConfiguration.Builder configBuilder)
        throws ParseException, InvalidHostException {

    final String raw = input.replace("\r", "").replace("\n", ",").replace(" ", "");

    final StringTokenizer tokenizer = new StringTokenizer(raw, ",");
    while (tokenizer.hasMoreTokens()) {
        parseHost(tokenizer.nextToken(), configBuilder);
    }/*from  w  ww. ja v  a  2  s .  co m*/
}

From source file:marytts.tools.install.LicenseRegistry.java

private static void loadLocalLicenses() {
    remote2local = new HashMap<URL, String>();
    File downloadDir = new File(System.getProperty("mary.downloadDir", "."));
    File licenseIndexFile = new File(downloadDir, "license-index.txt");
    if (!licenseIndexFile.canRead()) {
        return; // nothing to load
    }//from w  w w  .  j  a  v  a  2 s.  co  m
    try (BufferedReader br = new BufferedReader(
            new InputStreamReader(new FileInputStream(licenseIndexFile), "UTF-8"))) {
        // Each line in licenseIndexFile is expected to be a pair of local file name (relative to downloadDir) and URL string,
        // separated by a |(pipe) character.

        String line;
        while ((line = br.readLine()) != null) {
            line = line.trim();
            StringTokenizer st = new StringTokenizer(line, "|");
            if (!st.hasMoreTokens()) {
                continue; // skip empty lines
            }
            String localFilename = st.nextToken().trim();
            if (!st.hasMoreTokens()) {
                continue; // skip lines that don't contain a |
            }
            String remoteURLString = st.nextToken().trim();
            File localLicenseFile = new File(downloadDir, localFilename);
            if (!localLicenseFile.canRead()) {
                System.err.println("License index file " + licenseIndexFile.getAbsolutePath()
                        + " refers to license file " + localLicenseFile.getAbsolutePath()
                        + ", but that file cannot be read. Skipping.");
                continue;
            }
            URL remoteURL = new URL(remoteURLString);
            remote2local.put(remoteURL, localFilename);
        }
    } catch (IOException e) {
        System.err.println(
                "Problem reading local license index file " + licenseIndexFile.getAbsolutePath() + ":");
        e.printStackTrace();
    }
}

From source file:fr.paris.lutece.plugins.updater.util.sql.SqlUtils.java

/**
 * Executes an SQL script//  ww  w. j a v a2 s.c o m
 * @param strScript An SQL script
 * @param plugin The plugin
 * @throws SQLException If an SQL exception occurs
 */
public static void executeSqlScript(String strScript, Plugin plugin) throws SQLException {
    String strCleanScript = strScript.substring(0, strScript.lastIndexOf(";"));
    StringTokenizer st = new StringTokenizer(strCleanScript, ";");

    Transaction transaction = new Transaction();

    try {
        while (st.hasMoreTokens()) {
            String strSQL = st.nextToken();
            transaction.prepareStatement(strSQL);
            transaction.executeStatement();
        }

        transaction.commit();
    } catch (SQLException ex) {
        transaction.rollback(ex);
        AppLogService.error("Execute SQL script error : " + ex.getMessage() + " - transaction rolled back.",
                ex);
        throw ex;
    }
}

From source file:com.enonic.esl.io.FileUtil.java

public static String getFileName(FileItem fileItem) {
    String fileName = fileItem.getName();
    StringTokenizer nameTokenizer = new StringTokenizer(fileName, "\\/:");
    while (nameTokenizer.hasMoreTokens()) {
        fileName = nameTokenizer.nextToken();
    }//w ww  .ja va 2s.co m
    return fileName;
}

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

/**
 * Strips all delimiters//ww w. j a  v a  2 s  .  c  om
 * 
 * @param configurationLine
 * @return
 */
public static Collection getConfigurationList(String configurationLine, String delimiter) {

    List returnlist = new ArrayList();
    StringTokenizer st = new StringTokenizer(configurationLine, delimiter);
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        returnlist.add(token);
    }
    return returnlist;
}

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  w w  .ja  v  a 2s .  c  om
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: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  w w w .  j ava 2  s. co  m
                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:Main.java

public static String xmlEncoding(String input, String delimiter) {
    if (input == null || input.equals(""))
        return input;

    delimiter += '&';

    StringTokenizer tmpst = new StringTokenizer(input, delimiter, true);
    StringBuffer tmpsb = new StringBuffer(input.length() + 100);
    String tmps = null;/*from  www.  j a  v a 2s. com*/
    while (tmpst.hasMoreTokens()) {
        tmps = tmpst.nextToken();
        if (tmps.length() == 1 && delimiter.indexOf(tmps) >= 0) {
            switch (tmps.charAt(0)) {
            case '<':
                tmpsb.append("&lt;");
                break;
            case '>':
                tmpsb.append("&gt;");
                break;
            case '&':
                tmpsb.append("&amp;");
                break;
            case '\'':
                tmpsb.append("&apos;");
                break;
            case '\"':
                tmpsb.append("&quot;");
                break;
            case '\n':
                tmpsb.append("&#10;");
                break;
            case '\r':
                tmpsb.append("&#13;");
                break;
            case '\t':
                tmpsb.append("&#9;");
                break;
            }
        } else {
            tmpsb.append(tmps);
        }
    }

    return tmpsb.toString();
}