Author: lgiessmann Date: Thu Jun 30 03:30:38 2011 New Revision: 536
Log: gdl-frontend: Topic Maps Engine: fixed a bug when a topic reference or an array is set to null instead of being set to a value
Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/lib/GDL_TopicMaps_Model.jar branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java
Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/lib/GDL_TopicMaps_Model.jar ============================================================================== Binary file (source and/or target). No diff available.
Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java Thu Jun 30 03:28:32 2011 (r535) +++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java Thu Jun 30 03:30:38 2011 (r536) @@ -8,6 +8,8 @@ import com.google.gwt.json.client.JSONParser; import com.google.gwt.json.client.JSONString; import com.google.gwt.json.client.JSONValue; +import com.google.gwt.user.client.Window; + import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.ExporterException; import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.FormatException; import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.MissingReference; @@ -416,6 +418,8 @@
private Topic getReferenced(JSONValue reference, TopicMap tm, Prefixes prefixes) throws FormatException, MissingReference{ + if(reference.isNull() != null) return null; + JSONString stringValue = reference.isString(); if(stringValue == null){ throw new FormatException("expected a string value as topic reference, but found "" + reference.toString() + """); @@ -452,6 +456,10 @@ ArrayList<String> stringReferences = new ArrayList<String>();
JSONArray stringValues = references.isArray(); + if(references.isNull() != null){ + return getReferenceds(stringReferences, tm, prefixes); + } + if(stringValues == null){ throw new FormatException("expected an array of strings as topic references, but found "" + references.toString() + """); } @@ -553,17 +561,22 @@
if(object.containsKey(key)){ JSONValue jsonValue = object.get(key); - JSONArray jsonArray = jsonValue.isArray(); - if(jsonArray == null){ - throw new FormatException("the field "" + key + "" must be a string array"); + if(jsonValue.isNull() != null){ + // the value must be null, so return an emtpy ArrayList + return values; } else { - for(int i = 0; i != jsonArray.size(); ++i){ - JSONValue itemValue = jsonArray.get(i); - JSONString itemString = itemValue.isString(); - if(itemString == null){ - throw new FormatException("the field "" + key + "" must be a string array"); - } else { - values.add(itemString.stringValue()); + JSONArray jsonArray = jsonValue.isArray(); + if(jsonArray == null){ + throw new FormatException("the field "" + key + "" must be a string array, but is " + jsonValue); + } else { + for(int i = 0; i != jsonArray.size(); ++i){ + JSONValue itemValue = jsonArray.get(i); + JSONString itemString = itemValue.isString(); + if(itemString == null){ + throw new FormatException("the field "" + key + "" must be a string array, but is " + jsonValue); + } else { + values.add(itemString.stringValue()); + } } } } @@ -579,16 +592,21 @@ if(object.containsKey(key)){ JSONValue jsonValues = object.get(key); JSONArray jsonArray = jsonValues.isArray(); - if(jsonArray == null){ - throw new FormatException("the field "" + key + "" must be an array of JSON objects"); + if(jsonValues.isNull() != null){ + // the value must be null, so return an emtpy ArrayList + return values; } else { - for(int i = 0; i != jsonArray.size(); ++i){ - JSONValue jsonValue = jsonArray.get(i); - JSONObject jsonObject = jsonValue.isObject(); - if(jsonObject == null){ - throw new FormatException("the field "" + key + "" must be an array of JSON objects"); - } else { - values.add(jsonObject); + if(jsonArray == null){ + throw new FormatException("the field "" + key + "" must be an array of JSON objects"); + } else { + for(int i = 0; i != jsonArray.size(); ++i){ + JSONValue jsonValue = jsonArray.get(i); + JSONObject jsonObject = jsonValue.isObject(); + if(jsonObject == null){ + throw new FormatException("the field "" + key + "" must be an array of JSON objects"); + } else { + values.add(jsonObject); + } } } }
Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java Thu Jun 30 03:28:32 2011 (r535) +++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java Thu Jun 30 03:30:38 2011 (r536) @@ -29,19 +29,7 @@ private Label exportedJTMLabel = new Label(); private Label title = new Label(); private HorizontalPanel statusPanel = new HorizontalPanel(); - private String tmData = "{"version":"1.1","+ - ""item_type":"topicmap"," + - ""item_identifiers":["http://some.where/my-tm%5C"]," + - ""topics":[{"subject_identifiers":["http://some.where/my-top-1%5C"," + - ""http://some.where/my-top-1-1%5C"]," + - ""names":[{"item_identifiers":["http://some.where/my-name-ii-1%5C"]," + - ""value":"_Test_Topic_"," + - ""scope":["si:http://some.where/my-scope-1%5C"," + - ""si:http://some.where/my-scope-2%5C"]," + - ""type":"si:http://some.where/my-name-type-1%5C%22%7D%5D%7D," + - "{"subject_identifiers":["http://some.where/my-name-type-1%5C%22%5D%7D," + - "{"subject_identifiers":["http://some.where/my-scope-1%5C%22%5D%7D," + - "{"subject_identifiers":["http://some.where/my-scope-2%5C%22%5D%7D%5D%7D"; + private String tmData = "{"version":"1.1","prefixes":{"pref_1":"http://www.topicmaps.org/xtm/1.0/core.xtm#%5C%22,%5C%22pref_2%5C%22:%5C%22ht... Wolfgang","type":"si:[pref_4:first-name]","scope":null,"variants":null,"reifier":null},{"item_identifiers":null,"value":"von Goethe","type":"si:[pref_4:last-name]","scope":null,"variants":[{"item_identifiers":["[pref_8:goethe-variant]"],"datatype":"http://www.w3.org/2001/XMLSchema#string%5C%22,%5C%22value%5C%22:%5C%22Goethe... Wolfgang von Goethe","type":null,"scope":null,"variants":null,"reifier":null}],"occurrences":[{"item_identifiers":["[pref_8:goethe-occ]"],"datatype":"http://www.w3.org/2001/XMLSchema#date%5C%22,%5C%22type%5C%22:%5C%22si:%5Bpre... Zauberlehrling","type":"si:[pref_4:title]","scope":null,"variants":null,"reifier":null}],"occurrences":[{"item_identifiers":["[pref_7:occurrence]"],"datatype":"http://www.w3.org/2001/XMLSchema#string%5C%22,%5C%22type%5C%22:%5C%22si:%5Bp... der alte Hexenmeister ... sich doch einmal wegbegeben! ...","scope":["si:[pref_4:de]"],"reifier":null}]},{"subject_identifiers":null,"subject_locators":null,"item_identifiers":["[pref_8:association-reifier]"],"instance_of":["si:[pref_4:reifier-type]"],"names":null,"occurrences":null},{"subject_identifiers":null,"subject_locators":null,"item_identifiers":["[pref_8:role-reifier]"],"instance_of":["si:[pref_4:reifier-type]"],"names":null,"occurrences":null}],"associations":[{"item_identifiers":["[pref_8:association]"],"type":"si:[pref_4:written-by]","reifier":"ii:[pref_8:association-reifier]","scope":null,"roles":[{"item_identifiers":null,"type":"si:[pref_4:writer]","reifier":"ii:[pref_8:role-reifier]","player":"si:[pref_5:goethe]"},{"item_identifiers":["[pref_8:role-2]"],"type":"si:[pref_4:written]","reifier":null,"player":"si:[pref_6:zauberlehrling]"}]}],"item_type":"topicmap","reifier":null}";
@Override public void onModuleLoad() { @@ -111,10 +99,13 @@ try{ tme.importTopicMap(userInputField.getValue(), tm); }catch(FormatException fe){ + fe.printStackTrace(); Window.alert("caught error: " + fe.getMessage()); }catch(MissingReference me){ + me.printStackTrace(); Window.alert("caught error: " + me.getMessage()); }catch (Exception e){ + e.printStackTrace(); Window.alert("cought error: " + e.getMessage()); }finally { topicsLabel.setText("topics: " + tm.getTopics().length());