Changeset 6373 in josm for trunk/src/org


Ignore:
Timestamp:
2013-11-07T16:32:43+01:00 (11 years ago)
Author:
Don-vip
Message:

see #9285 - should fix exception of opening_hours validator test with Apple Java 6

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.
    12package org.openstreetmap.josm.data.validation.tests;
    23
     
    45
    56import java.io.InputStreamReader;
     7import java.lang.reflect.InvocationTargetException;
     8import java.lang.reflect.Method;
    69import java.util.ArrayList;
    710import java.util.Arrays;
     
    1417import javax.script.ScriptException;
    1518
     19import org.openstreetmap.josm.Main;
    1620import org.openstreetmap.josm.data.osm.Node;
    1721import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2832 * <a href="https://github.com/ypid/opening_hours.js">opening_hours.js</a>.
    2933 *
    30  * @author frsantos
     34 * @since 6370
    3135 */
    3236public class OpeningHourTest extends Test {
    3337
    3438    /**
    35      * Javascript Rhino engine
     39     * Javascript engine
    3640     */
    37     public static final ScriptEngine ENGINE = new ScriptEngineManager().getEngineByName("rhino");
     41    public static final ScriptEngine ENGINE = new ScriptEngineManager().getEngineByName("JavaScript");
    3842
    3943    /**
     
    4852    public void initialize() throws Exception {
    4953        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        }
    5260    }
    5361
     
    6573        } else if (obj instanceof List) {
    6674            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;
    6794        } else {
    6895            throw new IllegalArgumentException("Not expecting class " + obj.getClass());
     
    78105     */
    79106    public List<TestError> checkOpeningHourSyntax(final String value) {
    80         if (value == null || value.trim().isEmpty()) {
     107        if (ENGINE == null || value == null || value.trim().isEmpty()) {
    81108            return Collections.emptyList();
    82109        }
     
    90117        } catch (ScriptException ex) {
    91118            final String message = ex.getMessage()
    92                     .replace("sun.org.mozilla.javascript.JavaScriptException: ", "")
     119                    .replace("sun.org.mozilla.javascript.internal.JavaScriptException: ", "opening_hours - ")
    93120                    .replaceAll("\\(<Unknown source.*", "")
    94121                    .trim();
Note: See TracChangeset for help on using the changeset viewer.