1 package cz.cuni.amis.pogamut.ut2004.bot.sposh;
2
3 import java.io.FileReader;
4 import java.io.IOException;
5 import java.io.Reader;
6 import javax.script.ScriptEngine;
7 import javax.script.ScriptEngineManager;
8
9
10
11
12
13
14
15
16
17
18
19
20 @Deprecated
21 public abstract class FileScriptLogic extends StreamScriptLogic {
22
23
24
25
26
27
28
29 @Override
30 protected ScriptEngine createScriptEngine(ScriptEngineManager manager) {
31 String scriptExtension = getExt(getScriptFile());
32
33 return manager.getEngineByExtension(scriptExtension);
34 }
35
36
37
38
39
40
41 @Override
42 protected Reader getScriptStream() throws IOException {
43 return new FileReader(getScriptFile());
44 }
45
46
47
48
49
50
51
52 protected abstract String getScriptFile();
53
54
55
56
57
58
59 protected String getExt(String path) {
60 int separatorIndex = path.lastIndexOf(System.getProperty("file.separator"));
61 String filename = (separatorIndex == -1 ? path : path.substring(separatorIndex + 1));
62
63 System.out.println("filename is "+filename);
64 return (filename.lastIndexOf('.') == -1 ? "" : filename.substring(filename.lastIndexOf('.') + 1));
65 }
66 }