List of usage examples for java.util.regex Pattern CASE_INSENSITIVE
int CASE_INSENSITIVE
To view the source code for java.util.regex Pattern CASE_INSENSITIVE.
Click Source Link
From source file:com.evolveum.midpoint.prism.match.DistinguishedNameMatchingRule.java
@Override public boolean matchRegex(String a, String regex) throws SchemaException { a = normalize(a);//from w w w. j av a 2 s . c om if (a == null) { return false; } // Simple case-insensitive match Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(a); return matcher.matches(); }
From source file:com.norconex.importer.handler.transformer.impl.ReduceConsecutivesTransformer.java
@Override protected void transformStringContent(String reference, StringBuilder content, ImporterMetadata metadata, boolean parsed, boolean partialContent) { String text = content.toString(); content.setLength(0);// ww w .j av a2 s. c om Pattern pattern = null; for (String reduction : reductions) { String regex = "(" + escapeRegex(reduction) + ")+"; if (caseSensitive) { pattern = Pattern.compile(regex); } else { pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); } text = pattern.matcher(text).replaceAll("$1"); } content.append(text); }
From source file:me.doshou.admin.monitor.web.controller.JPAQLExecutorController.java
@PageableDefaults(pageNumber = 0, value = 10) @RequestMapping(value = "/ql", method = RequestMethod.POST) public String executeQL(final @RequestParam("ql") String ql, final Model model, final Pageable pageable) { model.addAttribute("sessionFactory", HibernateUtils.getSessionFactory(em)); try {/* w w w.ja va2 s .c o m*/ new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { //1?ql try { Query query = em.createQuery(ql); int updateCount = query.executeUpdate(); model.addAttribute("updateCount", updateCount); return null; } catch (Exception e) { } //2 ?ql String findQL = ql; String alias = QueryUtils.detectAlias(findQL); if (StringUtils.isEmpty(alias)) { Pattern pattern = Pattern.compile("^(.*\\s*from\\s+)(.*)(\\s*.*)", Pattern.MULTILINE | Pattern.CASE_INSENSITIVE); findQL = pattern.matcher(findQL).replaceFirst("$1$2 o $3"); } String countQL = QueryUtils.createCountQueryFor(findQL); Query countQuery = em.createQuery(countQL); Query findQuery = em.createQuery(findQL); findQuery.setFirstResult(pageable.getOffset()); findQuery.setMaxResults(pageable.getPageSize()); Page page = new PageImpl(findQuery.getResultList(), pageable, (Long) countQuery.getSingleResult()); model.addAttribute("resultPage", page); return null; } }); } catch (Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); model.addAttribute(Constants.ERROR, sw.toString()); } return showQLForm(); }
From source file:com.symbian.driver.remoting.master.TestResultSet.java
/** * Purpose : This function will create the physical zip file which will * contain the test logs for a job run Input : JOB unique identifier * /*w ww . j a v a2 s . c o m*/ * @param aJobID * A job id. * @throws IOException */ private void CreateZip(Integer aJobID) throws IOException { // Absolute path to the files to zip String lJobUIDPath = new String(MasterFolder + File.separator + aJobID.toString()); String lJobLogRoot = new String(lJobUIDPath + File.separator + "output"); File lTestLogPath = new File(lJobLogRoot); // Check the directory exists and it is a directory if (!lTestLogPath.exists() || !lTestLogPath.isDirectory()) { throw new IOException("Logs folder for Job " + aJobID.toString() + " does not exist!"); } // Absolute path of the zip file zipFileName = new File(lJobUIDPath + File.separator + RESULTS_ZIP); Zipper lZipResults = new Zipper(); // avoid picking the logger .lck file. Pattern lResultsPat[] = { Pattern.compile(".*(?<!\\.lck)", Pattern.CASE_INSENSITIVE) }; lZipResults.recurseFiles(lTestLogPath, lResultsPat); lZipResults.zip(zipFileName, lTestLogPath.getAbsolutePath()); }
From source file:at.gv.egiz.sl.util.BKUSLConnector.java
public static SLPdfAsException generateLegacySLException(String xmlResponse) { if (xmlResponse != null) { if (xmlResponse.contains("ErrorResponse")) { int errorCode = -1; String errorInfo = null; // Probably an ErrorResponse Pattern patternErrorCode = Pattern.compile(PATTERN_ERROR_CODE, Pattern.CASE_INSENSITIVE); Matcher matcherErrorCode = patternErrorCode.matcher(xmlResponse); if (matcherErrorCode.find()) { if (matcherErrorCode.groupCount() == 1) { String errorCodeString = matcherErrorCode.group(1); try { errorCode = Integer.parseInt(errorCodeString); } catch (NumberFormatException e) { // Ignore logger.trace("Failed to convert ErrorCode [{}] into number", errorCodeString); }/*ww w . j a v a 2 s . c o m*/ } } if (errorCode > 0) { Pattern patternErrorInfo = Pattern.compile(PATTERN_ERROR_INFO, Pattern.CASE_INSENSITIVE); Matcher matcherErrorInfo = patternErrorInfo.matcher(xmlResponse); if (matcherErrorInfo.find()) { if (matcherErrorInfo.groupCount() == 1) { errorInfo = matcherErrorInfo.group(1); } } return new SLPdfAsException(errorCode, errorInfo); } } } return null; }
From source file:zebrinho.controller.HomeController.java
@RequestMapping(value = "/register", method = RequestMethod.POST) public ModelAndView registerSave(HttpServletRequest request, @RequestParam("username") String username, @RequestParam("password") String password) throws NoSuchAlgorithmException, UnsupportedEncodingException { User user = getLoggedUser(request);/*from w w w .j a v a 2s . co m*/ ModelAndView m = new ModelAndView("home"); if (user != null) { return m; } if (User.fromUsername(username) != null) { ModelAndView mv = new ModelAndView("register"); mv.addObject("username", username); mv.addObject("message", "The '" + username + "'username already exists."); return mv; } Pattern pattern = Pattern.compile("([a-z0-9_]{1,20})", Pattern.CASE_INSENSITIVE); if (!pattern.matcher(username).matches()) { ModelAndView mv = new ModelAndView("register"); mv.addObject("username", username); mv.addObject("message", "Invalid username. A username can only have letters, numbers and _"); return mv; } user = new User(); user.setUsername(username); user.setPassword(User.genHash(password)); user.save(); return new ModelAndView("redirect:/"); }
From source file:com.google.code.configprocessor.processing.ModifyAction.java
protected int parseFlags() { int flagsToUse = 0; String flagsToTest = getFlags() == null ? DEFAULT_PATTERN_FLAGS : getFlags(); String[] flagArray = StringUtils.split(flagsToTest, PATTERN_FLAG_SEPARATOR); for (String flag : flagArray) { if ("UNIX_LINES".equals(flag)) { flagsToUse |= Pattern.UNIX_LINES; } else if ("CASE_INSENSITIVE".equals(flag)) { flagsToUse |= Pattern.CASE_INSENSITIVE; } else if ("COMMENTS".equals(flag)) { flagsToUse |= Pattern.COMMENTS; } else if ("MULTILINE".equals(flag)) { flagsToUse |= Pattern.MULTILINE; } else if ("LITERAL".equals(flag)) { flagsToUse |= Pattern.LITERAL; } else if ("DOTALL".equals(flag)) { flagsToUse |= Pattern.DOTALL; } else if ("UNICODE_CASE".equals(flag)) { flagsToUse |= Pattern.UNICODE_CASE; } else if ("CANON_EQ".equals(flag)) { flagsToUse |= Pattern.CANON_EQ; } else {//from w ww . jav a 2 s . c o m throw new IllegalArgumentException("Unknown flag: " + flag); } } return flagsToUse; }
From source file:com.github.dactiv.fear.user.service.sso.SimpleOrganizationManager.java
/** * ??//from w w w.j a v a2s . c o m * * @param wildcard ? * @return */ @Override public Organization getByWildcard(String wildcard) { if (StringUtils.isEmpty(wildcard)) { return null; } List<Map<String, Object>> maps = Apis.invoke("accessService", "findOrganizations", new HashMap<>()); for (Map<String, Object> map : maps) { String temp = Casts.cast(map.get("wildcard"), String.class); Pattern pattern = Pattern.compile(temp, Pattern.CASE_INSENSITIVE); if (pattern.matcher(wildcard).matches()) { return createOrganization(map); } } return null; }
From source file:cn.dockerfoundry.ide.eclipse.dockerfile.validator.DockerfileDelegatingValidator.java
@SuppressWarnings("unchecked") public Map<DockerfileValidationLevel, List<DockerfileValidationResult>> validate() { Map<DockerfileValidationLevel, List<DockerfileValidationResult>> result = new HashMap<DockerfileValidationLevel, List<DockerfileValidationResult>>(); if (this.dockerfileInputStream == null) return result; ValidatorUtils validatorUtils = new ValidatorUtils(); boolean fromCheck = false; int currentLine = 0; List<DockerfileValidationResult> errors = new ArrayList<DockerfileValidationResult>(); List<DockerfileValidationResult> warnings = new ArrayList<DockerfileValidationResult>(); List<DockerfileValidationResult> infos = new ArrayList<DockerfileValidationResult>(); Map<String, Object> ruleObject = validatorUtils .getRules(DockerfileDelegatingValidator.class.getResourceAsStream("default.yaml")); List<Map<String, Object>> requiredInstructions = validatorUtils.createReqInstructionHash(ruleObject); Map<String, Object> general = (Map<String, Object>) ruleObject.get("general"); List<String> valid_instructions = (List<String>) general.get("valid_instructions"); Pattern validInstructionsRegex = validatorUtils.createValidCommandRegex(valid_instructions); Pattern continuationRegex = null; // Pattern ignoreRegex = null; Object multiline_regex = general.get("multiline_regex"); if (multiline_regex != null && multiline_regex.toString().length() > 2) { String _multiline_regex = multiline_regex.toString().substring(1, multiline_regex.toString().length() - 1); continuationRegex = Pattern.compile(_multiline_regex, Pattern.CASE_INSENSITIVE); }/*w w w .ja v a 2 s . c o m*/ Object ignore_regex = general.get("ignore_regex"); if (ignore_regex != null && ignore_regex.toString().length() > 2) { String _ignore_regex = ignore_regex.toString().substring(1, ignore_regex.toString().length() - 1); Pattern ignoreRegex = Pattern.compile(_ignore_regex, Pattern.CASE_INSENSITIVE); System.out.println("ignore_regex is not used for now: " + ignoreRegex.pattern()); } try { String dockerfile = IOUtils.toString(dockerfileInputStream); String[] linesArr = dockerfile.split("(\\r|\\n)"); if (linesArr != null && linesArr.length > 0) { for (int i = 0; i < linesArr.length; i++) { currentLine++; String line = linesArr[i]; int lineOffSet = 0; if (line == null || line.length() == 0 || line.charAt(0) == '#') { continue; } while (validatorUtils.isPartialLine(line, continuationRegex)) { line = continuationRegex.matcher(line).replaceAll(" "); if (linesArr[currentLine + lineOffSet].charAt(0) == '#') { linesArr[currentLine + lineOffSet] = null; line = line + "\\"; } else { line = line + linesArr[currentLine + lineOffSet]; linesArr[currentLine + lineOffSet] = null; } lineOffSet++; } // First instruction must be FROM if (!fromCheck) { fromCheck = true; if (line.toUpperCase().indexOf("FROM") != 0) { DockerfileValidationResult error = new DockerfileValidationResult(); error.setLine(currentLine); error.setLevel(DockerfileValidationLevel.ERROR); error.setMessage("Missing or misplaced FROM"); error.setLineContent(line); errors.add(error); } } // end for FROM Matcher matcher = validInstructionsRegex.matcher(line); if (!matcher.find()) { DockerfileValidationResult error = new DockerfileValidationResult(); error.setLine(currentLine); error.setLevel(DockerfileValidationLevel.ERROR); error.setMessage("Invalid instruction"); error.setLineContent(line); errors.add(error); } else { String instruction = line.substring(matcher.start(), matcher.end()).trim(); String params = matcher.replaceAll(""); validatorUtils.checkLineRules(ruleObject, instruction, params, line, currentLine, errors, warnings, infos); requiredInstructions.remove(instruction); } // end for valid instructions checking } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } validatorUtils.checkRequiredInstructions(requiredInstructions, errors, warnings, infos); result.put(DockerfileValidationLevel.ERROR, errors); result.put(DockerfileValidationLevel.WARNING, warnings); result.put(DockerfileValidationLevel.INFO, infos); return result; }
From source file:com.michellemay.profiles.ProfilesFactory.java
private Profile createProfile(ProfileConfig profileConfig) { if (StringUtils.isBlank(profileConfig.name)) { throw new IllegalArgumentException("Blank profile name!"); }/*from www. j a v a2 s. c o m*/ Mapping tempMapping = null; if (profileConfig.mapping != null) { if (StringUtils.isBlank(profileConfig.mapping) || !mappingsFactory.getMappings().containsKey(profileConfig.mapping)) { throw new IllegalStateException("Mapping '" + profileConfig.mapping + "' does not exists!"); } tempMapping = mappingsFactory.getMappings().get(profileConfig.mapping); } Optional<Mapping> defaultMapping = Optional.ofNullable(tempMapping); if (profileConfig.domains == null || profileConfig.domains.isEmpty()) { throw new IllegalArgumentException("Profile must have non-empty domains list!"); } ArrayList<Pattern> domains = Lists.newArrayList(); profileConfig.domains.forEach((patternStr) -> { // Domain names are case insensitive. domains.add(Pattern.compile(patternStr, Pattern.CASE_INSENSITIVE)); }); ArrayList<Matcher> matchers = Lists.newArrayList(); profileConfig.matchers.forEach((matcherRef) -> { String mappingName = matcherRef.mapping; Optional<Mapping> localMapping = Optional.empty(); if (!StringUtils.isBlank(mappingName)) { if (!mappingsFactory.getMappings().containsKey(mappingName)) { throw new IllegalStateException("Mapping '" + mappingName + "' does not exists!"); } localMapping = Optional.of(mappingsFactory.getMappings().get(mappingName)); } String matcherName = matcherRef.matcher; if (StringUtils.isBlank(matcherName) || !matchersFactory.getMatchers().containsKey(matcherName)) { throw new IllegalStateException("Matcher '" + matcherName + "' does not exists!"); } Matcher matcher = matchersFactory.getMatchers().get(matcherName); // Validate that a matcher has a mapping. // Select in order of appearance: localMapping, defaultMapping, matcher.mapping. Optional<Mapping> finalMapping = Stream.of(localMapping, defaultMapping, matcher.getMapping()) .filter(Optional::isPresent).findFirst() .orElseThrow(() -> new IllegalStateException("Matcher '" + matcherName + "' does not have a valid mapping! (Profile '" + profileConfig.name + "')")); matchers.add(matcher.shallowCopyWithMapping(finalMapping)); }); return new Profile(profileConfig.name).withDomains(domains).withMatchers(matchers); }