Coverage Report - org.jtheque.films.services.impl.utils.web.analyzers.GenericFilmResultAnalyzer
 
Classes in this File Line Coverage Branch Coverage Complexity
GenericFilmResultAnalyzer
0 %
0/23
0 %
0/8
2.333
 
 1  
 package org.jtheque.films.services.impl.utils.web.analyzers;
 2  
 
 3  
 import org.jtheque.core.managers.Managers;
 4  
 import org.jtheque.core.managers.beans.IBeansManager;
 5  
 import org.jtheque.films.services.impl.utils.web.FilmResult;
 6  
 import org.jtheque.films.utils.Constants.Site;
 7  
 import org.jtheque.primary.utils.web.analyzers.generic.GenericGenerator;
 8  
 import org.jtheque.primary.utils.web.analyzers.generic.field.FieldGetter;
 9  
 import org.jtheque.primary.utils.web.analyzers.generic.operation.ScannerPossessor;
 10  
 import org.jtheque.utils.StringUtils;
 11  
 
 12  
 import java.util.Scanner;
 13  
 import java.util.regex.Pattern;
 14  
 
 15  
 /*
 16  
  * This file is part of JTheque.
 17  
  *
 18  
  * JTheque is free software: you can redistribute it and/or modify
 19  
  * it under the terms of the GNU General Public License as published by
 20  
  * the Free Software Foundation, either version 3 of the License.
 21  
  *
 22  
  * JTheque is distributed in the hope that it will be useful,
 23  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 24  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 25  
  * GNU General Public License for more details.
 26  
  *
 27  
  * You should have received a copy of the GNU General Public License
 28  
  * along with JTheque.  If not, see <http://www.gnu.org/licenses/>.
 29  
  */
 30  
 
 31  
 /**
 32  
  * A generic film result analyzer. It seems an objet who read web pages to find the result of a film search.
 33  
  *
 34  
  * @author Baptitste Wicht
 35  
  */
 36  
 public final class GenericFilmResultAnalyzer extends AbstractFilmResultAnalyzer implements ScannerPossessor {
 37  
     private final Site site;
 38  
 
 39  
     private final FieldGetter filmsGetter;
 40  
 
 41  0
     private static final Pattern RESULT_SEPARATOR_PATTERN = Pattern.compile("%%%");
 42  0
     private static final Pattern FIELD_SEPARATOR_PATTERN = Pattern.compile("---");
 43  
 
 44  
     /**
 45  
      * Construct a new GenericFilmResultAnalyzer.
 46  
      *
 47  
      * @param generator The generic generator to use.
 48  
      * @param site      The site.
 49  
      */
 50  
     public GenericFilmResultAnalyzer(GenericGenerator generator, Site site) {
 51  0
         super();
 52  
 
 53  0
         filmsGetter = generator.getFieldGetter("films");
 54  
 
 55  0
         Managers.getManager(IBeansManager.class).inject(this);
 56  
 
 57  0
         this.site = site;
 58  0
     }
 59  
 
 60  
     @Override
 61  
     public Scanner getScanner() {
 62  0
         return null;
 63  
     }
 64  
 
 65  
     @Override
 66  
     public void findFilms(String line) {
 67  0
         if (filmsGetter.mustGet(line)) {
 68  0
             String transformedLine = filmsGetter.performOperations(line, this);
 69  
 
 70  0
             String value = filmsGetter.getValue(transformedLine);
 71  
 
 72  0
             if (!StringUtils.isEmpty(value)) {
 73  0
                 String[] results = RESULT_SEPARATOR_PATTERN.split(value);
 74  
 
 75  0
                 for (String r : results) {
 76  0
                     if (!StringUtils.isEmpty(r)) {
 77  0
                         String[] parts = FIELD_SEPARATOR_PATTERN.split(r);
 78  
 
 79  0
                         FilmResult result = new FilmResult();
 80  0
                         result.setSite(site);
 81  0
                         result.setIndex(parts[0]);
 82  0
                         result.setTitre(parts[1]);
 83  
 
 84  0
                         getResults().add(result);
 85  
                     }
 86  
                 }
 87  
 
 88  0
                 setComplete(true);
 89  
             }
 90  
         }
 91  0
     }
 92  
 }