1 26 package org.htmlparser.filters; 27 28 import java.util.regex.Matcher ; 29 import java.util.regex.Pattern ; 30 31 import org.htmlparser.Node; 32 import org.htmlparser.NodeFilter; 33 import org.htmlparser.tags.LinkTag; 34 35 40 public class LinkRegexFilter implements NodeFilter 41 { 42 45 protected Pattern mRegex; 46 47 53 public LinkRegexFilter (String regexPattern) 54 { 55 this (regexPattern, true); 56 } 57 58 64 public LinkRegexFilter (String regexPattern, boolean caseSensitive) 65 { 66 if (caseSensitive) 67 mRegex = Pattern.compile (regexPattern); 68 else 69 mRegex = Pattern.compile (regexPattern, 70 Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE); 71 } 72 73 79 public boolean accept (Node node) 80 { 81 boolean ret; 82 83 ret = false; 84 if (LinkTag.class.isAssignableFrom (node.getClass ())) 85 { 86 String link = ((LinkTag)node).getLink (); 87 Matcher matcher = mRegex.matcher (link); 88 ret = matcher.find (); 89 } 90 91 return (ret); 92 } 93 } 94 | Popular Tags |