List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:DateParser.java
private static Calendar getCalendar(String isodate) { // YYYY-MM-DDThh:mm:ss.sTZD StringTokenizer st = new StringTokenizer(isodate, "-T:.+Z", true); Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); calendar.clear();/*from w w w . j a va 2 s . c o m*/ try { // Year if (st.hasMoreTokens()) { int year = Integer.parseInt(st.nextToken()); calendar.set(Calendar.YEAR, year); } else { return calendar; } // Month if (check(st, "-") && (st.hasMoreTokens())) { int month = Integer.parseInt(st.nextToken()) - 1; calendar.set(Calendar.MONTH, month); } else { return calendar; } // Day if (check(st, "-") && (st.hasMoreTokens())) { int day = Integer.parseInt(st.nextToken()); calendar.set(Calendar.DAY_OF_MONTH, day); } else { return calendar; } // Hour if (check(st, "T") && (st.hasMoreTokens())) { int hour = Integer.parseInt(st.nextToken()); calendar.set(Calendar.HOUR_OF_DAY, hour); } else { calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; } // Minutes if (check(st, ":") && (st.hasMoreTokens())) { int minutes = Integer.parseInt(st.nextToken()); calendar.set(Calendar.MINUTE, minutes); } else { calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; } // // Not mandatory now // // Secondes if (!st.hasMoreTokens()) { return calendar; } String tok = st.nextToken(); if (tok.equals(":")) { // secondes if (st.hasMoreTokens()) { int secondes = Integer.parseInt(st.nextToken()); calendar.set(Calendar.SECOND, secondes); if (!st.hasMoreTokens()) { return calendar; } // frac sec tok = st.nextToken(); if (tok.equals(".")) { // bug fixed, thx to Martin Bottcher String nt = st.nextToken(); while (nt.length() < 3) { nt += "0"; } nt = nt.substring(0, 3); // Cut trailing chars.. int millisec = Integer.parseInt(nt); // int millisec = Integer.parseInt(st.nextToken()) * 10; calendar.set(Calendar.MILLISECOND, millisec); if (!st.hasMoreTokens()) { return calendar; } tok = st.nextToken(); } else { calendar.set(Calendar.MILLISECOND, 0); } } else { throw new RuntimeException("No secondes specified"); } } else { calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); } // Timezone if (!tok.equals("Z")) { // UTC if (!(tok.equals("+") || tok.equals("-"))) { throw new RuntimeException("only Z, + or - allowed"); } boolean plus = tok.equals("+"); if (!st.hasMoreTokens()) { throw new RuntimeException("Missing hour field"); } int tzhour = Integer.parseInt(st.nextToken()); int tzmin = 0; if (check(st, ":") && (st.hasMoreTokens())) { tzmin = Integer.parseInt(st.nextToken()); } else { throw new RuntimeException("Missing minute field"); } if (plus) { calendar.add(Calendar.HOUR, -tzhour); calendar.add(Calendar.MINUTE, -tzmin); } else { calendar.add(Calendar.HOUR, tzhour); calendar.add(Calendar.MINUTE, tzmin); } } } catch (NumberFormatException ex) { throw new RuntimeException("[" + ex.getMessage() + "] is not an integer"); } return calendar; }
From source file:com.jaspersoft.jasperserver.rest.RESTUtils.java
public static List<String> stringToList(String roles, String delimiter) { List<String> lst = new LinkedList<String>(); StringTokenizer sTok = new StringTokenizer(roles, delimiter); while (sTok.hasMoreTokens()) { lst.add(sTok.nextToken().trim()); }//from ww w . j av a2 s. c o m return lst; }
From source file:org.bedework.notifier.web.MethodBase.java
/** Return a path, broken into its elements, after "." and ".." are removed. * If the parameter path attempts to go above the root we return null. * * Other than the backslash thing why not use URI? * * @param path String path to be fixed * @return String[] fixed path broken into elements * @throws NoteException on error//from w w w . j av a2 s . c o m */ public static List<String> fixPath(final String path) throws NoteException { if (path == null) { return null; } String decoded; try { decoded = URLDecoder.decode(path, "UTF8"); } catch (Throwable t) { throw new NoteException("bad path: " + path); } if (decoded == null) { return (null); } /** Make any backslashes into forward slashes. */ if (decoded.indexOf('\\') >= 0) { decoded = decoded.replace('\\', '/'); } /** Ensure a leading '/' */ if (!decoded.startsWith("/")) { decoded = "/" + decoded; } /** Remove all instances of '//'. */ while (decoded.indexOf("//") >= 0) { decoded = decoded.replaceAll("//", "/"); } /** Somewhere we may have /./ or /../ */ StringTokenizer st = new StringTokenizer(decoded, "/"); ArrayList<String> al = new ArrayList<String>(); while (st.hasMoreTokens()) { String s = st.nextToken(); if (s.equals(".")) { // ignore } else if (s.equals("..")) { // Back up 1 if (al.size() == 0) { // back too far return null; } al.remove(al.size() - 1); } else { al.add(s); } } return al; }
From source file:com.netscape.cmsutil.util.Utils.java
public static String normalizeString(String string, Boolean keepSpace) { if (string == null) { return string; }//from w ww. jav a2 s . co m StringBuffer sb = new StringBuffer(); StringTokenizer st = null; if (keepSpace) st = new StringTokenizer(string, "\r\n"); else st = new StringTokenizer(string, "\r\n "); while (st.hasMoreTokens()) { String nextLine = st.nextToken(); nextLine = nextLine.trim(); sb.append(nextLine); } return sb.toString(); }
From source file:net.sf.jasperreports.charts.util.ChartUtil.java
private static int[] getCoordinates(ChartEntity entity) { int[] coordinates = null; String shapeCoords = entity.getShapeCoords(); if (shapeCoords != null && shapeCoords.length() > 0) { StringTokenizer tokens = new StringTokenizer(shapeCoords, ","); coordinates = new int[tokens.countTokens()]; int idx = 0; while (tokens.hasMoreTokens()) { String coord = tokens.nextToken(); coordinates[idx] = Integer.parseInt(coord); ++idx;/*from ww w . j av a 2s . co m*/ } } return coordinates; }
From source file:com.meterware.httpunit.HttpUnitUtils.java
/** * Returns the content type and encoding as a pair of strings. * If no character set is specified, the second entry will be null. * @param header the header to parse//from ww w . jav a2 s . c o m * @return a string array with the content type and the content charset **/ public static String[] parseContentTypeHeader(String header) { String[] result = new String[] { "text/plain", null }; StringTokenizer st = new StringTokenizer(header, ";="); result[0] = st.nextToken(); while (st.hasMoreTokens()) { String parameter = st.nextToken(); if (st.hasMoreTokens()) { String value = stripQuotes(st.nextToken()); if (parameter.trim().equalsIgnoreCase("charset")) { result[1] = value; } } } return result; }
From source file:com.izforge.izpack.util.IoHelper.java
/** * Loads all environment variables via an exec. *//*from ww w. j a v a 2s.com*/ private static void loadEnv() { String[] output = new String[2]; String[] params; if (OsVersion.IS_WINDOWS) { String command = "cmd.exe"; if (System.getProperty("os.name").toLowerCase().contains("windows 9")) { command = "command.com"; } params = new String[] { command, "/C", "set" }; } else { params = new String[] { "env" }; } FileExecutor fe = new FileExecutor(); fe.executeCommand(params, output); if (output[0].length() <= 0) { return; } String lineSep = System.getProperty("line.separator"); StringTokenizer tokenizer = new StringTokenizer(output[0], lineSep); envVars = new Properties(); String var = null; while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken(); if (line.indexOf('=') == -1) { // May be a env var with a new line in it. if (var == null) { var = lineSep + line; } else { var += lineSep + line; } } else { // New var, perform the previous one. setEnvVar(var); var = line; } } setEnvVar(var); }
From source file:com.helpers.ServiceLocationsHelper.java
public static void addLocationToOpportunity(String opportunityID, String locationID) throws ConnectionException { System.out.println("addLocationToOpportunity\t" + opportunityID + "\t" + locationID); String tempArr[] = locationID.split(Pattern.quote("***")); String addLocations = tempArr[0]; String deleteLocations = tempArr.length > 1 ? tempArr[1] : null; StringTokenizer st = new StringTokenizer(addLocations, ","); List<Pricesenz__ServLocOppJn__c> locations = getLocationsForOpportunity(opportunityID); ArrayList<Pricesenz__ServLocOppJn__c> addList = new ArrayList<>(); ArrayList<Pricesenz__ServLocOppJn__c> deleteList = new ArrayList<>(); Pricesenz__ServLocOppJn__c tempJnObj; while (st.hasMoreTokens()) { boolean flag = true; String tempID = st.nextToken(); for (Pricesenz__ServLocOppJn__c l : locations) { if (l.getId().equals(tempID)) { // System.out.println(tempID); flag = false;/*from w w w .j a v a 2 s . c o m*/ break; } } if (flag) { tempJnObj = new Pricesenz__ServLocOppJn__c(); tempJnObj.setPricesenz__Service_Location__c(tempID); tempJnObj.setPricesenz__Opportunity__c(opportunityID); addList.add(tempJnObj); } } }
From source file:amqp.spring.camel.component.SpringAMQPConsumer.java
protected static Map<String, Object> parseKeyValues(String routingKey) { StringTokenizer tokenizer = new StringTokenizer(routingKey, "&|"); Map<String, Object> pairs = new HashMap<String, Object>(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); String[] keyValue = token.split("="); if (keyValue.length != 2) throw new IllegalArgumentException( "Couldn't parse key/value pair [" + token + "] out of string: " + routingKey); pairs.put(keyValue[0], keyValue[1]); }//from www . j a v a 2s. c om return pairs; }
From source file:hudson.plugins.testlink.util.TestLinkHelper.java
/** * <p>Defines TestLink Java API Properties. Following is the list of available * properties.</p>/*from w ww . java 2 s .c om*/ * * <ul> * <li>xmlrpc.basicEncoding</li> * <li>xmlrpc.basicPassword</li> * <li>xmlrpc.basicUsername</li> * <li>xmlrpc.connectionTimeout</li> * <li>xmlrpc.contentLengthOptional</li> * <li>xmlrpc.enabledForExceptions</li> * <li>xmlrpc.encoding</li> * <li>xmlrpc.gzipCompression</li> * <li>xmlrpc.gzipRequesting</li> * <li>xmlrpc.replyTimeout</li> * <li>xmlrpc.userAgent</li> * </ul> * * @param testLinkJavaAPIProperties * @param listener Jenkins Build listener */ public static void setTestLinkJavaAPIProperties(String testLinkJavaAPIProperties, BuildListener listener) { if (StringUtils.isNotBlank(testLinkJavaAPIProperties)) { final StringTokenizer tokenizer = new StringTokenizer(testLinkJavaAPIProperties, ","); if (tokenizer.countTokens() > 0) { while (tokenizer.hasMoreTokens()) { String systemProperty = tokenizer.nextToken(); maybeAddSystemProperty(systemProperty, listener); } } } }