List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:com.dosport.system.utils.ServletUtils.java
/** * ?? If-None-Match Header, Etag?.//from w w w. j av a 2 s.co m * * Etag, checkIfNoneMatchfalse, 304 not modify status. * * @param etag * ETag. */ public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) { String headerValue = request.getHeader("If-None-Match"); if (headerValue != null) { boolean conditionSatisfied = false; if (!"*".equals(headerValue)) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(etag)) { conditionSatisfied = true; } } } else { conditionSatisfied = true; } if (conditionSatisfied) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader("ETag", etag); return false; } } return true; }
From source file:Main.java
/** * // w w w. j a va 2s. c om * @param value * @return double[] */ public static double[] toDoubleArray(final String value) { if (value == null) { return new double[] {}; } final int BRACKET_LENGTH = 1; final String strippedValue = value.substring(BRACKET_LENGTH, value.length() - BRACKET_LENGTH); final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR); final Collection<Double> doubleCollection = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { doubleCollection.add(Double.valueOf(tokenizer.nextToken().trim())); } return toDoubleArray(doubleCollection); }
From source file:net.naijatek.myalumni.util.utilities.MailUtil.java
/** * This method trim the email variable, so if it contains only spaces, then * it will be empty string, then we have 0 token :-) The returned value is * never null/*from w w w. j a v a2 s .c om*/ * * @param email String * @throws BadInputException * @return String[] */ private static String[] getEmails(String email) throws BadInputException { if (email == null) { email = ""; } email = email.trim();// very important StringTokenizer t = new StringTokenizer(email, ";"); String[] ret = new String[t.countTokens()]; int index = 0; while (t.hasMoreTokens()) { String mail = t.nextToken().trim(); checkGoodEmail(mail); ret[index] = mail; //log.debug(ret[index]); index++; } return ret; }
From source file:com.bibisco.manager.TextEditorManager.java
private static void parseTextNode(HtmlParsingResult pHtmlParsingResult, Node pNode) { List<String> lListWords = new ArrayList<String>(); mLog.debug("Start parseTextNode(HtmlParsingResult, Node): ", pNode.toString()); // character count String lStrNodeText = StringUtils.replace(pNode.toString(), " ", " "); lStrNodeText = StringUtils.replace(lStrNodeText, "\n", ""); lStrNodeText = StringEscapeUtils.unescapeHtml(lStrNodeText); pHtmlParsingResult.characterCount += lStrNodeText.length(); // extract words lStrNodeText = pNode.toString();/*from w w w .j a v a2 s . c om*/ lStrNodeText = StringUtils.replace(lStrNodeText, " ", ""); lStrNodeText = StringUtils.replace(lStrNodeText, "«", ""); lStrNodeText = StringUtils.replace(lStrNodeText, "»", ""); lStrNodeText = StringUtils.replace(lStrNodeText, "—", ""); lStrNodeText = StringEscapeUtils.unescapeHtml(lStrNodeText); lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 33, 38); lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 40, 47); lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 58, 64); lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 91, 96); lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 123, 126); lStrNodeText = replaceCharIntervalWithWhiteSpace(lStrNodeText, 161, 191); lStrNodeText = StringUtils.replaceChars(lStrNodeText, '', ' '); lStrNodeText = StringUtils.replaceChars(lStrNodeText, '', ' '); lStrNodeText = StringUtils.replaceChars(lStrNodeText, '', ' '); lStrNodeText = lStrNodeText.trim(); if (StringUtils.isNotBlank(lStrNodeText)) { StringTokenizer lStringTokenizer = new StringTokenizer(lStrNodeText); while (lStringTokenizer.hasMoreTokens()) { lListWords.add(lStringTokenizer.nextToken()); } } pHtmlParsingResult.words.addAll(lListWords); mLog.debug("End parseTextNode(HtmlParsingResult, Node)"); }
From source file:marytts.features.FeatureRegistry.java
/** * Obtain a TargetFeatureComputer that knows how to compute features * for a Target using the given set of feature processor names. These names * must be known to the given Feature processor manager. * @param mgr //from w w w.j a v a 2 s . co m * @param features a String containing the names of the * feature processors to use, separated by white space, and in the * right order (byte-valued discrete feature processors first, then * short-valued, then continuous). If features is null, * use all available features processors. * @return a target feature computer * @throws IllegalArgumentException if one of the features is not known to the manager */ public static TargetFeatureComputer getTargetFeatureComputer(FeatureProcessorManager mgr, String features) { if (features == null) { features = mgr.listFeatureProcessorNames(); } else { // verify that each feature is known to the mgr StringTokenizer st = new StringTokenizer(features); while (st.hasMoreTokens()) { String feature = st.nextToken(); if (mgr.getFeatureProcessor(feature) == null) { throw new IllegalArgumentException("Feature processor manager '" + mgr.getClass().toString() + "' does not know the feature '" + feature + "'"); } } } TargetFeatureComputer tfc = (TargetFeatureComputer) computers.get(mgr, features); if (tfc == null) { tfc = new TargetFeatureComputer(mgr, features); } return tfc; }
From source file:com.handpay.ibenefit.framework.util.WebUtils.java
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) {//from ww w .j a v a 2 s . c o m String headerValue = request.getHeader("If-None-Match"); if (headerValue != null) { boolean conditionSatisfied = false; if (!"*".equals(headerValue)) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(etag)) { conditionSatisfied = true; } } } else { conditionSatisfied = true; } if (conditionSatisfied) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader("ETag", etag); return false; } } return true; }
From source file:PackageUtils.java
private static List<String> tokenize(String str, String sep) { StringTokenizer tokens = new StringTokenizer(str, sep); List<String> r = new ArrayList<String>(); while (tokens.hasMoreTokens()) { r.add(tokens.nextToken());// w w w . j av a2 s . co m } return r; }
From source file:com.tacitknowledge.util.discovery.ClasspathUtils.java
/** * Returns the classpath as a list directory and archive names. * * @return the classpath as a list of directory and archive file names; if * no components can be found then an empty list will be returned */// w w w . j a v a 2 s . c o m public static List getClasspathComponents() { List components = new LinkedList(); // walk the classloader hierarchy, trying to get all the components we can ClassLoader cl = Thread.currentThread().getContextClassLoader(); while ((null != cl) && (cl instanceof URLClassLoader)) { URLClassLoader ucl = (URLClassLoader) cl; components.addAll(getUrlClassLoaderClasspathComponents(ucl)); try { cl = ucl.getParent(); } catch (SecurityException se) { cl = null; } } // walking the hierarchy doesn't guarantee we get everything, so // lets grab the system classpath for good measure. String classpath = System.getProperty("java.class.path"); String separator = System.getProperty("path.separator"); StringTokenizer st = new StringTokenizer(classpath, separator); while (st.hasMoreTokens()) { String component = st.nextToken(); // Calling File.getPath() cleans up the path so that it's using // the proper path separators for the host OS component = getCanonicalPath(component); components.add(component); } // Set removes any duplicates, return a list for the api. return new LinkedList(new HashSet(components)); }
From source file:com.xpn.xwiki.render.macro.TableBuilder.java
public static Table build(String content) { Table table = new Table(); StringTokenizer tokenizer = new StringTokenizer(content, "|\n", true); String lastToken = null;//from w ww. j a v a2 s. com boolean firstCell = true; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.equals("\r")) { continue; } // If a token contains [, then all tokens up to one containing a ] are concatenated. Kind of a block marker. if (token.indexOf('[') != -1 && token.indexOf(']') == -1) { String linkToken = ""; while (token.indexOf(']') == -1 && tokenizer.hasMoreTokens()) { linkToken += token; token = tokenizer.nextToken(); } token = linkToken + token; } if ("\n".equals(token)) { // New line: either new row, or a literal newline. lastToken = (lastToken == null) ? "" : lastToken; if (!StringUtils.endsWith(lastToken, "\\")) { // A new row, not a literal newline. // If the last cell didn't contain any data, then it was skipped. Add a blank cell to compensate. if ((StringUtils.isEmpty(lastToken) || "|".equals(lastToken)) && !firstCell) { table.addCell(" "); } table.newRow(); } else { // A continued row, with a literal newline. String cell = lastToken; // Keep concatenating while the cell data ends with \\ while (cell.endsWith("\\") && tokenizer.hasMoreTokens()) { token = tokenizer.nextToken(); if (!"|".equals(token)) { cell = cell + token; } else { break; } } firstCell = false; table.addCell(cell.trim()); if (!tokenizer.hasMoreTokens()) { table.newRow(); } } } else if (!"|".equals(token)) { // Cell data if (!token.endsWith("\\")) { // If the cell data ends with \\, then it will be continued. Current data is stored in lastToken. table.addCell(token.trim()); firstCell = false; } else if (!tokenizer.hasMoreTokens()) { // Remove backslashes from the end while (token.endsWith("\\")) { token = StringUtils.chop(token); } table.addCell(token.trim()); } } else if ("|".equals(token)) { // Cell delimiter if ((StringUtils.isEmpty(lastToken) && firstCell) || "|".equals(lastToken)) { // If the last cell didn't contain any data, then it was skipped. Add a blank cell to compensate. table.addCell(" "); firstCell = false; } else if (StringUtils.endsWith(lastToken, "\\")) { // The last cell wasn't added because it ended with a continuation mark (\\). Add it now. table.addCell(lastToken.trim()); firstCell = false; } } lastToken = token; } return table; }
From source file:io.datenwelt.cargo.rest.utils.Rfc2047.java
public static String decodeHeader(String input) { StringTokenizer tokenizer = new StringTokenizer(input, " \t", true); StringBuilder decoded = new StringBuilder(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (!token.startsWith("=?") || !token.endsWith("?=")) { decoded.append(token);/* www .j a va 2 s. c o m*/ continue; } String encodedWord = token; String[] parts = encodedWord.substring(2, encodedWord.length() - 2).split("\\?", 3); if (parts.length != 3) { decoded.append(token); continue; } Charset charset; try { charset = Charset.forName(parts[0]); } catch (Exception ex) { LOG.debug("Skipping the decoding of a header value due to an unknown charset \"{}\" found in: ", parts[1], input, ex); decoded.append(token); continue; } String encoding = parts[1].toUpperCase(); switch (encoding) { case "B": BCodec bcodec = new BCodec(charset); try { decoded.append(bcodec.decode(encodedWord)); } catch (Exception ex) { LOG.debug("Skipping the decoding of BASE64 value from string \"{}\" found in: ", encodedWord, input, ex); decoded.append(token); } break; case "Q": QCodec qcodec = new QCodec(charset); try { decoded.append(qcodec.decode(encodedWord)); } catch (Exception ex) { LOG.debug("Skipping the decoding of Q encoded value from string \"{}\" found in: ", encodedWord, input, ex); decoded.append(token); } break; default: LOG.debug("Skipping the decoding of value from unknown encoding \"{}\" found in: ", encodedWord, input); decoded.append(token); } } return decoded.toString(); }