List of usage examples for org.apache.commons.lang3 StringUtils startsWithIgnoreCase
public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix)
Case insensitive check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:com.meltmedia.cadmium.cli.InitializeWarCommand.java
public void execute() throws Exception { if (war == null || FileSystemManager.canRead(war)) { if (secure && secureContentRoot != null) { System.setProperty("com.meltmedia.cadmium.contentRoot", secureContentRoot); }/* w w w . j a v a 2 s.c o m*/ if (newWarNames != null && newWarNames.size() != 0) { String warName = newWarNames.get(0); if (!warName.toLowerCase().trim().endsWith(".war")) { warName = warName + ".war"; newWarNames.clear(); newWarNames.add(warName); } } boolean validRequest = true; if (StringUtils.isNotBlank(branch) && !StringUtils.startsWithIgnoreCase(branch, UpdateRequest.CONTENT_BRANCH_PREFIX + "-")) { validRequest = false; System.err .println("Content branch must start with \"" + UpdateRequest.CONTENT_BRANCH_PREFIX + "-\""); } if (StringUtils.isNotBlank(configBranch) && !StringUtils.startsWithIgnoreCase(configBranch, UpdateRequest.CONFIG_BRANCH_PREFIX + "-")) { validRequest = false; System.err.println( "Configuration branch must start with \"" + UpdateRequest.CONFIG_BRANCH_PREFIX + "-\""); } if (!validRequest) { System.exit(1); } updateWar("cadmium-war.war", war, newWarNames, repoUri, branch, configRepoUri, configBranch, domain, context, secure, null); } else { System.err.println("ERROR: \"" + war + "\" does not exist or cannot be read."); System.exit(1); } }
From source file:de.undercouch.citeproc.helper.Levenshtein.java
/** * Searches the given collection of strings and returns a collection of * strings similar to a given string <code>t</code>. Uses reasonable default * values for human-readable strings. The returned collection will be * sorted according to their similarity with the string with the best * match at the first position./*w ww . j a v a 2 s . c om*/ * @param <T> the type of the strings in the given collection * @param ss the collection to search * @param t the string to compare to * @return a collection with similar strings */ public static <T extends CharSequence> Collection<T> findSimilar(Collection<T> ss, CharSequence t) { //look for strings prefixed by 't' Collection<T> result = new LinkedHashSet<T>(); for (T s : ss) { if (StringUtils.startsWithIgnoreCase(s, t)) { result.add(s); } } //find strings according to their levenshtein distance Collection<T> mins = findMinimum(ss, t, 5, Math.min(t.length() - 1, 7)); result.addAll(mins); return result; }
From source file:com.meltmedia.cadmium.cli.DeployCommand.java
/** * // www .j a va2 s . c om * @throws ClientProtocolException * @throws IOException */ public void execute() throws ClientProtocolException, IOException { if (parameters.size() < 2) { System.err.println("The site and repository must be specified."); System.exit(1); } String repo = parameters.get(0); String site = getSecureBaseUrl(parameters.get(1)); if (!site.endsWith("/")) site = site + "/"; if (StringUtils.isBlank(branch)) branch = UpdateRequest.CONTENT_BRANCH_PREFIX + "-master"; if (StringUtils.isBlank(configBranch)) configBranch = UpdateRequest.CONFIG_BRANCH_PREFIX + "-master"; boolean validRequest = true; if (!StringUtils.startsWithIgnoreCase(branch, UpdateRequest.CONTENT_BRANCH_PREFIX + "-")) { validRequest = false; System.err.println("Content branch must start with \"" + UpdateRequest.CONTENT_BRANCH_PREFIX + "-\""); } if (!StringUtils.startsWithIgnoreCase(configBranch, UpdateRequest.CONFIG_BRANCH_PREFIX + "-")) { validRequest = false; System.err.println( "Configuration branch must start with \"" + UpdateRequest.CONFIG_BRANCH_PREFIX + "-\""); } if (!validRequest) { System.exit(1); } String domain = URI.create(site).getHost(); String url = removeSubDomain(site) + "system/deploy"; System.out.println(url); log.debug("siteUrl + JERSEY_ENDPOINT = {}", url); String warName = null; try { HttpClient client = httpClient(); HttpPost post = new HttpPost(url); addAuthHeader(post); post.setHeader("Content-Type", MediaType.APPLICATION_JSON); DeployRequest req = new DeployRequest(); req.setBranch(branch); req.setConfigBranch(configBranch); req.setRepo(repo); req.setConfigRepo(StringUtils.isBlank(configRepo) ? repo : configRepo); req.setDomain(domain); req.setArtifact(artifact); req.setDisableSecurity(disableSecurity); post.setEntity(new StringEntity(new Gson().toJson(req), "UTF-8")); HttpResponse response = client.execute(post); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity entity = response.getEntity(); String resp = EntityUtils.toString(entity); try { post.releaseConnection(); } catch (Exception e) { log.warn("Failed to release connection.", e); } if (!resp.equals("ok") && canCheckWar(resp, url, client)) { System.out.println("Waiting for Jboss to deploy new war: " + resp); warName = resp; int secondsToWait = 120; while (secondsToWait-- > 0) { Thread.sleep(5000l); if (checkWarDeployment(warName, url, client)) { break; } } if (secondsToWait < 0) { System.err.println("Timeout: Deployment of cadmium application to [" + site + "], with repo [" + repo + "] and branch [" + branch + "]"); System.exit(1); } } else { System.out.println("Deployer not compatible with deployment waiting."); } log.debug("entity content type: {}", entity.getContentType().getValue()); System.out.println("Successfully deployed cadmium application to [" + site + "], with repo [" + repo + "] and branch [" + branch + "]"); } else { throw new Exception("Bad response status: " + response.getStatusLine().toString()); } } catch (Exception e) { System.err.println("Failed to deploy cadmium application to [" + site + "], with repo [" + repo + "] and branch [" + branch + "]"); if (warName != null) { try { System.err.println("Attempting to undeploy partial deployment of " + warName + "."); UndeployCommand.undeploy(removeSubDomain(site), warName, token); System.err.println(""); } catch (Exception e1) { System.err.println("Failed to undeploy partial deployment."); } } System.exit(1); } }
From source file:aiai.ai.launchpad.experiment.ExperimentUtils.java
public static NumberOfVariants getNumberOfVariants(String variantsAsStr) { if (StringUtils.isBlank(variantsAsStr)) { return ZERO_VARIANT; }//ww w . j a v a 2 s. c o m String s = variantsAsStr.trim(); if (s.charAt(0) != '(' && s.charAt(0) != '[' && !StringUtils.startsWithIgnoreCase(s.toLowerCase(), RANGE)) { final NumberOfVariants variants = new NumberOfVariants(true, null, 1); variants.values.add(s); return variants; } if (s.startsWith("[")) { int count = 0; final NumberOfVariants variants = new NumberOfVariants(true, null, 0); for (StringTokenizer st = new StringTokenizer(s, "[,] "); st.hasMoreTokens();) { String token = st.nextToken(); variants.values.add(token); count++; } variants.count = count; return variants; } String s1 = s; if (StringUtils.startsWithIgnoreCase(s1, RANGE)) { s1 = s1.substring(RANGE.length()).trim(); } if (s1.charAt(0) == '(') { Scanner scanner = new Scanner(s1.substring(1)); scanner.useDelimiter("[,)]"); int start; int end; int change; try { start = Integer.parseInt(scanner.next().trim()); end = Integer.parseInt(scanner.next().trim()); change = Integer.parseInt(scanner.next().trim()); } catch (NumberFormatException | NoSuchElementException e) { return new NumberOfVariants(false, "Wrong string format for string: " + s, 0); } int count = 0; final NumberOfVariants variants = new NumberOfVariants(true, null, 0); for (int i = start; i < end; i += change) { variants.values.add(Integer.toString(i)); count++; if (count > 100) { return new NumberOfVariants(false, "Too many variants for string: " + s, 0); } } variants.count = count; return variants; } return new NumberOfVariants(false, "Wrong number format for string: " + s, 0); }
From source file:com.iorga.iraj.security.SecurityUtils.java
private static String computeData(final HttpRequestToSign httpRequest) throws IOException, ParseException { final StringBuilder dataBuilder = new StringBuilder(); // HTTP method final String method = httpRequest.getMethod(); if (log.isDebugEnabled()) { log.debug("method = " + method); }// w w w .j a v a2 s .co m dataBuilder.append(method).append("\n"); // body MD5 final byte[] bodyBytes = httpRequest.getBodyBytes(); if (bodyBytes.length > 0) { final String bodyMd5 = DigestUtils.md5Hex(bodyBytes); if (log.isDebugEnabled()) { log.debug("bodyMd5 = " + bodyMd5); } dataBuilder.append(bodyMd5); } dataBuilder.append("\n"); // Content type final String contentType = httpRequest.getContentType(); if (StringUtils.isNotEmpty(contentType)) { if (log.isDebugEnabled()) { log.debug("contentType = " + contentType); } dataBuilder.append(contentType.toLowerCase()); } dataBuilder.append("\n"); /// Date String date = httpRequest.getHeader("Date"); if (log.isDebugEnabled()) { log.debug("date = " + date); } // Handle additional date header final String additionalDate = httpRequest.getHeader(SecurityUtils.ADDITIONAL_DATE_HEADER_NAME); if (additionalDate != null) { if (log.isDebugEnabled()) { log.debug("additionalDate = " + additionalDate); } date = additionalDate; } // Adding date DateUtil.parseDate(date); dataBuilder.append(date).append("\n"); // Handling security additional headers final List<String> canonicalizedHeaderNames = new ArrayList<String>(); final Map<String, String> canonicalizedHeaderNamesMap = new HashMap<String, String>(); for (final String headerName : httpRequest.getHeaderNames()) { if (StringUtils.startsWithIgnoreCase(headerName, SecurityUtils.ADDITIONAL_HEADER_PREFIX)) { // This is a security additional header final String lowerCasedHeaderName = headerName.toLowerCase(); canonicalizedHeaderNames.add(lowerCasedHeaderName); canonicalizedHeaderNamesMap.put(lowerCasedHeaderName, headerName); } } // Sort of the headers Collections.sort(canonicalizedHeaderNames); for (final String canonicalizedHeaderName : canonicalizedHeaderNames) { // Collect values final StringBuilder headerDataBuilder = new StringBuilder(); headerDataBuilder.append(canonicalizedHeaderName).append(":"); boolean firstValue = true; for (final String headerValue : httpRequest .getHeaders(canonicalizedHeaderNamesMap.get(canonicalizedHeaderName))) { if (firstValue) { firstValue = false; } else { headerDataBuilder.append(","); } headerDataBuilder.append(headerValue); } if (log.isDebugEnabled()) { log.debug("header [" + headerDataBuilder.toString() + "]"); } dataBuilder.append(headerDataBuilder).append("\n"); //TODO implement "4 "Unfold" long headers that span multiple lines (as allowed by RFC 2616, section 4.2) by replacing the folding white-space (including new-line) by a single space." http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html#d0e3869 } // Adding request final String resource = httpRequest.getResource(); if (log.isDebugEnabled()) { log.debug("resource = " + resource); } dataBuilder.append(resource).append("\n"); return dataBuilder.toString(); }
From source file:com.dreambox.web.logger.LoggingFilter.java
private boolean isIgnoreUri(String uri) { for (String ignoreUrl : INGORE_LOG_REQUESTMAPS) { if (StringUtils.startsWithIgnoreCase(uri, ignoreUrl)) { return true; }/*from w ww . j a va 2 s.c om*/ if (INGORE_LOG_REQUESTMAPS.contains(uri)) { return true; } } return false; }
From source file:com.sonicle.webtop.core.app.servlet.Login.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean redirect = false; if (logger.isTraceEnabled()) { logger.trace("X-REQUEST-URI: {}", request.getHeader("X-REQUEST-URI")); logger.trace("requestUrl: {}", request.getRequestURL().toString()); logger.trace("pathInfo: {}", request.getPathInfo()); logger.trace("baseUrl: {}", getBaseUrl(request)); logger.trace("forwardServletPath: {}", getRequestForwardServletPath(request)); }/*from w ww . j a v a 2 s.c o m*/ if (ServletUtils.isForwarded(request)) { String forwardServletPath = getRequestForwardServletPath(request); if (StringUtils.startsWithIgnoreCase(forwardServletPath, Login.URL) || StringUtils.startsWithIgnoreCase(forwardServletPath, Logout.URL)) { redirect = true; } if (StringUtils.startsWithIgnoreCase(forwardServletPath, PushEndpoint.URL)) { WebUtils.getAndClearSavedRequest(request); redirect = true; } } else { String requestUrl = request.getRequestURL().toString(); if (StringUtils.endsWithIgnoreCase(requestUrl, Login.URL)) { redirect = true; } } if (redirect) { WebUtils.issueRedirect(request, response, "/"); } else { super.doGet(request, response); } }
From source file:com.github.helenusdriver.driver.impl.SimpleStatementImpl.java
/** * Checks if the query string represents a "select" statement. * * @author paouelle//from w w w . j ava2 s . co m * * @return <code>true</code> if the query string represents a "select"; * <code>false</code> otherwise */ public boolean isSelect() { // don't any better ways to do this return StringUtils.startsWithIgnoreCase(query, "select"); }
From source file:com.norconex.collector.http.url.impl.DefaultURLExtractor.java
@Override public Set<String> extractURLs(Reader document, String documentUrl, ContentType contentType) throws IOException { // Do not extract if non-HTML if (!contentType.equals(ContentType.HTML)) { return null; }//from ww w . j av a 2 s . c o m UrlParts urlParts = new UrlParts(documentUrl); //TODO HOW TO HANDLE <BASE>????? Is it handled by Tika??? if (LOG.isDebugEnabled()) { LOG.debug("DOCUMENT URL ----> " + documentUrl); LOG.debug(" BASE RELATIVE -> " + urlParts.relativeBase); LOG.debug(" BASE ABSOLUTE -> " + urlParts.absoluteBase); } Set<String> urls = new HashSet<String>(); BufferedReader reader = new BufferedReader(document); String line; while ((line = reader.readLine()) != null) { Matcher matcher = URL_PATTERN.matcher(line); while (matcher.find()) { String attrName = matcher.group(URL_PATTERN_GROUP_ATTR_NAME); String url = matcher.group(URL_PATTERN_GROUP_URL); if (StringUtils.startsWithIgnoreCase(url, "mailto:")) { continue; } if (StringUtils.startsWithIgnoreCase(url, "javascript:")) { continue; } if (attrName != null && attrName.equalsIgnoreCase("url") && !META_REFRESH_PATTERN.matcher(line).find()) { continue; } url = extractURL(urlParts, url); if (url == null) { continue; } if (url.length() > maxURLLength) { LOG.warn("URL length (" + url.length() + ") exeeding " + "maximum length allowed (" + maxURLLength + ") to be extracted. URL (showing first 200 " + "chars): " + StringUtils.substring(url, 0, LOGGING_MAX_URL_LENGTH) + "..."); } else { urls.add(url); } } } return urls; }
From source file:com.evolveum.midpoint.gui.api.component.autocomplete.AutoCompleteQNamePanel.java
private Iterator<String> getIterator(String input) { Map<String, QName> choiceMap = getChoiceMap(); List<String> selected = new ArrayList<>(choiceMap.size()); for (Entry<String, QName> entry : choiceMap.entrySet()) { String key = entry.getKey(); if (StringUtils.startsWithIgnoreCase(key, input.toLowerCase())) { selected.add(key);/*from w w w . j a v a2s. c o m*/ } } return selected.iterator(); }