Created
January 18, 2010 13:51
-
-
Save cbeer/280020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fedora.server.storage.lowlevel; | |
import java.io.File; | |
import java.util.Map; | |
import fedora.server.errors.LowlevelStorageException; | |
/** | |
* @author Chris Beer | |
*/ | |
class PairtreePathAlgorithm | |
extends PathAlgorithm { | |
private final String storeBase; | |
private static final String SEP = File.separator; | |
public PairtreePathAlgorithm(Map<String, ?> configuration) { | |
super(configuration); | |
storeBase = (String) configuration.get("storeBase"); | |
} | |
@Override | |
public final String get(String pid) throws LowlevelStorageException { | |
return format(pid); | |
} | |
public String format(String pid) throws LowlevelStorageException { | |
String pt = to_pairtree(pid); | |
return storeBase + pt + "obj" + SEP + pid; | |
} | |
private String to_pairtree(String s) { | |
String pt = SEP; | |
String src = escape(s); | |
int i = 0; | |
while(i < src.length()) { | |
pt += src.substring(i, i+2) + SEP; | |
i+= 2; | |
} | |
if(i < src.length()) { | |
pt += src.substring(i); | |
} | |
return pt; | |
} | |
private String escape(String s) { | |
/* | |
Fedora PIDs do not support non-visible ASCII or the characters below, | |
so we skip hex encoding: | |
" hex 22 < hex 3c ? hex 3f | |
* hex 2a = hex 3d ^ hex 5e | |
+ hex 2b > hex 3e | hex 7c | |
, hex 2c | |
*/ | |
return s.replace("/", "+").replace(":", "+").replace(".", ","); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment