1. /*
  2.  * This file is part of DrFTPD, Distributed FTP Daemon.
  3.  *
  4.  * DrFTPD is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * DrFTPD is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with DrFTPD; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  17.  */
  18.  
  19. package org.drftpd.slave.diskselection;
  20.  
  21. import java.util.ArrayList;
  22. import java.util.Properties;
  23.  
  24. import org.apache.oro.text.GlobCompiler;
  25. import org.apache.oro.text.regex.Pattern;
  26. import org.apache.oro.text.regex.Perl5Matcher;
  27. import org.drftpd.PropertyHelper;
  28.  
  29. /**
  30.  * Sample configuration.
  31.  * <pre>
  32.  * X.filter=matchdir
  33.  * X.assign=<rootNumber>+100000
  34.  * X.match=<path glob match>
  35.  * </pre>
  36.  * @author fr0w
  37.  **/
  38. public class MatchdirFilter extends DiskFilter {
  39.        
  40.         private Pattern _p;
  41.         private Perl5Matcher _m = new Perl5Matcher();
  42.         private ArrayList _assignList;
  43.         private String _pattern;
  44.        
  45.         public MatchdirFilter(Properties p, Integer i) {
  46.                 super(p, i);
  47.                 _assignList = AssignRoot.parseAssign(PropertyHelper.getProperty(p, i + ".assign"));
  48.                 _pattern = PropertyHelper.getProperty(p, i + ".match");
  49.                
  50.                 try {
  51.                         _p = new GlobCompiler().compile(_pattern, GlobCompiler.CASE_INSENSITIVE_MASK);
  52.                 } catch (Exception e) {
  53.                         throw new RuntimeException(e);
  54.                 }
  55.         }
  56.        
  57.         public void process(ScoreChart sc, String path) {
  58.                 if (_m.matches(path, _p)) {
  59.                         AssignRoot.addScoresToChart(_assignList, sc);
  60.                 }
  61.         }      
  62. }
  63.  

Posted by Anonymous at 26 Feb 2014, 01:14:52 Europe/Berlin
Language: text