List of usage examples for java.util StringTokenizer nextToken
public String nextToken()
From source file:com.silverpeas.jcrutil.BetterRepositoryFactoryBean.java
protected static void prepareContext(InitialContext ic, String jndiName) throws NamingException { Context currentContext = ic;/* w w w . j av a 2s . c o m*/ 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); } } } }
From source file:de.kapsi.net.daap.DaapUtil.java
/** * Splits a query String ("key1=value1&key2=value2...") and * stores the data in a Map/*from w w w . j a v a 2s.co m*/ * * @param queryString a query String * @return the splitten query String as Map */ public static final Map parseQuery(String queryString) { Map map = new HashMap(); if (queryString != null && queryString.length() != 0) { StringTokenizer tok = new StringTokenizer(queryString, "&"); while (tok.hasMoreTokens()) { String token = tok.nextToken(); int q = token.indexOf('='); if (q != -1 && q != token.length()) { String key = token.substring(0, q); String value = token.substring(++q); map.put(key, value); } } } return map; }
From source file:RequestUtil.java
/** * Delete a cookie except the designated variable name from CookieString * //from w ww. jav a 2s . c om * @param cookieString * @param paramName * @return */ public static String removeCookieParam(String cookieString, Set<String> paramNames) { StringTokenizer tok = new StringTokenizer(cookieString, ";", false); String resultCookieString = ""; while (tok.hasMoreTokens()) { String token = tok.nextToken(); int i = token.indexOf("="); if (i > -1) { for (String paramName : paramNames) { String name = token.substring(0, i).trim(); if (paramName.equalsIgnoreCase(name)) { if (resultCookieString.length() > 0) resultCookieString += ";"; resultCookieString += token; } } } else { // we have a bad cookie.... just let it go } if (paramNames.isEmpty()) { if (resultCookieString.length() > 0) resultCookieString += ";"; resultCookieString += token; } } return resultCookieString.trim(); }
From source file:com.ikon.extractor.RegisteredExtractors.java
/** * Check for registered text extractor/*from ww w . j av a2s.c om*/ */ public static boolean isRegistered(String className) { List<String> classes = new ArrayList<String>(); if (Config.MANAGED_TEXT_EXTRACTION || Config.REPOSITORY_NATIVE) { classes = Config.REGISTERED_TEXT_EXTRACTORS; } else { try { RepositoryConfig rc = JcrRepositoryModule.getRepositoryConfig(); WorkspaceConfig wc = rc.getWorkspaceConfig(rc.getDefaultWorkspaceName()); SearchConfig sc = wc.getSearchConfig(); if (sc != null) { String tfClasses = (String) sc.getParameters().get("textFilterClasses"); StringTokenizer tokenizer = new StringTokenizer(tfClasses, ", \t\n\r\f"); while (tokenizer.hasMoreTokens()) { String clazz = tokenizer.nextToken(); classes.add(clazz); } } } catch (ConfigurationException e) { log.warn(e.getMessage(), e); } } for (String name : classes) { if (name.equals(className)) { return true; } } return false; }
From source file:com.francetelecom.clara.cloud.commons.MavenReference.java
/** * Construct a MavenReference from a gav String * @param gav/*w ww . j a v a 2s.c om*/ * format : Group:artifact:version:[classifier:[extension]] * @return Corresponding maven reference */ public static MavenReference fromGavString(String gav) { MavenReference resultMavenRef; if (gav == null || gav.length() < 5) { throw new IllegalArgumentException("String gav cannot be null nor empty"); } StringTokenizer gavTokenizer = new StringTokenizer(gav, ":", true); try { String groupId = gavTokenizer.nextToken(); if (":".equals(groupId)) { throw new NoSuchElementException("Missing groupId"); } gavTokenizer.nextToken(); String artifactId = gavTokenizer.nextToken(); if (":".equals(artifactId)) { throw new NoSuchElementException("Missing artifactId"); } gavTokenizer.nextToken(); String version = gavTokenizer.nextToken(); if (":".equals(version)) { throw new NoSuchElementException("Missing version"); } if (gavTokenizer.hasMoreTokens()) { gavTokenizer.nextToken(); } resultMavenRef = new MavenReference(groupId, artifactId, version); if (gavTokenizer.hasMoreTokens()) { String classifier = gavTokenizer.nextToken(); if (!":".equals(classifier)) { resultMavenRef.setClassifier(classifier); if (gavTokenizer.hasMoreTokens()) { gavTokenizer.nextToken(); } } } if (gavTokenizer.hasMoreTokens()) { String extension = gavTokenizer.nextToken(); if (!":".equals(extension)) { resultMavenRef.setExtension(extension); } } } catch (NoSuchElementException nsee) { throw new IllegalArgumentException( "Wrong format, should be groupId:artifactId:version:[classifier:[extension]]"); } return resultMavenRef; }
From source file:Main.java
static byte[] decryptJWE(String jwe, Key privRsaKey) { // Log.d("","decryptJWE"); try {/*ww w .j a v a 2s . c om*/ // split jwe string StringTokenizer tokens = new StringTokenizer(jwe, "."); int count = tokens.countTokens(); // Log.d("","parts.length: "+count); if (count != 5) return null; String jweProtectedHeader64 = tokens.nextToken(); String jweEncrypted64 = tokens.nextToken(); String jweInitVector64 = tokens.nextToken(); String cryptedBytes64 = tokens.nextToken(); String auth_tag64 = tokens.nextToken(); // decrypt cek using private rsa key byte[] cek = decryptRsaB64(jweEncrypted64, privRsaKey); // check cek result byte array if (cek == null || cek.length == 0 || (cek.length % 2) != 0) return null; int keySize = cek.length / 2; Log.d("", "Decryption AES: " + keySize * 8); // build aes_key and hmac_key byte aes_key[] = new byte[keySize]; byte hmac_key[] = new byte[keySize]; System.arraycopy(cek, 0, hmac_key, 0, keySize); System.arraycopy(cek, keySize, aes_key, 0, keySize); // decode initialization vector byte[] iv_key = decodeB64(jweInitVector64); Log.d("", "hmac_key: " + bytesToHex(hmac_key)); Log.d("", "aes_key: " + bytesToHex(aes_key)); Log.d("", "iv_key: " + bytesToHex(iv_key)); // decrypt content using aes_key and iv_key byte[] cryptedBytes = decodeB64(cryptedBytes64); Cipher decrypt = Cipher.getInstance("AES/CBC/PKCS5Padding", "SC"); decrypt.init(Cipher.DECRYPT_MODE, new SecretKeySpec(aes_key, "AES"), new IvParameterSpec(iv_key)); byte[] decryptedBytes = decrypt.doFinal(cryptedBytes); Log.d("", "decryptedBytes:"); Log.d("", bytesToHex(decryptedBytes)); // validation verification byte[] aad = jweProtectedHeader64.getBytes(); long al = aad.length * 8; // concatenate aad, iv_key, cryptedBytes and al byte[] hmacData = new byte[aad.length + iv_key.length + cryptedBytes.length + 8]; int offset = 0; System.arraycopy(aad, offset, hmacData, 0, aad.length); offset += aad.length; System.arraycopy(iv_key, 0, hmacData, offset, iv_key.length); offset += iv_key.length; System.arraycopy(cryptedBytes, 0, hmacData, offset, cryptedBytes.length); offset += cryptedBytes.length; ByteBuffer buffer = ByteBuffer.allocate(8); buffer.putLong(al); System.arraycopy(buffer.array(), 0, hmacData, offset, 8); // compute hmac Mac hmac = Mac.getInstance("HmacSHA256", "SC"); hmac.init(new SecretKeySpec(hmac_key, "HmacSHA256")); byte[] hmacValue = hmac.doFinal(hmacData); // pick authentication tag byte[] authTag = Arrays.copyOf(hmacValue, 16); // validate authentication tag byte[] authTagRead = decodeB64(auth_tag64); for (int i = 0; i < 16; i++) { if (authTag[i] != authTagRead[i]) { Log.d("", "validation failed"); return decryptedBytes; } } Log.d("", "validation success"); // validation success return decryptedBytes; } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:fr.gouv.finances.dgfip.xemelios.utils.XmlUtils.java
/** * For the moment, this method can only transform very simple XPath, like <tt>/n:foo/b:bar/@a</tt> * @param xpath/* w w w .j av a2 s .c o m*/ * @param ns * @return */ public static String normalizeNS(String xpath, NamespaceContext ns) { StringTokenizer tokenizer = new StringTokenizer(xpath, "/", true); StringBuilder sb = new StringBuilder(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (token.equals("/")) sb.append(token); else { boolean isAttribute = false; if (token.startsWith("@")) { token = token.substring(1); isAttribute = true; } int pos = token.indexOf(':'); if (pos >= 0) { String prefix = token.substring(0, pos); String localName = token.substring(pos + 1); String newPrefix = ns.getPrefix(ns.getNamespaceURI(prefix)); if (isAttribute && (newPrefix == null || newPrefix.length() == 0)) newPrefix = prefix; if (isAttribute) sb.append("@"); if (newPrefix.length() > 0) sb.append(newPrefix).append(":"); sb.append(localName); } else { if (!isAttribute) { String localName = token; if (XmlUtils.isValidNCName(localName)) { String uri = ns.getNamespaceURI(""); if (uri != null) { String newPrefix = ns.getPrefix(uri); if (newPrefix.length() > 0) sb.append(newPrefix).append(":"); } sb.append(token); } else { sb.append(token); } } else { // attribute didn't had a namespace, let it like that sb.append("@").append(token); } } } } return sb.toString(); }
From source file:io.github.bonigarcia.wdm.Downloader.java
public static Proxy createProxy() { String proxyString = System.getenv("HTTPS_PROXY"); if (proxyString == null || proxyString.length() < 1) proxyString = System.getenv("HTTP_PROXY"); if (proxyString == null || proxyString.length() < 1) { return null; }/*from w w w .j a v a 2s. c o m*/ proxyString = proxyString.replace("http://", ""); proxyString = proxyString.replace("https://", ""); StringTokenizer st = new StringTokenizer(proxyString, ":"); if (st.countTokens() != 2) return null; String host = st.nextToken(); String portString = st.nextToken(); try { int port = Integer.parseInt(portString); return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)); } catch (NumberFormatException e) { return null; } }
From source file:com.rabbitframework.commons.utils.StringUtils.java
public static List<String> tokenizeToArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens) { if (str == null) { return null; }//from w w w . java 2 s . c o m StringTokenizer st = new StringTokenizer(str, delimiters); List<String> tokens = new ArrayList<String>(); while (st.hasMoreTokens()) { String token = st.nextToken(); if (trimTokens) { token = token.trim(); } if (!ignoreEmptyTokens || token.length() > 0) { tokens.add(token); } } return tokens; }
From source file:com.trackplus.ddl.DataWriter.java
private static Integer getMaxColumnSize(Connection con, Map<String, Integer> columnSizeMap, String s) throws DDLException { ////UPDATE <tableName> SET <column>='...' StringTokenizer st = new StringTokenizer(s.substring(0, s.indexOf("="))); st.nextToken();//UPDATE String tableName = st.nextToken(); st.nextToken();//SET String columnName = st.nextToken(); String key = tableName + "_" + columnName; Integer maxSize = columnSizeMap.get(key); if (maxSize == null) { maxSize = MetaDataBL.getColumnSize(con, tableName, columnName); columnSizeMap.put(key, maxSize); LOGGER.debug("MAX size for column " + columnName + " in table " + tableName + " is " + maxSize); }/*from w w w . j av a 2 s. c om*/ return maxSize; }