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