List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:com.moviejukebox.scanner.artwork.PosterScanner.java
/** * Locate the PosterURL from the Internet. This is the main method and * should be called instead of the individual getPosterFrom* methods. * * @param movie The movieBean to search for * @return The posterImage with poster url that was found (Maybe * Image.UNKNOWN)/* w w w . j ava 2s.co m*/ */ public static IImage getPosterURL(Movie movie) { String posterSearchToken; IImage posterImage = Image.UNKNOWN; StringTokenizer st; if (movie.isTVShow()) { st = new StringTokenizer(TV_POSTER_SEARCH_PRIORITY, ","); } else { st = new StringTokenizer(MOVIE_POSTER_SEARCH_PRIORITY, ","); } while (st.hasMoreTokens() && StringTools.isNotValidString(posterImage.getUrl())) { posterSearchToken = st.nextToken(); IPosterPlugin iPosterPlugin = PLUGINS.get(posterSearchToken); // Check that plugin is register even on movie or tv if (iPosterPlugin == null) { LOG.error( "'{}' plugin doesn't exist, please check your moviejukebox properties. Valid plugins are : {}", posterSearchToken, getPluginsCode()); } String msg; if (movie.isTVShow()) { iPosterPlugin = TV_PLUGINS.get(posterSearchToken); msg = "TvShow"; } else { iPosterPlugin = MOVIE_PLUGINS.get(posterSearchToken); msg = "Movie"; } if (iPosterPlugin == null) { LOG.info("{} is not a {} Poster plugin - skipping", posterSearchToken, msg); } else { LOG.debug("Using {} to search for a {} poster for {}", posterSearchToken, msg, movie.getTitle()); posterImage = iPosterPlugin.getPosterUrl(movie, movie); } // Validate the poster- No need to validate if we're UNKNOWN if (!Movie.UNKNOWN.equalsIgnoreCase(posterImage.getUrl()) && POSTER_VALIDATE && !validatePoster(posterImage, POSTER_WIDTH, POSTER_HEIGHT, POSTER_VALIDATE_ASPECT)) { posterImage = Image.UNKNOWN; } else { if (!Movie.UNKNOWN.equalsIgnoreCase(posterImage.getUrl())) { LOG.debug("Poster URL found at {}: {}", posterSearchToken, posterImage.getUrl()); // TODO: This is a hack, but seeing as only one poster scanner uses it, it should be safe until it's all refactored to use the Artwork class posterImage.setSubimage(posterSearchToken); movie.setDirty(DirtyFlag.POSTER, Boolean.TRUE); } } } return posterImage; }
From source file:com.funambol.foundation.items.dao.PIMNoteDAO.java
private static String truncateStringList(String categoriesField, String separatorsString, int truncationSize) { if (categoriesField == null) { return null; }//from www . j a v a 2 s . co m StringTokenizer st = new StringTokenizer(categoriesField, separatorsString, true); StringBuilder sb = new StringBuilder(""); while (st.hasMoreTokens()) { String token = st.nextToken(); if (sb.length() + token.length() > truncationSize) { break; } sb.append(token); } if (sb.length() > 0) { char[] separators = separatorsString.toCharArray(); for (char separator : separators) { if (sb.charAt(sb.length() - 1) == separator) { sb.deleteCharAt(sb.length() - 1); break; } } } return sb.toString(); }
From source file:com.xhsoft.framework.common.utils.ClassUtil.java
/** * //from ww w.j ava2s. c o m * @param object * @param methodName * @return * @throws IllegalArgumentException * @throws SecurityException * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException - Object * @author: lizj */ public static Object call(Object object, String methodNames) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { java.util.StringTokenizer st = new java.util.StringTokenizer(methodNames, "."); while (object != null && st.hasMoreTokens()) { object = object.getClass().getMethod(st.nextToken(), new Class[0]).invoke(object, new Object[0]); } return object; }
From source file:org.web4thejob.web.util.ZkUtil.java
public static String replaceStyleElement(String style, String key, String value) { final StringBuilder sb = new StringBuilder(); if (style == null) { style = ""; } else {//from ww w . j a v a 2s . co m style = style.trim(); } if (!style.trim().endsWith(";")) { style += ";"; } boolean keyFound = false; final StringTokenizer st = new StringTokenizer(style, ";"); while (st.hasMoreTokens()) { final String token = st.nextToken(); final String[] pair = token.split(":"); final String[] newPair = new String[] { pair[0], "" }; if (pair.length > 1) { newPair[1] = pair[1]; } if (newPair[0].trim().equals(key)) { newPair[0] = key; newPair[1] = value; keyFound = true; } sb.append(newPair[0].trim()).append(":").append(newPair[1].trim()).append(";"); } if (!keyFound) { sb.append(key).append(":").append(value).append(";"); } return sb.toString(); }
From source file:de.tudarmstadt.ukp.clarin.webanno.project.page.ImportUtil.java
/** * Read Tag and Tag Description. A line has a tag name and a tag description separated by a TAB * //from w ww . j ava 2s .c o m * @param aLineSeparatedTags the line. * @return the parsed line. */ public static Map<String, String> getTagSetFromFile(String aLineSeparatedTags) { Map<String, String> tags = new LinkedHashMap<String, String>(); StringTokenizer st = new StringTokenizer(aLineSeparatedTags, "\n"); while (st.hasMoreTokens()) { StringTokenizer stTag = new StringTokenizer(st.nextToken(), "\t"); String tag = stTag.nextToken(); String description; if (stTag.hasMoreTokens()) { description = stTag.nextToken(); } else { description = tag; } tags.put(tag.trim(), description); } return tags; }
From source file:gate.DocumentFormat.java
/** * Returns a MymeType having as input a URL object. If the MimeType wasn't * recognized it returns <b>null</b>. * @param url The URL object from which the MimeType will be extracted * @return A MimeType object for that URL, or <b>null</b> if the Mime Type is * unknown./*from w w w. java2s . c o m*/ */ static private MimeType getMimeType(URL url) { String mimeTypeString = null; String charsetFromWebServer = null; String contentType = null; InputStream is = null; MimeType mimeTypeFromWebServer = null; MimeType mimeTypeFromFileSuffix = null; MimeType mimeTypeFromMagicNumbers = null; if (url == null) return null; // Ask the web server for the content type // We expect to get contentType something like this: // "text/html; charset=iso-8859-1" // Charset is optional try { try { URLConnection urlconn = url.openConnection(); is = urlconn.getInputStream(); contentType = urlconn.getContentType(); } catch (IOException e) { // Failed to get the content type with te Web server. // Let's try some other methods like FileSuffix or magic numbers. } // If a content Type was returned by the server, try to get the mime Type // string // If contentType is something like this:"text/html; charset=iso-8859-1" // try to get content Type string (text/html) if (contentType != null) { StringTokenizer st = new StringTokenizer(contentType, ";"); // We assume that the first token is the mime type string... // If this doesn't happen then BAD LUCK :(( ... if (st.hasMoreTokens()) mimeTypeString = st.nextToken().toLowerCase(); // The next token it should be the CharSet if (st.hasMoreTokens()) charsetFromWebServer = st.nextToken().toLowerCase(); if (charsetFromWebServer != null) { //We have something like : "charset=iso-8859-1" and let's extract the // encoding. st = new StringTokenizer(charsetFromWebServer, "="); // Don't need this anymore charsetFromWebServer = null; // Discarding the first token which is : "charset" if (st.hasMoreTokens()) st.nextToken(); // Get the encoding : "ISO-8859-1" if (st.hasMoreTokens()) charsetFromWebServer = st.nextToken().toUpperCase(); } // End if } // end if // Return the corresponding MimeType with WebServer from the associated MAP mimeTypeFromWebServer = mimeString2mimeTypeMap.get(mimeTypeString); // Let's try a file suffix detection // mimeTypeFromFileSuffix = getMimeType(getFileSuffix(url)); for (String suffix : getFileSuffixes(url)) { mimeTypeFromFileSuffix = getMimeType(suffix); if (mimeTypeFromFileSuffix != null) break; } // Let's perform a magic numbers guess.. mimeTypeFromMagicNumbers = guessTypeUsingMagicNumbers(is, charsetFromWebServer); } finally { IOUtils.closeQuietly(is); //null safe } //All those types enter into a deciding system return decideBetweenThreeMimeTypes(mimeTypeFromWebServer, mimeTypeFromFileSuffix, mimeTypeFromMagicNumbers); }
From source file:jp.terasoluna.fw.validation.ValidationUtil.java
/** * ?URL??????????/*from ww w . ja va 2 s .c o m*/ * * <code>null</code> ??????? * * @param value * @param allowallschemes ???????? * @param allow2slashes ?????? * @param nofragments URL?????? * @param schemesVar ?? * ????? * @return * ?URL?????? * <code>true</code>? * ?????<code>false</code>? */ public static boolean isUrl(String value, boolean allowallschemes, boolean allow2slashes, boolean nofragments, String schemesVar) { if (StringUtils.isEmpty(value)) { return true; } // ? int options = 0; if (allowallschemes) { options += UrlValidator.ALLOW_ALL_SCHEMES; } if (allow2slashes) { options += UrlValidator.ALLOW_2_SLASHES; } if (nofragments) { options += UrlValidator.NO_FRAGMENTS; } // ??????GenericValidator if (options == 0 && schemesVar == null) { if (GenericValidator.isUrl(value)) { return true; } return false; } // String[]?? String[] schemes = null; if (schemesVar != null) { StringTokenizer st = new StringTokenizer(schemesVar, ","); schemes = new String[st.countTokens()]; int i = 0; while (st.hasMoreTokens()) { schemes[i++] = st.nextToken().trim(); } } // ????UrlValidator UrlValidator urlValidator = new UrlValidator(schemes, options); if (urlValidator.isValid(value)) { return true; } return false; }
From source file:com.adito.reverseproxy.ReverseProxyMethodHandler.java
/** * Takes an unencoded URL query string, and encodes it. * @param query/* w ww . ja va 2 s . c o m*/ * @return */ public static final String encodeQuery(String query) { String encoded = ""; StringTokenizer pairs = new StringTokenizer(query, "&"); while (pairs.hasMoreTokens()) { StringTokenizer pair = new StringTokenizer(pairs.nextToken(), "="); if (pair.hasMoreTokens()) { encoded += (encoded.length() == 0 ? "" : "&") + URLUTF8Encoder.encode(pair.nextToken(), true); if (pair.hasMoreTokens()) { encoded += "=" + URLUTF8Encoder.encode(pair.nextToken(), true); } } } return encoded; }
From source file:it.univpm.deit.semedia.musicuri.core.Toolset.java
/** * Extracts a list of keywords from an audio file (currently only using its filename), * after ignoring certain words that are either among the 50 most common english words, * or are frequently occuring music-related terms commonly found in music filenames * @param audiofile the audio file to extract keywords from * @return an aArrayList object containing the extracted keywordss *///from w w w . j av a 2 s . c om public static ArrayList ExtractKeywords(File audiofile) { // Idea taken from: Franois Pachet and Damien Laigre, //"A Naturalist Approach to Music File Name Analysis" // Delimiter Hypothesis, Constant Term Hypothesis, Canonical Representation // of Identifiers (so that different spellings of a given identifier yield the same representation) // list of words to return ArrayList keywords = new ArrayList(); // list of words to ignore ArrayList ignored = new ArrayList(); // The 50 most common words in the english language // http://esl.about.com/library/vocabulary/bl1000_list1.htm // http://www.world-english.org/english500.htm // http://www.duboislc.org/EducationWatch/First100Words.html ignored.add("the"); ignored.add("of"); ignored.add("and"); ignored.add("a"); ignored.add("to"); ignored.add("in"); ignored.add("is"); ignored.add("you"); ignored.add("that"); ignored.add("it"); ignored.add("he"); ignored.add("was"); ignored.add("for"); ignored.add("on"); ignored.add("are"); ignored.add("as"); ignored.add("with"); ignored.add("his"); ignored.add("they"); ignored.add("i"); ignored.add("at"); ignored.add("be"); ignored.add("this"); ignored.add("have"); ignored.add("from"); ignored.add("or"); ignored.add("one"); ignored.add("had"); ignored.add("by"); ignored.add("word"); ignored.add("but"); ignored.add("not"); ignored.add("what"); ignored.add("all"); ignored.add("were"); ignored.add("we"); ignored.add("when"); ignored.add("your"); ignored.add("can"); ignored.add("said"); ignored.add("there"); ignored.add("use"); ignored.add("an"); ignored.add("each"); ignored.add("which"); ignored.add("she"); ignored.add("do"); ignored.add("how"); ignored.add("their"); ignored.add("if"); // Some frequently occuring words related to music filenames ignored.add("mp3"); ignored.add("&"); ignored.add("featuring"); ignored.add("+"); ignored.add("feat"); ignored.add("presenting"); ignored.add("pres"); ignored.add("live"); ignored.add("track"); ignored.add("album"); ignored.add("various"); ignored.add("artists"); ignored.add("artist"); ignored.add("va"); ignored.add("collection"); ignored.add("sampler"); ignored.add("mix"); ignored.add("complilation"); ignored.add("mixed"); ignored.add("remix"); ignored.add("remixed"); ignored.add("lp"); ignored.add("ep"); ignored.add("cd"); ignored.add(""); // replace all contents of the ignored list with lowercase for (int i = 0; i < ignored.size(); i++) { String tmp = (String) ignored.get(i); ignored.remove(i); tmp = tmp.toLowerCase(); ignored.add(tmp); } // the source used for token extraction is currently the filename String name = audiofile.getName(); // the delimiters to use when tokenizing StringTokenizer st = new StringTokenizer(name, " ,._-~\"'`/()[]:{}+#\t\n\r"); // loop over all tokens in string while (st.hasMoreTokens()) { // get the next String token = st.nextToken(); // convert it to lowercase token = token.toLowerCase(); // if it's on the list of ignored keywords if (!ignored.contains(token)) { // try to cast it to an integer try { // if it was an integer, do nothing Integer.parseInt(token); } catch (NumberFormatException e) { // if it wasn't, add it to the keywords list keywords.add(token); } } } return keywords; }
From source file:it.greenvulcano.util.txt.TextUtils.java
/** * Replaces JS invalid chars within <tt>input</tt> String with the * corresponding entities./*from ww w . j av a 2 s .c om*/ * * @param input * the input <tt>String</tt>. * @return the input string, with JS invalid chars replaced by the * corresponding entities. */ public static String replaceJSInvalidChars(String input) { // Shortcuts for efficiency final int len; if ((input == null) || ((len = input.length()) == 0)) { return input; } StringBuffer result = new StringBuffer((int) (len * 1.5)); StringTokenizer tokenizer = new StringTokenizer(input, jsInvalid, true); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); Object repl = jsReplacements.get(token); if (repl == null) { repl = token; } result.append((String) repl); } return result.toString(); }