List of usage examples for java.util StringTokenizer hasMoreElements
public boolean hasMoreElements()
From source file:org.programmatori.domotica.own.plugin.system.System.java
private Value devideString(String str, char devideKey) { StringTokenizer st = new StringTokenizer(str, "" + devideKey); Value v = null;/*from w w w.java 2 s . com*/ boolean first = true; while (st.hasMoreElements()) { String val = (String) st.nextElement(); if (first) { v = new Value(val); first = false; } else { v.addValue(val); } } return v; }
From source file:com.eviware.soapui.support.log.JLogList.java
public synchronized void addLine(Object line) { if (!isEnabled()) return;//from w w w . ja va2s.c o m synchronized (model.lines) { if (line instanceof LoggingEvent) { LoggingEvent ev = (LoggingEvent) line; linesToAdd.push(new LoggingEventWrapper(ev)); if (ev.getThrowableInformation() != null) { Throwable t = ev.getThrowableInformation().getThrowable(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); StringTokenizer st = new StringTokenizer(sw.toString(), "\r\n"); while (st.hasMoreElements()) linesToAdd.push(" " + st.nextElement()); } } else { linesToAdd.push(line); } } if (future == null) { released = false; future = SoapUI.getThreadPool().submit(model); } }
From source file:org.kuali.ole.select.service.OLEInvoiceSearchService.java
public OLEInvoiceSearchDocument convertToOleInvoiceDocument(DocumentSearchResult documentSearchResult) { OLEInvoiceSearchDocument invoiceDocument = new OLEInvoiceSearchDocument(); Document document = documentSearchResult.getDocument(); List<DocumentAttribute> documentAttributes = documentSearchResult.getDocumentAttributes(); for (DocumentAttribute docAttribute : documentAttributes) { String name = docAttribute.getName(); if (name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.INV_DATE)) { if (docAttribute.getValue() != null) { DateFormat sourceFormat = new SimpleDateFormat("MM/dd/yyyy"); String stringDateObj = (String) docAttribute.getValue().toString(); Method getMethod; try { java.util.Date date = sourceFormat.parse(stringDateObj); invoiceDocument.setInvoiceDate(date); } catch (Exception ex) { ex.printStackTrace(); }// w w w . j a v a2s . c o m } } if (name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.INV_PAY_DATE)) { if (docAttribute.getValue() != null) { DateFormat sourceFormat = new SimpleDateFormat("MM/dd/yyyy"); String stringDateObj = (String) docAttribute.getValue().toString(); Method getMethod; try { java.util.Date date = sourceFormat.parse(stringDateObj); invoiceDocument.setInvoicePayDate(date); } catch (Exception ex) { ex.printStackTrace(); } } } if (name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.INV_SUB_TYP_ID)) { if (docAttribute.getValue() != null) { String stringDateObj = (String) docAttribute.getValue().toString(); invoiceDocument.setInvoiceSubTypeId(Integer.parseInt(stringDateObj)); } } if (name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.PURAP_ID)) { if (invoiceDocument.getPurapDocumentIdentifier() != null && (!invoiceDocument.getPurapDocumentIdentifier().equalsIgnoreCase(""))) { Set<String> hashSet = new HashSet<String>(); String purarIdList = ""; StringTokenizer stringTokenizer = new StringTokenizer( invoiceDocument.getPurapDocumentIdentifier(), ","); while (stringTokenizer.hasMoreElements()) { hashSet.add(stringTokenizer.nextElement().toString()); } hashSet.add(((String) docAttribute.getValue().toString()).toString()); for (String s : hashSet) { if (purarIdList.equalsIgnoreCase("")) { purarIdList = s; } else { purarIdList = s + "," + purarIdList; } } invoiceDocument.setPurapDocumentIdentifier(purarIdList); } else { invoiceDocument .setPurapDocumentIdentifier(((String) docAttribute.getValue().toString()).toString()); } } if (name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.INV_TYP_ID)) { invoiceDocument.setInvoiceTypeId(((String) docAttribute.getValue().toString())); } if (name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.INV_VND_NM)) { invoiceDocument.setVendorName((String) docAttribute.getValue().toString()); } if (name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.INV_VND_NUM)) { invoiceDocument.setVendorNumber((String) docAttribute.getValue().toString()); } if (name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.INV_NUMBER)) { invoiceDocument.setInvoiceNumber((String) docAttribute.getValue().toString()); invoiceDocument.setInvoiceNbr((String) docAttribute.getValue().toString()); } if (name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.INV_DOC_NUM) || name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.INV_TYP) || name.equalsIgnoreCase(OleSelectConstant.InvoiceSearch.INV_SUB_TYP)) { Method getMethod; try { getMethod = getSetMethod(OLEInvoiceSearchDocument.class, name, new Class[] { String.class }); getMethod.invoke(invoiceDocument, docAttribute.getValue().toString()); } catch (Exception ex) { ex.printStackTrace(); } } } return invoiceDocument; }
From source file:util.IPChecker.java
private boolean isInvalidSubpartsIP4(final String part) { if (part.contains("-")) { final List<String> subparts = new ArrayList<String>(); final StringTokenizer tokenizer = new StringTokenizer(part, "-"); while (tokenizer.hasMoreElements()) { subparts.add(tokenizer.nextElement().toString().trim()); }/*from ww w . j a v a2 s. c o m*/ // we need exact two subparts if (subparts.size() != 2) { return true; } final String validChars = "0123456789"; for (final String subpart : subparts) { // ...and only contain digits and dash if (!org.apache.commons.lang.StringUtils.containsOnly(subpart, validChars) || isInvalidIP4PartRange(subpart)) { return true; } } // make sure subpart 1 is smaller than subpart 2 final int sp1 = Integer.valueOf(subparts.get(0)); final int sp2 = Integer.valueOf(subparts.get(1)); if (sp2 == sp1 || sp2 < sp1) { return true; } } else { // validate single part for 1-255 if (isInvalidIP4PartRange(part)) { return true; } } return false; }
From source file:util.IPChecker.java
private void validateIP6(final String ip, final IPForm ranges) { try {/*from w w w. ja va 2s . c o m*/ if (ip.contains("-")) { // range final List<String> parts = new ArrayList<String>(); final StringTokenizer tokenizer = new StringTokenizer(ip, "-"); while (tokenizer.hasMoreElements()) { parts.add(tokenizer.nextElement().toString()); } if (parts.size() == 2) { // try to parse range final IPv6AddressRange range = IPv6AddressRange.fromFirstAndLast( IPv6Address.fromString(parts.get(0)), IPv6Address.fromString(parts.get(1))); ranges.getIp6().add(range.getFirst().toString() + "-" + range.getLast().toString()); } else { // invalid ranges.getInvalidIPs().add(ip); } } else if (ip.contains("/")) { // try to parse network address final IPv6Network network = IPv6Network.fromString(ip); // convert to range ranges.getIp6().add(network.getFirst().toString() + "-" + network.getLast().toString()); } else { // try to parse single IP6 final IPv6Address ip6 = IPv6Address.fromString(ip); // convert to "range" ranges.getIp6().add(ip6.toString() + "-" + ip6.toString()); } } catch (final Exception e) { // invalid ranges.getInvalidIPs().add(ip); } }
From source file:com.epl.ticketws.services.QueryService.java
/** * This method generates the string to be signed based on the following rules: * * - Add the request method + \n/*from w w w . j a va2 s . co m*/ * - Add the timestamp + \n * - Add the request URI * - For each request parameter ordered alphabetically: * - First parameter delimiter ? * - Other parameters separated by & * - Name of the parameter * - Add = sign * - value of the parameter * * For example: * * Given a GET request with timestamp = 1316430943576 and uri = /uri_path/ejemplo with parameters, * Bc = 'Prueba1' * Aa = 'Prueba2' * bc = 'aPrueba3' * z1 = 'prueba4' * * The String to sign is: * * GET\n1316430943576\n/uri_path/ejemplo?amp;Aa=Prueba2&bc=aPrueba3&Bc=Prueba1&z1=prueba4 * * @param uri * @param method * @param timestamp * @return * @throws SignatureException */ private String getStringToSign(URI uri, String method, long timestamp, Map<String, String> params) throws SignatureException { SortedMap<String, String> sortedMap = new TreeMap<String, String>(); // Assuming GET. It actually processes URL parameters for all Method types if (uri.getRawQuery() != null) { StringTokenizer tokenizer = null; try { tokenizer = new StringTokenizer(URLDecoder.decode(uri.getRawQuery(), UTF_8), PARAMETERS_SEPARATOR); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } while (tokenizer.hasMoreElements()) { String token = tokenizer.nextToken(); sortedMap.put(token.split(PARAM_NAME_VALUE_SEPARATOR)[0].toLowerCase() + token.split(PARAM_NAME_VALUE_SEPARATOR)[1], token); } } // If POST process parameter map if (method.equals(HttpMethod.POST.name())) { for (String key : params.keySet()) { String valor = params.get(key); sortedMap.put(key.toLowerCase() + PARAM_NAME_VALUE_SEPARATOR + valor, key + PARAM_NAME_VALUE_SEPARATOR + valor); } } // Generating String to sign StringBuilder stringToSign = new StringBuilder(); stringToSign.append(method); stringToSign.append(HMAC_FIELD_SEPARATOR).append(timestamp); stringToSign.append(HMAC_FIELD_SEPARATOR).append(uri.getPath()); boolean firstParam = true; for (String param : sortedMap.values()) { if (firstParam) { stringToSign.append(URI_PARAMETERS_SEPARATOR).append(param); firstParam = false; } else { stringToSign.append(PARAMETERS_SEPARATOR).append(param); } } return stringToSign.toString(); }
From source file:de.tudarmstadt.ukp.uby.ubycreate.MainController.java
/** * This method dumps Germanet, Framenet, WordNet and XML into DB by instantiating the * appropriate classes and calling their methods *///from ww w . j a va 2 s . co m private void run(String args[]) throws XMLStreamException, SAXException, DocumentException { CmdLineParser parser = new CmdLineParser(this); try { Map<String, Class<? extends Creator>> creatorMap = createMap(); parser.parseArgument(args); /* Breaking the parameter value into lexicon and source path */ StringTokenizer tokSource = new StringTokenizer(source, ":"); String lexicon = tokSource.nextToken(); Creator creatorObj = creatorMap.get(lexicon).newInstance(); source = ""; while (tokSource.hasMoreTokens()) { source = source + tokSource.nextToken(); if (tokSource.hasMoreElements()) { source = source + ":"; } } StringTokenizer tokTarget = new StringTokenizer(target, ":"); String targetType = tokTarget.nextToken(); /* If block is run when target is uby xml */ if (targetType.equals("xml")) { String ubyXMLName = ""; while (tokTarget.hasMoreTokens()) { ubyXMLName = ubyXMLName + tokTarget.nextToken(); if (tokTarget.hasMoreElements()) { ubyXMLName = ubyXMLName + ":"; } } File lmfXML = new File(ubyXMLName); creatorObj.lexicon2XML(source, lmfXML); } else { DBConfig dbConfig = makeDBConfig(target); if (dbConfig == null) { return; } /* * the following has been commented as it throws exception when there is no table in * DB schema to drop */ // LMFDBUtils.dropTables(dbConfig); LMFDBUtils.createTables(dbConfig); creatorObj.lexicon2DB(dbConfig, source); } } catch (JWNLException e) { printHelpMessage(parser, e); } catch (IOException e) { printHelpMessage(parser, e); } catch (CmdLineException e) { printHelpMessage(parser, e); } catch (NullPointerException e) { printHelpMessage(parser, e); } catch (ClassNotFoundException e) { printHelpMessage(parser, e); } catch (NoSuchElementException e) { printHelpMessage(parser, e); } catch (IllegalAccessException e) { printHelpMessage(parser, e); } catch (InstantiationException e) { printHelpMessage(parser, e); } catch (Exception e) { printHelpMessage(parser, e); } }
From source file:henplus.commands.ConnectCommand.java
/** * create a session name from an URL.// w w w . ja v a 2 s . com */ private String createSessionName(final SQLSession session, String name) { String userName = null; String dbName = null; String hostname = null; final String url = session.getURL(); if (name == null || name.length() == 0) { final StringBuilder result = new StringBuilder(); userName = session.getUsername(); StringTokenizer st = new StringTokenizer(url, ":"); while (st.hasMoreElements()) { final String val = (String) st.nextElement(); if (val.toUpperCase().equals("JDBC")) { continue; } dbName = val; break; } int pos; if ((pos = url.indexOf('@')) >= 0) { st = new StringTokenizer(url.substring(pos + 1), ":/"); try { hostname = (String) st.nextElement(); } catch (final Exception e) { /* ignore */ } } else if ((pos = url.indexOf('/')) >= 0) { st = new StringTokenizer(url.substring(pos + 1), ":/"); while (st.hasMoreElements()) { final String val = (String) st.nextElement(); if (val.length() == 0) { continue; } hostname = val; break; } } if (userName != null) { result.append(userName + "@"); } if (dbName != null) { result.append(dbName); } if (dbName != null && hostname != null) { result.append(":"); } if (hostname != null) { result.append(hostname); } name = result.toString(); } String key = name; int count = 0; while (_sessionManager.sessionNameExists(key)) { ++count; key = name + "#" + count; } return key; }
From source file:com.serena.rlc.provider.jira.JiraRequestProvider.java
@Getter(name = STATUS_FILTERS, displayName = "Issue Status Filters", description = "Get JIRA status filters field values.") public FieldInfo getStatusFiltersFieldValues(String fieldName) throws ProviderException { if (StringUtils.isEmpty(statusFilters)) { return null; }/*from w w w .ja va2s . c o m*/ StringTokenizer st = new StringTokenizer(statusFilters, ",;"); FieldInfo fieldInfo = new FieldInfo(fieldName); List<FieldValueInfo> values = new ArrayList<>(); FieldValueInfo value; String status; while (st.hasMoreElements()) { status = (String) st.nextElement(); status = status.trim(); value = new FieldValueInfo(status, status); values.add(value); } fieldInfo.setValues(values); return fieldInfo; }
From source file:org.wso2.carbon.apimgt.keymgt.token.AbstractJWTGenerator.java
public String buildBody(TokenValidationContext validationContext) throws APIManagementException { Map<String, String> standardClaims = populateStandardClaims(validationContext); Map<String, String> customClaims = populateCustomClaims(validationContext); //get tenantId int tenantId = APIUtil.getTenantId(validationContext.getValidationInfoDTO().getEndUserName()); String claimSeparator = getMultiAttributeSeparator(tenantId); if (StringUtils.isNotBlank(claimSeparator)) { userAttributeSeparator = claimSeparator; }//from www . j av a 2s .com if (standardClaims != null) { if (customClaims != null) { standardClaims.putAll(customClaims); } Map<String, Object> claims = new HashMap<String, Object>(); JWTClaimsSet claimsSet = new JWTClaimsSet(); if (standardClaims != null) { Iterator<String> it = new TreeSet(standardClaims.keySet()).iterator(); while (it.hasNext()) { String claimURI = it.next(); String claimVal = standardClaims.get(claimURI); List<String> claimList = new ArrayList<String>(); if (userAttributeSeparator != null && claimVal != null && claimVal.contains(userAttributeSeparator)) { StringTokenizer st = new StringTokenizer(claimVal, userAttributeSeparator); while (st.hasMoreElements()) { String attValue = st.nextElement().toString(); if (StringUtils.isNotBlank(attValue)) { claimList.add(attValue); } } claims.put(claimURI, claimList.toArray(new String[claimList.size()])); } else if ("exp".equals(claimURI)) { claims.put("exp", new Date(Long.valueOf(standardClaims.get(claimURI)))); } else { claims.put(claimURI, claimVal); } } } claimsSet.setAllClaims(claims); return claimsSet.toJSONObject().toJSONString(); } return null; }