Ticket #9327: 9327v1.patch

File 9327v1.patch, 13.8 KB (added by simon04, 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.  
    13291329        <item name="Border Control" icon="presets/douane.png" type="node">
    13301330            <label text="Edit Border Control" />
    13311331            <key key="barrier" value="border_control" />
    1332             <optional text="Allowed traffic:">
     1332            <optional text="Allowed traffic:" id="barrier">
    13331333                <check key="foot" text="Foot" default="on" />
    13341334                <check key="bicycle" text="Bicycle" default="on" />
    13351335                <check key="horse" text="Horse" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    14471447                  ru.href="http://wiki.openstreetmap.org/wiki/RU:Tag:barrier=entrance" />
    14481448            <label text="Edit Entrance (barrier opening)" />
    14491449            <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" />
    14571451            <optional>
    14581452                <text key="maxwidth" text="Max. width (meters)" length="7" />
    14591453            </optional>
    Note that for a match, at least one positive and no negative is required.  
    14681462                  ru.href="http://wiki.openstreetmap.org/wiki/RU:Tag:barrier=gate" />
    14691463            <label text="Edit Gate" />
    14701464            <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" />
    14781466            <optional>
    14791467                <text key="maxwidth" text="Max. width (meters)" length="7" />
    14801468            </optional>
    Note that for a match, at least one positive and no negative is required.  
    14881476                  ru.href="http://wiki.openstreetmap.org/wiki/RU:Tag:barrier=lift_gate" />
    14891477            <label text="Edit Lift Gate" />
    14901478            <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" />
    14981480            <optional>
    14991481                <text key="maxwidth" text="Max. width (meters)" length="7" />
    15001482            </optional>
    Note that for a match, at least one positive and no negative is required.  
    15021484        <item name="Hampshire Gate" icon="presets/empty.png" type="node">
    15031485            <label text="Edit Hampshire Gate" />
    15041486            <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" />
    15121488            <optional>
    15131489                <text key="maxwidth" text="Max. width (meters)" length="7" />
    15141490            </optional>
    Note that for a match, at least one positive and no negative is required.  
    15161492        <item name="Bump Gate" icon="presets/empty.png" type="node">
    15171493            <label text="Edit Bump Gate" />
    15181494            <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" />
    15261496            <optional>
    15271497                <text key="maxwidth" text="Max. width (meters)" length="7" />
    15281498            </optional>
    Note that for a match, at least one positive and no negative is required.  
    15441514                  pl.href="http://wiki.openstreetmap.org/wiki/Pl:Tag:barrier=chain" />
    15451515            <label text="Edit Chain" />
    15461516            <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" />
    15541518            <optional>
    15551519                <text key="maxwidth" text="Max. width (meters)" length="7" />
    15561520            </optional>
    Note that for a match, at least one positive and no negative is required.  
    15841548            <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=sally_port" />
    15851549            <label text="Edit Sally Port" />
    15861550            <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" />
    15941552            <optional>
    15951553                <text key="maxheight" text="Max. height (meters)" length="7" />
    15961554                <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  
    88                errors, elements have specified prohibited attributes -->
    99
    1010        <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>
    1221
    1322        <complexType name="root">
    1423                <complexContent>
     
    5564                                <group ref="tns:optional_elements" />
    5665                                <element name="key" type="tns:key" />
    5766                                <element name="optional" type="tns:optional" minOccurs="0" />
     67                                <element name="reference" type="tns:reference" minOccurs="0" />
    5868                        </choice>
    5969                        <element name="roles" type="tns:roles" minOccurs="0" maxOccurs="1" />
    6070                </sequence>
     
    7282                <group ref="tns:optional_elements" maxOccurs="unbounded" />
    7383                <attribute name="text" type="string" />
    7484                <attribute name="text_context" type="string" />
     85        <attribute name="id" type="ID" use="optional" />
    7586        </complexType>
    7687
     88    <complexType name="reference">
     89        <attribute name="ref" type="IDREF" use="required" />
     90    </complexType>
     91
    7792        <group name="optional_elements">
    7893                <choice>
    7994                        <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;  
    2020 */
    2121public abstract class TaggingPresetItem {
    2222
     23    public String id;
     24
    2325    protected void initAutoCompletionField(AutoCompletingTextField field, String key) {
    2426        if (Main.main == null) return;
    2527        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;  
    1010import java.io.InputStreamReader;
    1111import java.io.Reader;
    1212import java.io.UnsupportedEncodingException;
     13import java.util.ArrayList;
     14import java.util.Arrays;
    1315import java.util.Collection;
     16import java.util.HashMap;
     17import java.util.Iterator;
    1418import java.util.LinkedList;
    1519import java.util.List;
     20import java.util.Map;
    1621
    1722import javax.swing.JOptionPane;
    1823
    public final class TaggingPresetReader {  
    4550
    4651        return sources;
    4752    }
     53
     54    /**
     55     * Holds a reference to an earlier item/object.
     56     */
     57    public static class Reference {
     58        public String ref;
     59    }
    4860   
    4961    public static List<TaggingPreset> readAll(Reader in, boolean validate) throws SAXException {
    5062        XmlObjectParser parser = new XmlObjectParser();
    public final class TaggingPresetReader {  
    5365        parser.mapBoth("group", TaggingPresetMenu.class);
    5466        parser.map("text", TaggingPresetItems.Text.class);
    5567        parser.map("link", TaggingPresetItems.Link.class);
    56         parser.mapOnStart("optional", TaggingPresetItems.Optional.class);
     68        parser.mapBoth("optional", TaggingPresetItems.Optional.class);
    5769        parser.mapOnStart("roles", TaggingPresetItems.Roles.class);
    5870        parser.map("role", TaggingPresetItems.Role.class);
    5971        parser.map("checkgroup", TaggingPresetItems.CheckGroup.class);
    public final class TaggingPresetReader {  
    6577        parser.map("key", TaggingPresetItems.Key.class);
    6678        parser.map("list_entry", TaggingPresetItems.PresetListEntry.class);
    6779        parser.map("item_separator", TaggingPresetItems.ItemSeparator.class);
     80        parser.map("reference", Reference.class);
    6881       
    6982        LinkedList<TaggingPreset> all = new LinkedList<TaggingPreset>();
    7083        TaggingPresetMenu lastmenu = null;
    7184        TaggingPresetItems.Roles lastrole = null;
    7285        final List<TaggingPresetItems.Check> checks = new LinkedList<TaggingPresetItems.Check>();
    7386        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;
    7490
    7591        if (validate) {
    7692            parser.startWithValidation(in, Main.JOSM_WEBSITE+"/tagging-preset-1.0", "resource://data/tagging-preset.xsd");
    public final class TaggingPresetReader {  
    7894            parser.start(in);
    7995        }
    8096        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            }
    82133            if (!(o instanceof TaggingPresetItem) && !checks.isEmpty()) {
    83134                all.getLast().data.addAll(checks);
    84135                checks.clear();