List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim, boolean returnDelims)
From source file:com.silverpeas.components.model.AbstractSpringJndiDaoTest.java
/** * Workaround to be able to use Sun's JNDI file system provider on Unix * * @param ic : the JNDI initial context/* w w w . j a va 2 s . c o m*/ * @param jndiName : the binding name * @param ref : the reference to be bound * @throws NamingException */ protected static void rebind(InitialContext ic, String jndiName, Object ref) throws NamingException { Context currentContext = ic; 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); } } else { currentContext.rebind(name, ref); } } }
From source file:com.qiongsong.ficus.dal.internal.DDLFormatterImpl.java
private String formatAlterTable(String sql) { final StringBuilder result = new StringBuilder(60).append("\n "); final StringTokenizer tokens = new StringTokenizer(sql, " (,)'[]\"", true); boolean quoted = false; while (tokens.hasMoreTokens()) { final String token = tokens.nextToken(); if (isQuote(token)) { quoted = !quoted;/* w ww.j a v a 2 s.c om*/ } else if (!quoted) { if (isBreak(token)) { result.append("\n "); } } result.append(token); } return result.toString(); }
From source file:ch.sentric.QueryFactory.java
public Query build(final String q) { if (null == q || "".equalsIgnoreCase(q)) { return new Query(); }//ww w . jav a2 s . c o m final ArrayList<QueryKeyValuePair> list = new ArrayList<QueryKeyValuePair>(0); ParserState state = ParserState.START; final StringTokenizer tokenizer = new StringTokenizer(q, "=&", true); String key = null; while (tokenizer.hasMoreTokens()) { final String token = tokenizer.nextToken(); switch (state) { case DELIMITER: if (token.equals("&")) { state = ParserState.KEY; } break; case KEY: if (!token.equals("=") && !token.equals("&") && !token.equalsIgnoreCase("PHPSESSID") && !token.equalsIgnoreCase("JSESSIONID")) { key = token; state = ParserState.EQUAL; } break; case EQUAL: if (token.equals("=")) { state = ParserState.VALUE; } else if (token.equals("&")) { list.add(new QueryKeyValuePair(key, null)); state = ParserState.KEY; } break; case VALUE: if (!token.equals("=") && !token.equals("&")) { if (token.contains(";jsessionid") || token.contains(";JSESSIONID")) { list.add(new QueryKeyValuePair(key, token.substring(0, token.lastIndexOf(";")))); } else { list.add(new QueryKeyValuePair(key, token)); } state = ParserState.DELIMITER; } else if (token.equals("&")) { list.add(new QueryKeyValuePair(key, null)); state = ParserState.KEY; } break; case START: if (!token.equalsIgnoreCase("PHPSESSID") && !token.equalsIgnoreCase("JSESSIONID")) { key = token; state = ParserState.EQUAL; } break; default: break; } } CollectionUtils.filter(list, new Predicate() { @Override public boolean evaluate(final Object object) { boolean allowedQueryParameter = true; final QueryKeyValuePair queryKeyValuePair = (QueryKeyValuePair) object; for (final String filter : filters) { if (queryKeyValuePair.getKey().startsWith(filter)) { allowedQueryParameter = false; } } return allowedQueryParameter; } }); return new Query(list, '&'); }
From source file:io.datenwelt.cargo.rest.utils.Rfc2047.java
public static String decodeHeader(String input) { StringTokenizer tokenizer = new StringTokenizer(input, " \t", true); StringBuilder decoded = new StringBuilder(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (!token.startsWith("=?") || !token.endsWith("?=")) { decoded.append(token);//from www .j av a2 s . c om continue; } String encodedWord = token; String[] parts = encodedWord.substring(2, encodedWord.length() - 2).split("\\?", 3); if (parts.length != 3) { decoded.append(token); continue; } Charset charset; try { charset = Charset.forName(parts[0]); } catch (Exception ex) { LOG.debug("Skipping the decoding of a header value due to an unknown charset \"{}\" found in: ", parts[1], input, ex); decoded.append(token); continue; } String encoding = parts[1].toUpperCase(); switch (encoding) { case "B": BCodec bcodec = new BCodec(charset); try { decoded.append(bcodec.decode(encodedWord)); } catch (Exception ex) { LOG.debug("Skipping the decoding of BASE64 value from string \"{}\" found in: ", encodedWord, input, ex); decoded.append(token); } break; case "Q": QCodec qcodec = new QCodec(charset); try { decoded.append(qcodec.decode(encodedWord)); } catch (Exception ex) { LOG.debug("Skipping the decoding of Q encoded value from string \"{}\" found in: ", encodedWord, input, ex); decoded.append(token); } break; default: LOG.debug("Skipping the decoding of value from unknown encoding \"{}\" found in: ", encodedWord, input); decoded.append(token); } } return decoded.toString(); }
From source file:ru.anr.base.tests.GlassfishLoader.java
/** * Note: This part of code is taken from Apache Ant CommandLine * implementation.//from w w w. j ava 2 s .c o m * * Crack a command line. * * @param toProcess * the command line to process. * @return the command line broken into strings. An empty or null toProcess * parameter results in a zero sized array. */ public static String[] translateCommandline(String toProcess) { if (toProcess == null || toProcess.length() == 0) { // no command? no string return new String[0]; } // parse with a simple finite state machine final int normal = 0; final int inQuote = 1; final int inDoubleQuote = 2; int state = normal; final StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true); final ArrayList<String> result = new ArrayList<String>(); final StringBuilder current = new StringBuilder(); boolean lastTokenHasBeenQuoted = false; while (tok.hasMoreTokens()) { String nextTok = tok.nextToken(); switch (state) { case inQuote: if ("\'".equals(nextTok)) { lastTokenHasBeenQuoted = true; state = normal; } else { current.append(nextTok); } break; case inDoubleQuote: if ("\"".equals(nextTok)) { lastTokenHasBeenQuoted = true; state = normal; } else { current.append(nextTok); } break; default: if ("\'".equals(nextTok)) { state = inQuote; } else if ("\"".equals(nextTok)) { state = inDoubleQuote; } else if (" ".equals(nextTok)) { if (lastTokenHasBeenQuoted || current.length() != 0) { result.add(current.toString()); current.setLength(0); } } else { current.append(nextTok); } lastTokenHasBeenQuoted = false; break; } } if (lastTokenHasBeenQuoted || current.length() != 0) { result.add(current.toString()); } if (state == inQuote || state == inDoubleQuote) { throw new ApplicationException("unbalanced quotes in " + toProcess); } return result.toArray(new String[result.size()]); }
From source file:org.agiso.tempel.support.base.repository.HashBasedTemplateRepository.java
@Override public void put(String key, String groupId, String templateId, String version, Template<?> template) { if (key == null) { Map<String, Template<?>> vMap = gtvTable.get(groupId, templateId); if (vMap == null) { vMap = new HashMap<String, Template<?>>(); gtvTable.put(groupId, templateId, vMap); } else if (vMap.containsKey(version)) { throw new IllegalStateException("Powtrzona definicja szablonu " + groupId + ":" + templateId + ":" + version + " (" + key + ")"); }/* w w w . j a v a2 s. com*/ vMap.put(version, template); } else if (key.indexOf(':') > 0) { StringTokenizer tokenizer = new StringTokenizer(key, ":", false); groupId = tokenizer.nextToken(); templateId = tokenizer.nextToken(); version = tokenizer.nextToken(); Map<String, Template<?>> vMap = gtvTable.get(groupId, templateId); if (vMap == null) { vMap = new HashMap<String, Template<?>>(); gtvTable.put(groupId, templateId, vMap); } else if (vMap.containsKey(version)) { throw new IllegalStateException("Powtrzona definicja szablonu " + groupId + ":" + templateId + ":" + version + " (" + key + ")"); } vMap.put(version, template); } else { if (kMap.containsKey(key)) { throw new IllegalStateException("Powtrzony klucz szablonu: " + key); } kMap.put(key, template); } }
From source file:it.grid.storm.authz.sa.model.FileAuthzDB.java
private void populateHeader() { this.authzDBType = SAAuthzType.getSAType(authzDB.getString("Type")); String[] version = authzDB.getStringArray("Version"); if (version != null) { String versionNr = version[0]; StringTokenizer versionsNr = new StringTokenizer(versionNr, ".", false); if (versionsNr.countTokens() > 0) { this.majorVersion = Integer.parseInt(versionsNr.nextToken()); this.minorVersion = Integer.parseInt(versionsNr.nextToken()); }//from w w w . j a va 2 s .c o m if (version.length > 1) { this.versionDescription = version[1]; } } }
From source file:de.escalon.hypermedia.spring.PartialUriTemplate.java
/** * Creates a new {@link PartialUriTemplate} using the given template string. * * @param template must not be {@literal null} or empty. *///from w w w . j av a 2 s .c o m public PartialUriTemplate(String template) { Assert.hasText(template, "Template must not be null or empty!"); Matcher matcher = VARIABLE_REGEX.matcher(template); // first group is the variable start without leading {: "", "/", "?", "#", // second group is the comma-separated name list without the trailing } of the variable int endOfPart = 0; while (matcher.find()) { // 0 is the current match, i.e. the entire variable expression int startOfPart = matcher.start(0); // add part before current match if (endOfPart < startOfPart) { final String partWithoutVariables = template.substring(endOfPart, startOfPart); final StringTokenizer stringTokenizer = new StringTokenizer(partWithoutVariables, "?", true); boolean inQuery = false; while (stringTokenizer.hasMoreTokens()) { final String token = stringTokenizer.nextToken(); if ("?".equals(token)) { inQuery = true; } else { if (!inQuery) { urlComponents.add(token); } else { urlComponents.add("?" + token); } variableIndices.add(Collections.<Integer>emptyList()); } } } endOfPart = matcher.end(0); // add current match as part final String variablePart = template.substring(startOfPart, endOfPart); urlComponents.add(variablePart); // collect variablesInPart and track for each part which variables it contains // group(1) is the variable head without the leading { TemplateVariable.VariableType type = TemplateVariable.VariableType.from(matcher.group(1)); // group(2) is the String[] names = matcher.group(2).split(","); List<Integer> variablesInPart = new ArrayList<Integer>(); for (String name : names) { TemplateVariable variable = new TemplateVariable(name, type); variablesInPart.add(variables.size()); variables.add(variable); variableNames.add(name); } variableIndices.add(variablesInPart); } // finish off remaining part if (endOfPart < template.length()) { urlComponents.add(template.substring(endOfPart)); variableIndices.add(Collections.<Integer>emptyList()); } }
From source file:com.qiongsong.ficus.dal.internal.DDLFormatterImpl.java
private String formatCreateTable(String sql) { final StringBuilder result = new StringBuilder(60).append("\n "); final StringTokenizer tokens = new StringTokenizer(sql, "(,)'[]\"", true); int depth = 0; boolean quoted = false; while (tokens.hasMoreTokens()) { final String token = tokens.nextToken(); if (isQuote(token)) { quoted = !quoted;/*from w w w .j a v a 2 s . c o m*/ result.append(token); } else if (quoted) { result.append(token); } else { if (")".equals(token)) { depth--; if (depth == 0) { result.append("\n "); } } result.append(token); if (",".equals(token) && depth == 1) { result.append("\n "); } if ("(".equals(token)) { depth++; if (depth == 1) { result.append("\n "); } } } } return result.toString(); }
From source file:org.agiso.tempel.support.maven.provider.ShrinkWrapMvnTemplateProviderElement.java
@Override protected List<File> resolve(String fqtn) throws Exception { if (supportLogger.isDebugEnabled()) supportLogger.debug(Logs.LOG_01, ansiString(GREEN, fqtn)); StringTokenizer tokenizer = new StringTokenizer(fqtn, ":", false); String groupId = tokenizer.nextToken(); String templateId = tokenizer.nextToken(); String version = tokenizer.nextToken(); return mvnDependencyResolver.resolve(groupId, templateId, version); }