Ticket #9327: 9327v2.patch

File 9327v2.patch, 27.8 KB (added by simon04, 12 years ago)
  • data/defaultpresets.xml

    diff --git a/data/defaultpresets.xml b/data/defaultpresets.xml
    index 2d4cb19..8dae8f3 100755
    a b the tags of an OSM object fit into this preset.  
    146146 - keyvalue: positive if key and value matches, negative otherwise
    147147Note that for a match, at least one positive and no negative is required.
    148148-->
     149  <chunk id="highway_base">
     150    <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
     151    <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
     152    <text key="maxspeed" text="Max. speed (km/h)" />
     153    <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     154  </chunk>
     155  <chunk id="barrier">
     156    <optional text="Allowed traffic:">
     157      <check key="foot" text="Foot" default="on" />
     158      <check key="bicycle" text="Bicycle" default="on" />
     159      <check key="horse" text="Horse" default="off" />
     160      <check key="motorcycle" text="Motorcycle" default="off" />
     161      <check key="motorcar" text="Motorcar" default="off" />
     162    </optional>
     163  </chunk>
    149164  <group name="Highways" icon="presets/way_secondary.png">
    150165    <group name="Streets" icon="presets/way_secondary.png">
    151166        <item name="Motorway" icon="presets/motorway.png" type="way">
    Note that for a match, at least one positive and no negative is required.  
    165180            <text key="ref" text="Reference" />
    166181            <optional>
    167182                <text key="name" text="Name" />
    168                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    169                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    170                 <text key="maxspeed" text="Max. speed (km/h)" />
    171                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     183                <reference ref="highway_base" />
    172184                <checkgroup columns="4">
    173185                    <check key="oneway" text="Oneway" default="on" />
    174186                    <check key="bridge" text="Bridge" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    193205            <label text="Edit Motorway Link" />
    194206            <key key="highway" value="motorway_link" />
    195207            <optional>
    196                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    197                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    198                 <text key="maxspeed" text="Max. speed (km/h)" />
    199                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     208                <reference ref="highway_base" />
    200209                <checkgroup columns="4">
    201210                    <check key="oneway" text="Oneway" default="on" />
    202211                    <check key="bridge" text="Bridge" />
    Note that for a match, at least one positive and no negative is required.  
    224233            <text key="ref" text="Reference" />
    225234            <optional>
    226235                <text key="name" text="Name" />
    227                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    228                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    229                 <text key="maxspeed" text="Max. speed (km/h)" />
    230                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     236                <reference ref="highway_base" />
    231237                <checkgroup columns="4">
    232238                    <check key="oneway" text="Oneway" default="on" />
    233239                    <check key="motorroad" text="Motorroad" default="on" />
    Note that for a match, at least one positive and no negative is required.  
    253259            <key key="highway" value="trunk_link" />
    254260            <text key="ref" text="Reference" />
    255261            <optional>
    256                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    257                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    258                 <text key="maxspeed" text="Max. speed (km/h)" />
    259                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     262                <reference ref="highway_base" />
    260263                <checkgroup columns="4">
    261264                    <check key="oneway" text="Oneway" default="on" />
    262265                    <check key="motorroad" text="Motorroad" default="on" />
    Note that for a match, at least one positive and no negative is required.  
    286289            <text key="ref" text="Reference" />
    287290            <optional>
    288291                <text key="name" text="Name" />
    289                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    290                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    291                 <text key="maxspeed" text="Max. speed (km/h)" />
    292                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     292                <reference ref="highway_base" />
    293293                <check key="oneway" text="Oneway" default="off" />
    294294                <check key="motorroad" text="Motorroad" default="off" />
    295295                <check key="bridge" text="Bridge" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    311311            <label text="Edit Primary Link" />
    312312            <key key="highway" value="primary_link" />
    313313            <optional>
    314                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    315                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    316                 <text key="maxspeed" text="Max. speed (km/h)" />
    317                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     314                <reference ref="highway_base" />
    318315                <check key="oneway" text="Oneway" default="off" />
    319316                <check key="motorroad" text="Motorroad" default="off" />
    320317                <check key="bridge" text="Bridge" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    342339            <text key="ref" text="Reference" />
    343340            <optional>
    344341                <text key="name" text="Name" />
    345                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    346                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    347                 <text key="maxspeed" text="Max. speed (km/h)" />
    348                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     342                <reference ref="highway_base" />
    349343                <check key="oneway" text="Oneway" default="off" />
    350344                <check key="bridge" text="Bridge" default="off" />
    351345                <check key="tunnel" text="Tunnel" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    366360            <label text="Edit Secondary Link" />
    367361            <key key="highway" value="secondary_link" />
    368362            <optional>
    369                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    370                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    371                 <text key="maxspeed" text="Max. speed (km/h)" />
    372                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     363                <reference ref="highway_base" />
    373364                <check key="oneway" text="Oneway" default="off" />
    374365                <check key="bridge" text="Bridge" default="off" />
    375366                <check key="tunnel" text="Tunnel" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    397388            <text key="ref" text="Reference" />
    398389            <optional>
    399390                <text key="name" text="Name" />
    400                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    401                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    402                 <text key="maxspeed" text="Max. speed (km/h)" />
    403                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     391                <reference ref="highway_base" />
    404392                <check key="oneway" text="Oneway" default="off" />
    405393                <check key="bridge" text="Bridge" default="off" />
    406394                <check key="tunnel" text="Tunnel" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    421409            <label text="Edit Tertiary Link" />
    422410            <key key="highway" value="tertiary_link" />
    423411            <optional>
    424                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    425                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    426                 <text key="maxspeed" text="Max. speed (km/h)" />
    427                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     412                <reference ref="highway_base" />
    428413                <check key="oneway" text="Oneway" default="off" />
    429414                <check key="bridge" text="Bridge" default="off" />
    430415                <check key="tunnel" text="Tunnel" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    449434            <optional>
    450435                <text key="name" text="Name" />
    451436                <text key="ref" text="Reference" />
    452                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    453                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    454                 <text key="maxspeed" text="Max. speed (km/h)" />
    455                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     437                <reference ref="highway_base" />
    456438                <check key="oneway" text="Oneway" default="off" />
    457439                <check key="bridge" text="Bridge" default="off" />
    458440                <check key="tunnel" text="Tunnel" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    479461            <key key="highway" value="residential" />
    480462            <text key="name" text="Name" />
    481463            <optional>
    482                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    483                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    484                 <text key="maxspeed" text="Max. speed (km/h)" />
    485                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     464                <reference ref="highway_base" />
    486465                <check key="oneway" text="Oneway" default="off" />
    487466                <check key="bridge" text="Bridge" default="off" />
    488467                <check key="tunnel" text="Tunnel" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    591570            <combo key="service" text="Service way type" values="alley,driveway,parking_aisle,drive-through" />
    592571            <optional>
    593572                <text key="name" text="Name" />
    594                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    595                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    596                 <text key="maxspeed" text="Max. speed (km/h)" />
    597                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     573                <reference ref="highway_base" />
    598574                <check key="oneway" text="Oneway" default="off" />
    599575                <check key="bridge" text="Bridge" default="off" />
    600576                <check key="tunnel" text="Tunnel" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    637613            <key key="highway" value="road" />
    638614            <optional>
    639615                <text key="name" text="Name" />
    640                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    641                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    642                 <text key="maxspeed" text="Max. speed (km/h)" />
    643                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     616                <reference ref="highway_base" />
    644617                <check key="oneway" text="Oneway" default="off" />
    645618                <check key="bridge" text="Bridge" default="off" />
    646619                <check key="tunnel" text="Tunnel" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    663636            <key key="highway" value="construction" />
    664637            <optional>
    665638                <text key="name" text="Name" />
    666                 <combo key="layer" text="Layer" values="5,4,3,2,1,0,-1,-2,-3,-4,-5" length="3" />
    667                 <combo key="lanes" text="Lanes" values="1,2,3,4,5" length="3" />
    668                 <text key="maxspeed" text="Max. speed (km/h)" />
    669                 <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" />
     639                <reference ref="highway_base" />
    670640                <check key="oneway" text="Oneway" default="off" />
    671641                <check key="bridge" text="Bridge" default="off" />
    672642                <check key="tunnel" text="Tunnel" default="off" />
    Note that for a match, at least one positive and no negative is required.  
    14471417                  ru.href="http://wiki.openstreetmap.org/wiki/RU:Tag:barrier=entrance" />
    14481418            <label text="Edit Entrance (barrier opening)" />
    14491419            <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>
     1420            <reference ref="barrier" />
    14571421            <optional>
    14581422                <text key="maxwidth" text="Max. width (meters)" length="7" />
    14591423            </optional>
    Note that for a match, at least one positive and no negative is required.  
    14681432                  ru.href="http://wiki.openstreetmap.org/wiki/RU:Tag:barrier=gate" />
    14691433            <label text="Edit Gate" />
    14701434            <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>
     1435            <reference ref="barrier" />
    14781436            <optional>
    14791437                <text key="maxwidth" text="Max. width (meters)" length="7" />
    14801438            </optional>
    Note that for a match, at least one positive and no negative is required.  
    14881446                  ru.href="http://wiki.openstreetmap.org/wiki/RU:Tag:barrier=lift_gate" />
    14891447            <label text="Edit Lift Gate" />
    14901448            <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>
     1449            <reference ref="barrier" />
    14981450            <optional>
    14991451                <text key="maxwidth" text="Max. width (meters)" length="7" />
    15001452            </optional>
    Note that for a match, at least one positive and no negative is required.  
    15021454        <item name="Hampshire Gate" icon="presets/empty.png" type="node">
    15031455            <label text="Edit Hampshire Gate" />
    15041456            <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>
     1457            <reference ref="barrier" />
    15121458            <optional>
    15131459                <text key="maxwidth" text="Max. width (meters)" length="7" />
    15141460            </optional>
    Note that for a match, at least one positive and no negative is required.  
    15161462        <item name="Bump Gate" icon="presets/empty.png" type="node">
    15171463            <label text="Edit Bump Gate" />
    15181464            <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>
     1465            <reference ref="barrier" />
    15261466            <optional>
    15271467                <text key="maxwidth" text="Max. width (meters)" length="7" />
    15281468            </optional>
    Note that for a match, at least one positive and no negative is required.  
    15441484                  pl.href="http://wiki.openstreetmap.org/wiki/Pl:Tag:barrier=chain" />
    15451485            <label text="Edit Chain" />
    15461486            <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>
     1487            <reference ref="barrier" />
    15541488            <optional>
    15551489                <text key="maxwidth" text="Max. width (meters)" length="7" />
    15561490            </optional>
    Note that for a match, at least one positive and no negative is required.  
    15841518            <link href="http://wiki.openstreetmap.org/wiki/Tag:highway=sally_port" />
    15851519            <label text="Edit Sally Port" />
    15861520            <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>
     1521            <reference ref="barrier" />
    15941522            <optional>
    15951523                <text key="maxheight" text="Max. height (meters)" length="7" />
    15961524                <text key="maxwidth" text="Max. width (meters)" length="7" />
    Note that for a match, at least one positive and no negative is required.  
    16051533                  fr.href="http://wiki.openstreetmap.org/wiki/FR:Key:tunnel"
    16061534                  it.href="http://wiki.openstreetmap.org/wiki/IT:Key:tunnel"
    16071535                  ja.href="http://wiki.openstreetmap.org/wiki/JA:Key:tunnel"
    1608                   pt_BR.href="http://wiki.openstreetmap.org/wiki/Pt-br:Key:tunnel"
     1536                  pt_BR.href="http://wiki.openstreetmap.org/wiki/PtsetMinimumSize-br:Key:tunnel"
    16091537                  ru.href="http://wiki.openstreetmap.org/wiki/RU:Key:tunnel"
    16101538                  uk.href="http://wiki.openstreetmap.org/wiki/Uk:Key:tunnel" />
    16111539            <label text="Edit Tunnel" />
  • data/tagging-preset.xsd

    diff --git a/data/tagging-preset.xsd b/data/tagging-preset.xsd
    index 1ec6353..b7b23cb 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="chunk_id">
     13                        <selector xpath=".//tns:chunk"/>
     14                        <field xpath="@id"/>
     15                </unique>
     16                <keyref name="chunk_ref" refer="tns:chunk_id">
     17                        <selector xpath=".//tns:reference"/>
     18                        <field xpath="@ref"/>
     19                </keyref>
     20        </element>
    1221
    1322        <complexType name="root">
    1423                <complexContent>
     
    2736        <complexType name="group-parent">
    2837                <sequence>
    2938                        <choice minOccurs="1" maxOccurs="unbounded">
     39                                <element name="chunk" type="tns:chunk"/>
    3040                                <element name="group" type="tns:group" />
    3141                                <element name="item" type="tns:item" />
    3242                                <element name="separator" type="tns:separator" />
     
    7484                <attribute name="text_context" type="string" />
    7585        </complexType>
    7686
     87    <complexType name="chunk">
     88        <sequence>
     89            <choice minOccurs="1" maxOccurs="unbounded">
     90                <group ref="tns:optional_elements" />
     91                <element name="key" type="tns:key" />
     92                <element name="optional" type="tns:optional" minOccurs="0" />
     93            </choice>
     94        </sequence>
     95        <attribute name="id" type="ID" use="required" />
     96    </complexType>
     97
     98    <complexType name="reference">
     99        <attribute name="ref" type="IDREF" use="required" />
     100    </complexType>
     101
    77102        <group name="optional_elements">
    78103                <choice>
    79104                        <element name="label" type="tns:label" />
     
    85110                        <element name="checkgroup" type="tns:checkgroup" />
    86111                        <element name="check" type="tns:check" />
    87112                        <element name="item_separator" type="tns:separator" />
     113                        <element name="reference" type="tns:reference" />
    88114                </choice>
    89115        </group>
    90116
  • 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..87dbb03 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 a chunk of  items/objects.
     56     */
     57    public static class Chunk {
     58        public String id;
     59    }
     60
     61    /**
     62     * Holds a reference to an earlier item/object.
     63     */
     64    public static class Reference {
     65        public String ref;
     66    }
    4867   
    4968    public static List<TaggingPreset> readAll(Reader in, boolean validate) throws SAXException {
    5069        XmlObjectParser parser = new XmlObjectParser();
    public final class TaggingPresetReader {  
    6584        parser.map("key", TaggingPresetItems.Key.class);
    6685        parser.map("list_entry", TaggingPresetItems.PresetListEntry.class);
    6786        parser.map("item_separator", TaggingPresetItems.ItemSeparator.class);
    68        
     87        parser.mapBoth("chunk", Chunk.class);
     88        parser.map("reference", Reference.class);
     89
    6990        LinkedList<TaggingPreset> all = new LinkedList<TaggingPreset>();
    7091        TaggingPresetMenu lastmenu = null;
    7192        TaggingPresetItems.Roles lastrole = null;
    7293        final List<TaggingPresetItems.Check> checks = new LinkedList<TaggingPresetItems.Check>();
    7394        List<TaggingPresetItems.PresetListEntry> listEntries = new LinkedList<TaggingPresetItems.PresetListEntry>();
     95        final Map<String, List<Object>> byId = new HashMap<String, List<Object>>();
     96        String lastId = null;
     97        Iterator<Object> lastIdIterator = null;
    7498
    7599        if (validate) {
    76100            parser.startWithValidation(in, Main.JOSM_WEBSITE+"/tagging-preset-1.0", "resource://data/tagging-preset.xsd");
    public final class TaggingPresetReader {  
    78102            parser.start(in);
    79103        }
    80104        while (parser.hasNext()) {
    81             Object o = parser.next();
     105            final Object o;
     106            if (lastIdIterator != null && lastIdIterator.hasNext()) {
     107                // obtain elements from lastIdIterator with higher priority
     108                o = lastIdIterator.next();
     109            } else {
     110                o = parser.next();
     111            }
     112            if (o instanceof Chunk) {
     113                if (((Chunk) o).id.equals(lastId)) {
     114                    // reset last id on end of object, don't process further
     115                    lastId = null;
     116                    ((Chunk) o).id = null;
     117                    continue;
     118                } else if (lastId == null) {
     119                    // if preset item contains an id, store a mapping for later usage
     120                    lastId = ((Chunk) o).id;
     121                    byId.put(lastId, new ArrayList<Object>());
     122                    continue;
     123                } else {
     124                    throw new IllegalStateException("Cannot deal with nested id objects (lastId was expected to be null)");
     125                }
     126            } else if (lastId != null) {
     127                // add object to mapping for later usage
     128                byId.get(lastId).add(o);
     129                continue;
     130            }
     131            if (o instanceof Reference) {
     132                // if o is a reference, obtain the corresponding objects from the mapping,
     133                // and iterate over those before consuming the next element from parser.
     134                final String ref = ((Reference) o).ref;
     135                if (byId.get(ref) == null) {
     136                    throw new SAXException(tr("Reference {0} is being used before it was defined", ref));
     137                }
     138                lastIdIterator = byId.get(ref).iterator();
     139                continue;
     140            }
    82141            if (!(o instanceof TaggingPresetItem) && !checks.isEmpty()) {
    83142                all.getLast().data.addAll(checks);
    84143                checks.clear();