@throws IOException
if a non-directory file exists with the same path as a needed directory
*/
private URIToFileReturn uriToFile(String baseDir, CrawlURI curi)
throws AttributeNotFoundException, IOException {
UURI uuri = curi.getUURI(); // Current URI.
String host = null;
boolean hd = getCreateHostDirectory();
if (hd) {
host = uuri.getHost();
List<String> hostMap = getHostMap();
if ((null != hostMap) && (hostMap.size() > 1)) {
ensurePairs(hostMap);
Iterator<String> i = hostMap.iterator();
for (boolean more = true; more && i.hasNext();) {
String h1 = i.next();
String h2 = i.next();
if (host.equalsIgnoreCase(h1)) {
more = false;
if ((null != h2) && (0 != h2.length())) {
host = h2;
}
}
}
}
}
int port = getCreatePortDirectory() ? uuri.getPort() : -1;
String suffix = null; // Replacement suffix.
List<String> ctm = getContentTypeMap();
if ((null != ctm) && (ctm.size() > 1)) {
ensurePairs(ctm);
String contentType = curi.getContentType().toLowerCase();
Iterator<String> i = ctm.iterator();
for (boolean more = true; more && i.hasNext();) {
String ct = (String) i.next();
String suf = (String) i.next();
if ((null != ct) && contentType.startsWith(ct.toLowerCase())) {
more = false;
if ((null != suf) && (0 != suf.length())) {
suffix = suf;
}
}
}
}
int maxSegLen = getMaxSegLength();
if (maxSegLen < 2) {
maxSegLen = 2; // MAX_SEG_LEN.getDefaultValue();
}
int maxPathLen = getMaxPathLength();
if (maxPathLen < 2) {
maxPathLen = 2; // MAX_PATH_LENGTH.getDefaultValue();
}
Map<String,String> characterMap = Collections.emptyMap();
List<String> cm = getCharacterMap();
if ((null != cm) && (cm.size() > 1)) {
ensurePairs(cm);
characterMap = new HashMap<String,String>(cm.size());
// Above will be half full.
for (Iterator<String> i = cm.iterator(); i.hasNext();) {
String s1 = (String) i.next();
String s2 = (String) i.next();
if ((null != s1) && (1 == s1.length()) && (null != s2)
&& (0 != s2.length())) {
characterMap.put(s1, s2);
}
}
}
String dotBegin = getDotBegin();
if (".".equals(dotBegin)) {
dotBegin = null;
}
String dotEnd = getDotEnd();
if (".".equals(dotEnd)) {
dotEnd = null;
}
String tld = getTooLongDirectory();
if ((null == tld) || (0 == tld.length())
|| (-1 != tld.indexOf(File.separatorChar))) {
tld = "LONG"; // TOO_LONG_DIRECTORY.getDefaultValue();
}
Set<String> underscoreSet = null;
List<String> us = getUnderscoreSet();
if ((null != us) && (0 != us.size())) {
underscoreSet = new HashSet<String>(us.size(), 0.5F);
for (String s: us) {
if ((null != s) && (0 != s.length())) {
underscoreSet.add(s.toLowerCase());
}
}
}
return uriToFile(curi, host, port, uuri.getPath(), uuri.getQuery(),
suffix, baseDir, maxSegLen, maxPathLen,
getCaseSensitiveFilesystem(),
getDirectoryFile(),
characterMap, dotBegin, dotEnd, tld,
getSuffixAtEnd(),