List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:com.openkm.util.DocumentUtils.java
/** * Text spell checker// w w w .ja v a 2 s.c o m */ 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:Main.java
public static List<String> toList(StringTokenizer tokenizer) { List<String> list = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { list.add(tokenizer.nextToken()); }/* w w w . ja v a 2 s .co m*/ return list; }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.util.AuthUtil.java
/** * Use the information from the request to see if it has the Basic authorization header. If it does * validate it./*from ww w .j a va 2 s .co m*/ * @param request * @return true if the user is authorized and false if the user is not authorized. * @throws IOException */ public static boolean isAuthorized(HttpServletRequest request) throws IOException { String username = null; String password = null; boolean authorized = false; String authHeader = request.getHeader(KEY_AUTHORIZATION); if (authHeader != null) { StringTokenizer st = new StringTokenizer(authHeader); if (st.hasMoreTokens()) { String basic = st.nextToken(); if (basic.equalsIgnoreCase(KEY_BASIC)) { try { String credentials = new String( org.apache.commons.codec.binary.Base64.decodeBase64(st.nextToken().getBytes()), MMXServerConstants.UTF8_ENCODING); LOGGER.debug("Auth header {} ", authHeader); int p = credentials.indexOf(":"); if (p != -1) { username = credentials.substring(0, p).trim(); password = credentials.substring(p + 1).trim(); } else { LOGGER.warn("Invalid authentication token"); } } catch (UnsupportedEncodingException e) { LOGGER.warn("Couldn't retrieve authentication", e); } } } } else { LOGGER.info("Request is missing the authorization header"); } AuthToken token = null; if (username != null && password != null) { try { token = AuthFactory.authenticate(username, password); } catch (ConnectionException e) { LOGGER.error("isAuthorized : ", e); } catch (InternalUnauthenticatedException e) { LOGGER.error("isAuthorized : ", e); } catch (UnauthorizedException e) { LOGGER.error("isAuthorized : ", e); } } if (token != null) { AdminManager manager = AdminManager.getInstance(); authorized = manager.isUserAdmin(username, false); if (!authorized) { LOGGER.info("User:{} is not an admin. Not granting access", username); } } return authorized; }
From source file:Main.java
/** * Creates a list of strings from a string within tokens. Empty tokens will * be omitted: If a string within tokens is <code>"a,,b,,c"</code> and the * delimiter string is <code>","</code>, the returned list of strings * contains the tree elements <code>"a", "b", "c"</code>. * * @param string String within tokens * @param delimiter Delimiter that separates the tokens. Every character * of the delimiter string is a separate delimiter. If * the string within tokens is <code>"I,like:ice"</code> * and the delimiter string is <code>",:"</code>, the * returned list of strings contains the three elements * <code>"I", "like", "ice"</code>. * @return List of strings/*ww w . java 2 s . c o m*/ */ public static List<String> stringTokenToList(String string, String delimiter) { if (string == null) { throw new NullPointerException("string == null"); } if (delimiter == null) { throw new NullPointerException("delimiter == null"); } StringTokenizer tokenizer = new StringTokenizer(string, delimiter); List<String> list = new ArrayList<>(tokenizer.countTokens()); while (tokenizer.hasMoreTokens()) { list.add(tokenizer.nextToken()); } return list; }
From source file:Main.java
/** * Convert a full XML name to its generic name. This is done by checking if * each part of the name is complex (if it consists of a generic name plus a * specific name). If so, then the specific part is removed. Example of a * complex name : model.infrastructure.node-edge.spdata Result of * getGenericName : model.infrastructure.node.spdata * * @param name The XML name/*from w w w .jav a2 s .com*/ * @param removeArrays Wether array elements have to be removed from the * name. * @return The result */ public static String getGenericName(String fullName, boolean removeArrays) { StringTokenizer s = new StringTokenizer(fullName, "."); String result = "", tmp; int dashIndex; while (s.hasMoreTokens()) { tmp = s.nextToken(); if (removeArrays && (("array").equals(tmp) || ("element").equals(tmp))) { continue; } if (result.length() > 0) { result += "."; } if ((dashIndex = tmp.indexOf('-')) == -1) { result += tmp; } else { result += tmp.substring(0, dashIndex); } } return result; }
From source file:architecture.common.util.LocaleUtils.java
/** * Converts a locale string like "en", "en_US" or "en_US_win" to a Java * locale object. If the conversion fails, null is returned. * * @param localeCode/*from ww w. j a va 2 s .c om*/ * the locale code for a Java locale. See the * {@link java.util.Locale} class for more details. * @return The Java Locale that matches the locale code, or <tt>null</tt>. */ public static Locale localeCodeToLocale(String localeCode) { Locale locale = null; if (localeCode != null) { String language = null; String country = null; String variant = null; StringTokenizer tokenizer = new StringTokenizer(localeCode, "_"); if (tokenizer.hasMoreTokens()) { language = tokenizer.nextToken(); if (tokenizer.hasMoreTokens()) { country = tokenizer.nextToken(); if (tokenizer.hasMoreTokens()) { variant = tokenizer.nextToken(); } } } locale = new Locale(language, ((country != null) ? country : ""), ((variant != null) ? variant : "")); } return locale; }
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 *//*from w w w . jav a2s . c o m*/ 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; }
From source file:Main.java
/** * utility method to get the last token in a "."-delimited package+classname string * * @return/* ww w. j a v a 2 s . c o m*/ */ private static String getSimpleName(String in) { if (in == null || in.length() == 0) { return in; } String out = null; StringTokenizer tokenizer = new StringTokenizer(in, "."); if (tokenizer.countTokens() == 0) out = in; else { while (tokenizer.hasMoreTokens()) { out = tokenizer.nextToken(); } } return out; }
From source file:com.spotify.scio.extra.transforms.ProcessUtil.java
static String[] tokenizeCommand(String command) { StringTokenizer st = new StringTokenizer(command); String[] cmdArray = new String[st.countTokens()]; for (int i = 0; st.hasMoreTokens(); i++) cmdArray[i] = st.nextToken();//w w w .j av a 2 s . c om return cmdArray; }
From source file:edu.stanford.muse.lang.Languages.java
public static void init() { allPatterns.clear();//from w w w . j a v a2 s .co m allLanguages.clear(); allScripts.clear(); allLanguages.add("English"); allScripts.add("Roman"); for (String[] lang : script_languages) { String scriptName = lang[0]; String langString = lang[1]; List<String> languages = new ArrayList<String>(); // tokenize langString by , StringTokenizer st = new StringTokenizer(langString, ","); while (st.hasMoreTokens()) { String language = st.nextToken(); language = language.trim(); if (language.length() == 0) continue; languages.add(language); } // build up pattern array or all pattern to languages for (String language : languages) { Pattern p = Pattern.compile(".*\\p{In" + scriptName + "}.*", Pattern.DOTALL); // DOTALL allows matching across lines which is what we want to detect chars in a given script allPatterns.add(new LangInfo(p, language)); allScripts.add(scriptName); allLanguages.add(language); } } log.info(allScripts.size() + " scripts, " + allLanguages.size() + " languages, " + allPatterns.size() + " patterns"); }