public Recurser(Connection connection) { super(connection); this.globCompiler = new GlobCompiler(); this.matcher = new Perl5Matcher(); }
public void setUrlPattern(String urlPattern) { this.urlPattern = urlPattern; this.pattern = null; try { PatternCompiler compiler = new GlobCompiler(); this.pattern = compiler.compile(this.urlPattern); } catch (Exception e) { log.error("Invalid url pattern: " + this.urlPattern); } }
String globString; String styleString; GlobCompiler glob = new GlobCompiler(); Pattern globPattern;
/** * Default constructor with the matcher pattern. * * @param pattern the file name regex pattern to use. * @throws FileManipulatorException if the regex pattern is malformed. */ public FileNameRegexSelector( String pattern ) throws FileManipulatorException { LOGGER.debug( "Creating the glob regex" ); PatternCompiler compiler = new GlobCompiler(); try { this.pattern = compiler.compile( pattern ); this.matcher = new Perl5Matcher(); } catch ( MalformedPatternException malformedPatternException ) { LOGGER.error( "Invalid regex pattern " + pattern, malformedPatternException ); throw new FileManipulatorException( "Invalid regex pattern " + pattern, malformedPatternException ); } }
public NameSelector(final String name, final boolean ignoreCase) throws MalformedPatternException { assert name != null; PatternCompiler compiler = new GlobCompiler(); int options; if (ignoreCase) { options = GlobCompiler.CASE_INSENSITIVE_MASK; } else { options = GlobCompiler.DEFAULT_MASK; } this.pattern = compiler.compile(name, options); this.matcher = new Perl5Matcher(); log.trace("Pattern: {}", pattern.getPattern()); }
public GlobMatcher(String expression) throws PatternSyntaxException { this.expression = expression; try { pattern = new GlobCompiler().compile(expression); } catch (MalformedPatternException e) { throw new PatternSyntaxException(e.getMessage(), expression, 0); } }
public NameSelector(final String name, final boolean ignoreCase) throws MalformedPatternException { assert name != null; PatternCompiler compiler = new GlobCompiler(); int options; if (ignoreCase) { options = GlobCompiler.CASE_INSENSITIVE_MASK; } else { options = GlobCompiler.DEFAULT_MASK; } this.pattern = compiler.compile(name, options); this.matcher = new Perl5Matcher(); log.trace("Pattern: {}", pattern.getPattern()); }
@SuppressWarnings( "unchecked" ) protected final void initInlineImagePatterns() { PatternCompiler compiler = new GlobCompiler(); // // We cache compiled patterns in the engine, since their creation is really expensive // List< Pattern > compiledpatterns = ( List< Pattern > )m_engine.getAttribute( INLINE_IMAGE_PATTERNS ); if( compiledpatterns == null ) { compiledpatterns = new ArrayList< >( 20 ); Collection< String > ptrns = m_engine.getAllInlinedImagePatterns(); // // Make them into Regexp Patterns. Unknown patterns are ignored. // for( Iterator< String > i = ptrns.iterator(); i.hasNext(); ) { String pattern = i.next(); try { compiledpatterns.add( compiler.compile( pattern, GlobCompiler.DEFAULT_MASK | GlobCompiler.READ_ONLY_MASK ) ); } catch( MalformedPatternException e ) { log.error( "Malformed pattern [" + pattern + "] in properties: ", e ); } } m_engine.setAttribute( INLINE_IMAGE_PATTERNS, compiledpatterns ); } m_inlineImagePatterns = Collections.unmodifiableList( compiledpatterns ); }
/** * Compile regexp parameter. * * @param name The name of the parameter. * @param value The parameter value. * @return Pattern[] The compiled patterns, or <code>null</code>. * @throws PluginException On malformed patterns. */ private Pattern[] compileGlobs( String name, String value ) throws PluginException { Pattern[] result = null; if( value != null && 0 < value.length() && !STR_GLOBSTAR.equals( value ) ) { try { PatternCompiler pc = new GlobCompiler(); String[] ptrns = StringUtils.split( value, STR_COMMA ); result = new Pattern[ptrns.length]; for( int n = 0; n < ptrns.length; n++ ) { result[n] = pc.compile( ptrns[n] ); } } catch( MalformedPatternException e ) { throw new PluginException( "Parameter " + name + " has a malformed pattern: " + e.getMessage() ); } } return result; }
GlobCompiler gc = new GlobCompiler(); try { Perl5Pattern pattern = (Perl5Pattern) gc.compile("[JKL][DEF][DEF]"); Perl5Matcher matcher = new Perl5Matcher(); String straw = "JEEVES"; if (matcher.matchesPrefix(straw, pattern)) { MatchResult res = matcher.getMatch(); for (int i = 0; i < res.groups(); i++) { String s = straw.substring(res.beginOffset(i), res.endOffset(i)); // 's' now contains a the match of group #i } } else { // No match } } catch (MalformedPatternException e) { // Oh noes }
PatternCompiler pc = new GlobCompiler(); PatternCompiler pc = new GlobCompiler();