File: FileResourceFinder.java

package info (click to toggle)
liblessen-java 1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 276 kB
  • sloc: java: 2,981; xml: 31; makefile: 5
file content (37 lines) | stat: -rw-r--r-- 800 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.metaweb.lessen;

import java.io.File;
import java.io.FileNotFoundException;

import com.metaweb.lessen.tokenizers.Tokenizer;


public class FileResourceFinder implements ResourceFinder {
    
    final protected File _dir;
    
    public FileResourceFinder(File file) {
        if (file.isDirectory()) {
            _dir = file;
        } else {
            _dir = file.getParentFile();
        }
    }

    @Override
    public Tokenizer open(String where) {
        File file = new File(_dir, where);
        
        try {
            return Utilities.open(file);
        } catch (FileNotFoundException e) {
            return null;
        }
    }

    @Override
    public ResourceFinder rebase(String where) {
        return new FileResourceFinder(new File(_dir, where));
    }

}