* @throws InvalidFolderException
* @throws DocumentNotFoundException
*/
public Folder getFolder( String path, boolean fromCache ) throws NodeException, FolderNotFoundException, InvalidFolderException
{
Folder folder = null;
File folderFile = new File(documentRootDir, path);
if(!folderFile.exists())
{
throw new FolderNotFoundException(folderFile.getAbsolutePath()+" does not exist.");
}
if(!folderFile.isDirectory())
{
throw new InvalidFolderException(folderFile.getAbsolutePath()+" is not a valid directory.");
}
// cleanup trailing separators
if (!path.equals(Folder.PATH_SEPARATOR) && path.endsWith(Folder.PATH_SEPARATOR))
{
path = path.substring(0, path.length()-1);
}
// check cache
if (fromCache)
{
folder = (Folder) fileCache.getDocument(path);
}
// get new folder
if (folder == null)
{
try
{
// look for metadata
FolderMetaDataImpl metadata = (FolderMetaDataImpl) metadataDocHandler.getDocument(path + Folder.PATH_SEPARATOR + FolderMetaDataImpl.DOCUMENT_TYPE);
folder = new FolderImpl(path, metadata, handlerFactory, this);
}
catch (DocumentNotFoundException e)
{
// no metadata
folder = new FolderImpl(path, handlerFactory, this);
}
// recursively set parent
if (!path.equals(Folder.PATH_SEPARATOR))
{
String parentPath = path;
int parentSeparatorIndex = parentPath.lastIndexOf(Folder.PATH_SEPARATOR_CHAR);
if (parentSeparatorIndex > 0)
{
parentPath = parentPath.substring(0, parentSeparatorIndex);
}
else
{
parentPath = Folder.PATH_SEPARATOR;
}
folder.setParent(getFolder(parentPath));
}
// folder unmarshalled
((FolderImpl) folder).unmarshalled();