Changeset 6373 in josm for trunk/src/org
- Timestamp:
- 2013-11-07T16:32:43+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java
r6372 r6373 1 // License: GPL. See LICENSE file for details. 1 2 package org.openstreetmap.josm.data.validation.tests; 2 3 … … 4 5 5 6 import java.io.InputStreamReader; 7 import java.lang.reflect.InvocationTargetException; 8 import java.lang.reflect.Method; 6 9 import java.util.ArrayList; 7 10 import java.util.Arrays; … … 14 17 import javax.script.ScriptException; 15 18 19 import org.openstreetmap.josm.Main; 16 20 import org.openstreetmap.josm.data.osm.Node; 17 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 28 32 * <a href="https://github.com/ypid/opening_hours.js">opening_hours.js</a>. 29 33 * 30 * @ author frsantos34 * @since 6370 31 35 */ 32 36 public class OpeningHourTest extends Test { 33 37 34 38 /** 35 * Javascript Rhinoengine39 * Javascript engine 36 40 */ 37 public static final ScriptEngine ENGINE = new ScriptEngineManager().getEngineByName(" rhino");41 public static final ScriptEngine ENGINE = new ScriptEngineManager().getEngineByName("JavaScript"); 38 42 39 43 /** … … 48 52 public void initialize() throws Exception { 49 53 super.initialize(); 50 ENGINE.eval(new InputStreamReader(new MirroredInputStream("resource://data/opening_hours.js"), "UTF-8")); 51 ENGINE.eval("var oh = function (x, y) {return new opening_hours(x, y);};"); 54 if (ENGINE != null) { 55 ENGINE.eval(new InputStreamReader(new MirroredInputStream("resource://data/opening_hours.js"), "UTF-8")); 56 ENGINE.eval("var oh = function (x, y) {return new opening_hours(x, y);};"); 57 } else { 58 Main.warn("Unable to initialize OpeningHourTest because no JavaScript engine has been found"); 59 } 52 60 } 53 61 … … 65 73 } else if (obj instanceof List) { 66 74 return (List<Object>) obj; 75 } else if ("sun.org.mozilla.javascript.internal.NativeArray".equals(obj.getClass().getName())) { 76 List<Object> list = new ArrayList<Object>(); 77 try { 78 Method getIds = obj.getClass().getMethod("getIds"); 79 Method get = obj.getClass().getMethod("get", long.class); 80 Object[] ids = (Object[]) getIds.invoke(obj); 81 for (Object id : ids) { 82 list.add(get.invoke(obj, id)); 83 } 84 } catch (NoSuchMethodException e) { 85 Main.error("Unable to run OpeningHourTest because of NoSuchMethodException by reflection: "+e.getMessage()); 86 } catch (IllegalArgumentException e) { 87 Main.error("Unable to run OpeningHourTest because of IllegalArgumentException by reflection: "+e.getMessage()); 88 } catch (IllegalAccessException e) { 89 Main.error("Unable to run OpeningHourTest because of IllegalAccessException by reflection: "+e.getMessage()); 90 } catch (InvocationTargetException e) { 91 Main.error("Unable to run OpeningHourTest because of InvocationTargetException by reflection: "+e.getMessage()); 92 } 93 return list; 67 94 } else { 68 95 throw new IllegalArgumentException("Not expecting class " + obj.getClass()); … … 78 105 */ 79 106 public List<TestError> checkOpeningHourSyntax(final String value) { 80 if ( value == null || value.trim().isEmpty()) {107 if (ENGINE == null || value == null || value.trim().isEmpty()) { 81 108 return Collections.emptyList(); 82 109 } … … 90 117 } catch (ScriptException ex) { 91 118 final String message = ex.getMessage() 92 .replace("sun.org.mozilla.javascript. JavaScriptException: ", "")119 .replace("sun.org.mozilla.javascript.internal.JavaScriptException: ", "opening_hours - ") 93 120 .replaceAll("\\(<Unknown source.*", "") 94 121 .trim();
Note:
See TracChangeset
for help on using the changeset viewer.