List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim)
From source file:org.dojotoolkit.zazl.internal.XMLHttpRequestUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static String xhrRequest(String shrDataString) { InputStream is = null;//from ww w. j a va2 s . co m String json = null; try { logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "shrDataString [" + shrDataString + "]"); Map<String, Object> xhrData = (Map<String, Object>) JSONParser.parse(new StringReader(shrDataString)); String url = (String) xhrData.get("url"); String method = (String) xhrData.get("method"); List headers = (List) xhrData.get("headers"); URL requestURL = createURL(url); URI uri = new URI(requestURL.toString()); HashMap httpMethods = new HashMap(7); httpMethods.put("DELETE", new HttpDelete(uri)); httpMethods.put("GET", new HttpGet(uri)); httpMethods.put("HEAD", new HttpHead(uri)); httpMethods.put("OPTIONS", new HttpOptions(uri)); httpMethods.put("POST", new HttpPost(uri)); httpMethods.put("PUT", new HttpPut(uri)); httpMethods.put("TRACE", new HttpTrace(uri)); HttpUriRequest request = (HttpUriRequest) httpMethods.get(method.toUpperCase()); if (request.equals(null)) { throw new Error("SYNTAX_ERR"); } for (Object header : headers) { StringTokenizer st = new StringTokenizer((String) header, ":"); String name = st.nextToken(); String value = st.nextToken(); request.addHeader(name, value); } HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(request); Map headerMap = new HashMap(); HeaderIterator headerIter = response.headerIterator(); while (headerIter.hasNext()) { Header header = headerIter.nextHeader(); headerMap.put(header.getName(), header.getValue()); } int status = response.getStatusLine().getStatusCode(); String statusText = response.getStatusLine().toString(); is = response.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { sb.append(line); sb.append('\n'); } Map m = new HashMap(); m.put("status", new Integer(status)); m.put("statusText", statusText); m.put("responseText", sb.toString()); m.put("headers", headerMap.toString()); StringWriter w = new StringWriter(); JSONSerializer.serialize(w, m); json = w.toString(); logger.logp(Level.FINER, XMLHttpRequestUtils.class.getName(), "xhrRequest", "json [" + json + "]"); } catch (Throwable e) { logger.logp(Level.SEVERE, XMLHttpRequestUtils.class.getName(), "xhrRequest", "Failed request for [" + shrDataString + "]", e); } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } } return json; }
From source file:net.servicefixture.parser.ExpressionTreeParser.java
public void addDataRow(Parse[] dataCells) { if ((dataCells.length != 2 && dataCells.length != 3) || StringUtils.isEmpty(dataCells[0].text()) || StringUtils.isEmpty(dataCells[1].text())) { throw new ServiceFixtureException("The data row must and only have 2 or 3 non-blank data cells."); }//ww w . j a va2s .com String expression = dataCells[0].text(); StringTokenizer tokenizer = new StringTokenizer(expression, EXPRESSION_DELIMITER); Group group = tree.getRoot(); //Creates group nodes while (tokenizer.countTokens() > 1) { group = getOrCreateGroupByName(group, tokenizer.nextToken()); } //Now let's handle the last token which represents the leaf with value //or object type. String value = dataCells[1].text(); if (value.startsWith(CLASS_TYPE_PREFIX) && value.endsWith(CLASS_TYPE_SUFFIX)) { //It is row that contains customized object type. String clazzName = value.substring(CLASS_TYPE_PREFIX.length(), value.length() - CLASS_TYPE_SUFFIX.length()); Node node = null; if (dataCells.length == 3) { //It is the lowest level object with customized object type. node = new Leaf(tokenizer.nextToken(), dataCells[2]); } else { node = new Group(tokenizer.nextToken()); } node.setObjectType(ReflectionUtils.newClass(clazzName)); group.addChild(node); } else { Leaf leaf = new Leaf(tokenizer.nextToken(), dataCells[1]); group.addChild(leaf); } }
From source file:net.padaf.preflight.IsartorTargetFileInformation.java
protected static IsartorTargetFileInformation getInformation(File file, Properties props) { Logger logger = Logger.getLogger("test.isartor"); String key = file.getName();//w ww. ja v a 2 s .c o m String line = props.getProperty(key); if (line != null) { // only one parameter for the moment String error = new StringTokenizer(line, "//").nextToken().trim(); return new IsartorTargetFileInformation(file, error); } else { logger.error("There is no expected error for " + key); return null; } }
From source file:com.flipkart.phantom.task.utils.StringUtils.java
public static Map<String, String> getQueryParams(String httpUrl) { Map<String, String> params = new HashMap<String, String>(); if (httpUrl == null) { return params; }// ww w . ja va 2 s . com URL url = null; try { url = new URL(httpUrl); } catch (MalformedURLException e) { throw new RuntimeException(e); } String query = url.getQuery(); if (query == null) { return params; } StringTokenizer tokenizer = new StringTokenizer(query, "&"); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); int index = token.indexOf("="); params.put(token.substring(0, index).trim(), token.substring(index + 1).trim()); } return params; }
From source file:edu.rit.flick.genetics.FastaFileInflator.java
private void getNextTandemRepeatChunk() { inTandemRepeat = false;//from w w w. ja v a 2 s . c om if (tandemFile.hasNext()) { final StringTokenizer tandems = new StringTokenizer(tandemFile.next(), RANGE); tandemStart = Long.parseLong(tandems.nextToken(), HexPrinter.RADIX); tandemEnd = Long.parseLong(tandems.nextToken(), HexPrinter.RADIX); } }
From source file:Main.java
/** * /* w w w. j a v a 2 s .co m*/ * @param value * @return Object[] */ public static Object[] toArray(final String value) { if (value == null) { return new Object[] {}; } final int BRACKET_LENGTH = 1; final String strippedValue = value.substring(BRACKET_LENGTH, value.length() - BRACKET_LENGTH); final StringTokenizer tokenizer = new StringTokenizer(strippedValue, ELEMENT_SEPARATOR); final Collection<Object> collection = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { collection.add(tokenizer.nextToken().trim()); } return collection.toArray(); }
From source file:com.bskyb.cg.environments.message.MessageHandler.java
private Map<String, String> getFields(String key) { Map<String, String> map = new HashMap<String, String>(); StringTokenizer tk = new StringTokenizer(key, "_"); String datestring = (String) tk.nextElement(); map.put("date", datestring); String hostname = (String) tk.nextElement(); map.put("hostname", hostname); String msgtype = (String) tk.nextElement(); map.put("msgtype", msgtype); String uuid = (String) tk.nextElement(); map.put("uuid", uuid); String epochtime = (String) tk.nextElement(); map.put("epochtime", epochtime); return map;// w ww . ja v a2 s. c om }
From source file:de.suse.swamp.core.data.datatypes.personDatabit.java
/** * Checks if the given value v fits this Databit's Type. * // w w w .j av a2 s. c om * @param v */ public String checkDataType(String v) throws InvalidArgumentException, Exception { // empty values are allowed if (!v.equals("") && !checkedValues.contains(v)) { // datatype person may be a comma-separated // email, or loginname list StringTokenizer st = new StringTokenizer(v, ","); while (st.hasMoreTokens()) { String tokenvalue = st.nextToken().trim(); // valid SWAMP user? if (tokenvalue.indexOf('@') < 0) { try { SecurityManager.getUser(tokenvalue); } catch (UnknownElementException e) { throw new InvalidArgumentException( i18n.tr("Unknown User: ") + tokenvalue + i18n.tr(" in field ") + this.getName()); } catch (Exception e) { Logger.ERROR("Exception from backend: " + e.getMessage()); e.printStackTrace(); throw e; } } else { // assuming Email-Address if (!(org.apache.commons.validator.EmailValidator.getInstance().isValid(tokenvalue))) { throw new InvalidArgumentException(tokenvalue + i18n.tr(" is not a valid E-Mail address.")); } } } // value is valid checkedValues.add(v); } return v; }
From source file:org.sglover.alfrescoextensions.common.CassandraSession.java
private Session buildCassandraSession(String hostsStr) { List<String> hosts = new LinkedList<>(); StringTokenizer st = new StringTokenizer(hostsStr, ","); while (st.hasMoreTokens()) { hosts.add(st.nextToken());// w w w .j av a2 s.c om } this.cluster = Cluster.builder().addContactPoints(hosts.toArray(new String[0])) .withRetryPolicy(DefaultRetryPolicy.INSTANCE) .withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy())).build(); Session session = cluster.connect(); return session; }
From source file:com.alternatecomputing.jschnizzle.renderer.YUMLRenderer.java
public BufferedImage render(Diagram diagram) { String script = diagram.getScript(); if (script == null) { throw new RendererException("no script defined."); }/*w ww .j av a 2 s . c o m*/ StringTokenizer st = new StringTokenizer(script.trim(), "\n"); StringBuilder buffer = new StringBuilder(); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.startsWith("#")) { continue; // skip over comments } buffer.append(token.trim()); if (st.hasMoreTokens()) { buffer.append(", "); } } buffer.append(".svg"); String style = diagram.getStyle().getValue(); String baseURL = getBaseURL(); try { HttpClient client = new HttpClient(); String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); if (StringUtils.isNotBlank(proxyHost) && StringUtils.isNotBlank(proxyPort)) { client.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort)); } String postURI = baseURL + "diagram/" + style + "/" + diagram.getType().getUrlModifier() + "/"; LOGGER.debug(postURI); PostMethod postMethod = new PostMethod(postURI); postMethod.addParameter("dsl_text", buffer.toString()); client.executeMethod(postMethod); String svgResourceName = postMethod.getResponseBodyAsString(); postMethod.releaseConnection(); LOGGER.debug(svgResourceName); String getURI = baseURL + svgResourceName; LOGGER.debug(getURI); GetMethod getMethod = new GetMethod(getURI); client.executeMethod(getMethod); String svgContents = getMethod.getResponseBodyAsString(); getMethod.releaseConnection(); LOGGER.debug(svgContents); diagram.setEncodedImage(svgContents); TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(svgContents.getBytes())); BufferedImageTranscoder imageTranscoder = new BufferedImageTranscoder(); imageTranscoder.transcode(input, null); return imageTranscoder.getBufferedImage(); } catch (MalformedURLException e) { throw new RendererException(e); } catch (IOException e) { throw new RendererException(e); } catch (TranscoderException e) { throw new RendererException(e); } }