001    package hirondelle.web4j.security;
002    
003    import java.util.regex.*;
004    import hirondelle.web4j.util.Util;
005    
006    /**
007     Fails all text containing links, except those appearing in 
008     <a href='../ui/translate/Text.html#WikiStyleFormatting'>wiki-style formatting</a>.
009     
010     <P>Almost all spam contains links. This implementation will reject all text that contains 
011     '<tt>http://</tt>', <em>except</em> if the text contains any wiki-style links in the form 
012     <tt>[link:http://www.google.ca Google]</tt>. 
013    */
014    public class SpamDetectorImpl implements SpamDetector {
015    
016      /** See class comment. */
017      public boolean isSpam(String aText) {
018        boolean result = false;
019        if( Util.contains(WIKI_LINK_PATTERN, aText)){
020          //OK
021        }
022        else {
023          if ( Util.contains(STANDARD_LINK_PATTERN, aText)) {
024            result = true;
025          }
026        }
027        return result;
028      }
029      
030      // PRIVATE //
031      private static final Pattern WIKI_LINK_PATTERN = Pattern.compile("\\[link:http://");
032      private static final Pattern STANDARD_LINK_PATTERN = Pattern.compile("http://");
033    }