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 | 44389 | jjdelcerro | package org.gvsig.expressionevaluator.impl.function.foldersmanager; |
---|---|---|---|
2 | 43512 | jjdelcerro | |
3 | 44389 | jjdelcerro | import java.io.File; |
4 | 43512 | jjdelcerro | import org.apache.commons.lang3.Range; |
5 | 43521 | jjdelcerro | import org.gvsig.expressionevaluator.Interpreter; |
6 | 43512 | jjdelcerro | import org.gvsig.expressionevaluator.spi.AbstractFunction; |
7 | 44389 | jjdelcerro | import org.gvsig.tools.ToolsLocator; |
8 | import org.gvsig.tools.folders.FoldersManager; |
||
9 | 43512 | jjdelcerro | |
10 | 44389 | jjdelcerro | public class UniqueTemporaryFileFunction extends AbstractFunction { |
11 | 43512 | jjdelcerro | |
12 | 44389 | jjdelcerro | 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 | 44408 | jjdelcerro | " "+NAME+"('folder','name.txt')\n" + |
23 | 44389 | jjdelcerro | "For this call, the return value will have the form:\n" +
|
24 | 44408 | jjdelcerro | " {PATH}/folder/name-{HEX1}-{HEX2}.txt",
|
25 | 44389 | jjdelcerro | NAME+"({{pathComponents...}})",
|
26 | new String[] { |
||
27 | "pathComponents - relative pathname"
|
||
28 | }, |
||
29 | "File",
|
||
30 | false
|
||
31 | ); |
||
32 | 43512 | jjdelcerro | } |
33 | |||
34 | @Override
|
||
35 | 44009 | jjdelcerro | public boolean allowConstantFolding() { |
36 | 44389 | jjdelcerro | return false; |
37 | 44009 | jjdelcerro | } |
38 | 44389 | jjdelcerro | |
39 | 44009 | jjdelcerro | @Override
|
40 | 43521 | jjdelcerro | public Object call(Interpreter interpreter, Object[] args) { |
41 | 44389 | jjdelcerro | 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 | 43512 | jjdelcerro | } |
49 | } |