List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:net.sf.j2ep.model.AllowedMethodHandler.java
/** * Will set the allowed methods, both by setting the string * and also by adding all the methods to the set of allowed. * @param allowed The list of allowed methods, should be comma separated *///www. ja v a2 s . com @SuppressWarnings("unchecked") public synchronized static void setAllowedMethods(String allowed) { allowedMethods = new HashSet(); allowString = allowed; StringTokenizer tokenizer = new StringTokenizer(allowed, ","); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken().trim().toUpperCase(); allowedMethods.add(token); } }
From source file:Main.java
/** * Build schema location map of schemas used in given * <code>schemaLocationAttribute</code> and adds them to the given * <code>schemaLocationMap</code>. * //from w w w . j a v a 2 s . c om * @see <a href="http://www.w3.org/TR/xmlschema-0/#schemaLocation">XML Schema * Part 0: Primer Second Edition | 5.6 schemaLocation</a> * * @param schemaLocationMap * {@link Map} to add schema locations to. * @param schemaLocation * attribute value to build schema location map from. * @return {@link Map} of schema namespace URIs to location URLs. * @since 8.1 */ static final Map<String, List<String>> buildSchemaLocationMap(Map<String, List<String>> schemaLocationMap, final String schemaLocation) { if (null == schemaLocation) { return schemaLocationMap; } if (null == schemaLocation || schemaLocation.isEmpty()) { // should really ever be null but being safe. return schemaLocationMap; } final StringTokenizer st = new StringTokenizer(schemaLocation, " \n\t\r"); while (st.hasMoreElements()) { final String ns = st.nextToken(); final String loc = st.nextToken(); List<String> locs = schemaLocationMap.get(ns); if (null == locs) { locs = new ArrayList<>(); schemaLocationMap.put(ns, locs); } if (!locs.contains(loc)) { locs.add(loc); } } return schemaLocationMap; }
From source file:com.openkm.util.DocumentUtils.java
/** * Text spell checker/*from www. ja va 2 s . c om*/ */ public static String spellChecker(String text) throws IOException { log.debug("spellChecker({})", text); StringBuilder sb = new StringBuilder(); if (Config.SYSTEM_OPENOFFICE_DICTIONARY.equals("")) { log.warn("OpenOffice dictionary not configured"); sb.append(text); } else { log.info("Using OpenOffice dictionary: {}", Config.SYSTEM_OPENOFFICE_DICTIONARY); ZipFile zf = new ZipFile(Config.SYSTEM_OPENOFFICE_DICTIONARY); OpenOfficeSpellDictionary oosd = new OpenOfficeSpellDictionary(zf); SpellChecker sc = new SpellChecker(oosd); sc.setCaseSensitive(false); StringTokenizer st = new StringTokenizer(text); while (st.hasMoreTokens()) { String w = st.nextToken(); List<String> s = sc.getDictionary().getSuggestions(w); if (s.isEmpty()) { sb.append(w).append(" "); } else { sb.append(s.get(0)).append(" "); } } zf.close(); } log.debug("spellChecker: {}", sb.toString()); return sb.toString(); }
From source file:gsn.storage.SQLUtils.java
public static String getTableName(String query) { String q = SQLValidator.removeSingleQuotes(SQLValidator.removeQuotes(query)).toLowerCase(); StringTokenizer tokens = new StringTokenizer(q, " "); while (tokens.hasMoreElements()) if (tokens.nextToken().equalsIgnoreCase("from") && tokens.hasMoreTokens()) return tokens.nextToken(); return null;//from w w w. j a v a 2 s. c o m }
From source file:net.sf.j2ep.model.AllowedMethodHandler.java
/** * Will go through all the methods sent in * checking to see that the method is allowed. * If it's allowed it will be included/* ww w .java 2s . c o m*/ * in the returned value. * * @param allowSent The header returned by the server * @return The allowed headers for this request */ public static String processAllowHeader(String allowSent) { StringBuffer allowToSend = new StringBuffer(""); StringTokenizer tokenizer = new StringTokenizer(allowSent, ","); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken().trim().toUpperCase(); if (allowedMethods.contains(token)) { allowToSend.append(token).append(","); } } return allowToSend.toString(); }
From source file:Main.java
public static String encodeUrl(String url, String charset) throws UnsupportedEncodingException { if (url == null) { return ""; }// w w w .ja v a2 s. com int index = url.indexOf("?"); if (index >= 0) { String result = url.substring(0, index + 1); String paramsPart = url.substring(index + 1); StringTokenizer tokenizer = new StringTokenizer(paramsPart, "&"); while (tokenizer.hasMoreTokens()) { String definition = tokenizer.nextToken(); int eqIndex = definition.indexOf("="); if (eqIndex >= 0) { String paramName = definition.substring(0, eqIndex); String paramValue = definition.substring(eqIndex + 1); result += paramName + "=" + encodeUrlParam(paramValue, charset) + "&"; } else { result += encodeUrlParam(definition, charset) + "&"; } } if (result.endsWith("&")) { result = result.substring(0, result.length() - 1); } return result; } return url; }
From source file:Main.java
public static List<String> toList(StringTokenizer tokenizer) { List<String> list = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { list.add(tokenizer.nextToken()); }//from w w w.ja v a 2 s. c om return list; }
From source file:org.wicketstuff.gmap.api.GLatLng.java
/** * (37.34068368469045, -122.48519897460936) *//* www.jav a 2 s. c om*/ public static GLatLng parse(String value) { try { StringTokenizer tokenizer = new StringTokenizer(value, "(, )"); float lat = Float.valueOf(tokenizer.nextToken()); float lng = Float.valueOf(tokenizer.nextToken()); return new GLatLng(lat, lng); } catch (Exception e) { return null; } }
From source file:com.flipkart.phantom.task.utils.StringUtils.java
public static Map<String, String> getQueryParams(String httpUrl) { Map<String, String> params = new HashMap<String, String>(); if (httpUrl == null) { return params; }/*from w w w .java 2 s.c o m*/ URL url = null; try { url = new URL(httpUrl); } catch (MalformedURLException e) { throw new RuntimeException(e); } String query = url.getQuery(); if (query == null) { return params; } StringTokenizer tokenizer = new StringTokenizer(query, "&"); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); int index = token.indexOf("="); params.put(token.substring(0, index).trim(), token.substring(index + 1).trim()); } return params; }
From source file:net.sf.jabref.exporter.layout.WSITools.java
/** * @param vcr {@link java.util.Vector} of <tt>String</tt> * @param s Description of the Parameter * @param delimstr Description of the Parameter * @param limit Description of the Parameter * @return Description of the Return Value *//* w ww. java 2s . c om*/ public static boolean tokenize(Vector<String> vcr, String s, String delimstr, int limit) { LOGGER.warn("Tokenize \"" + s + '"'); vcr.clear(); s = s + '\n'; int endpos; int matched = 0; StringTokenizer st = new StringTokenizer(s, delimstr); while (st.hasMoreTokens()) { String tmp = st.nextToken(); vcr.add(tmp); matched++; if (matched == limit) { endpos = s.lastIndexOf(tmp); vcr.add(s.substring(endpos + tmp.length())); break; } } return true; }