svn-gvsig-desktop / 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 / foldersmanager / UniqueTemporaryFileFunction.java @ 45043
History | View | Annotate | Download (1.67 KB)
1 |
package org.gvsig.expressionevaluator.impl.function.foldersmanager; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import org.apache.commons.lang3.Range; |
5 |
import org.gvsig.expressionevaluator.Interpreter; |
6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
7 |
import org.gvsig.tools.ToolsLocator; |
8 |
import org.gvsig.tools.folders.FoldersManager; |
9 |
|
10 |
public class UniqueTemporaryFileFunction extends AbstractFunction { |
11 |
|
12 |
public static final String NAME = "UNIQUETEMPORARYFILE"; |
13 |
|
14 |
public UniqueTemporaryFileFunction() {
|
15 |
super(
|
16 |
"Folders",
|
17 |
NAME, |
18 |
Range.between(1,1000), |
19 |
"Return a unique file with the specified relative path to the temporary folder.\n" +
|
20 |
"The base name of the file is modified to be unique.\n" +
|
21 |
"The file will be deleted when the application exits.\n" +
|
22 |
" "+NAME+"('folder','name.txt')\n" + |
23 |
"For this call, the return value will have the form:\n" +
|
24 |
" {PATH}/folder/name-{HEX1}-{HEX2}.txt",
|
25 |
NAME+"({{pathComponents...}})",
|
26 |
new String[] { |
27 |
"pathComponents - relative pathname"
|
28 |
}, |
29 |
"File",
|
30 |
false
|
31 |
); |
32 |
} |
33 |
|
34 |
@Override
|
35 |
public boolean allowConstantFolding() { |
36 |
return false; |
37 |
} |
38 |
|
39 |
@Override
|
40 |
public Object call(Interpreter interpreter, Object[] args) { |
41 |
FoldersManager folderManager = ToolsLocator.getFoldersManager(); |
42 |
String[] pathComponents = new String[args.length]; |
43 |
for (int i = 0; i < args.length; i++) { |
44 |
pathComponents[i] = getStr(args,i); |
45 |
} |
46 |
File f = folderManager.getUniqueTemporaryFile(pathComponents);
|
47 |
return f;
|
48 |
} |
49 |
} |