Changeset 6558 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-12-28T23:40:51+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java
r6552 r6558 10 10 import java.io.InputStreamReader; 11 11 import java.io.Reader; 12 import java.util.ArrayList; 12 13 import java.util.Collection; 14 import java.util.HashMap; 15 import java.util.Iterator; 13 16 import java.util.LinkedList; 14 17 import java.util.List; 18 import java.util.Map; 15 19 16 20 import javax.swing.JOptionPane; … … 44 48 45 49 return sources; 50 } 51 52 /** 53 * Holds a reference to a chunk of items/objects. 54 */ 55 public static class Chunk { 56 public String id; 57 } 58 59 /** 60 * Holds a reference to an earlier item/object. 61 */ 62 public static class Reference { 63 public String ref; 46 64 } 47 65 … … 65 83 parser.map("list_entry", TaggingPresetItems.PresetListEntry.class); 66 84 parser.map("item_separator", TaggingPresetItems.ItemSeparator.class); 67 85 parser.mapBoth("chunk", Chunk.class); 86 parser.map("reference", Reference.class); 87 68 88 LinkedList<TaggingPreset> all = new LinkedList<TaggingPreset>(); 69 89 TaggingPresetMenu lastmenu = null; … … 71 91 final List<TaggingPresetItems.Check> checks = new LinkedList<TaggingPresetItems.Check>(); 72 92 List<TaggingPresetItems.PresetListEntry> listEntries = new LinkedList<TaggingPresetItems.PresetListEntry>(); 93 final Map<String, List<Object>> byId = new HashMap<String, List<Object>>(); 94 String lastId = null; 95 Iterator<Object> lastIdIterator = null; 73 96 74 97 if (validate) { … … 78 101 } 79 102 while (parser.hasNext()) { 80 Object o = parser.next(); 103 final Object o; 104 if (lastIdIterator != null && lastIdIterator.hasNext()) { 105 // obtain elements from lastIdIterator with higher priority 106 o = lastIdIterator.next(); 107 } else { 108 o = parser.next(); 109 } 110 if (o instanceof Chunk) { 111 if (((Chunk) o).id.equals(lastId)) { 112 // reset last id on end of object, don't process further 113 lastId = null; 114 ((Chunk) o).id = null; 115 continue; 116 } else if (lastId == null) { 117 // if preset item contains an id, store a mapping for later usage 118 lastId = ((Chunk) o).id; 119 byId.put(lastId, new ArrayList<Object>()); 120 continue; 121 } else { 122 throw new IllegalStateException("Cannot deal with nested id objects (lastId was expected to be null)"); 123 } 124 } else if (lastId != null) { 125 // add object to mapping for later usage 126 byId.get(lastId).add(o); 127 continue; 128 } 129 if (o instanceof Reference) { 130 // if o is a reference, obtain the corresponding objects from the mapping, 131 // and iterate over those before consuming the next element from parser. 132 final String ref = ((Reference) o).ref; 133 if (byId.get(ref) == null) { 134 throw new SAXException(tr("Reference {0} is being used before it was defined", ref)); 135 } 136 lastIdIterator = byId.get(ref).iterator(); 137 continue; 138 } 81 139 if (!(o instanceof TaggingPresetItem) && !checks.isEmpty()) { 82 140 all.getLast().data.addAll(checks);
Note:
See TracChangeset
for help on using the changeset viewer.