List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:de.pawlidi.openaletheia.utils.AletheiaUtils.java
/** * /*from w ww .j a v a 2s .co m*/ * @return */ public static String getWindowsMacAddress() { final String ipConfigResponse = executeCommand("ipconfig", "/all"); if (ipConfigResponse == null) { return null; } String localHost = getLocalhostAddress(); if (localHost == null) { return null; } String lastMacAddressCandidate = null; StringTokenizer tokenizer = new StringTokenizer(ipConfigResponse, "\n"); while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken().trim(); if ((line.indexOf(localHost) >= 0) && (lastMacAddressCandidate != null)) { return lastMacAddressCandidate; } int colon = line.indexOf(":"); if (colon <= 0) { continue; } String candidate = line.substring(colon + 1).trim(); if (isMacAddressCandidate(candidate)) { lastMacAddressCandidate = normalizeMacAddress(candidate); } } return lastMacAddressCandidate; }
From source file:cn.vlabs.duckling.vwb.VWBFilter.java
private static Locale getLocale(String lstr) { if (lstr == null || lstr.length() < 1) { return null; }//w ww .j a va 2 s .c o m Locale locale = locales.get(lstr.toLowerCase()); if (locale != null) { return locale; } else { StringTokenizer localeTokens = new StringTokenizer(lstr, "_"); String lang = null; String country = null; if (localeTokens.hasMoreTokens()) { lang = localeTokens.nextToken(); } if (localeTokens.hasMoreTokens()) { country = localeTokens.nextToken(); } locale = new Locale(lang, country); Locale crtls[] = Locale.getAvailableLocales(); for (int i = 0; i < crtls.length; i++) { if (crtls[i].equals(locale)) { locale = crtls[i]; break; } } locales.put(lstr.toLowerCase(), locale); } return locale; }
From source file:com.legstar.codegen.tasks.SourceToXsdCobolTask.java
/** * Converts a URI into a package name. We assume a hierarchical, * server-based URI with the following syntax: * [scheme:][//host[:port]][path][?query][#fragment] * The package name is derived from host, path and fragment. * /*from w ww . j a va 2 s. c om*/ * @param namespaceURI the input namespace URI * @return the result package name */ public static String packageFromURI(final URI namespaceURI) { StringBuilder result = new StringBuilder(); URI nURI = namespaceURI.normalize(); boolean firstToken = true; /* * First part of package name is built from host with tokens in * reverse order. */ if (nURI.getHost() != null && nURI.getHost().length() != 0) { Vector<String> v = new Vector<String>(); StringTokenizer t = new StringTokenizer(nURI.getHost(), "."); while (t.hasMoreTokens()) { v.addElement(t.nextToken()); } for (int i = v.size(); i > 0; i--) { if (!firstToken) { result.append('.'); } else { firstToken = false; } result.append(v.get(i - 1)); } } /* Next part of package is built from the path tokens */ if (nURI.getPath() != null && nURI.getPath().length() != 0) { Vector<String> v = new Vector<String>(); StringTokenizer t = new StringTokenizer(nURI.getPath(), "/"); while (t.hasMoreTokens()) { v.addElement(t.nextToken()); } for (int i = 0; i < v.size(); i++) { String token = v.get(i); /* ignore situations such as /./../ */ if (token.equals(".") || token.equals("..")) { continue; } if (!firstToken) { result.append('.'); } else { firstToken = false; } result.append(v.get(i)); } } /* Finally append any fragment */ if (nURI.getFragment() != null && nURI.getFragment().length() != 0) { if (!firstToken) { result.append('.'); } else { firstToken = false; } result.append(nURI.getFragment()); } /* * By convention, namespaces are lowercase and should not contain * invalid Java identifiers */ String s = result.toString().toLowerCase(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { Character c = s.charAt(i); if (Character.isJavaIdentifierPart(c) || c.equals('.')) { sb.append(c); } else { sb.append("_"); } } return sb.toString(); }
From source file:ca.uhn.fhir.util.UrlUtil.java
private static void parseQueryString(String theQueryString, HashMap<String, List<String>> map) { String query = theQueryString; if (query.startsWith("?")) { query = query.substring(1);// ww w .jav a2 s .co m } StringTokenizer tok = new StringTokenizer(query, "&"); while (tok.hasMoreTokens()) { String nextToken = tok.nextToken(); if (isBlank(nextToken)) { continue; } int equalsIndex = nextToken.indexOf('='); String nextValue; String nextKey; if (equalsIndex == -1) { nextKey = nextToken; nextValue = ""; } else { nextKey = nextToken.substring(0, equalsIndex); nextValue = nextToken.substring(equalsIndex + 1); } nextKey = unescape(nextKey); nextValue = unescape(nextValue); List<String> list = map.get(nextKey); if (list == null) { list = new ArrayList<String>(); map.put(nextKey, list); } list.add(nextValue); } }
From source file:ca.uhn.hl7v2.sourcegen.SourceGenerator.java
/** * Creates the given directory if it does not exist. *///from ww w . jav a2 s.co m public static File makeDirectory(String directory) throws IOException { StringTokenizer tok = new StringTokenizer(directory, "\\/", false); File currDir = directory.startsWith("/") ? new File("/") : null; while (tok.hasMoreTokens()) { String thisDirName = tok.nextToken(); currDir = new File(currDir, thisDirName); //if currDir null, defaults to 1 arg call if (!currDir.exists()) { //create currDir.mkdir(); ; } else if (currDir.isFile()) { throw new IOException("Can't create directory " + thisDirName + " - file with same name exists."); } } return currDir; }
From source file:Which4J.java
/** * Iterate over the system classpath defined by "java.class.path" searching * for all occurrances of the given class name. * //from w w w .j a va 2 s . co m * @param classname the fully qualified class name to search for */ private static void findIt(String classname) { try { // get the system classpath String classpath = System.getProperty("java.class.path", ""); if (classpath.equals("")) { System.err.println("error: classpath is not set"); } if (debug) { System.out.println("classname: " + classname); System.out.println("system classpath = " + classpath); } if (isPrimitiveOrVoid(classname)) { System.out.println("'" + classname + "' primitive"); return; } StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator); while (st.hasMoreTokens()) { String token = st.nextToken(); File classpathElement = new File(token); if (debug) System.out.println(classpathElement.isDirectory() ? "dir: " + token : "jar: " + token); URL[] url = { classpathElement.toURL() }; URLClassLoader cl = URLClassLoader.newInstance(url, null); String classnameAsResource = classname.replace('.', '/') + ".class"; URL it = cl.findResource(classnameAsResource); if (it != null) { System.out.println("found in: " + token); System.out.println(" url: " + it.toString()); System.out.println(""); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:marytts.server.http.MaryHttpServerUtils.java
/** * Convert HTTP request string into key-value pairs * @param httpString the query part of the http request url * @param performUrlDecode whether to URL-decode the keys and values * @return/*from ww w .ja v a2s . com*/ */ public static Map<String, String> toKeyValuePairs(String httpString, boolean performUrlDecode) { if (httpString == null || httpString.length() == 0) { return null; } Map<String, String> keyValuePairs = new HashMap<String, String>(); StringTokenizer st = new StringTokenizer(httpString); String newToken = null; String param, val; int equalSignInd; while (st.hasMoreTokens() && (newToken = st.nextToken("&")) != null) { equalSignInd = newToken.indexOf("="); //Default values unless we have a param=value pair param = newToken; val = ""; // //We have either a "param=value" pair, or "param=" only if (equalSignInd > -1) { param = newToken.substring(0, equalSignInd); val = newToken.substring(equalSignInd + 1); } if (performUrlDecode) { param = StringUtils.urlDecode(param); val = StringUtils.urlDecode(val); } keyValuePairs.put(param, val); } return keyValuePairs; }
From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java
public static ArrayList stringToNodeList(String s, SpreadSheet spreadsheet, List fields, NodeModelDataFactory factory) {/*from w ww . j av a 2s. com*/ ArrayList list = new ArrayList(); StringTokenizer st = new StringTokenizer(s, "\n\r"); Node node; while (st.hasMoreTokens()) { node = stringToNode(st.nextToken(), spreadsheet, fields, factory); if (node != null) list.add(node); } return list; }
From source file:com.salesmanager.core.service.common.impl.ModuleManagerImpl.java
public static IntegrationKeys stripCredentials(String configvalue) throws Exception { if (configvalue == null) return new IntegrationKeys(); StringTokenizer st = new StringTokenizer(configvalue, ";"); int i = 1;//from www. j av a2 s . c o m int j = 1; IntegrationKeys keys = new IntegrationKeys(); while (st.hasMoreTokens()) { String value = st.nextToken(); if (i == 1) { // decrypt keys.setUserid(value); } else if (i == 2) { // decrypt keys.setPassword(value); } else if (i == 3) { // decrypt keys.setTransactionKey(value); } else { if (j == 1) { keys.setKey1(value); } else if (j == 2) { keys.setKey2(value); } else if (j == 3) { keys.setKey3(value); } j++; } i++; } return keys; }
From source file:com.projity.pm.graphic.spreadsheet.common.transfer.NodeListTransferable.java
public static Node stringToNode(String s, SpreadSheet spreadsheet, List fields, NodeModelDataFactory factory) { String category = spreadsheet.getSpreadSheetCategory(); Node node = null;/*www . ja v a 2s . c om*/ String delim = "\t"; StringTokenizer st = new StringTokenizer(s, delim, true); if (st.hasMoreTokens()) { if (SpreadSheet.TASK_CATEGORY.equals(category)) node = NodeFactory.getInstance().createTask((Project) factory); else if (SpreadSheet.RESOURCE_CATEGORY.equals(category)) node = NodeFactory.getInstance().createResource((ResourcePool) factory); else return null; CommonSpreadSheetModel model = (CommonSpreadSheetModel) spreadsheet.getModel(); String valueS; Field field; Iterator fieldsIterator = fields.iterator(); while (st.hasMoreTokens() && fieldsIterator.hasNext()) { valueS = st.nextToken(); if (delim.equals(valueS)) valueS = ""; else if (st.hasMoreTokens()) st.nextToken(); field = (Field) fieldsIterator.next(); try { field.setValue(node, model.getCache().getWalkersModel(), spreadsheet, valueS, model.getFieldContext()); } catch (FieldParseException e) { } } } return node; }