Subversion Repositories general

Rev

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

Rev Author Line No. Line
1249 dev 1
package ak.photoalbum.logic;
1242 dev 2
 
3
import java.io.File;
4
import java.io.IOException;
5
import java.util.Map;
6
import java.util.Hashtable;
7
 
8
public class MetaInfo
9
{
10
  private File   dir;
11
  private String dirPath;
1274 dev 12
  private final Map items = new Hashtable(); // <String, MetaInfoItem>
1242 dev 13
 
14
  public MetaInfo()
15
  {
16
  }
17
 
18
  public File getDir()
19
  {
20
    return dir;
21
  }
22
 
23
  public void setDir(File dir)
24
    throws IOException
25
  {
26
    this.dir     = dir;
27
    this.dirPath = dir.getCanonicalPath();
28
    if(!this.dirPath.endsWith(File.separator))
29
      this.dirPath += File.separator;
30
  }
31
 
32
  public void addItem(MetaInfoItem item)
33
  {
34
    items.put(item.getId(), item);
35
  }
36
 
37
  public MetaInfoItem findItem(File file)
38
    throws IOException
39
  {
40
    String filePath = file.getCanonicalPath();
41
    String id;
42
 
43
    if(file.isDirectory() && !filePath.endsWith(File.separator))
44
      filePath += File.separator;
45
 
46
    if(filePath.length() < dirPath.length())
47
      return null;
48
    else if(filePath.length() == dirPath.length())
49
      id = ".";
50
    else
51
      id = filePath.substring(dirPath.length());
52
 
53
    return (MetaInfoItem)items.get(id);
54
  }
55
}
56