List of usage examples for java.util StringTokenizer nextElement
public Object nextElement()
From source file:util.IPChecker.java
private void validateIP6(final String ip, final IPForm ranges) { try {//from w w w. j a v a2 s .co 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:de.betterform.xml.xforms.ui.Selector.java
@Override public void performDefault(Event event) { super.performDefault(event); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Selector: perform default event:" + event.getType()); }// w w w .ja v a2 s. co m XMLEvent ev = (XMLEvent) event; String contextInfo = (String) ev.getContextInfo().get("context-info"); ArrayList list = new ArrayList(); if (contextInfo != null) { StringTokenizer tokens = new StringTokenizer(contextInfo, ";"); while (tokens.hasMoreTokens()) { list.add(tokens.nextElement()); } } String itemId; Item item; Iterator iterator = null; List elemContext = de.betterform.xml.xpath.impl.saxon.XPathUtil.getElementContext(getElement(), container.getProcessor().getBaseURI()); String xformsPrefix = null; if (this.xformsPrefix != null) { xformsPrefix = this.xformsPrefix; } else { xformsPrefix = NamespaceConstants.XFORMS_PREFIX; } String xpath = "(" + xformsPrefix + ":" + XFormsConstants.ITEM + " | *//" + xformsPrefix + ":" + XFormsConstants.ITEM + "[not(ancestor::" + NamespaceConstants.BETTERFORM_PREFIX + ":data)])/@id"; try { iterator = XPathCache.getInstance() .evaluate(elemContext, 1, xpath, extendedPrefixMapping, xpathFunctionContext).iterator(); } catch (XFormsException e) { LOGGER.error("Error evaluating xpath " + xpath); } List<EventTarget> selectList = new ArrayList<EventTarget>(); List<EventTarget> deselectList = new ArrayList<EventTarget>(); while (iterator.hasNext()) { itemId = ((NodeInfo) iterator.next()).getStringValue(); item = (Item) this.container.lookup(itemId); if (list.contains(item.getId()) && !item.isSelected()) { item.select(); selectList.add(item.getTarget()); } else if (!list.contains(item.getId()) && item.isSelected()) { item.deselect(); deselectList.add(item.getTarget()); } } for (EventTarget evt : deselectList) { try { this.container.dispatch(evt, XFormsEventNames.DESELECT, null); } catch (XFormsException e) { LOGGER.error("Error dispatching " + XFormsEventNames.DESELECT + " to target " + evt.toString()); } } deselectList.clear(); for (EventTarget evt : selectList) { try { this.container.dispatch(evt, XFormsEventNames.SELECT, null); } catch (XFormsException e) { LOGGER.error("Error dispatching " + XFormsEventNames.SELECT + " to target " + evt.toString()); } } selectList.clear(); }
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 ww . ja va 2s . com 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:com.bigdata.dastor.db.ColumnFamilyStore.java
public static int getGenerationFromFileName(String filename) { /*/*from w w w.ja va2 s .c om*/ * File name is of the form <table>-<column family>-<index>-Data.db. * This tokenizer will strip the .db portion. */ StringTokenizer st = new StringTokenizer(filename, "-"); /* * Now I want to get the index portion of the filename. We accumulate * the indices and then sort them to get the max index. */ int count = st.countTokens(); int i = 0; String index = null; while (st.hasMoreElements()) { index = (String) st.nextElement(); if (i == (count - 2)) { break; } ++i; } return Integer.parseInt(index); }
From source file:henplus.commands.ConnectCommand.java
/** * create a session name from an URL./*w w w . ja v a2 s . c om*/ */ 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:org.gridsphere.servlets.GridSphereFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { log.info("START"); if ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse)) { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; //PersistenceManagerService pms = null; // If first time being called, instantiate all portlets if (firstDoGet.equals(Boolean.TRUE)) { SettingsService settingsService = (SettingsService) PortletServiceFactory .createPortletService(SettingsService.class, true); // check if database file exists String release = SportletProperties.getInstance().getProperty("gridsphere.release"); int idx = release.lastIndexOf(" "); String gsversion = release.substring(idx + 1); //System.err.println("gsversion=" + gsversion); String dbpath = settingsService.getRealSettingsPath("/database/GS_" + gsversion); File dbfile = new File(dbpath); if (!dbfile.exists()) { request.setAttribute("setup", "true"); RequestDispatcher rd = request.getRequestDispatcher("/setup"); rd.forward(request, response); return; }//ww w .j ava 2 s. c o m PersistenceManagerService pms = (PersistenceManagerService) PortletServiceFactory .createPortletService(PersistenceManagerService.class, true); PersistenceManagerRdbms pm = null; boolean noAdmin = true; try { log.info("Starting a database transaction"); pm = pms.createGridSphereRdbms(); pm.setClassLoader(Thread.currentThread().getContextClassLoader()); pm.beginTransaction(); RoleManagerService roleService = (RoleManagerService) PortletServiceFactory .createPortletService(RoleManagerService.class, true); noAdmin = roleService.getUsersInRole(PortletRole.ADMIN).isEmpty(); pm.endTransaction(); } catch (StaleObjectStateException staleEx) { log.error("This interceptor does not implement optimistic concurrency control!"); log.error("Your application will not work until you add compensation actions!"); } catch (Throwable ex) { ex.printStackTrace(); pm.endTransaction(); try { pm.rollbackTransaction(); } catch (Throwable rbEx) { log.error("Could not rollback transaction after exception!", rbEx); } } if (noAdmin) { request.setAttribute("setup", "true"); RequestDispatcher rd = request.getRequestDispatcher("/setup"); rd.forward(request, response); return; } if (!portletsLoaded) { System.err.println("Loading portlets!!!"); log.info("Loading portlets"); try { // load all portlets PortletManagerService portletManager = (PortletManagerService) PortletServiceFactory .createPortletService(PortletManagerService.class, true); portletManager.loadAllPortletWebApplications(req, res); portletsLoaded = Boolean.TRUE; } catch (Exception e) { log.error("GridSphere initialization failed!", e); RequestDispatcher rd = req.getRequestDispatcher("/jsp/errors/init_error.jsp"); req.setAttribute("error", e); rd.forward(req, res); return; } } PortletsSetupModuleService portletsSetupModuleService = null; try { portletsSetupModuleService = (PortletsSetupModuleService) PortletServiceFactory .createPortletService(PortletsSetupModuleService.class, true); if (!portletsSetupModuleService.isPreInitSetupDone()) { request.setAttribute("setup", "true"); RequestDispatcher rd = request.getRequestDispatcher("/setup"); rd.forward(request, response); return; } } catch (Exception e) { log.error("GridSphere initialization failed!", e); RequestDispatcher rd = req.getRequestDispatcher("/jsp/errors/init_error.jsp"); req.setAttribute("error", e); rd.forward(req, res); return; } if (!portletsInitialized) { System.err.println("Initializing portlets!!!"); log.info("Initializing portlets"); try { // initialize all portlets PortletManagerService portletManager = (PortletManagerService) PortletServiceFactory .createPortletService(PortletManagerService.class, true); portletManager.initAllPortletWebApplications(req, res); portletsInitialized = Boolean.TRUE; } catch (Exception e) { log.error("GridSphere initialization failed!", e); RequestDispatcher rd = req.getRequestDispatcher("/jsp/errors/init_error.jsp"); req.setAttribute("error", e); rd.forward(req, res); return; } } if (!portletsSetupModuleService.isPostInitSetupDone()) { request.setAttribute("setup", "true"); RequestDispatcher rd = request.getRequestDispatcher("/setup"); rd.forward(request, response); return; } firstDoGet = Boolean.FALSE; } String pathInfo = req.getPathInfo(); StringBuffer requestURL = req.getRequestURL(); String requestURI = req.getRequestURI(); String query = req.getQueryString(); log.info("\ncontext path = " + req.getContextPath() + " servlet path=" + req.getServletPath()); log.info("\n pathInfo= " + pathInfo + " query= " + query); log.info(" requestURL= " + requestURL + " requestURI= " + requestURI + "\n"); String extraInfo = ""; // use the servlet path to determine where to forward // expect servlet path = /servletpath/XXXX String path = req.getServletPath(); int start = path.indexOf("/", 1); if ((start > 0) && (path.length() - 1) > start) { String parsePath = path.substring(start + 1); //System.err.println(parsePath); extraInfo = "?"; StringTokenizer st = new StringTokenizer(parsePath, "/"); String layoutId = null; if (st.hasMoreTokens()) { layoutId = (String) st.nextElement(); extraInfo += SportletProperties.LAYOUT_PAGE_PARAM + "=" + layoutId; } if (st.hasMoreTokens()) { String cid = (String) st.nextElement(); extraInfo += "&" + SportletProperties.COMPONENT_ID + "=" + cid; } if (st.hasMoreTokens()) { // check for /a/ or /r/ to indicate if it's a render or action String phase = (String) st.nextElement(); if (phase.equals("a")) { if (st.hasMoreTokens()) { extraInfo += "&" + SportletProperties.IS_ACTION + "=1" + "&" + SportletProperties.DEFAULT_PORTLET_ACTION + "=" + (String) st.nextElement(); } else { extraInfo += "&" + SportletProperties.IS_ACTION + "=1"; } } else if (phase.equals("r")) { if (st.hasMoreTokens()) { extraInfo += "&" + SportletProperties.DEFAULT_PORTLET_RENDER + "=" + (String) st.nextElement(); } else { extraInfo += "&" + SportletProperties.DEFAULT_PORTLET_RENDER + "="; } } else if (phase.equals("m")) { if (st.hasMoreTokens()) { extraInfo += "&" + SportletProperties.PORTLET_MODE + "=" + (String) st.nextElement(); } } else if (phase.equals("s")) { if (st.hasMoreTokens()) { extraInfo += "&" + SportletProperties.PORTLET_WINDOW + "=" + (String) st.nextElement(); } } HttpSession session = req.getSession(); //capture after login redirect (GPF-463 feature) URI but not for: // - login or register layout // - logged in users // - actions (security reasons) // - sessions which already has captured URI if (!"login".equals(layoutId) && !"register".equals(layoutId) && !"a".equals(phase) && null != session && null == session.getAttribute(SportletProperties.PORTLET_USER) && null == session.getAttribute(SportletProperties.PORTAL_REDIRECT_PATH)) { String afterLoginRedirect = requestURI; if (null != query) { afterLoginRedirect += '?' + query; } session.setAttribute(SportletProperties.PORTAL_REDIRECT_PATH, afterLoginRedirect); } } if (query != null) { extraInfo += "&" + query; } //String ctxPath = "/" + configService.getProperty("gridsphere.context"); } //chain.doFilter(request, response); String ctxPath = "/gs"; log.info("forwarded URL: " + ctxPath + extraInfo); context.getRequestDispatcher(ctxPath + extraInfo).forward(req, res); log.info("END"); } }
From source file:com.serena.rlc.provider.tfs.TFSDeploymentUnitProvider.java
@Getter(name = BUILD_STATUS_FILTER, displayName = "Build Status Filter", description = "Build Status Filter.") public FieldInfo getBuildStatusFilterFieldValues(String fieldName, List<Field> properties) throws ProviderException { if (StringUtils.isEmpty(buildStatusFilter)) { return null; }/*from ww w .j a v a2 s . c o m*/ StringTokenizer st = new StringTokenizer(buildStatusFilter, ",;"); 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:com.serena.rlc.provider.tfs.TFSDeploymentUnitProvider.java
@Getter(name = BUILD_RESULT_FILTER, displayName = "Build Result Filter", description = "Build Result Filter.") public FieldInfo getBuildResultFilterFieldValues(String fieldName, List<Field> properties) throws ProviderException { if (StringUtils.isEmpty(buildResultFilter)) { return null; }/*ww w .java 2 s. c o m*/ StringTokenizer st = new StringTokenizer(buildResultFilter, ",;"); 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; }/* ww w .j a v a 2 s . c o m*/ 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; }
From source file:com.sshtools.j2ssh.transport.AbstractKnownHostsKeyVerification.java
/** * <p>/* ww w . ja v a2 s. c o m*/ * Verifies a host key against the list of known_hosts. * </p> * * <p> * If the host unknown or the key does not match the currently allowed host * key the abstract <code>onUnknownHost</code> or * <code>onHostKeyMismatch</code> methods are called so that the caller * may identify and allow the host. * </p> * * @param host the name of the host * @param pk the host key supplied * * @return true if the host is accepted, otherwise false * * @throws TransportProtocolException if an error occurs * * @since 0.2.0 */ public boolean verifyHost(String host, SshPublicKey pk) throws TransportProtocolException { String fingerprint = pk.getFingerprint(); log.info("Verifying " + host + " host key"); if (log.isDebugEnabled()) { log.debug("Fingerprint: " + fingerprint); } Iterator it = allowedHosts.keySet().iterator(); while (it.hasNext()) { // Could be a comma delimited string of names/ip addresses String names = (String) it.next(); if (names.equals(host)) { return validateHost(names, pk); } StringTokenizer tokens = new StringTokenizer(names, ","); while (tokens.hasMoreElements()) { // Try the allowed hosts by looking at the allowed hosts map String name = (String) tokens.nextElement(); if (name.equalsIgnoreCase(host)) { return validateHost(names, pk); } } } // The host is unknown os ask the user onUnknownHost(host, pk); // Recheck ans return the result return checkKey(host, pk); }