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 * @author mdurbin 030 */ 031 032public class NativeFoxmlDirectoryObjectSource implements ObjectSource { 033 034 private InternalIDResolver resolver; 035 036 private URLFetcher fetcher; 037 038 private File root; 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 * A constructor for use with the data storage directories that underly a 049 * fedora 3.x repository. First, this constructor will build an index of 050 * all of the datastreams in the provided datastreamStore directory for use 051 * resolving internal id references within the foxml. 052 * @param objectStore a directory containing just directories and FOXML files 053 * @param resolver an InternalIDResolver implementation that can resolve 054 * references to internally managed datastreams. 055 * @param localFedoraServer the domain and port for the server that hosted the fedora objects in the format 056 * "localhost:8080". 057 */ 058 public NativeFoxmlDirectoryObjectSource(final File objectStore, 059 final InternalIDResolver resolver, final String localFedoraServer) { 060 this.root = objectStore; 061 this.resolver = resolver; 062 this.fetcher = new HttpClientURLFetcher(); 063 this.localFedoraServer = localFedoraServer; 064 } 065 066 /** 067 * set the fetcher. 068 * @param fetcher the fetcher 069 */ 070 public void setFetcher(final URLFetcher fetcher) { 071 this.fetcher = fetcher; 072 } 073 074 /** 075 * Sets a FileFilter to determine which files will be considered as object 076 * files in the source directories. 077 * @param fileFilter a FileFilter implementation 078 */ 079 public void setFileFilter(final FileFilter fileFilter) { 080 this.fileFilter = fileFilter; 081 } 082 083 @Override 084 public Iterator<FedoraObjectProcessor> iterator() { 085 return new FoxmlDirectoryDFSIterator(root, resolver, fetcher, localFedoraServer, fileFilter); 086 } 087 088}