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.gargoylesoftware.htmlunit.html.HtmlArea.java
/** * {@inheritDoc}/*w w w .j a v a2 s . c o m*/ */ @Override protected boolean doClickStateUpdate() throws IOException { final HtmlPage enclosingPage = (HtmlPage) getPage(); final WebClient webClient = enclosingPage.getWebClient(); final String href = getHrefAttribute().trim(); if (!href.isEmpty()) { final HtmlPage page = (HtmlPage) getPage(); if (StringUtils.startsWithIgnoreCase(href, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { page.executeJavaScriptIfPossible(href, "javascript url", getStartLineNumber()); return false; } final URL url; try { url = enclosingPage.getFullyQualifiedUrl(getHrefAttribute()); } catch (final MalformedURLException e) { throw new IllegalStateException("Not a valid url: " + getHrefAttribute()); } final WebRequest request = new WebRequest(url); request.setAdditionalHeader("Referer", page.getUrl().toExternalForm()); final WebWindow webWindow = enclosingPage.getEnclosingWindow(); webClient.getPage(webWindow, enclosingPage.getResolvedTarget(getTargetAttribute()), request); } return false; }
From source file:com.erudika.scoold.controllers.SigninController.java
@GetMapping("/signin") public String get(@RequestParam(name = "returnto", required = false, defaultValue = HOMEPAGE) String returnto, HttpServletRequest req, HttpServletResponse res, Model model) { if (utils.isAuthenticated(req)) { return "redirect:" + (StringUtils.startsWithIgnoreCase(returnto, SIGNINLINK) ? HOMEPAGE : returnto); }//from w w w . j a v a2 s .c o m if (!HOMEPAGE.equals(returnto) && !SIGNINLINK.equals(returnto)) { HttpUtils.setStateParam("returnto", Utils.urlEncode(returnto), req, res); } else { HttpUtils.removeStateParam("returnto", req, res); } model.addAttribute("path", "signin.vm"); model.addAttribute("title", utils.getLang(req).get("signin.title")); model.addAttribute("signinSelected", "navbtn-hover"); model.addAttribute("fbLoginEnabled", !Config.FB_APP_ID.isEmpty()); model.addAttribute("gpLoginEnabled", !Config.getConfigParam("google_client_id", "").isEmpty()); model.addAttribute("ghLoginEnabled", !Config.GITHUB_APP_ID.isEmpty()); model.addAttribute("inLoginEnabled", !Config.LINKEDIN_APP_ID.isEmpty()); model.addAttribute("twLoginEnabled", !Config.TWITTER_APP_ID.isEmpty()); model.addAttribute("msLoginEnabled", !Config.MICROSOFT_APP_ID.isEmpty()); model.addAttribute("oa2LoginEnabled", !Config.getConfigParam("oa2_app_id", "").isEmpty()); model.addAttribute("ldapLoginEnabled", !Config.getConfigParam("security.ldap.server_url", "").isEmpty()); model.addAttribute("passwordLoginEnabled", Config.getConfigBoolean("password_auth_enabled", true)); model.addAttribute("oa2LoginProvider", Config.getConfigParam("security.oauth.provider", "Continue with OpenID Connect")); return "base"; }
From source file:com.cognifide.aet.job.common.datafilters.w3chtmlfilter.W3cHtml5IssuesFilter.java
private boolean match(W3cHtml5Issue issue) { final boolean messageNotSetOrIgnored = StringUtils.isBlank(message) || StringUtils.startsWithIgnoreCase(issue.getMessage(), message); final boolean lineNotSetOrIgnored = line == 0 || line == issue.getLine(); final boolean columnNotSetOrIgnored = column == 0 || column == issue.getColumn(); return messageNotSetOrIgnored && lineNotSetOrIgnored && columnNotSetOrIgnored; }
From source file:com.meltmedia.cadmium.servlets.jersey.UpdateService.java
private BasicApiResponse sendJgroupsMessage(UpdateRequest req, String auth, String cmd, String prefix) throws Exception { if (!this.isAuth(auth)) { throw new Exception("Unauthorized!"); }//w ww . j a v a 2 s. c o m BasicApiResponse resp = new BasicApiResponse(); resp.setUuid(UUID.randomUUID().toString()); if (sender == null) { resp.setMessage("Cadmium is not fully deployed. See logs for details."); log.error("Channel is not wired"); return resp; } else if (StringUtils.isBlank(req.getComment())) { resp.setMessage("invalid request"); return resp; } else if (StringUtils.isNotBlank(req.getBranch()) && !StringUtils.startsWithIgnoreCase(req.getBranch(), prefix)) { resp.setMessage("Branch must begin with prefix \"" + prefix + "-\""); return resp; } // NOTE: if the headers had the openId and UUID, then we could reuse the request from the client. ContentUpdateRequest body = new ContentUpdateRequest(); body.setContentLocation(new GitLocation(emptyStringIfNull(req.getRepo()), emptyStringIfNull(req.getBranch()), emptyStringIfNull(req.getSha()))); body.setComment(req.getComment()); body.setOpenId(openId); body.setUuid(resp.getUuid()); body.setRevertable(true); Message<ContentUpdateRequest> msg = new Message<ContentUpdateRequest>(cmd, body); sender.sendMessage(msg, null); resp.setMessage("ok"); return resp; }
From source file:de.adorsys.oauth.loginmodule.OAuthClientIdLoginModule.java
private boolean validateRequest() throws LoginException { HttpServletRequest request = fromPolicyContext(HttpServletRequest.class); if (request != null && request.getUserPrincipal() != null) { return false; }// ww w . ja v a 2s . c om AuthorizationRequest authorizationRequest = fromPolicyContext(AuthorizationRequest.class); if (authorizationRequest == null) { return false; } ClientID clientID = authorizationRequest.getClientID(); String redirectionURIs = System.getProperty("oauth.clients." + clientID + ".redirectionURIs"); if (redirectionURIs == null) { LOG.warn( "Unknow OAUTH ClientID {} requested a token. Please define system property 'oauth.clients.{}.redirectionURIs'.", clientID, clientID); throw new LoginException( "Unknow OAUTH ClientID {} requested a token. Please define system property 'oauth.clients.{}.redirectionURIs'."); } String redirectUri = authorizationRequest.getRedirectionURI().toString(); for (String allowedUri : Arrays.asList(redirectionURIs.split(","))) { if (StringUtils.startsWithIgnoreCase(redirectUri, allowedUri)) { return true; } } LOG.warn( "OAUTH ClientID {} requested a token but the redirect urls does not match. Actual redirectionurl {} is not defined in {}.", clientID, authorizationRequest.getRedirectionURI(), redirectionURIs); throw new LoginException( "OAUTH ClientID {} requested a token but the redirect urls does not match. Actual redirectionurl {} is not defined in {}."); }
From source file:com.mtt.myapp.home.service.HomeService.java
/** * Get panel entries containing the entries from the given RSS * url./*from w w w. j a v a 2s . co m*/ * * @param feedURL rss url message * @param maxSize max size * @param includeReply if including reply * @return {@link PanelEntry} list */ public List<PanelEntry> getPanelEntries(String feedURL, int maxSize, boolean includeReply) { SyndFeedInput input = new SyndFeedInput(); XmlReader reader = null; HttpURLConnection feedConnection = null; try { List<PanelEntry> panelEntries = new ArrayList<PanelEntry>(); URL url = new URL(feedURL); feedConnection = (HttpURLConnection) url.openConnection(); feedConnection.setConnectTimeout(4000); feedConnection.setReadTimeout(4000); reader = new XmlReader(feedConnection); SyndFeed feed = input.build(reader); int count = 0; for (Object eachObj : feed.getEntries()) { SyndEntryImpl each = cast(eachObj); if (!includeReply && StringUtils.startsWithIgnoreCase(each.getTitle(), "Re: ")) { continue; } if (count++ > maxSize) { break; } PanelEntry entry = new PanelEntry(); entry.setAuthor(each.getAuthor()); entry.setLastUpdatedDate( each.getUpdatedDate() == null ? each.getPublishedDate() : each.getUpdatedDate()); entry.setTitle(each.getTitle()); entry.setLink(each.getLink()); panelEntries.add(entry); } Collections.sort(panelEntries); return panelEntries; } catch (Exception e) { LOG.error("Error while patching the feed entries for {} : {}", feedURL, e.getMessage()); } finally { if (feedConnection != null) { feedConnection.disconnect(); } IOUtils.closeQuietly(reader); } return Collections.emptyList(); }
From source file:eu.usrv.amdiforge.core.GraveFileHandler.java
public List<String> getMatchedDumps(World world, String prefix) { File saveFolder = getSaveFolder(world); final String actualPrefix = StringUtils.startsWithIgnoreCase(prefix, PREFIX) ? prefix : PREFIX + prefix; File[] files = saveFolder.listFiles(new FilenameFilter() { @Override/*from www.j av a 2 s. com*/ public boolean accept(File dir, String name) { return name.startsWith(actualPrefix); } }); List<String> result = Lists.newArrayList(); int toCut = PREFIX.length(); for (File f : files) { String name = f.getName(); result.add(name.substring(toCut, name.length() - 4)); } return result; }
From source file:com.norconex.importer.handler.tagger.impl.ForceSingleValueTagger.java
@Override public void tagApplicableDocument(String reference, InputStream document, ImporterMetadata metadata, boolean parsed) throws ImporterHandlerException { for (String name : singleFields.keySet()) { List<String> values = metadata.getStrings(name); String action = singleFields.get(name); if (values != null && !values.isEmpty() && StringUtils.isNotBlank(action)) { String singleValue = null; if ("keepFirst".equalsIgnoreCase(action)) { singleValue = values.get(0); } else if ("keepLast".equalsIgnoreCase(action)) { singleValue = values.get(values.size() - 1); } else if (StringUtils.startsWithIgnoreCase(action, "mergeWith")) { String sep = StringUtils.substringAfter(action, ":"); singleValue = StringUtils.join(values, sep); } else { singleValue = StringUtils.join(values, ","); }/* www .j a v a 2 s .co m*/ metadata.setString(name, singleValue); } } }
From source file:com.fusionx.lightirc.ui.ChannelFragment.java
@OnClick(R.id.auto_complete_button) public void onAutoCompleteClick(final ImageButton autoComplete) { if (isPopupShown) { mPopupMenu.dismiss();//from www . ja va 2s. co m } else { // TODO - this needs to be synchronized properly final Collection<WorldUser> users = getChannel().getUsers(); final List<WorldUser> sortedList = new ArrayList<>(users.size()); final String message = mMessageBox.getText().toString(); final String finalWord = Iterables.getLast(IRCUtils.splitRawLine(message, false)); for (final WorldUser user : users) { if (StringUtils.startsWithIgnoreCase(user.getNick(), finalWord)) { sortedList.add(user); } } if (sortedList.size() == 1) { changeLastWord(Iterables.getLast(sortedList).getNick()); } else if (sortedList.size() > 1) { if (mPopupMenu == null) { mPopupMenu = new PopupMenu(getActivity(), autoComplete); mPopupMenu.setOnDismissListener(this); mPopupMenu.setOnMenuItemClickListener(this); } final Menu innerMenu = mPopupMenu.getMenu(); innerMenu.clear(); Collections.sort(sortedList, new IRCUserComparator(getChannel())); for (final WorldUser user : sortedList) { innerMenu.add(user.getNick()); } mPopupMenu.show(); } } }
From source file:com.gargoylesoftware.htmlunit.html.HtmlAnchor.java
/** * Same as {@link #doClickStateUpdate()}, except that it accepts an href suffix, needed when a click is * performed on an image map to pass information on the click position. * * @param hrefSuffix the suffix to add to the anchor's href attribute (for instance coordinates from an image map) * @throws IOException if an IO error occurs *//*from w w w. j av a2 s. c o m*/ protected void doClickStateUpdate(final String hrefSuffix) throws IOException { final String href = (getHrefAttribute() + hrefSuffix).trim(); if (LOG.isDebugEnabled()) { final String w = getPage().getEnclosingWindow().getName(); LOG.debug("do click action in window '" + w + "', using href '" + href + "'"); } if (ATTRIBUTE_NOT_DEFINED == getHrefAttribute()) { return; } HtmlPage htmlPage = (HtmlPage) getPage(); if (StringUtils.startsWithIgnoreCase(href, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { final StringBuilder builder = new StringBuilder(href.length()); builder.append(JavaScriptURLConnection.JAVASCRIPT_PREFIX); for (int i = JavaScriptURLConnection.JAVASCRIPT_PREFIX.length(); i < href.length(); i++) { final char ch = href.charAt(i); if (ch == '%' && i + 2 < href.length()) { final char ch1 = Character.toUpperCase(href.charAt(i + 1)); final char ch2 = Character.toUpperCase(href.charAt(i + 2)); if ((Character.isDigit(ch1) || ch1 >= 'A' && ch1 <= 'F') && (Character.isDigit(ch2) || ch2 >= 'A' && ch2 <= 'F')) { builder.append((char) Integer.parseInt(href.substring(i + 1, i + 3), 16)); i += 2; continue; } } builder.append(ch); } if (hasFeature(ANCHOR_IGNORE_TARGET_FOR_JS_HREF)) { htmlPage.executeJavaScriptIfPossible(builder.toString(), "javascript url", getStartLineNumber()); } else { final WebWindow win = htmlPage.getWebClient().openTargetWindow(htmlPage.getEnclosingWindow(), htmlPage.getResolvedTarget(getTargetAttribute()), "_self"); final Page page = win.getEnclosedPage(); if (page != null && page.isHtmlPage()) { htmlPage = (HtmlPage) page; htmlPage.executeJavaScriptIfPossible(builder.toString(), "javascript url", getStartLineNumber()); } } return; } final URL url = getTargetUrl(href, htmlPage); final BrowserVersion browser = htmlPage.getWebClient().getBrowserVersion(); final WebRequest webRequest = new WebRequest(url, browser.getHtmlAcceptHeader()); webRequest.setCharset(htmlPage.getPageEncoding()); webRequest.setAdditionalHeader("Referer", htmlPage.getUrl().toExternalForm()); if (LOG.isDebugEnabled()) { LOG.debug("Getting page for " + url.toExternalForm() + ", derived from href '" + href + "', using the originating URL " + htmlPage.getUrl()); } htmlPage.getWebClient().download(htmlPage.getEnclosingWindow(), htmlPage.getResolvedTarget(getTargetAttribute()), webRequest, true, false, "Link click"); }