List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:fr.openwide.talendalfresco.alfresco.util.ContentDataUtil.java
/** * [talendalfresco] In comparison to ContentData.createContentProperty(), * if there is no mimetype it guesses it using the mimetypeService, therefore * not exploding if no mimetype./*from ww w . jav a 2 s . c o m*/ * * Construct a content property from a string * * @param contentPropertyStr the string representing the content details * @return Returns a bean version of the string */ public static ContentData createContentPropertyWithGuessedMimetype(String contentPropertyStr, MimetypeService mimetypeService) { String contentUrl = null; String mimetype = null; long size = 0L; String encoding = null; Locale locale = null; // now parse the string StringTokenizer tokenizer = new StringTokenizer(contentPropertyStr, "|"); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.startsWith("contentUrl=")) { contentUrl = token.substring(11); if (contentUrl.length() == 0) { contentUrl = null; } } else if (token.startsWith("mimetype=")) { mimetype = token.substring(9); if (mimetype.length() == 0) { mimetype = null; } } else if (token.startsWith("size=")) { String sizeStr = token.substring(5); if (sizeStr.length() > 0) { size = Long.parseLong(sizeStr); } } else if (token.startsWith("encoding=")) { encoding = token.substring(9); if (encoding.length() == 0) { encoding = null; } } else if (token.startsWith("locale=")) { String localeStr = token.substring(7); if (localeStr.length() > 0) { locale = I18NUtil.parseLocale(localeStr); } } } // [talendalfresco] if no mimetype, let's guess it if (mimetype == null) { mimetype = mimetypeService.guessMimetype(contentUrl); } ContentData property = new ContentData(contentUrl, mimetype, size, encoding, locale); // done return property; }
From source file:com.salesmanager.core.util.StringUtil.java
public static Map deformatUrlResponse(String payload) throws Exception { HashMap nvp = new HashMap(); StringTokenizer stTok = new StringTokenizer(payload, "&"); while (stTok.hasMoreTokens()) { StringTokenizer stInternalTokenizer = new StringTokenizer(stTok.nextToken(), "="); if (stInternalTokenizer.countTokens() == 2) { String key = URLDecoder.decode(stInternalTokenizer.nextToken(), "UTF-8"); String value = URLDecoder.decode(stInternalTokenizer.nextToken(), "UTF-8"); nvp.put(key.toUpperCase(), value); }//ww w .jav a 2 s . c o m } return nvp; }
From source file:edu.cmu.cs.lti.ark.fn.data.prep.ParsePreparation.java
/** * Converts a POS tagged file into conll format * @param posFile//from w ww. j a va 2s . com * @param conllInputFile */ public static void printCoNLLTypeInput(String posFile, String conllInputFile) throws IOException { List<String> posSentences = readLines(posFile); BufferedWriter bWriter = new BufferedWriter(new FileWriter(conllInputFile)); try { for (String posSentence : posSentences) { posSentence = replaceSentenceWithPTBWords(posSentence); ArrayList<String> words = new ArrayList<String>(); ArrayList<String> pos = new ArrayList<String>(); ArrayList<String> parents = new ArrayList<String>(); ArrayList<String> labels = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(posSentence.trim()); while (st.hasMoreTokens()) { String token = st.nextToken(); int lastIndex = token.lastIndexOf('_'); String word = token.substring(0, lastIndex); String POS = token.substring(lastIndex + 1); words.add(word); pos.add(POS); parents.add("0"); labels.add("SUB"); } writeStuff(bWriter, words, pos, parents, labels); } } finally { IOUtils.closeQuietly(bWriter); } }
From source file:Main.java
/** * Normalize a uri containing ../ and ./ paths. * * @param uri The uri path to normalize/*from w w w .j a va 2s. co m*/ * @return The normalized uri */ public static String normalize(String uri) { if ("".equals(uri)) { return uri; } int leadingSlashes; for (leadingSlashes = 0; leadingSlashes < uri.length() && uri.charAt(leadingSlashes) == '/'; ++leadingSlashes) { } boolean isDir = (uri.charAt(uri.length() - 1) == '/'); StringTokenizer st = new StringTokenizer(uri, "/"); LinkedList clean = new LinkedList(); while (st.hasMoreTokens()) { String token = st.nextToken(); if ("..".equals(token)) { if (!clean.isEmpty() && !"..".equals(clean.getLast())) { clean.removeLast(); if (!st.hasMoreTokens()) { isDir = true; } } else { clean.add(".."); } } else if (!".".equals(token) && !"".equals(token)) { clean.add(token); } } StringBuffer sb = new StringBuffer(); while (leadingSlashes-- > 0) { sb.append('/'); } for (Iterator it = clean.iterator(); it.hasNext();) { sb.append(it.next()); if (it.hasNext()) { sb.append('/'); } } if (isDir && sb.length() > 0 && sb.charAt(sb.length() - 1) != '/') { sb.append('/'); } return sb.toString(); }
From source file:Main.java
/** * Parses a string into a locale. The string is expected to be of the same * format of the string obtained by calling Locale.toString(). * // w w w . j av a 2 s.c o m * @param localeString * string representation of a locale * @return a locale or <code>null</code> if string is empty or null */ public static Locale parseLocale(String localeString) { if (localeString == null || localeString.trim().length() == 0) { return null; } StringTokenizer tokens = new StringTokenizer(localeString, "_"); //$NON-NLS-1$ List<String> localeSections = new ArrayList<String>(); while (tokens.hasMoreTokens()) { localeSections.add(tokens.nextToken()); } Locale locale = null; switch (localeSections.size()) { case 1: locale = new Locale(localeSections.get(0)); break; case 2: locale = new Locale(localeSections.get(0), localeSections.get(1)); break; case 3: locale = new Locale(localeSections.get(0), localeSections.get(1), localeSections.get(2)); break; default: break; } return locale; }
From source file:net.sf.j2ep.requesthandlers.RequestHandlerBase.java
/** * Adds all the headers in the input to the list * of banned headers. The input string should be * comma separated e.g. "Server,Connection,Via" * /* www . j a va 2 s. c o m*/ * This method is normally called by the factory that * is using this request handler. * * @param headers The headers that are banned */ @SuppressWarnings("unchecked") public static void addBannedHeaders(String headers) { StringTokenizer tokenizer = new StringTokenizer(headers, ","); while (tokenizer.hasMoreTokens()) { bannedHeaders.add(tokenizer.nextToken().trim().toLowerCase()); } }
From source file:ca.uhn.fhir.rest.method.ElementsParameter.java
public static Set<String> getElementsValueOrNull(RequestDetails theRequest) { String[] summary = theRequest.getParameters().get(Constants.PARAM_ELEMENTS); if (summary != null && summary.length > 0) { Set<String> retVal = new HashSet<String>(); for (String next : summary) { StringTokenizer tok = new StringTokenizer(next, ","); while (tok.hasMoreTokens()) { String token = tok.nextToken(); if (isNotBlank(token)) { retVal.add(token);//from w w w . jav a2s. co m } } } if (retVal.isEmpty()) { return null; } // Always include the meta element even for subsetted values retVal.add("meta"); return retVal; } else { return null; } }
From source file:com.microsoft.aad.adal.HashMapExtensions.java
/** * decode url string into a key value pairs with given query delimiter given * string as a=1&b=2 will return key value of [[a,1],[b,2]]. * /*from w ww. j a v a 2 s.com*/ * @param parameters * @param delimiter * @return key value pairs */ static final HashMap<String, String> URLFormDecodeData(String parameters, String delimiter) { HashMap<String, String> result = new HashMap<String, String>(); if (!StringExtensions.IsNullOrBlank(parameters)) { StringTokenizer parameterTokenizer = new StringTokenizer(parameters, delimiter); while (parameterTokenizer.hasMoreTokens()) { String pair = parameterTokenizer.nextToken(); String[] elements = pair.split("="); if (elements != null && elements.length == 2) { String key = null; String value = null; try { key = StringExtensions.URLFormDecode(elements[0].trim()); value = StringExtensions.URLFormDecode(elements[1].trim()); } catch (UnsupportedEncodingException e) { Log.d(TAG, e.getMessage()); } if (!StringExtensions.IsNullOrBlank(key) && !StringExtensions.IsNullOrBlank(value)) { result.put(key, value); } } } } return result; }
From source file:com.silverpeas.components.model.AbstractSpringJndiDaoTest.java
/** * Workaround to be able to use Sun's JNDI file system provider on Unix * * @param ic : the JNDI initial context//from ww w . jav a 2 s . c om * @param jndiName : the binding name * @param ref : the reference to be bound * @throws NamingException */ protected static void rebind(InitialContext ic, String jndiName, Object ref) throws NamingException { Context currentContext = ic; StringTokenizer tokenizer = new StringTokenizer(jndiName, "/", false); while (tokenizer.hasMoreTokens()) { String name = tokenizer.nextToken(); if (tokenizer.hasMoreTokens()) { try { currentContext = (Context) currentContext.lookup(name); } catch (javax.naming.NameNotFoundException nnfex) { currentContext = currentContext.createSubcontext(name); } } else { currentContext.rebind(name, ref); } } }
From source file:com.evolveum.liferay.usercreatehook.ws.WSConfig.java
public static List<String> getAllwaysPermittedEmailDomains() { List<String> result = new ArrayList<String>(); String value = PropsUtil.get(PROPERTY_EMAIL_DOMAINS_ALLWAYS_PERMITTED); if (!StringUtils.isBlank(value)) { StringTokenizer st = new StringTokenizer(value, ","); while (st.hasMoreTokens()) { String domain = st.nextToken().trim().toLowerCase(); result.add(domain);//from w w w .j a v a2 s .com } } LOG.debug("Property '" + PROPERTY_EMAIL_DOMAINS_ALLWAYS_PERMITTED + "' value: '" + value + "'. Used domains from list: '" + result + "'"); return result; }