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.IOException; 020import java.io.UnsupportedEncodingException; 021import java.net.URLDecoder; 022 023/** 024 * An extension of DirectoryScanningIDResolver for datastream directories of fedora 025 * repositories using the akubra-fs storage implementation. 026 * 027 * @author mdurbin 028 */ 029public class AkubraFSIDResolver extends DirectoryScanningIDResolver { 030 031 /** 032 * Basic constructor. 033 * @param indexDir A directory that will serve as a lucene index directory to cache ID resolution. 034 * @param dsRoot the root directory of the AkubraFS datastream store. 035 * @throws IOException IO exception creating temp and index files/directories 036 */ 037 public AkubraFSIDResolver(final File indexDir, final File dsRoot) throws IOException { 038 super(indexDir, dsRoot); 039 } 040 041 /** 042 * Basic constructor. 043 * @param dsRoot the root directory of the AkubraFS datastream store. 044 * @throws IOException IO exception creating temp and index files/directories 045 */ 046 public AkubraFSIDResolver(final File dsRoot) throws IOException { 047 super(null, dsRoot); 048 } 049 050 @Override 051 protected String getInternalIdForFile(final File f) { 052 String id = f.getName(); 053 try { 054 id = URLDecoder.decode(id, "UTF-8"); 055 } catch (UnsupportedEncodingException e) { 056 throw new RuntimeException(e); 057 } 058 if (!id.startsWith("info:fedora/")) { 059 throw new IllegalArgumentException(f.getName() 060 + " does not appear to be a valid akubraFS datastream file!"); 061 } 062 id = id.substring("info:fedora/".length()); 063 id = id.replace('/', '+'); 064 return id; 065 } 066}