001/*
002 * #%L
003 * Netarchivesuite - common
004 * %%
005 * Copyright (C) 2005 - 2014 The Royal Danish Library, the Danish State and University Library,
006 *             the National Library of France and the Austrian National Library.
007 * %%
008 * This program is free software: you can redistribute it and/or modify
009 * it under the terms of the GNU Lesser General Public License as
010 * published by the Free Software Foundation, either version 2.1 of the
011 * License, or (at your option) any later version.
012 * 
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Lesser Public License for more details.
017 * 
018 * You should have received a copy of the GNU General Lesser Public
019 * License along with this program.  If not, see
020 * <http://www.gnu.org/licenses/lgpl-2.1.html>.
021 * #L%
022 */
023
024package dk.netarkivet.common.utils.archive;
025
026import java.io.FilenameFilter;
027import java.util.regex.Pattern;
028
029import dk.netarkivet.common.Constants;
030import dk.netarkivet.common.utils.FileUtils;
031
032/**
033 * Assemble the constants related to an archive format into profiles. Currently only an ARC and WARC profile.
034 */
035public class ArchiveProfile {
036
037    /** Archive filename filter. */
038    public final FilenameFilter filename_filter;
039
040    /** Archive filename string pattern. */
041    public final String filename_pattern;
042
043    /** Archive metadata filename regex pattern. */
044    public final Pattern metadataFilenamePattern;
045
046    /** Archive directory. */
047    public final String archive_directory;
048
049    /**
050     * Construct an archive profile.
051     *
052     * @param filename_filter archive filename filter
053     * @param filename_pattern archive filename string pattern
054     * @param metadataFilenamePattern archive metadata filename regex pattern
055     * @param archive_directory archive directory
056     */
057    protected ArchiveProfile(FilenameFilter filename_filter, String filename_pattern, Pattern metadataFilenamePattern,
058            String archive_directory) {
059        this.filename_filter = filename_filter;
060        this.filename_pattern = filename_pattern;
061        this.metadataFilenamePattern = metadataFilenamePattern;
062        this.archive_directory = archive_directory;
063    }
064
065    /** ARC archive profile. */
066    public static final ArchiveProfile ARC_PROFILE = new ArchiveProfile(FileUtils.ARCS_FILTER, FileUtils.ARC_PATTERN,
067            Pattern.compile("([0-9]+)-metadata-([0-9]+).arc"), Constants.ARCDIRECTORY_NAME);
068
069    /** WARC archive profile. */
070    public static final ArchiveProfile WARC_PROFILE = new ArchiveProfile(FileUtils.WARCS_FILTER,
071            FileUtils.WARC_PATTERN, Pattern.compile("([0-9]+)-metadata-([0-9]+).warc"), Constants.WARCDIRECTORY_NAME);
072
073}