Revision 44924 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/programming/FileFunction.java

View differences:

FileFunction.java
2 2

  
3 3
import java.io.File;
4 4
import java.net.URI;
5
import java.net.URL;
5 6
import org.apache.commons.lang3.Range;
6 7
import org.gvsig.expressionevaluator.ExpressionRuntimeException;
7 8
import org.gvsig.expressionevaluator.Function;
......
17 18
            NAME, 
18 19
            Range.is(1),
19 20
            null,
21
            NAME+"({{expression}})",
20 22
            null,
21
            null,
22 23
            "Object",
23 24
            false
24 25
        );
......
31 32
    
32 33
    @Override
33 34
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
34
        Object value;
35 35
        Object obj = getObject(args, 0);
36
        File value = toFile(obj);
37
        return value;
38
    }
39
    
40
    public static File toFile(Object obj) {
36 41
        if( obj == null ) {
37
            return 0;
42
            return null;
38 43
        }        
39 44
        if( obj instanceof File ) {
40
            return obj;
45
            return (File) obj;
41 46
        } else if( obj instanceof CharSequence ) {
42
            value = new File(((CharSequence)obj).toString());
47
            return new File(((CharSequence)obj).toString());
43 48
        } else if( obj instanceof URI ) {
44
            value = new File(((URI)obj));
49
            return new File(((URI)obj));
50
        } else if( obj instanceof URL ) {
51
            return new File(((URL)obj).getPath());
45 52
        } else {
46 53
            throw new ExpressionRuntimeException("The "+NAME+" function require a File or a String and a received a '"+obj.getClass().getSimpleName()+"'.");
47 54
        }
48
        return value;
49 55
    }
50 56
    
51 57
}

Also available in: Unified diff