List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:ClassPath.java
private static final void getPathComponents(String path, List list) { if (path != null) { StringTokenizer tok = new StringTokenizer(path, File.pathSeparator); while (tok.hasMoreTokens()) { String name = tok.nextToken(); File file = new File(name); if (file.exists()) { list.add(name);//from w w w . ja va 2s . c o m } } } }
From source file:com.sonyericsson.hudson.plugins.gerrit.trigger.dependency.DependencyQueueTaskDispatcher.java
/** * Return a list of Abstract Projects from their string names. * @param projects The string containing the projects, comma-separated. * @param context The context in which to read the string * @return the list of projects/*from ww w .j av a 2s .c o m*/ */ public static List<Job> getProjectsFromString(String projects, Item context) { List<Job> dependencyJobs = new ArrayList<Job>(); if (StringUtils.isEmpty(projects)) { return null; } else { Jenkins jenkins = Jenkins.getInstance(); assert jenkins != null; StringTokenizer tokens = new StringTokenizer(projects, ","); while (tokens.hasMoreTokens()) { String projectName = tokens.nextToken().trim(); if (!projectName.isEmpty()) { Item item = jenkins.getItem(projectName, context, Item.class); if ((item != null) && (item instanceof Job)) { dependencyJobs.add((Job) item); logger.debug("project dependency job added : {}", item); } } } } return dependencyJobs; }
From source file:au.org.intersect.dms.bookinggw.impl.BookingGatewayServiceImpl.java
/** * Calculate initials from name parts./*from www. j ava2 s. c om*/ * * @param fname * the first name. * @param mname * the middle name. * @param lname * the last name. * @return initials */ private static String calculateInitials(String fname, String mname, String lname) { StringTokenizer tokenizer = new StringTokenizer(fname + SPACE + mname + SPACE + lname); StringBuffer sb = new StringBuffer(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.length() > 0) { sb.append(Character.toUpperCase(token.charAt(0))); } } return sb.toString(); }
From source file:FTPApp.java
public static int getFileSize(FtpClient client, String fileName) throws IOException { TelnetInputStream lst = client.list(); String str = ""; fileName = fileName.toLowerCase();//w ww .j ava 2 s. c o m while (true) { int c = lst.read(); char ch = (char) c; if (c < 0 || ch == '\n') { str = str.toLowerCase(); if (str.indexOf(fileName) >= 0) { StringTokenizer tk = new StringTokenizer(str); int index = 0; while (tk.hasMoreTokens()) { String token = tk.nextToken(); if (index == 4) try { return Integer.parseInt(token); } catch (NumberFormatException ex) { return -1; } index++; } } str = ""; } if (c <= 0) break; str += ch; } return -1; }
From source file:elaborate.util.StringUtil.java
@SuppressWarnings("boxing") public static String replace(String originalTerm, String replacementTerm, String body, List<Integer> occurrencesToReplace, boolean preserveCase) { StringTokenizer tokenizer = new StringTokenizer(body, DELIM, true); // Log.info("body:[{}]", body); StringBuilder replaced = new StringBuilder(body.length()); int occurrence = 1; while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); DelimiterDetector delimiterDetector = new DelimiterDetector(token); String strippedToken = delimiterDetector.getStripped(); if (strippedToken.equalsIgnoreCase(originalTerm)) { String replacement = preserveCase ? TextCase.detectCase(strippedToken).applyTo(replacementTerm) : replacementTerm;//from w w w. ja v a 2s .c o m replaced.append(occurrencesToReplace.contains(occurrence) ? delimiterDetector.getPreDelimiters() + replacement + delimiterDetector.getPostDelimiters() : token); occurrence++; } else { replaced.append(token); } } // Log.info("replaced:[{}]", replaced); return replaced.toString(); }
From source file:edu.duke.cabig.c3pr.utils.StringUtils.java
public static String camelCase(String inputString) { String camelCaseStr = ""; if (inputString == null) return camelCaseStr; String lowerCase = inputString.toLowerCase(); StringTokenizer strTokenizer = new StringTokenizer(lowerCase, " "); String strToken = ""; StringBuffer strBuf = null;// ww w. ja va 2s . co m char[] charAry = null; while (strTokenizer.hasMoreTokens()) { strBuf = new StringBuffer(); strToken = strTokenizer.nextToken(); charAry = strToken.toCharArray(); strBuf.append(Character.toUpperCase(charAry[0])); int remaingstrLength = charAry.length - 1; strBuf.append(charAry, 1, remaingstrLength); camelCaseStr = camelCaseStr + " " + strBuf.toString(); } return camelCaseStr; }
From source file:it.eng.spagobi.commons.utilities.PortletUtilities.java
/** * Starting from the original URL and the request, creates a string representing the * Portlet URL.//from ww w . j a va 2 s . com * * @param aHttpServletRequest The request object at input * @param originalURL The starting original URL * * @return A String representing the Portlet URL */ public static String createPortletURL(HttpServletRequest aHttpServletRequest, String originalURL) { RenderResponse renderResponse = (RenderResponse) aHttpServletRequest.getAttribute("javax.portlet.response"); PortletURL aPortletURL = renderResponse.createActionURL(); logger.debug("Original URL.... " + originalURL + "indexOf ? is " + originalURL.indexOf("?")); String parameters = originalURL.substring(originalURL.indexOf("?") + 1); StringTokenizer st = new StringTokenizer(parameters, "&", false); String parameterToken = null; String parameterName = null; String parameterValue = null; while (st.hasMoreTokens()) { parameterToken = st.nextToken(); logger.debug("Parameter Token [" + parameterToken + "]"); parameterName = parameterToken.substring(0, parameterToken.indexOf("=")); parameterValue = parameterToken.substring(parameterToken.indexOf("=") + 1); logger.debug("Parameter Name [" + parameterName + "]"); logger.debug("Parameter Value [" + parameterValue + "]"); aPortletURL.setParameter(parameterName, parameterValue); } return aPortletURL.toString(); }
From source file:de.vanita5.twittnuker.util.net.ssl.AbstractCheckSignatureVerifier.java
public static String[] getCNs(final X509Certificate cert) { final LinkedList<String> cnList = new LinkedList<String>(); /*//from w w w . j a v a 2 s. c om * Sebastian Hauer's original StrictSSLProtocolSocketFactory used * getName() and had the following comment: * * Parses a X.500 distinguished name for the value of the "Common Name" * field. This is done a bit sloppy right now and should probably be * done a bit more according to <code>RFC 2253</code>. * * I've noticed that toString() seems to do a better job than getName() * on these X500Principal objects, so I'm hoping that addresses * Sebastian's concern. * * For example, getName() gives me this: * 1.2.840.113549.1.9.1=#16166a756c6975736461766965734063756362632e636f6d * * whereas toString() gives me this: EMAILADDRESS=juliusdavies@cucbc.com * * Looks like toString() even works with non-ascii domain names! I * tested it with "花子.co.jp" and it worked fine. */ final String subjectPrincipal = cert.getSubjectX500Principal().toString(); final StringTokenizer st = new StringTokenizer(subjectPrincipal, ",+"); while (st.hasMoreTokens()) { final String tok = st.nextToken().trim(); if (tok.length() > 3) { if (tok.substring(0, 3).equalsIgnoreCase("CN=")) { cnList.add(tok.substring(3)); } } } if (!cnList.isEmpty()) { final String[] cns = new String[cnList.size()]; cnList.toArray(cns); return cns; } else return null; }
From source file:com.teamsun.framework.util.ConvertUtil.java
/** * lf add ??// w w w .ja v a2 s.c o m */ public static String dealField(String field) { String result = ""; if (StringUtils.isEmpty(field)) return result; if (field.indexOf("_") > -1) { StringBuffer sb = new StringBuffer(); StringTokenizer st = new StringTokenizer(field, "_"); int i = 0; while (st.hasMoreTokens()) { if (i == 0) sb.append(st.nextToken().toLowerCase()); else { String sec = st.nextToken(); String one = sec.substring(0, 1); String two = sec.substring(1); sec = one.toLowerCase() + two.toLowerCase(); sb.append(sec); } i++; } result = sb.toString(); } else { // _??????? result = field.toLowerCase(); } return result; }
From source file:org.sakaiproject.imagegallery.springutil.SqlScriptParser.java
/** * Parse a line of text to remove comments. * @param line The line to parse. The string must not have any new line, * carriage return, or form feed characters. It also may not * contain a double-quote outside of a string literal, and the * statement delimiter character may only appear at the end of * the line.//from w w w . j av a2 s. c o m * @param sql String buffer that stores the result, which is appended to the * end. When the method returns, it will contain the trimmed line * with comments removed. If the line contains no usable SQL * fragment, nothing is appended. * @param lineNumber Line number used for exceptions. * @throws ParseException * @throws IllegalArgumentException if the line is null or contains one of * the line terminating characters mentioned above. * @throws UncategorizedDataAccessException if parsing fails for some other reason. */ private static void parseLine(String line, StringBuffer sql, int lineNumber, char statementDelimiter) { // Parse line looking for single quote string delimiters. Anything // that's part of a string just passes through. StringTokenizer quoteTokenizer = new StringTokenizer(line, "'", true); // true if we're parsing through a string literal. boolean inLiteral = false; while (quoteTokenizer.hasMoreTokens()) { String token = quoteTokenizer.nextToken(); if (token.equals("'")) { // Token is a string delimiter. Toggle "inLiteral" flag. inLiteral = !inLiteral; } else if (!inLiteral) { // Look for EOL comments. int commentIndex = indexOfComment(token); if (commentIndex >= 0) { // Truncate token to the comment marker. token = token.substring(0, commentIndex).trim(); } // Thwart any attempt to use double-quote outside of a string // literal. if (token.indexOf("\"") >= 0) { throw new RuntimeException( new ParseException("Double quote character" + " cannot be used in a string literal.", token.indexOf("\""))); } // Thwart any attempt to have the statement delimiter embedded // in a line. Not supported at this point. int statementEndIndex = token.indexOf(statementDelimiter); if (statementEndIndex >= 0 && statementEndIndex != (token.length() - 1)) { throw new RuntimeException(new ParseException( "SQL statement delimiter" + " embedded in a line. (Not supported at this point)", statementEndIndex)); } // If we've hit a comment, we're done with this line. Just // append the token and break out. if (commentIndex >= 0) { sql.append(token); break; } } // Else, we're in a string literal. Just let it pass through. sql.append(token); } if (inLiteral) { // If the inLiteral flag is set here, the line has an unterminated // string literal. throw new RuntimeException(new ParseException("Unterminated string literal.", 0)); } }