return (new File(dir, filename).isDirectory() || isValidFilename(filename));
}
};
List<String> filenames = Arrays.asList(gedcomFile.list(filter));
//Collections.sort(filenames);
GCSContentView content = new GCSContentView();
String requestURL = request.getRequestURL().toString();
//GCSContent parent = new GCSContent();
//parent.setLinkContent(gedcomFilePath);
//parent.setLinkURL(requestURL);
//content.setParent(parent);
if(!requestURL.endsWith("/"))
{
requestURL += "/";
}
long lastModified = 0;
for(String filename : filenames)
{
File contentFile = new File(gedcomFile, filename);
//if filename.length() == 2 then
//need to check all of it's subdirs to
//list the ones that are of length == 2
//and then check all of it's subfiles to make sure
//that they hash to filename+File.separato+filename_subdir
//and for the ones that DO create a new GCSContent()
//object using the new hashedFilename and add it to the GCSContentView object
//and for the ones that DO NOT create a new GCSContent()
//object using the current filename
if(filename.length() == 2 && contentFile.isDirectory())
{
File[] contentFiles = contentFile.listFiles();
for(File subContentFile : contentFiles)
{
if(subContentFile.getName().length() == 2 && subContentFile.isDirectory())
{
File[] subFiles = subContentFile.listFiles();
for(File subFile : subFiles)
{
if(isValidFilename(subFile.getName()))
{
// if the subFile is a hashedFilename then add it to GCSContentView object
boolean validHash = GLinkURL.justFileHash(subFile.getName()).equals(contentFile.getName()+File.separator+subContentFile.getName());
if(subFile.isFile() && validHash)
{
LOG.finest("1) Adding file: "+subFile.getAbsolutePath());
GCSContent gcsContent = new GCSContent();
if(lastModified < subFile.lastModified())
{
lastModified = subFile.lastModified();
}
gcsContent.setIsFile(subFile.isFile());
gcsContent.setJsContent((gedcomFilePath.length() > 0 ? gedcomFilePath.substring(1)+"/" : gedcomFilePath)+subFile.getName());
gcsContent.setLinkURL(requestURL+subFile.getName());
gcsContent.setLinkContent(subFile.getName());
content.addContent(gcsContent);
}
else
{
if((subContentFile.isDirectory() || isValidFilename(subContentFile.getName())) &&
validHash)
{
LOG.finest("2) Adding file: "+subContentFile.getAbsolutePath());
// found one that does not match, therefore, need to add the full
// path to subContentFile (make sure and do this only once)
GCSContent gcsContent = new GCSContent();
if(lastModified < subContentFile.lastModified())
{
lastModified = subContentFile.lastModified();
}
gcsContent.setIsFile(subContentFile.isFile());
gcsContent.setJsContent((gedcomFilePath.length() > 0 ? gedcomFilePath.substring(1)+"/" : gedcomFilePath)+subContentFile.getName());
gcsContent.setLinkURL(requestURL+subContentFile.getName());
gcsContent.setLinkContent(subContentFile.getName());
content.addContent(gcsContent);
}
}
}
}
}
else
{
// as part of the isValidFilename check method, the hash of the name of the file
// needs to be compared to it's two immediate parent directories to make sure
// that the file is not added if the hash of the name of the file is equal to
// it's two immediate parent directories
LOG.finest("The full path to the file: "+subContentFile.getAbsolutePath());
LOG.finest("File hash: "+GLinkURL.justFileHash(subContentFile.getName()));
LOG.finest("Two parent dirs: "+contentFile.getParentFile().getName()+File.separator+contentFile.getName());
if((contentFile.isDirectory() || isValidFilename(contentFile.getName())) &&
!GLinkURL.justFileHash(subContentFile.getName()).equals(contentFile.getParentFile().getName()+File.separator+contentFile.getName()) &&
isValidFilename(subContentFile.getName()))
{
LOG.finest("3) Adding file: "+contentFile.getAbsolutePath());
// found one that does not match, therefore, need to add the full
// path to contentFile (make sure and do this only once)
GCSContent gcsContent = new GCSContent();
if(lastModified < contentFile.lastModified())
{
lastModified = contentFile.lastModified();
}
gcsContent.setIsFile(contentFile.isFile());
gcsContent.setJsContent((gedcomFilePath.length() > 0 ? gedcomFilePath.substring(1)+"/" : gedcomFilePath)+contentFile.getName());
gcsContent.setLinkURL(requestURL+contentFile.getName());
gcsContent.setLinkContent(contentFile.getName());
content.addContent(gcsContent);
}
}
}
}
else if(!contentFile.isFile() || !GLinkURL.justFileHash(contentFile.getName()).equals(contentFile.getParentFile().getParentFile().getName()+File.separator+contentFile.getParentFile().getName()))
{
LOG.finest("4) Adding file: "+contentFile.getAbsolutePath());
GCSContent gcsContent = new GCSContent();
if(lastModified < contentFile.lastModified())
{
lastModified = contentFile.lastModified();
}
gcsContent.setIsFile(contentFile.isFile());
gcsContent.setJsContent((gedcomFilePath.length() > 0 ? gedcomFilePath.substring(1)+"/" : gedcomFilePath)+filename);
gcsContent.setLinkURL(requestURL+filename);
gcsContent.setLinkContent(filename);
content.addContent(gcsContent);
}
}
sendJSONResponse(response, content, lastModified);
/*}*/
}