Changeset 4656 in josm


Ignore:
Timestamp:
Dec 12, 2011 1:37:20 PM (18 months ago)
Author:
bastiK
Message:

Fix ambiguities of empty collection vs. empty array by renaming the top level xml tags. This change breaks forward compatibility. (see #7027)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/preferences.xsd

    r4612 r4656  
    1111                                <element name="collection" type="tns:collection" /> 
    1212                                <element name="list" type="tns:list" /> 
     13                                <element name="lists" type="tns:lists" /> 
     14                                <element name="maps" type="tns:maps" /> 
    1315                        </choice> 
    1416                </sequence> 
     
    3638                            <element name="entry" type="tns:entry" minOccurs="0" maxOccurs="unbounded"/> 
    3739            </sequence> 
     40            <!-- deprecated: remove mid 2012 --> 
    3841            <sequence> 
    3942                            <element name="list" type="tns:slist" minOccurs="0" maxOccurs="unbounded"/> 
    4043            </sequence> 
     44            <!-- deprecated: remove mid 2012 --> 
    4145            <sequence> 
    4246                            <element name="map" type="tns:map" minOccurs="0" maxOccurs="unbounded"/> 
     
    4650        </complexType> 
    4751         
     52        <complexType name="lists"> 
     53        <sequence> 
     54                    <element name="list" type="tns:slist" minOccurs="0" maxOccurs="unbounded"/> 
     55        </sequence> 
     56                <attribute name="key" type="string" use="required" /> 
     57        </complexType> 
     58 
     59        <complexType name="maps"> 
     60        <sequence> 
     61                    <element name="map" type="tns:map" minOccurs="0" maxOccurs="unbounded"/> 
     62        </sequence> 
     63                <attribute name="key" type="string" use="required" /> 
     64        </complexType> 
     65 
    4866        <complexType name="slist"> 
    4967        <sequence> 
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r4635 r4656  
    13441344            } 
    13451345            public void visit(ListListSetting setting) { 
    1346                 changed = putArray(key, (Collection) setting.getValue()); 
     1346                @SuppressWarnings("unchecked") 
     1347                boolean changed = putArray(key, (Collection) setting.getValue()); 
     1348                this.changed = changed; 
    13471349            } 
    13481350            public void visit(MapListSetting setting) { 
     
    14651467                    properties.put(parser.getAttributeValue(null, "key"), parser.getAttributeValue(null, "value")); 
    14661468                    jumpToEnd(); 
    1467                 } else if (parser.getLocalName().equals("list") || parser.getLocalName().equals("collection")) { 
     1469                } else if (parser.getLocalName().equals("list") || 
     1470                        parser.getLocalName().equals("collection") || 
     1471                        parser.getLocalName().equals("lists") || 
     1472                        parser.getLocalName().equals("maps") 
     1473                ) { 
    14681474                    parseToplevelList(); 
    14691475                } else { 
     
    14891495    protected void parseToplevelList() throws XMLStreamException { 
    14901496        String key = parser.getAttributeValue(null, "key"); 
     1497        String name = parser.getLocalName(); 
     1498 
    14911499        List<String> entries = null; 
    14921500        List<List<String>> lists = null; 
     
    15201528        if (entries != null) { 
    15211529            collectionProperties.put(key, Collections.unmodifiableList(entries)); 
    1522         } 
    1523         if (lists != null) { 
     1530        } else if (lists != null) { 
    15241531            arrayProperties.put(key, Collections.unmodifiableList(lists)); 
    1525         } 
    1526         if (maps != null) { 
     1532        } else if (maps != null) { 
    15271533            listOfStructsProperties.put(key, Collections.unmodifiableList(maps)); 
     1534        } else { 
     1535            if (name.equals("lists")) { 
     1536                arrayProperties.put(key, Collections.<List<String>>emptyList()); 
     1537            } else if (name.equals("maps")) { 
     1538                listOfStructsProperties.put(key, Collections.<Map<String, String>>emptyList()); 
     1539            } else { 
     1540                collectionProperties.put(key, Collections.<String>emptyList()); 
     1541            } 
    15281542        } 
    15291543    } 
     
    16231637 
    16241638        public void visit(ListListSetting setting) { 
    1625             b.append("  <list key='").append(XmlWriter.encode(key)).append("'>\n"); 
     1639            b.append("  <lists key='").append(XmlWriter.encode(key)).append("'>\n"); 
    16261640            for (List<String> list : setting.getValue()) { 
    16271641                b.append("    <list>\n"); 
     
    16311645                b.append("    </list>\n"); 
    16321646            } 
    1633             b.append("  </list>\n"); 
     1647            b.append("  </lists>\n"); 
    16341648        } 
    16351649 
    16361650        public void visit(MapListSetting setting) { 
    1637             b.append("  <list key='").append(XmlWriter.encode(key)).append("'>\n"); 
     1651            b.append("  <maps key='").append(XmlWriter.encode(key)).append("'>\n"); 
    16381652            for (Map<String, String> struct : setting.getValue()) { 
    16391653                b.append("    <map>\n"); 
     
    16431657                b.append("    </map>\n"); 
    16441658            } 
    1645             b.append("  </list>\n"); 
     1659            b.append("  </maps>\n"); 
    16461660        } 
    16471661    } 
Note: See TracChangeset for help on using the changeset viewer.