001/* 002 * Copyright 2015 DuraSpace, Inc. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.fcrepo.migration.foxml; 017 018import java.io.File; 019import java.io.FileFilter; 020import java.util.Iterator; 021import java.util.regex.Pattern; 022 023import org.apache.commons.io.filefilter.RegexFileFilter; 024import org.fcrepo.migration.FedoraObjectProcessor; 025import org.fcrepo.migration.ObjectSource; 026 027/** 028 * An ObjectSource implementation that exposes FOXML from a provided directory. 029 * The FOXML is expected to have been produced using the export API method with 030 * the "archive" context. As such, each file will be a completely self-contained 031 * serialization of the Fedora 3 object. 032 * @author mdurbin 033 */ 034public class ArchiveExportedFoxmlDirectoryObjectSource implements ObjectSource { 035 036 private File root; 037 038 private URLFetcher fetcher; 039 040 private String localFedoraServer; 041 042 /** 043 * Defaults to match any filename that doesn't begin with a "." character. 044 */ 045 private FileFilter fileFilter = new RegexFileFilter(Pattern.compile("^[^\\.].*$")); 046 047 /** 048 * archive exported foxml directory object source. 049 * @param exportDir the export directory 050 * @param localFedoraServer the domain and port for the server that hosted the fedora objects in the format 051 * "localhost:8080". 052 */ 053 public ArchiveExportedFoxmlDirectoryObjectSource(final File exportDir, final String localFedoraServer) { 054 this.root = exportDir; 055 this.fetcher = new HttpClientURLFetcher(); 056 this.localFedoraServer = localFedoraServer; 057 } 058 059 /** 060 * set the fetcher. 061 * @param fetcher the fetcher 062 */ 063 public void setFetcher(final URLFetcher fetcher) { 064 this.fetcher = fetcher; 065 } 066 067 /** 068 * Sets a FileFilter to determine which files will be considered as object 069 * files in the source directories. 070 * @param fileFilter a FileFilter implementation 071 */ 072 public void setFileFilter(final FileFilter fileFilter) { 073 this.fileFilter = fileFilter; 074 } 075 076 @Override 077 public Iterator<FedoraObjectProcessor> iterator() { 078 return new FoxmlDirectoryDFSIterator(root, fetcher, localFedoraServer, fileFilter); 079 } 080}