List of usage examples for java.util StringTokenizer hasMoreElements
public boolean hasMoreElements()
From source file:Main.java
/** * Replace all occurrences of the characters &, ', ", < and > by the escaped * characters &, ", ', < and > *///from w w w . j a v a 2s . c o m public static String XMLEscape(String s) { if (s == null) { return ""; } boolean contains = false; for (int i = 0; i < XML_ESCAPE_DELIMITERS.length(); i++) { if (s.indexOf(XML_ESCAPE_DELIMITERS.charAt(i)) != -1) { contains = true; } } if (!contains) { return s; } if (s.length() == 0) { return s; } StringTokenizer tokenizer = new StringTokenizer(s, XML_ESCAPE_DELIMITERS, true); StringBuffer result = new StringBuffer(); while (tokenizer.hasMoreElements()) { String substring = tokenizer.nextToken(); if (substring.length() == 1) { switch (substring.charAt(0)) { case '&': result.append("&"); break; //case '\'' : // result.append("'"); // break; case ';': result.append("\\;"); break; case '<': result.append("<"); break; case '>': result.append(">"); break; case '\"': result.append("""); break; // case '\n' : // result.append("\\n"); // break; default: result.append(substring); } } else { result.append(substring); } } return result.toString(); }
From source file:net.rim.ejde.internal.legacy.Util.java
static public List<String> getSources(Project proj) { List<String> sources = new ArrayList<String>(); String udata = proj.getUserData(); StringTokenizer st = new StringTokenizer(udata, "|"); String token;/*from w ww .j ava 2 s .co m*/ while (st.hasMoreElements()) { token = st.nextToken(); if (StringUtils.isNotBlank(token)) { sources.add(token); } } return sources; }
From source file:org.rivetlogic.utils.IntegrationUtils.java
public static String encodePath(String alfPath) { StringBuilder pathBuilder = new StringBuilder(100); StringTokenizer tokenizer = new StringTokenizer(alfPath, Character.toString(File.separatorChar)); while (tokenizer.hasMoreElements()) { String pStr = tokenizer.nextElement().toString(); if (!pStr.startsWith("/")) { for (String prefix : IntegrationConstants.NAMESPACE_PREFIX_RESOLVER.getPrefixes()) { if (pStr.startsWith(prefix)) { pStr = pStr.substring(0, prefix.length() + 1) + ISO9075.encode(pStr.substring(prefix.length() + 1)); }/*from ww w . j a v a 2 s .c o m*/ } pathBuilder.append(File.separatorChar); pathBuilder.append(pStr); } } return pathBuilder.toString(); }
From source file:com.jaspersoft.jasperserver.export.RemoveDuplicatedDisplayName.java
private static List getPaths(String listOfXML) { ArrayList lst = new ArrayList(); StringTokenizer str = new StringTokenizer(listOfXML, ","); while (str.hasMoreElements()) { lst.add(str.nextElement());/*w w w . ja va2 s. c o m*/ } return lst; }
From source file:org.energy_home.jemma.internal.ah.hap.client.HapServiceConfiguration.java
private static String[] propertyValueToStringArray(String propertyValue) { propertyValue = propertyValue.replace("[", ""); propertyValue = propertyValue.replace("]", ""); propertyValue = propertyValue.trim(); StringTokenizer st = new StringTokenizer(propertyValue, ","); String[] result = new String[st.countTokens()]; int i = 0;//from www.j a va 2 s.c om while (st.hasMoreElements()) { result[i] = ((String) st.nextElement()).trim(); i++; } return result; }
From source file:org.apache.manifoldcf.crawler.connectors.cmis.CmisRepositoryConnectorUtils.java
private static String getSelectClause(String cmisQuery) { StringTokenizer cmisQueryTokenized = new StringTokenizer(cmisQuery.trim()); String selectClause = StringUtils.EMPTY; boolean firstTerm = true; while (cmisQueryTokenized.hasMoreElements()) { String term = cmisQueryTokenized.nextToken(); if (!term.equalsIgnoreCase(FROM_TOKEN)) { if (firstTerm) { selectClause += term;/*from w ww . j av a 2 s . co m*/ firstTerm = false; } else { selectClause += SEP + term; } } else { break; } } return selectClause; }
From source file:arena.mail.MailSender.java
protected static Session makeSession(String smtpServer, String smtpServerDelimiter, Properties extraMailProperties) { Properties mailProps = new Properties(); mailProps.put("mail.transport.protocol", "smtp"); // Support alternate syntax for core properties: "server,user,pass,localhost" StringTokenizer st = new StringTokenizer(smtpServer, smtpServerDelimiter); String property = null;/* w w w .ja v a2 s.c o m*/ for (int i = 0; st.hasMoreElements(); i++) { property = st.nextToken(); if (!property.trim().equals("")) { mailProps.put(PROPS_KEYS[i], property); } } if (extraMailProperties != null) { mailProps.putAll(extraMailProperties); } LogFactory.getLog(MailSender.class) .debug("mailProps['mail.smtp.host'] ->" + mailProps.getProperty("mail.smtp.host")); return Session.getInstance(mailProps, null); }
From source file:de.perdian.commons.servlet.ServletUtils.java
/** * Extracts the locales supported by the client that sent a given request. * According to RFC 2161 the result list will be sorted according to any * specified preferenc value (see the RFC for details) * * @param servletRequest/*from w w w.j av a 2 s .c o m*/ * the request from which to extract the information * @param defaultLocales * the locales to be returned if no locales could be extracted from the * request * @return * a {@code List} containing the accepted {@code java.util.Locale} * objects. If no locales are found in the request, then the method will * return the default locale list or an empty list if no default locales * have been passed - never {@code null} */ public static List<Locale> extractAcceptedLocales(HttpServletRequest servletRequest, List<Locale> defaultLocales) { Map<Float, List<Locale>> localeValuesByPriority = new TreeMap<>((o1, o2) -> -1 * Float.compare(o1, o2)); String headerValue = servletRequest.getHeader("accept-language"); if (headerValue != null) { StringTokenizer headerTokenizer = new StringTokenizer(headerValue, ","); while (headerTokenizer.hasMoreElements()) { String header = headerTokenizer.nextToken().trim(); int semicolonSeparator = header.indexOf(";"); String localeValue = semicolonSeparator > 0 ? header.substring(0, semicolonSeparator) : header; Locale locale = LocaleUtils.toLocale(localeValue); if (locale != null) { Float qValue = Float.valueOf(1f); String qParameter = ";q="; int qParameterIndex = header.indexOf(qParameter); if (qParameterIndex > 0) { try { String qParameterValue = header.substring(qParameterIndex + qParameter.length()); qValue = Float.valueOf(qParameterValue); } catch (Exception e) { // Ignore here and use the default } } List<Locale> targetList = localeValuesByPriority.get(qValue); if (targetList == null) { targetList = new ArrayList<>(); localeValuesByPriority.put(qValue, targetList); } targetList.add(locale); } } } List<Locale> localeValues = new ArrayList<>(); for (Map.Entry<Float, List<Locale>> localeValueEntry : localeValuesByPriority.entrySet()) { for (Locale locale : localeValueEntry.getValue()) { localeValues.add(locale); } } if (localeValues.isEmpty() && defaultLocales != null) { localeValues.addAll(defaultLocales); } return Collections.unmodifiableList(localeValues); }
From source file:org.apache.manifoldcf.crawler.connectors.cmis.CmisRepositoryConnectorUtils.java
/** * Utility method to consider the objectId whenever it is not present in the select clause * @param cmisQuery/*from w ww . ja v a 2 s.co m*/ * @return the cmisQuery with the cmis:objectId property added in the select clause */ public static String getCmisQueryWithObjectId(String cmisQuery) { String cmisQueryResult = StringUtils.EMPTY; String selectClause = getSelectClause(cmisQuery); if (selectClause.equalsIgnoreCase(SELECT_STAR_CLAUSE)) { cmisQueryResult = cmisQuery; } else { //get the second term and add the cmis:objectId term StringTokenizer selectClauseTokenized = new StringTokenizer(selectClause.trim()); boolean firstTermSelectClause = true; String secondTerm = StringUtils.EMPTY; while (selectClauseTokenized.hasMoreElements()) { String term = selectClauseTokenized.nextToken(); if (firstTermSelectClause) { firstTermSelectClause = false; } else if (!firstTermSelectClause) { //this is the second term secondTerm = term; break; } } cmisQueryResult = StringUtils.replaceOnce(cmisQuery, secondTerm, OBJECT_ID_TERM + secondTerm); } return cmisQueryResult; }
From source file:savant.controller.BookmarkController.java
private static Bookmark parseBookmark(String line, boolean addMargin) { StringTokenizer st = new StringTokenizer(line, "\t"); String ref = st.nextToken();/*from w ww .ja v a 2 s. c o m*/ int from = Integer.parseInt(st.nextToken()); int to = Integer.parseInt(st.nextToken()); String annotation = ""; if (st.hasMoreElements()) { annotation = st.nextToken(); annotation.trim(); } return new Bookmark(ref, new Range(from, to), annotation, addMargin); }