List of usage examples for java.util StringTokenizer hasMoreTokens
public boolean hasMoreTokens()
From source file:com.npower.dm.util.DDFTreeHelper.java
/** * Split the nodePath into a List. The "./" prefix in the node path will be * ignored. eg: ./a/b/c/d/ results: {a, b, c, d} /a/b/c/d/ results: {a, b, c, * d} a/b/c/d results: {a, b, c, d}// ww w . j a va 2 s . c o m * * @param nodePath * @return */ public static List<String> getPathVector(String nodePath) { String path = nodePath; if (path.startsWith("./")) { path = nodePath.substring(2, path.length()); } StringTokenizer tokenizer = new StringTokenizer(path, "/"); List<String> pathVector = new Vector<String>(); while (tokenizer.hasMoreTokens()) { pathVector.add(tokenizer.nextToken()); } return pathVector; }
From source file:axiom.util.MimePart.java
/** * Get a sub-header from a header, e.g. the charset from * <code>Content-Type: text/plain; charset="UTF-8"</code> */// w w w . ja va 2 s. c o m public static String getSubHeader(String header, String subHeaderName) { if (header == null) { return null; } StringTokenizer headerTokenizer = new StringTokenizer(header, ";"); while (headerTokenizer.hasMoreTokens()) { String token = headerTokenizer.nextToken().trim(); int i = token.indexOf("="); if (i > 0) { String hname = token.substring(0, i).trim(); if (hname.equalsIgnoreCase(subHeaderName)) { String value = token.substring(i + 1); return value.replace('"', ' ').trim(); } } } return null; }
From source file:com.redhat.lightblue.util.Error.java
public static Error fromJson(JsonNode node) { if (node instanceof ObjectNode) { String e = null;//from ww w . j a v a 2s . c om String m = null; JsonNode x; x = ((ObjectNode) node).get("errorCode"); if (x != null) { e = x.asText(); } x = ((ObjectNode) node).get("msg"); if (x != null) { m = x.asText(); } Error ret = new Error(e, m); x = ((ObjectNode) node).get("context"); if (x != null) { StringTokenizer tok = new StringTokenizer(x.asText(), "/"); while (tok.hasMoreTokens()) { ret.pushContext(tok.nextToken()); } } return ret; } return null; }
From source file:cn.com.qiqi.order.utils.Servlets.java
/** * ?? If-None-Match Header, Etag?.// w w w. java2s . c o m * * Etag, checkIfNoneMatchfalse, 304 not modify status. * * @param etag ETag. */ public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) { String headerValue = request.getHeader(HttpHeaders.IF_NONE_MATCH); if (headerValue != null) { boolean conditionSatisfied = false; if (!"*".equals(headerValue)) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(etag)) { conditionSatisfied = true; } } } else { conditionSatisfied = true; } if (conditionSatisfied) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader(HttpHeaders.ETAG, etag); return false; } } return true; }
From source file:org.springframework.core.util.StringUtils.java
/** * Tokenize the given String into a String array via a StringTokenizer. * <p>The given delimiters string is supposed to consist of any number of * delimiter characters. Each of those characters can be used to separate * tokens. A delimiter is always a single character; for multi-character * delimiters, consider using <code>delimitedListToStringArray</code> * * @param str the String to tokenize * @param delimiters the delimiter characters, assembled as String * (each of those characters is individually considered as delimiter) * @param trimTokens trim the tokens via String's <code>trim</code> * @param ignoreEmptyTokens omit empty tokens from the result array * (only applies to tokens that are empty after trimming; StringTokenizer * will not consider subsequent delimiters as token in the first place). * @return an array of the tokens (<code>null</code> if the input String * was <code>null</code>) * @see java.util.StringTokenizer/*from w ww. j a va2 s . c om*/ * @see String#trim() */ public static String[] tokenizeToStringArray(final String str, final String delimiters, final boolean trimTokens, final boolean ignoreEmptyTokens) { if (str == null) { return null; } 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 toStringArray(tokens); }
From source file:org.jberet.support.io.MappingJsonFactoryObjectFactory.java
static void configureCustomSerializersAndDeserializers(final ObjectMapper objectMapper, final String customSerializers, final String customDeserializers, final String customDataTypeModules, final ClassLoader classLoader) throws Exception { if (customDeserializers != null || customSerializers != null) { final SimpleModule simpleModule = new SimpleModule("custom-serializer-deserializer-module"); if (customSerializers != null) { final StringTokenizer st = new StringTokenizer(customSerializers, ", "); while (st.hasMoreTokens()) { final Class<?> aClass = classLoader.loadClass(st.nextToken()); simpleModule.addSerializer(aClass, (JsonSerializer) aClass.newInstance()); }/*from w w w . j a v a2 s . c o m*/ } if (customDeserializers != null) { final StringTokenizer st = new StringTokenizer(customDeserializers, ", "); while (st.hasMoreTokens()) { final Class<?> aClass = classLoader.loadClass(st.nextToken()); simpleModule.addDeserializer(aClass, (JsonDeserializer) aClass.newInstance()); } } objectMapper.registerModule(simpleModule); } if (customDataTypeModules != null) { final StringTokenizer st = new StringTokenizer(customDataTypeModules, ", "); while (st.hasMoreTokens()) { final Class<?> aClass = classLoader.loadClass(st.nextToken()); objectMapper.registerModule((Module) aClass.newInstance()); } } }
From source file:com.funambol.server.db.DataSourceContextHelper.java
/** * Create all intermediate subcontexts./*from www .ja v a 2s .c om*/ */ private static void createSubcontexts(javax.naming.Context ctx, String name) throws NamingException { javax.naming.Context currentContext = ctx; StringTokenizer tokenizer = new StringTokenizer(name, "/"); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if ((!token.equals("")) && (tokenizer.hasMoreTokens())) { try { currentContext = currentContext.createSubcontext(token); } catch (NamingException e) { // Silent catch. Probably an object is already bound in // the context. currentContext = (javax.naming.Context) currentContext.lookup(token); } } } }
From source file:com.intel.chimera.codec.OpensslCipher.java
private static Transform tokenizeTransformation(String transformation) throws NoSuchAlgorithmException { if (transformation == null) { throw new NoSuchAlgorithmException("No transformation given."); }/* ww w.j a v a 2 s. co m*/ /* * Array containing the components of a Cipher transformation: * * index 0: algorithm (e.g., AES) * index 1: mode (e.g., CTR) * index 2: padding (e.g., NoPadding) */ String[] parts = new String[3]; int count = 0; StringTokenizer parser = new StringTokenizer(transformation, "/"); while (parser.hasMoreTokens() && count < 3) { parts[count++] = parser.nextToken().trim(); } if (count != 3 || parser.hasMoreTokens()) { throw new NoSuchAlgorithmException("Invalid transformation format: " + transformation); } return new Transform(parts[0], parts[1], parts[2]); }
From source file:com.cnksi.core.web.utils.Servlets.java
/** * ?? If-None-Match Header, Etag?./*ww w . ja va 2 s . com*/ * * Etag, checkIfNoneMatchfalse, 304 not modify status. * * @param etag ETag. */ public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) { String headerValue = request.getHeader(HttpHeaders.IF_NONE_MATCH); if (headerValue != null) { boolean conditionSatisfied = false; if (!"*".equals(headerValue)) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(etag)) { conditionSatisfied = true; } } } else { conditionSatisfied = true; } if (conditionSatisfied) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader(HttpHeaders.ETAG, etag); return false; } } return true; }
From source file:com.concursive.connect.web.utils.PermissionUtils.java
public static boolean hasPermissionToAction(ServletRequest request, HttpSession session, String permission, String includeIf, String objectName) { // Use the object name specified, or use the default here String thisObjectName = objectName; if (thisObjectName == null) { thisObjectName = "project"; }//from www .j a v a2s. c o m try { // Find the project to check for permissions... Project thisProject = null; // Check the current portlet first PortletRequest renderRequest = (PortletRequest) request .getAttribute(org.apache.pluto.tags.Constants.PORTLET_REQUEST); if (renderRequest != null) { // Get the requested object Object object = null; int dotPos = thisObjectName.indexOf("."); if (dotPos > -1) { // Get the base object from the request String currentObject = thisObjectName.substring(0, dotPos); object = renderRequest.getAttribute(currentObject); // Get the parsed object currentObject = thisObjectName.substring(dotPos + 1); object = ObjectUtils.getObject(object, currentObject); thisProject = (Project) object; } else { thisProject = (Project) renderRequest.getAttribute(thisObjectName); } if (thisProject == null && objectName == null) { thisProject = PortalUtils.getProject(renderRequest); } } // Check the request object if (thisProject == null) { // Get the requested object Object object = null; int dotPos = thisObjectName.indexOf("."); if (dotPos > -1) { // Get the base object from the request String currentObject = thisObjectName.substring(0, dotPos); object = request.getAttribute(currentObject); // Get the parsed object currentObject = thisObjectName.substring(dotPos + 1); object = ObjectUtils.getObject(object, currentObject); thisProject = (Project) object; } else { thisProject = (Project) request.getAttribute(thisObjectName); } } // Deny if not found if (thisProject == null) { LOG.debug("Project is null"); return false; } // Check this user's permissions User thisUser = null; // Check the portlet if (thisUser == null && renderRequest != null) { thisUser = PortalUtils.getUser(renderRequest); } // Check the session object if (thisUser == null) { thisUser = (User) session.getAttribute(Constants.SESSION_USER); } // Deny if not found if (thisUser == null) { return false; } // Multiple permissions to check boolean doCheck = true; String thisPermission = null; StringTokenizer st = new StringTokenizer(permission, ","); while (st.hasMoreTokens() || doCheck) { doCheck = false; if (st.hasMoreTokens()) { thisPermission = st.nextToken(); } else { thisPermission = permission; } if (NONE.equals(includeIf)) { if (ProjectUtils.hasAccess(thisProject.getId(), thisUser, thisPermission)) { return false; } } else if (ANY.equals(includeIf)) { if (ProjectUtils.hasAccess(thisProject.getId(), thisUser, thisPermission)) { return true; } } else { if (!ProjectUtils.hasAccess(thisProject.getId(), thisUser, thisPermission)) { return false; } } } // If the above didn't trigger, then go with the default if (NONE.equals(includeIf)) { return true; } else if (ANY.equals(includeIf)) { return false; } else { return true; } } catch (Exception e) { LOG.error("hasPermissionToAction", e); return false; } }