Subversion Repositories general

Rev

Rev 1249 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package ak.photoalbum.logic;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Hashtable;

public class MetaInfo
{
  private File   dir;
  private String dirPath;
  private final Map items = new Hashtable(); // <String, MetaInfoItem>

  public MetaInfo()
  {
  }

  public File getDir()
  {
    return dir;
  }

  public void setDir(File dir)
    throws IOException
  {
    this.dir     = dir;
    this.dirPath = dir.getCanonicalPath();
    if(!this.dirPath.endsWith(File.separator))
      this.dirPath += File.separator;
  }

  public void addItem(MetaInfoItem item)
  {
    items.put(item.getId(), item);
  }

  public MetaInfoItem findItem(File file)
    throws IOException
  {
    String filePath = file.getCanonicalPath();
    String id;
    
    if(file.isDirectory() && !filePath.endsWith(File.separator))
      filePath += File.separator;

    if(filePath.length() < dirPath.length())
      return null;
    else if(filePath.length() == dirPath.length())
      id = ".";
    else
      id = filePath.substring(dirPath.length());

    return (MetaInfoItem)items.get(id);
  }
}