1 package rero.client.functions; 2 3 import sleep.engine.*; 4 import sleep.runtime.*; 5 import sleep.interfaces.*; 6 import sleep.bridges.BridgeUtilities; 7 8 import rero.config.*; 9 10 import rero.client.*; 11 import java.util.*; 12 13 public class ConfigOperators extends Feature implements Loadable 14 { 15 public void init() 16 { 17 getCapabilities().getScriptCore().addBridge(this); 18 } 19 20 public boolean scriptLoaded(ScriptInstance script) 21 { 22 script.getScriptEnvironment().getEnvironment().put("&getProperty", new getProperty()); 23 script.getScriptEnvironment().getEnvironment().put("&getPropertyList", new getPropertyList()); 24 script.getScriptEnvironment().getEnvironment().put("&setProperty", new setProperty()); 25 script.getScriptEnvironment().getEnvironment().put("&setPropertyList", new setPropertyList()); 26 script.getScriptEnvironment().getEnvironment().put("&baseDirectory", new getBaseDirectory()); 27 28 29 script.getScriptEnvironment().getEnvironment().put("-isSetT", new isSet1()); 30 script.getScriptEnvironment().getEnvironment().put("-isSetF", new isSet2()); 31 32 return true; 33 } 34 35 public boolean scriptUnloaded(ScriptInstance script) 36 { 37 return true; 38 } 39 40 private static class getPropertyList implements Function 41 { 42 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 43 { 44 String a = locals.pop().toString(); 45 46 Scalar value = SleepUtils.getArrayScalar(); 47 Iterator i = ClientState.getClientState().getStringList(a).getList().iterator(); 48 while (i.hasNext()) 49 { 50 value.getArray().push(SleepUtils.getScalar(i.next().toString())); 51 } 52 53 return value; 54 } 55 } 56 57 private static class setPropertyList implements Function 58 { 59 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 60 { 61 String a = locals.pop().toString(); 62 Scalar b = (Scalar)locals.pop(); 63 64 StringList list = ClientState.getClientState().getStringList(a); 65 66 list.clear(); 67 68 Iterator i = b.getArray().scalarIterator(); 69 while (i.hasNext()) 70 { 71 list.add(i.next().toString()); 72 } 73 list.save(); 74 75 return SleepUtils.getEmptyScalar(); 76 } 77 } 78 79 private static class getProperty implements Function 80 { 81 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 82 { 83 String a = locals.pop().toString(); 84 String def = ""; 85 86 if (!locals.isEmpty()) 87 { 88 def = locals.pop().toString(); 89 } 90 91 return SleepUtils.getScalar(ClientState.getClientState().getString(a, def)); 92 } 93 } 94 95 private static class setProperty implements Function 96 { 97 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 98 { 99 String a = locals.pop().toString(); 100 String b = locals.pop().toString(); 101 102 ClientState.getClientState().setString(a, b); 103 104 return SleepUtils.getEmptyScalar(); 105 } 106 } 107 108 private static class isSet1 implements Predicate 109 { 110 public boolean decide(String f, ScriptInstance si, Stack locals) 111 { 112 String a = locals.pop().toString(); 113 114 return ClientState.getClientState().isOption(a, true); 115 } 116 } 117 118 private static class isSet2 implements Predicate 119 { 120 public boolean decide(String f, ScriptInstance si, Stack locals) 121 { 122 String a = locals.pop().toString(); 123 124 return ClientState.getClientState().isOption(a, false); 125 } 126 } 127 128 private static class getBaseDirectory implements Function 129 { 130 public Scalar evaluate(String f, ScriptInstance si, Stack locals) 131 { 132 return SleepUtils.getScalar(ClientState.getClientState().getBaseDirectory().getAbsolutePath()); 133 } 134 } 135 } 136 | Popular Tags |