Revision 1112
org.gvsig.scripting/trunk/org.gvsig.scripting/pom.xml | ||
---|---|---|
187 | 187 |
<artifactId>tika-core</artifactId> |
188 | 188 |
<version>1.12</version> |
189 | 189 |
</dependency> |
190 |
<!-- Eliminar para org.gvsig.desktop > 2.0.115 --> |
|
191 |
<!-- |
|
192 | 190 |
<dependency> |
193 |
<groupId>org.jopendocument</groupId> |
|
194 |
<artifactId>jOpenDocument</artifactId> |
|
195 |
<version>1.3</version> |
|
196 |
</dependency> |
|
197 |
--> |
|
198 |
<dependency> |
|
199 | 191 |
<groupId>net.sf.cssbox</groupId> |
200 | 192 |
<artifactId>swingbox</artifactId> |
201 | 193 |
<version>1.1</version> |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/MutableURLClassLoader.java | ||
---|---|---|
50 | 50 |
|
51 | 51 |
@Override |
52 | 52 |
public URL getResource(String name) { |
53 |
// Para acceder a esto desde python |
|
54 |
// import sys |
|
55 |
// print sys.getClassLoader().getResource("pylint/utils$py.class") |
|
56 |
|
|
53 | 57 |
URL x = super.getResource(name); |
54 | 58 |
if( needRecompile(name, x) ) { |
55 | 59 |
logger.trace("getResoure("+name+") -> null (need recompile)."); |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/DefaultScriptingScript.java | ||
---|---|---|
935 | 935 |
return true; |
936 | 936 |
} |
937 | 937 |
|
938 |
@Override |
|
939 |
public List<String> getNames() { |
|
940 |
ScriptEngine theEngine = this.getEngine(); |
|
941 |
if( theEngine instanceof MyPyScriptEngine ) { |
|
942 |
return ((MyPyScriptEngine) theEngine).getLocalNames(); |
|
943 |
} |
|
944 |
return null; |
|
945 |
} |
|
938 | 946 |
} |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/AbstractUnit.java | ||
---|---|---|
4 | 4 |
import java.beans.PropertyChangeListener; |
5 | 5 |
import java.io.File; |
6 | 6 |
import java.io.IOException; |
7 |
import java.net.URI; |
|
7 |
import java.net.MalformedURLException; |
|
8 |
import java.net.URL; |
|
8 | 9 |
import java.util.ArrayList; |
9 | 10 |
import java.util.HashMap; |
10 | 11 |
import java.util.HashSet; |
... | ... | |
25 | 26 |
|
26 | 27 |
public abstract class AbstractUnit implements ScriptingUnit, Unit { |
27 | 28 |
|
28 |
protected static final Logger logger = LoggerFactory.getLogger(AbstractUnit.class);
|
|
29 |
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractUnit.class);
|
|
29 | 30 |
|
30 | 31 |
protected DefaultScriptingManager manager; |
31 | 32 |
|
... | ... | |
68 | 69 |
listener.propertyChange(event); |
69 | 70 |
} |
70 | 71 |
} catch(Exception ex) { |
71 |
logger.warn("Problems firing PropertyChangeListener to listener "+listener+".",ex);
|
|
72 |
LOGGER.warn("Problems firing PropertyChangeListener to listener "+listener+".",ex);
|
|
72 | 73 |
} |
73 | 74 |
} |
74 | 75 |
} |
... | ... | |
206 | 207 |
File f = prefs.getFile(); |
207 | 208 |
String fname = (f == null) ? "(null)" : f.getAbsolutePath(); |
208 | 209 |
String msg = "Can't save inf file '" + fname + "'."; |
209 |
logger.warn(msg);
|
|
210 |
LOGGER.warn(msg);
|
|
210 | 211 |
throw new RuntimeException(msg, e); |
211 | 212 |
} |
212 | 213 |
|
... | ... | |
217 | 218 |
if (!this.getTypeName().equalsIgnoreCase(typename)) { |
218 | 219 |
File f = prefs.getFile(); |
219 | 220 |
String fname = (f == null) ? "(null)" : f.getAbsolutePath(); |
220 |
logger.warn("inconsistent type in inf file '" + fname + "'. Curent type '" + this.getTypeName() + "', type from inf file '" + typename + "'.");
|
|
221 |
LOGGER.warn("inconsistent type in inf file '" + fname + "'. Curent type '" + this.getTypeName() + "', type from inf file '" + typename + "'.");
|
|
221 | 222 |
} |
222 | 223 |
this.setName(getInfString(prefs, "Unit", "name", this.getName())); |
223 | 224 |
this.setDescription(getInfString(prefs, "Unit", "description", null)); |
... | ... | |
266 | 267 |
} |
267 | 268 |
|
268 | 269 |
protected void console_println(String s) { |
269 |
logger.info(s);
|
|
270 |
LOGGER.info(s);
|
|
270 | 271 |
} |
271 | 272 |
|
272 | 273 |
public void create(ScriptingFolder folder, String id) { |
... | ... | |
277 | 278 |
try { |
278 | 279 |
file.createNewFile(); |
279 | 280 |
} catch (IOException e) { |
280 |
logger.warn("Can't create inf file in '" + file.getAbsolutePath() + "'.", e);
|
|
281 |
LOGGER.warn("Can't create inf file in '" + file.getAbsolutePath() + "'.", e);
|
|
281 | 282 |
} |
282 | 283 |
} |
283 | 284 |
|
... | ... | |
295 | 296 |
return new File(getParent().getFile(), this.getId() + ".inf"); |
296 | 297 |
} |
297 | 298 |
|
298 |
public URI getURI() {
|
|
299 |
public URL getURL() {
|
|
299 | 300 |
File f = this.getFile(); |
300 |
return f.toURI(); |
|
301 |
try { |
|
302 |
return f.toURI().toURL(); |
|
303 |
} catch (MalformedURLException ex) { |
|
304 |
return null; |
|
305 |
} |
|
301 | 306 |
} |
302 | 307 |
|
303 | 308 |
@Override |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/DefaultScriptingExternalFile.java | ||
---|---|---|
38 | 38 |
try { |
39 | 39 |
file.createNewFile(); |
40 | 40 |
} catch (IOException e) { |
41 |
logger.warn("Can't create inf file in '" + file.getAbsolutePath() + "'.", e);
|
|
41 |
LOGGER.warn("Can't create inf file in '" + file.getAbsolutePath() + "'.", e);
|
|
42 | 42 |
} |
43 | 43 |
} |
44 | 44 |
|
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/python/jsr223/MyPyScriptEngine.java | ||
---|---|---|
5 | 5 |
import java.io.Reader; |
6 | 6 |
import java.lang.reflect.InvocationHandler; |
7 | 7 |
import java.lang.reflect.Proxy; |
8 |
import java.util.List; |
|
8 | 9 |
import javax.script.AbstractScriptEngine; |
9 | 10 |
import javax.script.Bindings; |
10 | 11 |
import javax.script.Compilable; |
... | ... | |
32 | 33 |
return this.interp; |
33 | 34 |
} |
34 | 35 |
|
36 |
@Override |
|
35 | 37 |
public Object eval(String script, ScriptContext context) throws ScriptException { |
36 | 38 |
return eval(compileScript(script, context), context); |
37 | 39 |
} |
... | ... | |
48 | 50 |
} |
49 | 51 |
} |
50 | 52 |
|
53 |
@Override |
|
51 | 54 |
public Object eval(Reader reader, ScriptContext context) throws ScriptException { |
52 | 55 |
return eval(compileScript(reader, context), context); |
53 | 56 |
} |
54 | 57 |
|
58 |
@Override |
|
55 | 59 |
public Bindings createBindings() { |
56 | 60 |
return new SimpleBindings(); |
57 | 61 |
} |
58 | 62 |
|
63 |
@Override |
|
59 | 64 |
public ScriptEngineFactory getFactory() { |
60 | 65 |
return factory; |
61 | 66 |
} |
62 | 67 |
|
68 |
@Override |
|
63 | 69 |
public CompiledScript compile(String script) throws ScriptException { |
64 | 70 |
return new PyCompiledScript(compileScript(script, context)); |
65 | 71 |
} |
66 | 72 |
|
73 |
@Override |
|
67 | 74 |
public CompiledScript compile(Reader reader) throws ScriptException { |
68 | 75 |
return new PyCompiledScript(compileScript(reader, context)); |
69 | 76 |
} |
... | ... | |
94 | 101 |
} |
95 | 102 |
} |
96 | 103 |
|
104 |
@Override |
|
97 | 105 |
public Object invokeMethod(Object thiz, String name, Object... args) throws ScriptException, |
98 | 106 |
NoSuchMethodException { |
99 | 107 |
try { |
... | ... | |
143 | 151 |
} |
144 | 152 |
} |
145 | 153 |
|
154 |
@Override |
|
146 | 155 |
public <T> T getInterface(Class<T> clazz) { |
147 | 156 |
return getInterface(new PyModule("__jsr223__", interp.getLocals()), clazz); |
148 | 157 |
} |
149 | 158 |
|
159 |
@Override |
|
150 | 160 |
public <T> T getInterface(Object obj, Class<T> clazz) { |
151 | 161 |
if (obj == null) { |
152 | 162 |
throw new IllegalArgumentException("object expected"); |
... | ... | |
161 | 171 |
clazz.getClassLoader(), |
162 | 172 |
new Class[] { clazz }, |
163 | 173 |
new InvocationHandler() { |
174 |
@Override |
|
164 | 175 |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
165 | 176 |
try { |
166 | 177 |
interp.setLocals(new PyScriptEngineScope(MyPyScriptEngine.this, context)); |
... | ... | |
183 | 194 |
} |
184 | 195 |
|
185 | 196 |
private static ScriptException scriptException(PyException pye) { |
186 |
ScriptException se = null;
|
|
197 |
ScriptException se; |
|
187 | 198 |
try { |
188 | 199 |
pye.normalize(); |
189 | 200 |
|
... | ... | |
225 | 236 |
} |
226 | 237 |
|
227 | 238 |
private class PyCompiledScript extends CompiledScript { |
228 |
private PyCode code; |
|
239 |
private final PyCode code;
|
|
229 | 240 |
|
230 | 241 |
PyCompiledScript(PyCode code) { |
231 | 242 |
this.code = code; |
... | ... | |
240 | 251 |
public Object eval(ScriptContext ctx) throws ScriptException { |
241 | 252 |
return MyPyScriptEngine.this.eval(code, ctx); |
242 | 253 |
} |
254 |
|
|
243 | 255 |
} |
244 | 256 |
|
257 |
@Override |
|
245 | 258 |
public void close() { |
246 | 259 |
interp.close(); |
247 | 260 |
} |
261 |
|
|
262 |
public List<String> getLocalNames() { |
|
263 |
PyScriptEngineScope locals = (PyScriptEngineScope) interp.getLocals(); |
|
264 |
PyList names = (PyList) locals.scope_keys(); |
|
265 |
return names; |
|
266 |
} |
|
267 |
|
|
248 | 268 |
} |
Also available in: Unified diff