List of usage examples for java.util StringTokenizer countTokens
public int countTokens()
From source file:org.pdfgal.pdfgalweb.services.impl.WatermarkServiceImpl.java
/** * Gets the pages from a string with tokens. * /*from w w w . j a va 2s. c o m*/ * @param pages * @return */ private List<Integer> getPages(final String pages) { final List<Integer> result = new ArrayList<Integer>(); final StringTokenizer st = new StringTokenizer(pages, ","); while (st.hasMoreElements()) { final String token = (String) st.nextElement(); try { final Integer page = Integer.parseInt(token); result.add(page); } catch (final Exception e) { final StringTokenizer secondSt = new StringTokenizer(token, "-"); if (secondSt.countTokens() != 2) { throw new IllegalArgumentException(); } final String secondTokenFirst = (String) secondSt.nextElement(); final String secondTokenLast = (String) secondSt.nextElement(); try { final Integer firstPage = Integer.parseInt(secondTokenFirst); final Integer lastPage = Integer.parseInt(secondTokenLast); for (int i = firstPage; i <= lastPage; i++) { result.add(i); } } catch (final Exception e2) { throw new IllegalArgumentException(); } } } return result; }
From source file:com.alkacon.opencms.v8.documentcenter.CategoryTree.java
/** * Turns comma-separated string into a List of strings.<p> * /*w w w. j a v a2 s .c om*/ * @param str the string to be split * @param sep a separator character * @return a List of tokens */ public static List<String> commaStringToList(String str, String sep) { List<String> result = null; StringTokenizer tokenizer = null; if (str != null) { tokenizer = new StringTokenizer(str, sep); result = new ArrayList<String>(tokenizer.countTokens()); while (tokenizer.hasMoreTokens()) { result.add(tokenizer.nextToken()); } Collections.sort(result); } else { result = new ArrayList<String>(); } return result; }
From source file:org.apache.archiva.webdav.util.MimeTypes.java
public void load(InputStream mimeStream) { mimeMap.clear();/*from w w w.j a v a 2 s .c om*/ try (InputStreamReader reader = new InputStreamReader(mimeStream)) { try (BufferedReader buf = new BufferedReader(reader)) { String line = null; while ((line = buf.readLine()) != null) { line = line.trim(); if (line.length() == 0) { // empty line. skip it continue; } if (line.startsWith("#")) { // Comment. skip it continue; } StringTokenizer tokenizer = new StringTokenizer(line); if (tokenizer.countTokens() > 1) { String type = tokenizer.nextToken(); while (tokenizer.hasMoreTokens()) { String extension = tokenizer.nextToken().toLowerCase(); this.mimeMap.put(extension, type); } } } } } catch (IOException e) { log.error("Unable to read mime types from input stream : " + e.getMessage(), e); } }
From source file:GUIManagerQuery.java
/*************************************************************************** * Respond to button presses from the user indicating the desire for * information such as a list of players. **************************************************************************/ public void actionPerformed(ActionEvent e) { int type;//from w ww. jav a 2 s . c om String[] cons; //////////////////////////////////////////////////////////////// // Handle hints - simplest case [no need to check content types] //////////////////////////////////////////////////////////////// if (e.getSource() == hintsButton) { results.setText(ManagerQuery.getHints()); } ///////////////////////////////////////////////////////////////////// // Players, processors, or datasources. Need to check the contents // field and if it has text in there then use that as a qualifier // in the search for classes. However if empty then generate a // complete list of all classes of the required type. User may // enter multiple content types either comma or space separated, // hence use of StringTokenizer. //////////////////////////////////////////////////////////////////// else { if (e.getSource() == playersButton) type = ManagerQuery.HANDLERS; else if (e.getSource() == processorsButton) type = ManagerQuery.PROCESSORS; else type = ManagerQuery.DATASOURCES; String contents = contentsField.getText(); if (contents == null || contents.length() == 0) cons = null; else { StringTokenizer tokenizer = new StringTokenizer(contents, " ,\t;"); cons = new String[tokenizer.countTokens()]; for (int i = 0; i < cons.length; i++) cons[i] = tokenizer.nextToken(); } if (cons != null && cons.length > 0) results.setText(ManagerQuery.getHandlersOrProcessors(cons, type)); else if (type == ManagerQuery.HANDLERS) results.setText(ManagerQuery.getHandlers()); else if (type == ManagerQuery.PROCESSORS) results.setText(ManagerQuery.getProcessors()); else results.setText(ManagerQuery.getDataSources()); } }
From source file:com.hs.mail.security.login.PropertiesLoginModule.java
@Override protected Principal[] validate(Callback[] callbacks) throws LoginException { String username = ((NameCallback) callbacks[0]).getName(); char[] password = ((PasswordCallback) callbacks[1]).getPassword(); String entry = getLine(file, username + "="); if (entry == null) throw new AccountNotFoundException("Account for " + username + " not found"); int index = entry.indexOf('='); if (index == -1) throw new FailedLoginException("Invalid user record"); entry = entry.substring(index + 1);/* ww w. j a v a 2 s. c o m*/ index = entry.indexOf(':'); if (index == -1) throw new FailedLoginException("Invalid user record"); String encodedPwd = entry.substring(0, index); String roles = entry.substring(index + 1); StringTokenizer st = new StringTokenizer(roles, ","); Principal[] principals = new Principal[st.countTokens() + 1]; for (int i = 0; i < principals.length - 1; i++) { principals[i] = new RolePrincipal(st.nextToken().trim()); } principals[principals.length - 1] = new UserPrincipal(username); boolean ok = checkPassword(encodedPwd, password); if (!ok) throw new CredentialException("Incorrect password for " + username); else return principals; }
From source file:com.l2jfree.gameserver.handler.admincommands.AdminContest.java
@Override public boolean useAdminCommand(String command, L2Player activeChar) { StringTokenizer st = new StringTokenizer(command, " "); command = st.nextToken();/* ww w . j a v a2s . c o m*/ if (command.startsWith("admin_contest")) { if (st.countTokens() == 0) { activeChar.sendMessage("Specify clan hall ID (34 - Devastated castle, 64 - Fortress of the Dead)!"); return false; } try { int hallId = Integer.parseInt(st.nextToken()); if (command.endsWith("start")) ClanHallManager.getInstance().getClanHallById(hallId).getSiege().startSiege(); else if (command.endsWith("cancel")) ClanHallManager.getInstance().getClanHallById(hallId).getSiege().endSiege(null); return true; } catch (NumberFormatException nfe) { activeChar.sendMessage("That's not a clan hall ID."); } catch (NullPointerException npe) { activeChar.sendMessage("That clan hall doesn't exist/is not contestable."); } catch (IndexOutOfBoundsException e) { _log.fatal("Caught it!", e); } } return false; }
From source file:edu.stanford.muse.lens.LensPrefs.java
private void loadPrefs(String file) throws IOException { List<String> lines = Util.getLinesFromFile(file, true /*ignore comment lines starting with # */); for (String line : lines) { StringTokenizer st = new StringTokenizer(line, "\t"); if (st.countTokens() != 3) { log.warn("Dropping bad line in lens prefs file: " + file + ": " + line); continue; }/*from w ww . j a v a 2 s . c om*/ String term = st.nextToken(), url = st.nextToken(), weight = st.nextToken(); Float W = Float.parseFloat(weight); Map<String, Float> map = prefs.get(term); if (map == null) { map = new LinkedHashMap<String, Float>(); prefs.put(term, map); } map.put(url, W); } }
From source file:com.l2jfree.gameserver.handler.admincommands.AdminExpSp.java
private boolean adminAddExpSp(L2Player activeChar, String ExpSp) { L2Object target = activeChar.getTarget(); L2Player player = null;/* w w w. ja v a2 s. c o m*/ if (target instanceof L2Player) { player = (L2Player) target; } else { activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET); return false; } StringTokenizer st = new StringTokenizer(ExpSp); if (st.countTokens() != 2) return false; String exp = st.nextToken(); String sp = st.nextToken(); long expval = 0; int spval = 0; try { expval = Long.parseLong(exp); spval = Integer.parseInt(sp); } catch (Exception e) { return false; } if (expval != 0 || spval != 0) { //Common character information player.sendMessage("Admin is adding you " + expval + " xp and " + spval + " sp."); player.addExpAndSp(expval, spval); //Admin information activeChar.sendMessage("Added " + expval + " xp and " + spval + " sp to " + player.getName() + "."); if (_log.isDebugEnabled()) _log.debug("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") added " + expval + " xp and " + spval + " sp to " + player.getObjectId() + "."); } return true; }
From source file:com.l2jfree.gameserver.handler.admincommands.AdminExpSp.java
private boolean adminRemoveExpSP(L2Player activeChar, String ExpSp) { L2Object target = activeChar.getTarget(); L2Player player = null;//from w w w . j ava 2s . c om if (target instanceof L2Player) { player = (L2Player) target; } else { activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET); return false; } StringTokenizer st = new StringTokenizer(ExpSp); if (st.countTokens() != 2) return false; String exp = st.nextToken(); String sp = st.nextToken(); long expval = 0; int spval = 0; try { expval = Long.parseLong(exp); spval = Integer.parseInt(sp); } catch (Exception e) { return false; } if (expval != 0 || spval != 0) { //Common character information player.sendMessage("Admin is removing you " + expval + " xp and " + spval + " sp."); player.removeExpAndSp(expval, spval); //Admin information activeChar.sendMessage("Removed " + expval + " xp and " + spval + " sp from " + player.getName() + "."); if (_log.isDebugEnabled()) _log.debug("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") removed " + expval + " xp and " + spval + " sp from " + player.getObjectId() + "."); } return true; }
From source file:com.insprise.common.lang.StringUtilities.java
/** * Tokenize the given string with the specified delimiter and returns the tokens in an array. * @param str the string to be tokenized. * @param delimiter the delimiter//from www .ja v a 2 s .com * @return an array containing all the tokens. */ public static String[] tokenizeStringIntoArray(String str, String delimiter) { StringTokenizer st = new StringTokenizer(str, delimiter); String[] tokens = new String[st.countTokens()]; int index = 0; while (st.hasMoreTokens()) { tokens[index++] = st.nextToken().trim(); } return tokens; }