Exemplo n.º 1
0
  /**
   * Valide tout les site web de caroline et liste les erreurs s'il y en a.
   *
   * @return La liste des erreur qui rendent le site instable. Retourne une liste vide si le site
   *     est correct.
   * @throws IOException
   * @throws FtpManagerException
   */
  public List<ValidationError> validate() throws IOException, FtpManagerException {
    List<ValidationError> errors = new ArrayList<ValidationError>();

    // Construit le dossier qui servira à récupérer les fichiers pour la validation.
    LOGGER.info(workingFolder.getAbsolutePath());
    FileUtils.deleteDirectory(workingFolder);
    workingFolder.mkdir();

    // Lecture du fichier gallery.hyml
    File galleryHtmlFile = ftpManager.getCopyGalleryHtmlFile();
    String blocs = extractAlbumsBloc(galleryHtmlFile);

    // Validation du fichier gallery.html et récupération des noms de fichiers.
    Pattern albumBlocPattern = Pattern.compile("grid_4(.*?)</div></div></div>");
    Matcher albumMBlocMatcher = albumBlocPattern.matcher(blocs.replace(" ", ""));
    Set<String> phpFileNames = new TreeSet<>();
    Set<String> jpgFileNames = new TreeSet<>();
    while (albumMBlocMatcher.find()) {
      validateBlocAndExtract(albumMBlocMatcher.group(), phpFileNames, jpgFileNames, errors);
    }

    checkGalleryPictures(errors, jpgFileNames);
    checkPhpFiles(errors, phpFileNames);

    // Valide les album photos.
    Set<String> albumToTest = checkAlbumExistance(errors, phpFileNames, jpgFileNames);
    for (String album : albumToTest) {
      checkAlbumContent(errors, album);
    }

    return errors;
  }