List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:org.ardverk.daap.DaapUtil.java
/** * Splits a query String ("key1=value1&key2=value2...") and stores the data * in a Map/*w ww .ja va 2s. c o m*/ * * @param queryString * a query String * @return the splitten query String as Map */ public static final Map<String, String> parseQuery(String queryString) { Map<String, String> map = new HashMap<String, String>(); 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:edu.stanford.muse.util.JSONUtils.java
public static String jsonForNewNewAlgResults(AddressBook ab, String resultsFile) throws IOException, JSONException { LineNumberReader lnr = new LineNumberReader(new InputStreamReader(new FileInputStream(resultsFile))); JSONObject result = new JSONObject(); JSONArray groups = new JSONArray(); int groupNum = 0; while (true) { String line = lnr.readLine(); if (line == null) break; line = line.trim();// ww w . j a v a 2s . com // line: group 8, freq 49: seojiwon@gmail.com sseong@stanford.edu debangsu@cs.stanford.edu // ignore lines without a ':' int idx = line.indexOf(":"); if (idx == -1) continue; String vars = line.substring(0, idx); // vars: freq=5 foo bar somevar=someval // we'll pick up all tokens with a = in them and assume they mean key=value StringTokenizer varsSt = new StringTokenizer(vars); JSONObject group = new JSONObject(); while (varsSt.hasMoreTokens()) { String str = varsSt.nextToken(); // str: freq=5 int x = str.indexOf("="); if (x >= 0) { String key = str.substring(0, x); String value = ""; // we should handle the case of key= (empty string) if (x < str.length() - 1) value = str.substring(x + 1); group.put(key, value); } } String groupsStr = line.substring(idx + 1); // groupsStr: seojiwon@gmail.com sseong@stanford.edu debangsu@cs.stanford.edu StringTokenizer st = new StringTokenizer(groupsStr); JSONArray groupMembers = new JSONArray(); int i = 0; while (st.hasMoreTokens()) { String s = st.nextToken(); Contact ci = ab.lookupByEmail(s); if (ci == null) { System.out.println("WARNING: no contact info for email address: " + s); continue; } groupMembers.put(i++, ci.toJson()); } group.put("members", groupMembers); groups.put(groupNum, group); groupNum++; } result.put("groups", groups); return result.toString(); }
From source file:hu.netmind.beankeeper.node.impl.NodeManagerImpl.java
/** * Determine if an address is available. *///from w ww.j av a 2 s. c o m public static boolean isAlive(String ips, int port) { if (logger.isDebugEnabled()) logger.debug("trying to reach: " + ips + ":" + port); try { if ("".equals(ips)) ips = InetAddress.getLocalHost().getHostAddress(); } catch (Exception e) { throw new StoreException( "can not determine local adapter, but there is another node, which would need to be contacted.", e); } StringTokenizer tokens = new StringTokenizer(ips, ","); while (tokens.hasMoreTokens()) { String ip = tokens.nextToken(); if (logger.isDebugEnabled()) logger.debug("determining whether '" + ip + ":" + port + "' is alive..."); try { Socket socket = new Socket(); socket.connect(new InetSocketAddress(ip, port), SOCKET_CONNECT_TIMEOUT); socket.close(); return true; // Success, so return true } catch (Exception e) { logger.debug("unreachable node at '" + ip + ":" + port + ", " + e.getMessage()); } } logger.debug("could not reach any of the ips given for node"); return false; }
From source file:com.qtplaf.library.util.StringUtils.java
/** * Parse a string/*from w w w . j a va 2 s. c o m*/ * * @param string The string to parse. * @param separator The separator. * @return the array of tokens */ public static String[] parse(String string, String separator) { StringTokenizer tokenizer = new StringTokenizer(string, separator); ArrayList<String> list = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { list.add(tokenizer.nextToken().trim()); } return list.toArray(new String[list.size()]); }
From source file:eu.europa.esig.dss.XmlDom.java
private static String addNamespacePrefix(final String formatedXPath) { if (formatedXPath.startsWith("/dss:") || formatedXPath.startsWith("./dss:")) { // Already formated. return formatedXPath; }/*from w ww . j a va2 s . c o m*/ String formatedXPath_ = formatedXPath; CharSequence from = "//"; CharSequence to = "{#double}/"; boolean special = formatedXPath_.indexOf("//") != -1; if (special) { formatedXPath_ = formatedXPath_.replace(from, to); } StringTokenizer tokenizer = new StringTokenizer(formatedXPath_, "/"); StringBuilder stringBuilder = new StringBuilder(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); final boolean isDot = ".".equals(token); final boolean isCount = "count(".equals(token) || "count(.".equals(token); final boolean isDoubleDot = "..".equals(token); final boolean isAt = token.startsWith("@"); final boolean isText = token.equals("text()"); final boolean isDoubleSlash = token.equals("{#double}"); final String slash = isDot || isCount || isDoubleSlash ? "" : "/"; String prefix = isDot || isCount || isDoubleDot || isAt || isText || isDoubleSlash ? "" : "dss:"; stringBuilder.append(slash).append(prefix).append(token); } String normalizedXPath = stringBuilder.toString(); if (special) { normalizedXPath = normalizedXPath.replace(to, from); } return normalizedXPath; }
From source file:Log.java
/** * Logs a message. This method is thread-safe. * * The following code sends a typical debugging message to the activity * log:/*w w w. j a v a2 s .c o m*/ * <pre>Log.log(Log.DEBUG,this,"counter = " + counter);</pre> * The corresponding activity log entry might read as follows: * <pre>[debug] JavaParser: counter = 15</pre> * * @param urgency The urgency; can be one of * <code>Log.DEBUG</code>, <code>Log.MESSAGE</code>, * <code>Log.NOTICE</code>, <code>Log.WARNING</code>, or * <code>Log.ERROR</code>. * @param source The source of the message, either an object or a * class instance. When writing log messages from macros, set * this parameter to <code>BeanShell.class</code> to make macro * errors easier to spot in the activity log. * @param message The message. This can either be a string or * an exception * * @since jEdit 2.2pre2 */ public static void log(int urgency, Object source, Object message) { String _source; if (source == null) { _source = Thread.currentThread().getName(); if (_source == null) { _source = Thread.currentThread().getClass().getName(); } } else if (source instanceof Class) _source = ((Class) source).getName(); else _source = source.getClass().getName(); int index = _source.lastIndexOf('.'); if (index != -1) _source = _source.substring(index + 1); if (message instanceof Throwable) { _logException(urgency, source, (Throwable) message); } else { String _message = String.valueOf(message); // If multiple threads log stuff, we don't want // the output to get mixed up synchronized (LOCK) { StringTokenizer st = new StringTokenizer(_message, "\r\n"); int lineCount = 0; boolean oldWrap = wrap; while (st.hasMoreTokens()) { lineCount++; _log(urgency, _source, st.nextToken().replace('\t', ' ')); } listModel.update(lineCount, oldWrap); } } }
From source file:edu.stanford.muse.util.ThunderbirdUtils.java
/** returns list of accounts; each account has a list of properties, the order is fragile! */ private static List<List<String>> getThunderbirdAccountsNew() { // read all user prefs as a map try {/* ww w .j av a 2s . c o m*/ String rootDir = ThunderbirdUtils.getThunderbirdProfileDir(); String prefs = rootDir + File.separator + "prefs.js"; File f = new File(prefs); if (!f.exists() || !f.canRead()) { EmailUtils.log.info("Thunderbird probably not installed: no prefs.js in directory: " + prefs); return null; } // ok, now have map. look for accounts and their information. List<List<String>> result = new ArrayList<List<String>>(); Map<String, String> userPrefsMap = readUserPrefs(prefs); // get the account list: original line looks like: user_pref("mail.accountmanager.accounts", "account2,account1"); String accounts = userPrefsMap.get("mail.accountmanager.accounts"); // sometimes this is null e.g. if tbird has been installed, but the accounts have been deleted if (Util.nullOrEmpty(accounts)) return result; StringTokenizer st = new StringTokenizer(accounts, ","); while (st.hasMoreTokens()) { String account = st.nextToken(); String server = userPrefsMap.get("mail.account." + account + ".server"); if (server == null) continue; // hidden is set to true for "unified folders" account if ("true".equals(userPrefsMap.get("mail.server." + server + ".hidden"))) continue; String serverType = userPrefsMap.get("mail.server." + server + ".type"); // ignore a/c if server type is nntp if ("nntp".equals(serverType)) continue; String accountName = userPrefsMap.get("mail.server." + server + ".name"); String serverRealHostName = userPrefsMap.get("mail.server." + server + ".realhostname"); if (serverRealHostName == null) serverRealHostName = userPrefsMap.get("mail.server." + server + ".hostname"); String userName = userPrefsMap.get("mail.server." + server + ".userName"); // note: userName, not username String serverPort = userPrefsMap.get("mail.server." + server + ".port"); String directoryRel = userPrefsMap.get("mail.server." + server + ".directory-rel"); // note: userName, not username if (directoryRel != null && directoryRel.startsWith("[ProfD]")) directoryRel = directoryRel.replace("[ProfD]", ThunderbirdUtils.getThunderbirdProfileDir() + File.separator); // we'll add it later since its later in the param sequence String ids = userPrefsMap.get("mail.account." + account + ".identities"); if (ids == null) { // must be local folders, they don't have any id's List<String> accountParams = new ArrayList<String>(); accountParams.add(accountName); accountParams.add(serverRealHostName); accountParams.add(serverType); accountParams.add(userName); accountParams.add(null); // no useremail accountParams.add(null); // fullname accountParams.add(directoryRel); accountParams.add(null); // no fcc accountParams.add(null); // no port result.add(accountParams); log.info(" account: Local Folders " + " userName: " + userName + " accountName: " + accountName + " hostname: " + serverRealHostName + " serverRealHostName: " + serverRealHostName + " type: " + serverType + " port: " + serverPort + " directoryRel: " + directoryRel); continue; } // there may multiple id's under this account, we create multiple entries in the result StringTokenizer st1 = new StringTokenizer(ids, ","); while (st1.hasMoreTokens()) { // create a result entry for each id List<String> accountParams = new ArrayList<String>(); accountParams.add(accountName); accountParams.add(serverRealHostName); accountParams.add(serverType); accountParams.add(userName); String id = st1.nextToken(); String useremail = userPrefsMap.get("mail.identity." + id + ".useremail"); accountParams.add(useremail); String fullname = userPrefsMap.get("mail.identity." + id + ".fullName"); accountParams.add(fullname); accountParams.add(directoryRel); String fcc_folder_full = userPrefsMap.get("mail.identity." + id + ".fcc_folder"); String fcc_folder = null; if (fcc_folder_full != null) { // fccFolder imap://hangal@xenon.stanford.edu/Sent fcc_folder = fcc_folder_full.replaceAll("[^/]*/+[^/]*/+(.*$)", "$1"); // skip the first 2 tokens, split by / if (!fcc_folder_full.equals(fcc_folder)) // only if not equal is it valid fcc_folder = null; } log.info(" account: " + account + " userName: " + userName + " useremail = " + useremail + " id: " + id + " accountName: " + accountName + " hostname: " + serverRealHostName + " serverRealHostName: " + serverRealHostName + " type: " + serverType + " port: " + serverPort + " directoryRel: " + directoryRel + " fullname = " + fullname + " fcc_folder_full = " + fcc_folder_full + " fcc_folder = " + fcc_folder); accountParams.add(fcc_folder); // tack on port at the end, though we're not using it right now accountParams.add(serverPort); result.add(accountParams); } } return result; } catch (Exception e) { Util.print_exception(e, log); } return null; }
From source file:jp.ikedam.jenkins.plugins.jobcopy_builder.JobcopyBuilder.java
/** * Reimplementation of {@link Jenkins#getItem(String, ItemGroup, Class)} * //from w w w. j a va2s . c o m * Existing implementation has following problems: * * Falls back to {@link Jenkins#getItemByFullName(String)} * * Cannot get {@link ItemGroup} * * @param pathName * @param context * @param klass * @return */ public static <T> T getRelative(String pathName, ItemGroup<?> context, Class<T> klass) { if (context == null) { context = Jenkins.getInstance().getItemGroup(); } if (pathName == null) { return null; } if (pathName.startsWith("/")) { // absolute Item item = Jenkins.getInstance().getItemByFullName(pathName); return klass.isInstance(item) ? klass.cast(item) : null; } Object/*Item|ItemGroup*/ ctx = context; StringTokenizer tokens = new StringTokenizer(pathName, "/"); while (tokens.hasMoreTokens()) { String s = tokens.nextToken(); if (s.equals("..")) { if (!(ctx instanceof Item)) { // can't go up further return null; } ctx = ((Item) ctx).getParent(); continue; } if (s.equals(".")) { continue; } if (!(ctx instanceof ItemGroup)) { return null; } ItemGroup<?> g = (ItemGroup<?>) ctx; Item i = g.getItem(s); if (i == null || !i.hasPermission(Item.READ)) { return null; } ctx = i; } return klass.isInstance(ctx) ? klass.cast(ctx) : null; }
From source file:com.salesmanager.core.util.ShippingUtil.java
/** * Strip the list of configuration if buit as 1;2;3;4;5.... * //from w ww . j av a 2 s . co m * @param serviceline * @return */ public static List getConfigurationList(String serviceline) { List returnlist = new ArrayList(); StringTokenizer st = new StringTokenizer(serviceline, ";"); while (st.hasMoreTokens()) { String token = st.nextToken(); returnlist.add(token); } return returnlist; }
From source file:it.intecs.pisa.toolbox.util.URLReader.java
private static final boolean compareVersions(String newVersion, String currentVersion, boolean isMin) { int i;/*from w w w .ja va2 s . com*/ StringTokenizer newer = new StringTokenizer(newVersion, "._-"); StringTokenizer current = new StringTokenizer(currentVersion, "._-"); while (current.hasMoreTokens()) { if (!newer.hasMoreTokens()) return (false); String last = newer.nextToken(); String cur = current.nextToken(); int lastVal = 0; int curVal = 0; try { lastVal = Integer.parseInt(last); curVal = Integer.parseInt(cur); } catch (NumberFormatException nfe) { return (false); } if (!isMin) { if (lastVal < curVal) return false; else if (lastVal > curVal) return true; } else { if (lastVal > curVal) return false; } } if (newVersion.equals(currentVersion)) return false; return (true); }