List of usage examples for org.apache.commons.lang3 StringUtils containsIgnoreCase
public static boolean containsIgnoreCase(final CharSequence str, final CharSequence searchStr)
Checks if CharSequence contains a search CharSequence irrespective of case, handling null .
From source file:org.wikipedia.nirvana.nirvanabot.NirvanaBot.java
@SuppressWarnings("unused") protected void go() throws InterruptedException { long startMillis = Calendar.getInstance().getTimeInMillis(); commons = createCommonsWiki();/*from w w w. ja v a 2 s . c o m*/ commons.setMaxLag(MAX_LAG); try { serviceManager = createServiceManager(); } catch (BotFatalError e) { log.fatal(e); return; } serviceManager.setTimeout(servicesTimeout); if (!serviceManager.checkServices()) { log.fatal("Some services are down. Exiting. "); return; } BotReporter reporter = new BotReporter(wiki, 1000, true, getVersion(), reportPreambulaFile); if (UPDATE_STATUS) { try { reporter.updateStartStatus(STATUS_WIKI_PAGE, STATUS_WIKI_TEMPLATE); } catch (LoginException | IOException e) { log.error(e); } } try { userNamespace = wiki.namespaceIdentifier(Wiki.USER_NAMESPACE); } catch (IOException e) { log.fatal("Failed to retrieve user namespace"); return; } // this is a workaround for bad support of keep alive feature in HttpUrlConnection // without it, writing of big articles (~500KB) may hang // (when reading answer from server after writing) System.setProperty("http.keepAlive", "false"); // adjust HTTP connections List<String> tasks = null; if (TASK) { log.info("reading tasks from file: " + TASK_LIST_FILE); tasks = FileTools.readFileToList(TASK_LIST_FILE, true); if (tasks == null) { log.fatal("Failed to read tasks file: " + TASK_LIST_FILE); return; } log.info("loaded tasks: " + tasks.size() + " total"); for (String task : tasks) { log.debug("task: " + task); } } boolean fatalProblem = false; boolean noServicesOrTimeout = false; for (String newpagesTemplate : newpagesTemplates) { long startT = Calendar.getInstance().getTimeInMillis(); log.info("template to check: " + newpagesTemplate); String[] portalNewPagesLists = null; int repeat = 2; boolean overridden = false; while (repeat > 0) { try { overridden = loadOverridenProperties(newpagesTemplate); } catch (IOException e) { log.error("failed to get page: " + newpagesTemplate); if (!serviceManager.checkServices()) { log.fatal("Some services are down. Stopping..."); fatalProblem = true; break; } repeat--; continue; } try { portalNewPagesLists = wiki.whatTranscludesHere(newpagesTemplate, Wiki.ALL_NAMESPACES); } catch (IOException e) { log.fatal("failed to get portal list"); if (!serviceManager.checkServices()) { log.fatal("Some services are down. Stopping..."); fatalProblem = true; break; } repeat--; continue; } break; } if (repeat == 0 || fatalProblem) { break; } if (overridden) { try { log.debug("Update service manager with default service: " + DEFAULT_SERVICE_NAME + " and selected service: " + SELECTED_SERVICE_NAME); serviceManager.updateCatScan(DEFAULT_SERVICE_NAME, SELECTED_SERVICE_NAME); } catch (BotFatalError e1) { log.fatal(e1); return; } } log.info("loaded portal settings: " + portalNewPagesLists.length); java.util.Arrays.sort(portalNewPagesLists); int i = 0; // int t = 0; // int retry_count = 0; boolean retry = false; ReportItem reportItem = null; String portalName = null; while (i < portalNewPagesLists.length) { if (!noServicesOrTimeout && botTimeout > 0 && (Calendar.getInstance().getTimeInMillis() - startMillis > botTimeout)) { log.debug("Bot work time exceeded allowed maximum of " + botTimeout + " ms. Stopping bot."); noServicesOrTimeout = true; } log.debug("start processing portal No: " + i); if (retry) { retry = false; log.info("retrying portal: " + portalName); retry_count++; //reportItem = report.get(report.size()-1); } else { retry_count = 0; portalName = portalNewPagesLists[i]; //i++; int percent = (i * 100) / portalNewPagesLists.length; log.info(String.format( "=[ %1$d/%2$d: %3$d%% ]===================================================================", i + 1, portalNewPagesLists.length, percent)); log.info("processing portal: " + portalName); //Calendar startPortalTime = Calendar.getInstance(); reportItem = new ReportItem(newpagesTemplate, portalName); if (reporter != null) reporter.add(reportItem); reportItem.start(); } if (!checkPortalInTaskList(tasks, portalName)) { log.info("SKIP portal: " + portalName); reportItem.skip(); i++; continue; } if (noServicesOrTimeout) { reportItem.error(BotError.FATAL); i++; continue; } if (retry_count == 0) t++; if (t < START_FROM) { log.info("SKIP portal: " + portalName); reportItem.skip(); i++; continue; } if (retry_count == 0) reporter.portalChecked(); boolean mayBeSomeServiceProblem = false; try { serviceManager.timeToFixProblems(); String portalSettingsText = wiki.getPageText(portalName); if (DEBUG_MODE) { FileTools.dump(portalSettingsText, "dump", portalName + ".settings.txt"); } if (!wiki.allowEditsByCurrentBot(portalSettingsText)) { log.info("SKIP portal: " + portalName); reportItem.skip(); i++; continue; } Map<String, String> parameters = new HashMap<String, String>(); if (TryParseTemplate(newpagesTemplate, userNamespace, portalSettingsText, parameters, true)) { log.info("validate portal settings OK"); logPortalSettings(parameters); NewPagesData data = new NewPagesData(); if (createPortalModule(parameters, data)) { if ((TYPE.equals("all") || TYPE.equals(data.type)) && data.portalModule != null) { if (DEBUG_MODE || !DEBUG_BUILD || !portalName .contains("ValidParam") /*&& !portalName.contains("Testing")*/) { if (retry_count == 0) { reporter.portalProcessed(); reportItem.processed(); } if (data.portalModule.update(wiki, reportItem, COMMENT)) { reporter.portalUpdated(); reportItem.updated(); } if (UPDATE_PAUSE > 0) Thread.sleep(UPDATE_PAUSE); } } else { reportItem.skip(); log.info("SKIP portal: " + portalName); } } else { log.warn("portal module not created"); reportItem.error(BotError.SETTINGS_ERROR); } if (!data.errors.isEmpty()) { log.warn("errors occured during checking settings"); for (String str : data.errors) { log.info(str); } reportItem.errors = data.errors.size(); String errorText = StringUtils.join(data.errors, "\n"); FileTools.dump(errorText, "dump", portalName + ".err"); if (ERROR_NOTIFICATION) { for (String err : data.errors) { log.info(err); } } } } else { reportItem.settingsValid = false; reportItem.error(BotError.SETTINGS_ERROR); log.error("validate portal settings FAILED"); } } catch (IllegalArgumentException | IndexOutOfBoundsException | NullPointerException | java.util.zip.ZipException e) { // includes ArrayIndexOfBoundsException log.error(e.toString()); if (retry_count < retryMax) { log.info("RETRY AGAIN"); retry = true; } else { reporter.portalError(); reportItem.error(BotError.BOT_ERROR); //e.printStackTrace(); log.error("OOOOPS!!!", e); // print stack trace } } catch (ServiceError | IOException e) { log.error(e.toString()); mayBeSomeServiceProblem = true; if (retry_count < retryMax) { log.info("RETRY AGAIN"); retry = true; } else { reporter.portalError(); if (e instanceof ServiceError) reportItem.error(BotError.SERVICE_ERROR); else reportItem.error(BotError.IO_ERROR); //e.printStackTrace(); log.error("OOOOPS!!!", e); // print stack trace } } catch (LoginException e) { log.fatal(e.toString()); fatalProblem = true; break; //e.printStackTrace(); } catch (Exception e) { log.error(e.toString()); if (retry_count < retryMax) { log.info("RETRY AGAIN"); retry = true; } else { reporter.portalError(); reportItem.error(); //e.printStackTrace(); log.error("OOOOPS!!!", e); // print stack trace } } catch (Error e) { log.error(e.toString()); if (retry_count < retryMax) { log.info("RETRY AGAIN"); retry = true; } else { reporter.portalError(); reportItem.error(); //e.printStackTrace(); log.error("OOOOPS!!!", e); // print stack trace } } reportItem.end(); if (STOP_AFTER > 0 && t >= STOP_AFTER) break; if (!retry) i++; if (mayBeSomeServiceProblem) { if (!serviceManager.checkServices()) { log.fatal("Some services are down. Stopping..."); if (serviceManager.getMainWikiService().isOk() == Status.OK) { noServicesOrTimeout = true; continue; } else { fatalProblem = true; break; } } } } reportItem.end(); Calendar cEnd = Calendar.getInstance(); long endT = cEnd.getTimeInMillis(); reporter.addToTotal(portalNewPagesLists.length); log.info("TEMPLATE " + ((fatalProblem || noServicesOrTimeout) ? "STOPPED" : "FINISHED") + " at " + String.format("%1$tT", cEnd)); log.info("WORK TIME for TEMPLATE: " + BotReporter.printTimeDiff(endT - startT)); if (fatalProblem) { break; } } reporter.logStatus(); if (GENERATE_REPORT) { if (StringUtils.containsIgnoreCase(REPORT_FORMAT, "txt")) { reporter.reportTXT(REPORT_FILE_NAME); } if (StringUtils.containsIgnoreCase(REPORT_FORMAT, "wiki")) { if (serviceManager.getMainWikiService().isOk() == Status.OK) { reporter.reportWiki(REPORT_WIKI_PAGE, startNumber == 1); } else { log.warn("Wiki is not available. Reporting to wiki skipped."); } } } if (UPDATE_STATUS) { try { reporter.updateEndStatus(STATUS_WIKI_PAGE, STATUS_WIKI_TEMPLATE); } catch (LoginException | IOException e) { log.error(e); } } reporter.botFinished(true); }
From source file:org.xlcloud.console.applications.autocomplete.AutocompleteMatcher.java
/** {@inheritDoc} */ @Override// w ww .j a v a 2 s . co m protected boolean matchesSafely(String item) { return StringUtils.containsAny(item, query) || StringUtils.containsIgnoreCase(item, query); }
From source file:org.xlrnet.metadict.engines.heinzelnisse.HeinzelnisseEngine.java
private void extractAdjectiveForms(@NotNull String otherInformation, @NotNull DictionaryObjectBuilder builder) { for (String s : StringUtils.split(otherInformation, ',')) { String flectedForm = StringUtils.strip(StringUtils.substringAfter(s, ":")); if (StringUtils.containsIgnoreCase(s, "bestemt form:")) { builder.setAdditionalForm(GrammaticalCase.DEFINITE_FORM, flectedForm); }//from w w w.j av a2 s . c o m if (StringUtils.containsIgnoreCase(s, "intetkjnn:")) { builder.setAdditionalForm(GrammaticalGender.NEUTER, flectedForm); } if (StringUtils.containsIgnoreCase(s, "flertall:")) { builder.setAdditionalForm(GrammaticalNumber.PLURAL, flectedForm); } } }
From source file:org.xlrnet.metadict.engines.heinzelnisse.HeinzelnisseEngine.java
private void extractComparisonForms(@NotNull String otherInformation, @NotNull DictionaryObjectBuilder builder) { for (String s : StringUtils.split(otherInformation, ',')) { String flectedForm = StringUtils.strip(StringUtils.substringAfter(s, ":")); if (StringUtils.containsIgnoreCase(s, "komparativ:")) { builder.setAdditionalForm(GrammaticalComparison.COMPARATIVE, flectedForm); }/*from w w w .j a va 2 s. c o m*/ if (StringUtils.containsIgnoreCase(s, "superlativ:")) { builder.setAdditionalForm(GrammaticalComparison.SUPERLATIVE, flectedForm); } } }
From source file:org.xwiki.contrib.mailarchive.utils.internal.MailUtils.java
@Override public List<IType> extractTypes(final Collection<IType> types, final MailItem mailItem) { logger.debug("extractTypes(types={}, mailItem={})", types, mailItem); List<IType> result = new ArrayList<IType>(); if (types == null || mailItem == null) { throw new IllegalArgumentException("extractTypes: Types and mailitem can't be null"); }//from w w w .j a v a 2 s.co m // set IType for (IType type : types) { logger.debug("Checking for type " + type); boolean matched = true; for (IMailMatcher mailMatcher : type.getMatchers()) { logger.debug(" Checking for matcher " + mailMatcher); List<String> fields = mailMatcher.getFields(); String regexp = mailMatcher.getExpression(); Pattern pattern = null; if (mailMatcher.isAdvancedMode()) { // Manage multi line and ignore case in regexp if needed if (mailMatcher.isIgnoreCase() || mailMatcher.isMultiLine()) { String prefix = "(?"; if (mailMatcher.isIgnoreCase()) { prefix += 'i'; } if (mailMatcher.isMultiLine()) { prefix += 'm'; } prefix += ')'; regexp = prefix + regexp; } try { pattern = Pattern.compile(regexp); } catch (PatternSyntaxException e) { logger.warn("Invalid Pattern " + regexp + "can't be compiled, skipping this mail type"); break; } } Matcher matcher = null; boolean fieldMatch = false; for (String field : fields) { String fieldValue = ""; if ("from".equals(field)) { fieldValue = mailItem.getFrom(); } else if ("to".equals(field)) { fieldValue = mailItem.getTo(); } else if ("cc".equals(field)) { fieldValue = mailItem.getCc(); } else if ("subject".equals(field)) { fieldValue = mailItem.getSubject(); } logger.debug(" Checking field " + field + " with value [" + fieldValue + "] against pattern [" + regexp + "] DEBUG [" + textUtils.byte2hex(regexp.getBytes()) + "]"); if (mailMatcher.isAdvancedMode()) { matcher = pattern.matcher(fieldValue); logger.debug("Matcher : " + matcher); if (matcher != null) { fieldMatch = matcher.find(); logger.debug("fieldMatch: " + fieldMatch); logger.debug("matcher.matches : " + matcher.matches()); } } else { if (mailMatcher.isIgnoreCase()) { fieldMatch = StringUtils.containsIgnoreCase(fieldValue, regexp); } else { fieldMatch = StringUtils.contains(fieldValue, regexp); } } if (fieldMatch) { logger.debug( "Field " + field + " value [" + fieldValue + "] matches pattern [" + regexp + "]"); break; } } matched = matched && fieldMatch; } if (matched) { logger.info("Matched type " + type.getName()); result.add(type); matched = true; } } return result; }
From source file:org.xwiki.validator.DutchWebGuidelinesValidator.java
/** * Do not use frames on websites. Therefore, also do not use the Frameset version of HTML 4.01 or XHTML 1.0. *//* w w w . ja v a2s . c om*/ public void validateRpd2s5() { // Usage of frameset doctype is forbidden if (this.document.getDoctype() != null) { assertFalse(Type.ERROR, "rpd2s5.framesetDoctype", StringUtils.containsIgnoreCase(this.document.getDoctype().getPublicId(), "frameset")); } // Usage of frameset is forbidden assertFalse(Type.ERROR, "rpd2s5.frameset", containsElement(ELEM_FRAMESET)); // Usage of frames is forbidden assertFalse(Type.ERROR, "rpd2s5.frame", containsElement(ELEM_FRAME)); }
From source file:org.xwiki.validator.DutchWebGuidelinesValidator.java
/** * Each HTML or XHTML document must begin with a valid doctype declaration. *//*from ww w .j ava 2 s . c o m*/ public void validateRpd6s1() { assertTrue(Type.ERROR, "rpd6s1.doctype", StringUtils.containsIgnoreCase(this.document.getDoctype().getPublicId(), ELEM_HTML)); }
From source file:org.xwiki.validator.DutchWebGuidelinesValidator.java
/** * Do not describe the mechanism behind following a link. *//*from w w w . j a va 2 s. com*/ public void validateRpd8s1() { List<String> forbiddenLinkTexts = Arrays.asList(messages.getString("rpd8s1.forbiddenLinkTexts").split(",")); for (Node link : getElements(ELEM_LINK)) { for (Node linkChild : new NodeListIterable(link.getChildNodes())) { if (linkChild.getNodeType() == Node.TEXT_NODE) { for (String forbiddenLinkText : forbiddenLinkTexts) { assertFalse(Type.ERROR, "rpd8s1.link", StringUtils.containsIgnoreCase(linkChild.getTextContent(), forbiddenLinkText)); } } } } }
From source file:org.xwiki.validator.DutchWebGuidelinesValidator.java
/** * Specify the character set for web pages. *//* w w w . j a va 2 s . co m*/ public void validateRpd16s1() { NodeListIterable metas = new NodeListIterable( (NodeList) evaluate(this.document, CONTENT_TYPE_META_SELECTOR, XPathConstants.NODESET)); assertTrue(Type.ERROR, "rpd16s1.nometa", metas.getNodeList().getLength() > 0); for (Node meta : metas) { assertTrue(Type.ERROR, "rpd16s1.charset", StringUtils .containsIgnoreCase(getAttributeValue(meta, ATTR_CONTENT), CONTENT_CHARSET_FRAGMENT)); } }
From source file:org.xwiki.validator.DutchWebGuidelinesValidator.java
/** * Specify the UTF-8 character set./*from w ww . ja va 2s. co m*/ */ public void validateRpd16s2() { NodeListIterable metas = new NodeListIterable( (NodeList) evaluate(this.document, CONTENT_TYPE_META_SELECTOR, XPathConstants.NODESET)); assertTrue(Type.ERROR, "rpd16s2.nometa", metas.getNodeList().getLength() > 0); for (Node meta : metas) { String content = getAttributeValue(meta, ATTR_CONTENT); assertTrue(Type.ERROR, "rpd16s2.notutf8", StringUtils.containsIgnoreCase(content, "charset=utf-8")); assertTrue(Type.ERROR, "rpd16s2.differs", StringUtils.containsIgnoreCase(content, CONTENT_CHARSET_FRAGMENT + this.document.getXmlEncoding())); } }