List of usage examples for java.util StringTokenizer hasMoreElements
public boolean hasMoreElements()
From source file:com.microsoft.tfs.core.httpclient.methods.OptionsMethod.java
/** * <p>/*from w w w .j a va 2 s. c o m*/ * This implementation will parse the <tt>Allow</tt> header to obtain the * set of methods supported by the resource identified by the Request-URI. * </p> * * @param state * the {@link HttpState state} information associated with this * method * @param conn * the {@link HttpConnection connection} used to execute this HTTP * method * * @see #readResponse * @see #readResponseHeaders * @since 2.0 */ @Override protected void processResponseHeaders(final HttpState state, final HttpConnection conn) { LOG.trace("enter OptionsMethod.processResponseHeaders(HttpState, HttpConnection)"); final Header allowHeader = getResponseHeader("allow"); if (allowHeader != null) { final String allowHeaderValue = allowHeader.getValue(); final StringTokenizer tokenizer = new StringTokenizer(allowHeaderValue, ","); while (tokenizer.hasMoreElements()) { final String methodAllowed = tokenizer.nextToken().trim().toUpperCase(); methodsAllowed.addElement(methodAllowed); } } }
From source file:org.cloudifysource.quality.iTests.framework.utils.network.OpenstackNetworkApiHelper.java
public OpenstackNetworkApiHelper(final Cloud cloud, final String computeTemplateName) { ComputeTemplate computeTemplate = cloud.getCloudCompute().getTemplates().get(computeTemplateName); if (computeTemplate == null) { throw new IllegalStateException( "Template with name \"" + computeTemplateName + "\" could not be found."); }/*from w w w . ja v a 2 s . c o m*/ String endpoint = null; final Map<String, Object> overrides = computeTemplate.getOverrides(); if (overrides != null && !overrides.isEmpty()) { endpoint = (String) overrides.get(OPENSTACK_ENDPOINT); } final String region = computeTemplate.getImageId().split(REGION_SEPARATOR)[0]; final String cloudUser = cloud.getUser().getUser(); final String password = cloud.getUser().getApiKey(); if (cloudUser == null || password == null) { throw new IllegalStateException("Cloud user or password not found"); } final StringTokenizer st = new StringTokenizer(cloudUser, ":"); final String tenant = st.hasMoreElements() ? (String) st.nextToken() : null; final String username = st.hasMoreElements() ? (String) st.nextToken() : null; try { networkClient = new OpenStackNetworkClient(endpoint, username, password, tenant, region); } catch (final Exception e) { throw new RuntimeException("Failed to initialize network helper : " + e.getMessage(), e); } }
From source file:org.wso2.carbon.identity.entitlement.pip.DefaultAttributeFinder.java
public Set<String> getAttributeValues(String subjectId, String resourceId, String actionId, String environmentId, String attributeId, String issuer) throws Exception { Set<String> values = new HashSet<String>(); subjectId = MultitenantUtils.getTenantAwareUsername(subjectId); if (UserCoreConstants.ClaimTypeURIs.ROLE.equals(attributeId)) { if (log.isDebugEnabled()) { log.debug("Looking for roles via DefaultAttributeFinder"); }//ww w . j ava 2 s .c o m String[] roles = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager() .getRoleListOfUser(subjectId); if (roles != null && roles.length > 0) { for (String role : roles) { if (log.isDebugEnabled()) { log.debug(String.format("User %1$s belongs to the Role %2$s", subjectId, role)); } values.add(role); } } } else { String claimValue = null; try { claimValue = CarbonContext.getThreadLocalCarbonContext().getUserRealm().getUserStoreManager() .getUserClaimValue(subjectId, attributeId, null); } catch (UserStoreException e) { if (e.getMessage().startsWith(IdentityCoreConstants.USER_NOT_FOUND)) { if (log.isDebugEnabled()) { log.debug("User: " + subjectId + " not found in user store"); } } else { throw e; } } if (claimValue == null && log.isDebugEnabled()) { log.debug(String.format("Request attribute %1$s not found", attributeId)); } // Fix for multiple claim values if (claimValue != null) { String claimSeparator = CarbonContext.getThreadLocalCarbonContext().getUserRealm() .getRealmConfiguration() .getUserStoreProperty(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR); if (StringUtils.isBlank(claimSeparator)) { claimSeparator = IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR_DEFAULT; } if (claimValue.contains(claimSeparator)) { StringTokenizer st = new StringTokenizer(claimValue, claimSeparator); while (st.hasMoreElements()) { String attributeValue = st.nextElement().toString(); if (StringUtils.isNotBlank(attributeValue)) { values.add(attributeValue); } } } else { values.add(claimValue); } } } return values; }
From source file:org.wso2.carbon.apimgt.handlers.AuthenticationHandler.java
private String getDeviceType(String url) { StringTokenizer parts = new StringTokenizer(url, "/"); while (parts.hasMoreElements()) { if (parts.nextElement().equals("api")) { return (String) parts.nextElement(); }/*from w w w. j a va2s. co m*/ } return null; }
From source file:org.commoncrawl.util.URLUtils.java
public static String invertAndMarkTLDNameStartInString(String hostName) { // and invert it ... hostName = URLUtils.invertHostName(hostName); // LOG.info("Inverted HostName for Key:" + key.toString() +":" + hostName); // create a buffer StringBuffer tempBuffer = new StringBuffer(hostName.length()); // now walk it skipping tld names StringTokenizer tokenizer = new StringTokenizer(hostName, "."); boolean foundTLDName = false; while (tokenizer.hasMoreElements()) { char delimiterToUse = '.'; String token = tokenizer.nextToken(); if (!foundTLDName) { if (!URLUtils.isTLDStopWord(token)) { foundTLDName = true;/*from w w w .ja v a2 s. c o m*/ delimiterToUse = '!'; } } if (tempBuffer.length() != 0) tempBuffer.append(delimiterToUse); tempBuffer.append(token); } return tempBuffer.toString(); }
From source file:it.unibo.alchemist.boundary.monitors.SAPERENearestNodeSampler.java
@Override protected double[] getProperties(final Environment<List<? extends ILsaMolecule>> env, final Position pos, final Reaction<List<? extends ILsaMolecule>> r, final Time time, final long step) { if (mobility || !HashUtils.pointerEquals(env, envCache)) { pnCache.clear();//from w ww .j ava2 s.c o m envCache = env; } if (!HashUtils.pointerEquals(propertyCache, property)) { propertyCache = property; properties.clear(); final StringTokenizer tk = new StringTokenizer(propertyCache, propertySeparators); while (tk.hasMoreElements()) { properties.add(tk.nextToken()); } } if (!HashUtils.pointerEquals(lsaCache, lsa)) { lsaCache = lsa; mol = sapere.createMolecule(lsaCache); } if (env.getNodesNumber() > 0 && mol != null) { final double[] res = new double[properties.size()]; int i = 0; Node<List<? extends ILsaMolecule>> node = pnCache.get(pos); if (node == null) { double range = Arrays.stream(env.getSize()).reduce(1, (x, y) -> FastMath.max(x, y) / FastMath.sqrt(env.getNodesNumber())); Collection<Node<List<? extends ILsaMolecule>>> neighs = env.getNodesWithinRange(pos, range); while (neighs.isEmpty()) { range *= 2; neighs = env.getNodesWithinRange(pos, range); } node = neighs.stream().reduce( (n1, n2) -> env.getPosition(n1).getDistanceTo(pos) < env.getPosition(n2).getDistanceTo(pos) ? n1 : n2) .get(); pnCache.put(pos, node); } for (final String prop : properties) { /* * Take the nearest node */ res[i++] = sapere.getProperty(node, mol, prop); } return res; } return new double[0]; }
From source file:org.commoncrawl.util.URLUtils.java
static String replicateNameNormalization(String hostNameIn) { // and invert it ... String hostName = URLUtils.invertHostName(hostNameIn); // LOG.info("Inverted HostName for Key:" + key.toString() +":" + hostName); // create a buffer StringBuffer tempBuffer = new StringBuffer(hostName.length()); // now walk it skipping tld names StringTokenizer tokenizer = new StringTokenizer(hostName, "."); boolean foundTLDName = false; while (tokenizer.hasMoreElements()) { char delimiterToUse = '.'; String token = tokenizer.nextToken(); if (!foundTLDName) { if (!URLUtils.isTLDStopWord(token)) { foundTLDName = true;// w w w .j a v a2 s . c o m delimiterToUse = '!'; } } tempBuffer.append(delimiterToUse); tempBuffer.append(token); } hostName = tempBuffer.toString(); return hostName; }
From source file:io.starter.datamodel.ContentData.java
/** * assign categories to an item/*w w w. ja v a2s. co m*/ * * @param obj * @param cats * @throws ServletException */ public static void setCategories(Integer objId, String cats, SqlSession session) throws ServletException { int rowsInserted = 0; StringTokenizer toker = new StringTokenizer(cats, ","); while (toker.hasMoreElements()) { String st = toker.nextElement().toString(); if (st.contains("[")) { st = st.substring(1); } if (st.contains("]")) { st = st.substring(0, st.length() - 1); } Integer categoryId = Integer.parseInt(st); ContentCategoryIdx cat = new ContentCategoryIdx(); cat.setCategoryId(categoryId); cat.setContentId(objId); rowsInserted = session.insert("io.starter.dao.ContentCategoryIdxMapper.insert", cat); session.commit(); } if (rowsInserted > 0) { ; } else { throw new ServletException( "Null rows inserted in ContentCategory IDX -- could not assign categories to Content object."); } }
From source file:org.craftercms.commons.mongo.MongoClientFactory.java
@Override protected MongoClient createInstance() throws Exception { if (StringUtils.isBlank(connectionString)) { logger.info("No connection string specified, connecting to {}:{}", connectionString, DEFAULT_MONGO_HOST, DEFAULT_MONGO_PORT);//from ww w.jav a 2 s . co m return new MongoClient(new ServerAddress(DEFAULT_MONGO_HOST, DEFAULT_MONGO_PORT)); } StringTokenizer st = new StringTokenizer(connectionString, ","); List<ServerAddress> addressList = new ArrayList<>(); while (st.hasMoreElements()) { String server = st.nextElement().toString(); logger.debug("Processing first server found with string {}", server); String[] serverAndPort = server.split(":"); if (serverAndPort.length == 2) { logger.debug("Server string defines host {} and port {}", serverAndPort[0], serverAndPort[1]); if (StringUtils.isBlank(serverAndPort[0])) { throw new IllegalArgumentException("Given host can't be empty"); } int portNumber = NumberUtils.toInt(serverAndPort[1]); if (portNumber == 0) { throw new IllegalArgumentException("Given port number " + portNumber + " is not valid"); } addressList.add(new ServerAddress(serverAndPort[0], portNumber)); } else if (serverAndPort.length == 1) { logger.debug("Server string defines host {} only. Using default port ", serverAndPort[0]); if (StringUtils.isBlank(serverAndPort[0])) { throw new IllegalArgumentException("Given host can't be empty"); } addressList.add(new ServerAddress(serverAndPort[0], DEFAULT_MONGO_PORT)); } else { throw new IllegalArgumentException("Given connection string is not valid"); } } logger.debug("Creating MongoClient with addresses: {}", addressList); if (options != null) { return new MongoClient(addressList, options); } else { return new MongoClient(addressList); } }
From source file:org.eclipse.ocl.examples.build.utilities.ConvertToUnixLineEndings.java
@Override protected void invokeInternal(final WorkflowContext model, final ProgressMonitor monitor, final Issues issues) { if (directory != null) { final StringTokenizer st = new StringTokenizer(directory, ","); while (st.hasMoreElements()) { final String dir = st.nextToken().trim(); final File f = new File(dir); if (f.exists() && f.isDirectory()) { LOG.info("Converting " + f.getAbsolutePath()); try { cleanFolder(f.getAbsolutePath()); } catch (FileNotFoundException e) { issues.addError(e.getMessage()); }//from w w w .j a v a2s.c o m } } } }