Ticket #9327: 9327v1.patch
| File 9327v1.patch, 13.8 KB (added by , 12 years ago) |
|---|
-
data/defaultpresets.xml
diff --git a/data/defaultpresets.xml b/data/defaultpresets.xml index 1af1e86..e877a2d 100755
a b Note that for a match, at least one positive and no negative is required. 1329 1329 <item name="Border Control" icon="presets/douane.png" type="node"> 1330 1330 <label text="Edit Border Control" /> 1331 1331 <key key="barrier" value="border_control" /> 1332 <optional text="Allowed traffic:" >1332 <optional text="Allowed traffic:" id="barrier"> 1333 1333 <check key="foot" text="Foot" default="on" /> 1334 1334 <check key="bicycle" text="Bicycle" default="on" /> 1335 1335 <check key="horse" text="Horse" default="off" /> … … Note that for a match, at least one positive and no negative is required. 1447 1447 ru.href="http://wiki.openstreetmap.org/wiki/RU:Tag:barrier=entrance" /> 1448 1448 <label text="Edit Entrance (barrier opening)" /> 1449 1449 <key key="barrier" value="entrance" /> 1450 <optional text="Allowed traffic:"> 1451 <check key="foot" text="Foot" default="on" /> 1452 <check key="bicycle" text="Bicycle" default="on" /> 1453 <check key="horse" text="Horse" default="off" /> 1454 <check key="motorcycle" text="Motorcycle" default="off" /> 1455 <check key="motorcar" text="Motorcar" default="off" /> 1456 </optional> 1450 <reference ref="barrier" /> 1457 1451 <optional> 1458 1452 <text key="maxwidth" text="Max. width (meters)" length="7" /> 1459 1453 </optional> … … Note that for a match, at least one positive and no negative is required. 1468 1462 ru.href="http://wiki.openstreetmap.org/wiki/RU:Tag:barrier=gate" /> 1469 1463 <label text="Edit Gate" /> 1470 1464 <key key="barrier" value="gate" /> 1471 <optional text="Allowed traffic:"> 1472 <check key="foot" text="Foot" default="on" /> 1473 <check key="bicycle" text="Bicycle" default="on" /> 1474 <check key="horse" text="Horse" default="off" /> 1475 <check key="motorcycle" text="Motorcycle" default="off" /> 1476 <check key="motorcar" text="Motorcar" default="off" /> 1477 </optional> 1465 <reference ref="barrier" /> 1478 1466 <optional> 1479 1467 <text key="maxwidth" text="Max. width (meters)" length="7" /> 1480 1468 </optional> … … Note that for a match, at least one positive and no negative is required. 1488 1476 ru.href="http://wiki.openstreetmap.org/wiki/RU:Tag:barrier=lift_gate" /> 1489 1477 <label text="Edit Lift Gate" /> 1490 1478 <key key="barrier" value="lift_gate" /> 1491 <optional text="Allowed traffic:"> 1492 <check key="foot" text="Foot" default="on" /> 1493 <check key="bicycle" text="Bicycle" default="on" /> 1494 <check key="horse" text="Horse" default="off" /> 1495 <check key="motorcycle" text="Motorcycle" default="off" /> 1496 <check key="motorcar" text="Motorcar" default="off" /> 1497 </optional> 1479 <reference ref="barrier" /> 1498 1480 <optional> 1499 1481 <text key="maxwidth" text="Max. width (meters)" length="7" /> 1500 1482 </optional> … … Note that for a match, at least one positive and no negative is required. 1502 1484 <item name="Hampshire Gate" icon="presets/empty.png" type="node"> 1503 1485 <label text="Edit Hampshire Gate" /> 1504 1486 <key key="barrier" value="hampshire_gate" /> 1505 <optional text="Allowed traffic:"> 1506 <check key="foot" text="Foot" default="on" /> 1507 <check key="bicycle" text="Bicycle" default="on" /> 1508 <check key="horse" text="Horse" default="off" /> 1509 <check key="motorcycle" text="Motorcycle" default="off" /> 1510 <check key="motorcar" text="Motorcar" default="off" /> 1511 </optional> 1487 <reference ref="barrier" /> 1512 1488 <optional> 1513 1489 <text key="maxwidth" text="Max. width (meters)" length="7" /> 1514 1490 </optional> … … Note that for a match, at least one positive and no negative is required. 1516 1492 <item name="Bump Gate" icon="presets/empty.png" type="node"> 1517 1493 <label text="Edit Bump Gate" /> 1518 1494 <key key="barrier" value="bump_gate" /> 1519 <optional text="Allowed traffic:"> 1520 <check key="foot" text="Foot" default="on" /> 1521 <check key="bicycle" text="Bicycle" default="on" /> 1522 <check key="horse" text="Horse" default="off" /> 1523 <check key="motorcycle" text="Motorcycle" default="off" /> 1524 <check key="motorcar" text="Motorcar" default="off" /> 1525 </optional> 1495 <reference ref="barrier" /> 1526 1496 <optional> 1527 1497 <text key="maxwidth" text="Max. width (meters)" length="7" /> 1528 1498 </optional> … … Note that for a match, at least one positive and no negative is required. 1544 1514 pl.href="http://wiki.openstreetmap.org/wiki/Pl:Tag:barrier=chain" /> 1545 1515 <label text="Edit Chain" /> 1546 1516 <key key="barrier" value="chain" /> 1547 <optional text="Allowed traffic:"> 1548 <check key="foot" text="Foot" default="on" /> 1549 <check key="bicycle" text="Bicycle" default="on" /> 1550 <check key="horse" text="Horse" default="off" /> 1551 <check key="motorcycle" text="Motorcycle" default="off" /> 1552 <check key="motorcar" text="Motorcar" default="off" /> 1553 </optional> 1517 <reference ref="barrier" /> 1554 1518 <optional> 1555 1519 <text key="maxwidth" text="Max. width (meters)" length="7" /> 1556 1520 </optional> … … Note that for a match, at least one positive and no negative is required. 1584 1548 <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=sally_port" /> 1585 1549 <label text="Edit Sally Port" /> 1586 1550 <key key="barrier" value="sally_port" /> 1587 <optional text="Allowed traffic:"> 1588 <check key="foot" text="Foot" default="on" /> 1589 <check key="bicycle" text="Bicycle" default="on" /> 1590 <check key="horse" text="Horse" default="off" /> 1591 <check key="motorcycle" text="Motorcycle" default="off" /> 1592 <check key="motorcar" text="Motorcar" default="off" /> 1593 </optional> 1551 <reference ref="barrier" /> 1594 1552 <optional> 1595 1553 <text key="maxheight" text="Max. height (meters)" length="7" /> 1596 1554 <text key="maxwidth" text="Max. width (meters)" length="7" /> -
data/tagging-preset.xsd
diff --git a/data/tagging-preset.xsd b/data/tagging-preset.xsd index 1ec6353..c7ea4c0 100644
a b 8 8 errors, elements have specified prohibited attributes --> 9 9 10 10 <element name="annotations" type="tns:root" /> 11 <element name="presets" type="tns:root" /> 11 <element name="presets" type="tns:root"> 12 <unique name="optional_id"> 13 <selector xpath=".//tns:optional"/> 14 <field xpath="@id"/> 15 </unique> 16 <keyref name="optional_ref" refer="tns:optional_id"> 17 <selector xpath=".//tns:reference"/> 18 <field xpath="@ref"/> 19 </keyref> 20 </element> 12 21 13 22 <complexType name="root"> 14 23 <complexContent> … … 55 64 <group ref="tns:optional_elements" /> 56 65 <element name="key" type="tns:key" /> 57 66 <element name="optional" type="tns:optional" minOccurs="0" /> 67 <element name="reference" type="tns:reference" minOccurs="0" /> 58 68 </choice> 59 69 <element name="roles" type="tns:roles" minOccurs="0" maxOccurs="1" /> 60 70 </sequence> … … 72 82 <group ref="tns:optional_elements" maxOccurs="unbounded" /> 73 83 <attribute name="text" type="string" /> 74 84 <attribute name="text_context" type="string" /> 85 <attribute name="id" type="ID" use="optional" /> 75 86 </complexType> 76 87 88 <complexType name="reference"> 89 <attribute name="ref" type="IDREF" use="required" /> 90 </complexType> 91 77 92 <group name="optional_elements"> 78 93 <choice> 79 94 <element name="label" type="tns:label" /> -
src/org/openstreetmap/josm/gui/tagging/TaggingPresetItem.java
diff --git a/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItem.java b/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItem.java index 3b66147..f9c569e 100644
a b import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 20 20 */ 21 21 public abstract class TaggingPresetItem { 22 22 23 public String id; 24 23 25 protected void initAutoCompletionField(AutoCompletingTextField field, String key) { 24 26 if (Main.main == null) return; 25 27 OsmDataLayer layer = Main.main.getEditLayer(); -
src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java
diff --git a/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java b/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java index 0efe5fe..86c0ed9 100644
a b import java.io.InputStream; 10 10 import java.io.InputStreamReader; 11 11 import java.io.Reader; 12 12 import java.io.UnsupportedEncodingException; 13 import java.util.ArrayList; 14 import java.util.Arrays; 13 15 import java.util.Collection; 16 import java.util.HashMap; 17 import java.util.Iterator; 14 18 import java.util.LinkedList; 15 19 import java.util.List; 20 import java.util.Map; 16 21 17 22 import javax.swing.JOptionPane; 18 23 … … public final class TaggingPresetReader { 45 50 46 51 return sources; 47 52 } 53 54 /** 55 * Holds a reference to an earlier item/object. 56 */ 57 public static class Reference { 58 public String ref; 59 } 48 60 49 61 public static List<TaggingPreset> readAll(Reader in, boolean validate) throws SAXException { 50 62 XmlObjectParser parser = new XmlObjectParser(); … … public final class TaggingPresetReader { 53 65 parser.mapBoth("group", TaggingPresetMenu.class); 54 66 parser.map("text", TaggingPresetItems.Text.class); 55 67 parser.map("link", TaggingPresetItems.Link.class); 56 parser.map OnStart("optional", TaggingPresetItems.Optional.class);68 parser.mapBoth("optional", TaggingPresetItems.Optional.class); 57 69 parser.mapOnStart("roles", TaggingPresetItems.Roles.class); 58 70 parser.map("role", TaggingPresetItems.Role.class); 59 71 parser.map("checkgroup", TaggingPresetItems.CheckGroup.class); … … public final class TaggingPresetReader { 65 77 parser.map("key", TaggingPresetItems.Key.class); 66 78 parser.map("list_entry", TaggingPresetItems.PresetListEntry.class); 67 79 parser.map("item_separator", TaggingPresetItems.ItemSeparator.class); 80 parser.map("reference", Reference.class); 68 81 69 82 LinkedList<TaggingPreset> all = new LinkedList<TaggingPreset>(); 70 83 TaggingPresetMenu lastmenu = null; 71 84 TaggingPresetItems.Roles lastrole = null; 72 85 final List<TaggingPresetItems.Check> checks = new LinkedList<TaggingPresetItems.Check>(); 73 86 List<TaggingPresetItems.PresetListEntry> listEntries = new LinkedList<TaggingPresetItems.PresetListEntry>(); 87 final Map<String, List<Object>> byId = new HashMap<String, List<Object>>(); 88 String lastId = null; 89 Iterator<Object> lastIdIterator = null; 74 90 75 91 if (validate) { 76 92 parser.startWithValidation(in, Main.JOSM_WEBSITE+"/tagging-preset-1.0", "resource://data/tagging-preset.xsd"); … … public final class TaggingPresetReader { 78 94 parser.start(in); 79 95 } 80 96 while (parser.hasNext()) { 81 Object o = parser.next(); 97 final Object o; 98 if (lastIdIterator != null && lastIdIterator.hasNext()) { 99 // obtain elements from lastIdIterator with higher priority 100 o = lastIdIterator.next(); 101 System.out.println(o); 102 } else { 103 o = parser.next(); 104 } 105 if (o instanceof TaggingPresetItem && ((TaggingPresetItem) o).id != null) { 106 if (((TaggingPresetItem) o).id.equals(lastId)) { 107 // reset last id on end of object, don't process further 108 lastId = null; 109 ((TaggingPresetItem) o).id = null; 110 continue; 111 } else if (lastId == null) { 112 // if preset item contains an id, store a mapping for later usage 113 lastId = ((TaggingPresetItem) o).id; 114 byId.put(lastId, new ArrayList<Object>(Arrays.asList(o))); 115 } else { 116 throw new IllegalStateException("Cannot deal with nested id objects (lastId was expected to be null)"); 117 } 118 } else if (lastId != null) { 119 // add object to mapping for later usage 120 byId.get(lastId).add(o); 121 } 122 if (o instanceof Reference) { 123 // if o is a reference, obtain the corresponding objects from the mapping, 124 // and iterate over those before consuming the next element from parser. 125 final String ref = ((Reference) o).ref; 126 if (byId.get(ref) == null) { 127 throw new SAXException(tr("Reference {0} is being used before it was defined", ref)); 128 } 129 System.out.println(ref + byId.get(ref)); 130 lastIdIterator = byId.get(ref).iterator(); 131 continue; 132 } 82 133 if (!(o instanceof TaggingPresetItem) && !checks.isEmpty()) { 83 134 all.getLast().data.addAll(checks); 84 135 checks.clear();
