List of usage examples for java.util.regex Pattern pattern
pattern
From source file:org.codehaus.mojo.license.api.DefaultDependenciesTool.java
/** * Tests if the given project is excludable against a groupdId pattern and a artifact pattern. * * @param project the project to test * @param excludedGroupPattern the exlcude group pattern * @param excludedArtifactPattern the exclude artifact pattenr * @return {@code true} if the project is excludable, {@code false} otherwise *//* ww w .j a v a 2 s. c o m*/ protected boolean isExcludable(Artifact project, Pattern excludedGroupPattern, Pattern excludedArtifactPattern) { Logger log = getLogger(); // check if the groupId of the project should be included if (excludedGroupPattern != null) { // we have some defined license filters try { Matcher matchGroupId = excludedGroupPattern.matcher(project.getGroupId()); if (matchGroupId.find()) { if (log.isDebugEnabled()) { log.debug("Exclude " + project.getGroupId()); } return true; } } catch (PatternSyntaxException e) { log.warn(String.format(INVALID_PATTERN_MESSAGE, excludedGroupPattern.pattern())); } } // check if the artifactId of the project should be included if (excludedArtifactPattern != null) { // we have some defined license filters try { Matcher matchGroupId = excludedArtifactPattern.matcher(project.getArtifactId()); if (matchGroupId.find()) { if (log.isDebugEnabled()) { log.debug("Exclude " + project.getArtifactId()); } return true; } } catch (PatternSyntaxException e) { log.warn(String.format(INVALID_PATTERN_MESSAGE, excludedArtifactPattern.pattern())); } } return false; }
From source file:net.timbusproject.extractors.debiansoftwareextractor.CLI.java
public void process() throws InterruptedException, JSchException, JSONException, IOException, ParseException { Pattern remotePattern = Pattern .compile("(\\w[\\w\\-\\.]+\\$?){1,32}@([\\p{Alnum}\\.]+)(?::(22$|[0-9]{4,5}))?"); Level logLevel = cmd.hasOption("debug") ? Level.DEBUG : cmd.hasOption("quiet") ? Level.WARN : Level.INFO; ((ch.qos.logback.classic.Logger) log).setLevel(logLevel); if (cmd.hasOption("universe") && cmd.hasOption('p')) log.warn("Formatted output disabled on universe extraction."); Engine.Scope scope = cmd.hasOption("universe") ? Engine.Scope.UNIVERSE : Engine.Scope.INSTALLED_PACKAGES; if (cmd.hasOption('l')) { printResult(finalizeResult(new Engine(logLevel).run(scope))); } else if (cmd.hasOption('r')) { boolean nl = false; for (String remote : cmd.getOptionValues('r')) { if (nl) log.info(""); if (!remote.matches(remotePattern.pattern())) { log.warn("Invalid remote (skipping): " + remote); nl = true;/*from ww w .jav a 2 s .co m*/ continue; } Matcher matcher = remotePattern.matcher(remote); matcher.find(); SSHManager sshManager; if (matcher.group(3) != null) sshManager = new SSHManager(matcher.group(1), matcher.group(2), Integer.parseInt(matcher.group(3))); else sshManager = new SSHManager(matcher.group(1), matcher.group(2)); getLoggerStdOut().write(("Enter password for " + matcher.group(1) + "@" + matcher.group(2) + (matcher.group(3) != null ? ":" + matcher.group(3) : "") + ": ").getBytes()); sshManager.setPassword(new String(System.console().readPassword())); printResult(finalizeResult(new Engine(sshManager, logLevel).run(scope)), cmd.getOptionValues('r').length > 1 ? matcher.group(2) + (matcher.group(3) != null ? '-' + matcher.group(3) : "") : ""); nl = true; } } }
From source file:org.kuali.rice.kns.kim.type.DataDictionaryTypeServiceBase.java
protected List<RemotableAttributeError> validateAttributeFormat(String kimTypeId, String objectClassName, String attributeName, String attributeValue, String errorKey) { List<RemotableAttributeError> errors = new ArrayList<RemotableAttributeError>(); List<KimAttributeField> attributeDefinitions = getAttributeDefinitions(kimTypeId); KimAttributeField definition = DataDictionaryTypeServiceHelper.findAttributeField(attributeName, attributeDefinitions);//from w w w . j a va2 s. c o m String errorLabel = DataDictionaryTypeServiceHelper.getAttributeErrorLabel(definition); if (LOG.isDebugEnabled()) { LOG.debug("(bo, attributeName, attributeValue) = (" + objectClassName + "," + attributeName + "," + attributeValue + ")"); } if (StringUtils.isNotBlank(attributeValue)) { Integer maxLength = definition.getAttributeField().getMaxLength(); if ((maxLength != null) && (maxLength.intValue() < attributeValue.length())) { errors.add( RemotableAttributeError.Builder .create(errorKey, DataDictionaryTypeServiceHelper.createErrorString( RiceKeyConstants.ERROR_MAX_LENGTH, errorLabel, maxLength.toString())) .build()); return errors; } Pattern validationExpression = getAttributeValidatingExpression(definition); if (!ANY_CHAR_PATTERN_S.equals(validationExpression.pattern())) { if (LOG.isDebugEnabled()) { LOG.debug("(bo, attributeName, validationExpression) = (" + objectClassName + "," + attributeName + "," + validationExpression + ")"); } if (!validationExpression.matcher(attributeValue).matches()) { boolean isError = true; final Formatter formatter = getAttributeFormatter(definition); if (formatter != null) { Object o = formatter.format(attributeValue); isError = !validationExpression.matcher(String.valueOf(o)).matches(); } if (isError) { errors.add(RemotableAttributeError.Builder .create(errorKey, DataDictionaryTypeServiceHelper.createErrorString(definition)) .build()); } return errors; } } Double min = getAttributeMinValue(definition); if (min != null) { try { if (Double.parseDouble(attributeValue) < min) { errors.add(RemotableAttributeError.Builder .create(errorKey, DataDictionaryTypeServiceHelper.createErrorString( RiceKeyConstants.ERROR_INCLUSIVE_MIN, errorLabel, min.toString())) .build()); return errors; } } catch (NumberFormatException e) { // quash; this indicates that the DD contained a min for a non-numeric attribute } } Double max = getAttributeMaxValue(definition); if (max != null) { try { if (Double.parseDouble(attributeValue) > max) { errors.add(RemotableAttributeError.Builder .create(errorKey, DataDictionaryTypeServiceHelper.createErrorString( RiceKeyConstants.ERROR_INCLUSIVE_MAX, errorLabel, max.toString())) .build()); return errors; } } catch (NumberFormatException e) { // quash; this indicates that the DD contained a max for a non-numeric attribute } } } return errors; }
From source file:org.stanwood.media.setup.ConfigReader.java
private void writeMediaDirs(StringBuilder document, IProgressMonitor progress) throws XMLParserException { for (MediaDirConfig dir : mediaDir) { document.append(" <mediaDirectory"); //$NON-NLS-1$ document.append(" directory=\"" + dir.getMediaDir().getAbsolutePath() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ document.append(" mode=\"" + dir.getMode() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ if (dir.isDefaultForMode()) { document.append(" default=\"true\""); //$NON-NLS-1$ }// ww w . ja va 2 s. c o m document.append(" pattern=\"" + dir.getPattern() + "\""); //$NON-NLS-1$ //$NON-NLS-2$ document.append(" ignoreSeen=\"" + dir.getIgnoreSeen() + "\">" + FileHelper.LS); //$NON-NLS-1$ //$NON-NLS-2$ if (dir.getIgnorePatterns() != null) { for (Pattern p : dir.getIgnorePatterns()) { document.append(" <ignore>" + p.pattern() + "</ignore>" + FileHelper.LS); //$NON-NLS-1$ //$NON-NLS-2$ } } if (dir.getStripTokens() != null) { if (dir.getStripTokens() != DEFAULT_STRIP_TOKENS) { for (Pattern p : dir.getStripTokens()) { document.append("<strip>" + p.pattern() + "</strip>" + FileHelper.LS); //$NON-NLS-1$//$NON-NLS-2$ } } } if (dir.getExtensions().size() > 0 && !Arrays.equals(dir.getExtensions().toArray(new String[0]), DEFAULT_EXTS)) { document.append(" <extensions>" + FileHelper.LS); //$NON-NLS-1$ for (String ext : dir.getExtensions()) { document.append(" <extension>" + ext + "</extension>" + FileHelper.LS); //$NON-NLS-1$//$NON-NLS-2$ } document.append(" </extensions>" + FileHelper.LS); //$NON-NLS-1$ } if (dir.getSources().size() > 0) { document.append(" <sources>" + FileHelper.LS); //$NON-NLS-1$ for (SourceConfig source : dir.getSources()) { document.append(" <source"); //$NON-NLS-1$ witeBaseMediaDirSubItem(document, source); document.append(" </source>"); //$NON-NLS-1$ } document.append(" </sources>" + FileHelper.LS); //$NON-NLS-1$ } if (dir.getStores().size() > 0) { document.append(" <stores>" + FileHelper.LS); //$NON-NLS-1$ for (StoreConfig store : dir.getStores()) { document.append(" <store"); //$NON-NLS-1$ witeBaseMediaDirSubItem(document, store); document.append(" </store>"); //$NON-NLS-1$ } document.append(" </stores>" + FileHelper.LS); //$NON-NLS-1$ } if (dir.getActions().size() > 0) { document.append(" <actions>" + FileHelper.LS); //$NON-NLS-1$ for (ActionConfig action : dir.getActions()) { document.append(" <action"); //$NON-NLS-1$ witeBaseMediaDirSubItem(document, action); document.append(" </action>"); //$NON-NLS-1$ } document.append(" </actions>" + FileHelper.LS); //$NON-NLS-1$ } document.append(" </mediaDirectory>" + FileHelper.LS); //$NON-NLS-1$ progress.worked(1); } }
From source file:guru.qas.martini.jmeter.sampler.MartiniSampler.java
protected SampleResult getSubResult(Step step, Method method, Pattern pattern) { String label = getLabel(step); SampleResult result = new SampleResult(); result.setSuccessful(true);// w w w . j a v a 2s . c o m result.sampleStart(); SamplerContext samplerContext = new SamplerContext(super.getThreadContext()); try { ApplicationContext applicationContext = this.getApplicationContext(); Parameter[] parameters = method.getParameters(); Object[] arguments = new Object[parameters.length]; if (parameters.length > 0) { String text = step.getText(); Matcher matcher = pattern.matcher(text); checkState(matcher.find(), "unable to locate substitution parameters for pattern %s with input %s", pattern.pattern(), text); ConversionService conversionService = applicationContext.getBean(ConversionService.class); int groupCount = matcher.groupCount(); for (int i = 0; i < groupCount; i++) { String parameterAsString = matcher.group(i + 1); Parameter parameter = parameters[i]; Class<?> parameterType = parameter.getType(); Object converted = conversionService.convert(parameterAsString, parameterType); arguments[i] = converted; } } samplerContext.setStatus(Status.PASSED); Class<?> declaringClass = method.getDeclaringClass(); Object bean = applicationContext.getBean(declaringClass); Object returnValue = method.invoke(bean, arguments); if (HttpEntity.class.isInstance(returnValue)) { HttpEntity entity = HttpEntity.class.cast(returnValue); samplerContext.setHttpEntities(Collections.singleton(entity)); } } catch (Exception e) { samplerContext.setStatus(Status.FAILED); samplerContext.setException(e); result.setSuccessful(false); label = "FAIL: " + label; } finally { result.sampleEnd(); result.setSampleLabel(label); } return result; }
From source file:com.sinosoft.one.mvc.web.impl.thread.ActionEngine.java
/** * ???{@link ParamExistenceChecker}//from w w w . j a v a2 s . c o m * * @return */ private ParamExistenceChecker[] compileParamExistenceChecker() { IfParamExists ifParamExists = method.getAnnotation(IfParamExists.class); //IfParamExistsIfParamExists("")? if (ifParamExists == null || ifParamExists.value().trim().length() == 0) { return new ParamExistenceChecker[] {}; } List<ParamExistenceChecker> checkers = new ArrayList<ParamExistenceChecker>(); //? String value = ifParamExists.value(); //???: type&subtype=value&anothername=value2 String[] terms = StringUtils.split(value, "&"); Assert.isTrue(terms.length >= 1); //? //'&'??term? for (final String term : terms) { final int index = term.indexOf('='); //'=' if (index == -1) { //=????term??? checkers.add(new ParamExistenceChecker() { final String paramName = term.trim(); public int check(Map<String, String[]> params) { String[] paramValues = params.get(paramName); if (logger.isDebugEnabled()) { logger.debug(this.toString() + " is checking param:" + paramName + "=" + Arrays.toString(paramValues)); } //????ok if (paramValues != null && paramValues.length > 0) { return 10; } else { return -1; } } }); } else { //term'=' final String paramName = term.substring(0, index).trim(); //??? final String expected = term.substring(index + 1).trim(); //? if (expected.startsWith(":")) { //expected? Pattern tmpPattern = null; try { tmpPattern = Pattern.compile(expected.substring(1)); } catch (PatternSyntaxException e) { logger.error("@IfParamExists pattern error, " + controllerClass.getName() + "#" + method.getName(), e); } final Pattern pattern = tmpPattern; //?final checkers.add(new ParamExistenceChecker() { public int check(Map<String, String[]> params) { String[] paramValues = params.get(paramName); if (logger.isDebugEnabled()) { logger.debug(this.toString() + " is checking param:" + paramName + "=" + Arrays.toString(paramValues) + ", pattern=" + pattern.pattern()); } if (paramValues == null) { //??? return -1; } for (String paramValue : paramValues) { if (pattern != null && pattern.matcher(paramValue).matches()) { return 12; } } return -1; } }); } else { //expected?"" checkers.add(new ParamExistenceChecker() { public int check(Map<String, String[]> params) { String[] paramValues = params.get(paramName); if (logger.isDebugEnabled()) { logger.debug(this.toString() + " is checking param:" + paramName + "=" + Arrays.toString(paramValues) + ", expected=" + expected); } if (paramValues == null) { //??? return -1; } for (String paramValue : paramValues) { if (expected.equals(paramValue)) { return 13;// 13?12 } } return -1; } }); } } } return checkers.toArray(new ParamExistenceChecker[] {}); }
From source file:de.saly.elasticsearch.mailsource.ParallelPollingIMAPMailSource.java
protected void recurseFolders(final Folder folder, final Pattern pattern) throws MessagingException, IOException { if (folder != null) { if (es == null || es.isShutdown() || es.isTerminated() || Thread.currentThread().isInterrupted()) { logger.warn("Stop processing of mails due to mail source is closed"); return; }//from ww w. j a v a2s. co m if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) { if (pattern != null && !pattern.matcher(folder.getFullName()).matches()) { logger.info("Pattern {} does not match {}", pattern.pattern(), folder.getFullName()); return; } IMAPUtils.open(folder); try { fetch(folder); } finally { IMAPUtils.close(folder); logger.debug("fetch {} done", folder.getFullName()); } } if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) { for (final Folder subfolder : folder.list()) { recurseFolders(subfolder, pattern); } } } }
From source file:com.laxser.blitz.web.impl.thread.ActionEngine.java
/** * ???{@link ParamExistenceChecker}//from www . j a v a 2 s. c om * * @return */ private ParamExistenceChecker[] compileParamExistenceChecker() { IfParamExists ifParamExists = method.getAnnotation(IfParamExists.class); //IfParamExistsIfParamExists("")? if (ifParamExists == null || ifParamExists.value().trim().length() == 0) { return new ParamExistenceChecker[] {}; } List<ParamExistenceChecker> checkers = new ArrayList<ParamExistenceChecker>(); //? String value = ifParamExists.value(); //???: type&subtype=value&anothername=value2 String[] terms = StringUtils.split(value, "&"); Assert.isTrue(terms.length >= 1); //? //'&'??term? for (final String term : terms) { final int index = term.indexOf('='); //'=' if (index == -1) { //=????term??? checkers.add(new ParamExistenceChecker() { final String paramName = term.trim(); @Override public int check(Map<String, String[]> params) { String[] paramValues = params.get(paramName); if (logger.isDebugEnabled()) { logger.debug(this.toString() + " is checking param:" + paramName + "=" + Arrays.toString(paramValues)); } //????ok if (paramValues != null && paramValues.length > 0) { return 10; } else { return -1; } } }); } else { //term'=' final String paramName = term.substring(0, index).trim(); //??? final String expected = term.substring(index + 1).trim(); //? if (expected.startsWith(":")) { //expected? Pattern tmpPattern = null; try { tmpPattern = Pattern.compile(expected.substring(1)); } catch (PatternSyntaxException e) { logger.error("@IfParamExists pattern error, " + controllerClass.getName() + "#" + method.getName(), e); } final Pattern pattern = tmpPattern; //?final checkers.add(new ParamExistenceChecker() { @Override public int check(Map<String, String[]> params) { String[] paramValues = params.get(paramName); if (logger.isDebugEnabled()) { logger.debug(this.toString() + " is checking param:" + paramName + "=" + Arrays.toString(paramValues) + ", pattern=" + pattern.pattern()); } if (paramValues == null) { //??? return -1; } for (String paramValue : paramValues) { if (pattern != null && pattern.matcher(paramValue).matches()) { return 12; } } return -1; } }); } else { //expected?"" checkers.add(new ParamExistenceChecker() { @Override public int check(Map<String, String[]> params) { String[] paramValues = params.get(paramName); if (logger.isDebugEnabled()) { logger.debug(this.toString() + " is checking param:" + paramName + "=" + Arrays.toString(paramValues) + ", expected=" + expected); } if (paramValues == null) { //??? return -1; } for (String paramValue : paramValues) { if (expected.equals(paramValue)) { return 13;// 13?12 } } return -1; } }); } } } return checkers.toArray(new ParamExistenceChecker[] {}); }
From source file:de.saly.elasticsearch.importer.imap.mailsource.ParallelPollingIMAPMailSource.java
protected void recurseFolders(final Folder folder, final Pattern pattern) throws MessagingException, IOException { if (folder != null) { if (es == null || es.isShutdown() || es.isTerminated() || Thread.currentThread().isInterrupted()) { logger.warn("Stop processing of mails due to mail source is closed"); return; }//from w w w . j av a 2 s .c o m if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) { if (pattern != null && !pattern.matcher(folder.getFullName()).matches()) { logger.debug("Pattern {} does not match {}", pattern.pattern(), folder.getFullName()); return; } IMAPUtils.open(folder); try { fetch(folder); } finally { IMAPUtils.close(folder); logger.debug("fetch {} done", folder.getFullName()); } } if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) { for (final Folder subfolder : folder.list()) { recurseFolders(subfolder, pattern); } } } }
From source file:com.google.enterprise.connector.sharepoint.spiimpl.SPDocument.java
public boolean matches(String metadataName, List<Pattern> excludedMetadataPatterns) { boolean flag = false; for (Pattern pattern : excludedMetadataPatterns) { if (metadataName.matches(pattern.pattern())) { flag = true;//from www . j a v a 2 s . co m break; } } return flag; }