001/**
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 *
006 */
007package org.fcrepo.migration.foxml;
008
009import java.io.File;
010import java.io.FileFilter;
011import java.util.Iterator;
012import java.util.regex.Pattern;
013
014import org.apache.commons.io.filefilter.RegexFileFilter;
015import org.fcrepo.migration.FedoraObjectProcessor;
016import org.fcrepo.migration.ObjectSource;
017
018/**
019 * An ObjectSource implementation that exposes FOXML from a provided directory.
020 * The FOXML is expected to have been produced using the export API method with
021 * the "archive" context.  As such, each file will be a completely self-contained
022 * serialization of the Fedora 3 object.
023 * @author mdurbin
024 */
025public class ArchiveExportedFoxmlDirectoryObjectSource implements ObjectSource {
026
027    private File root;
028
029    private URLFetcher fetcher;
030
031    private String localFedoraServer;
032
033    /**
034     * Defaults to match any filename that doesn't begin with a "." character.
035     */
036    private FileFilter fileFilter = new RegexFileFilter(Pattern.compile("^[^\\.].*$"));
037
038    /**
039     * archive exported foxml directory object source.
040     * @param exportDir the export directory
041     * @param localFedoraServer the domain and port for the server that hosted the fedora objects in the format
042     *                          "localhost:8080".
043     */
044    public ArchiveExportedFoxmlDirectoryObjectSource(final File exportDir, final String localFedoraServer) {
045        this.root = exportDir;
046        this.fetcher = new HttpClientURLFetcher();
047        this.localFedoraServer = localFedoraServer;
048    }
049
050    /**
051     * set the fetcher.
052     * @param fetcher the fetcher
053     */
054    public void setFetcher(final URLFetcher fetcher) {
055        this.fetcher = fetcher;
056    }
057
058    /**
059     * Sets a FileFilter to determine which files will be considered as object
060     * files in the source directories.
061     * @param fileFilter a FileFilter implementation
062     */
063    public void setFileFilter(final FileFilter fileFilter) {
064        this.fileFilter = fileFilter;
065    }
066
067    @Override
068    public Iterator<FedoraObjectProcessor> iterator() {
069        return new FoxmlDirectoryDFSIterator(root, fetcher, localFedoraServer, fileFilter);
070    }
071}