Changeset 7889 in josm for trunk/src


Ignore:
Timestamp:
2014-12-25T21:52:53+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #10801 - presets reading: checkgroup in chunk leads to checks added multiple times

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java

    r7847 r7889  
    1010import java.io.InputStreamReader;
    1111import java.io.Reader;
    12 import java.nio.charset.StandardCharsets;
     12import java.util.ArrayDeque;
    1313import java.util.ArrayList;
    1414import java.util.Collection;
     15import java.util.Deque;
    1516import java.util.HashMap;
    1617import java.util.Iterator;
     
    1920import java.util.Map;
    2021import java.util.Set;
    21 import java.util.Stack;
    2222
    2323import javax.swing.JOptionPane;
     
    7272    }
    7373
    74     public static List<TaggingPreset> readAll(Reader in, boolean validate) throws SAXException {
     74    private static XmlObjectParser buildParser() {
    7575        XmlObjectParser parser = new XmlObjectParser();
    7676        parser.mapOnStart("item", TaggingPreset.class);
     
    9494        parser.mapBoth("chunk", Chunk.class);
    9595        parser.map("reference", Reference.class);
    96 
    97         LinkedList<TaggingPreset> all = new LinkedList<>();
     96        return parser;
     97    }
     98
     99    /**
     100     * Reads all tagging presets from the input reader.
     101     * @param in The input reader
     102     * @param validate if {@code true}, XML validation will be performed
     103     * @return collection of tagging presets
     104     * @throws SAXException if any XML error occurs
     105     */
     106    public static Collection<TaggingPreset> readAll(Reader in, boolean validate) throws SAXException {
     107        XmlObjectParser parser = buildParser();
     108
     109        Deque<TaggingPreset> all = new LinkedList<>();
    98110        TaggingPresetMenu lastmenu = null;
    99111        TaggingPresetItems.Roles lastrole = null;
     
    101113        List<TaggingPresetItems.PresetListEntry> listEntries = new LinkedList<>();
    102114        final Map<String, List<Object>> byId = new HashMap<>();
    103         final Stack<String> lastIds = new Stack<>();
     115        final Deque<String> lastIds = new ArrayDeque<>();
    104116        /** lastIdIterators contains non empty iterators of items to be handled before obtaining the next item from the XML parser */
    105         final Stack<Iterator<Object>> lastIdIterators = new Stack<>();
     117        final Deque<Iterator<Object>> lastIdIterators = new ArrayDeque<>();
    106118
    107119        if (validate) {
     
    200212                    } else if (o instanceof TaggingPresetItems.CheckGroup) {
    201213                        all.getLast().data.add((TaggingPresetItem) o);
     214                        // Make sure list of checks is empty to avoid adding checks several times
     215                        // when used in chunks (fix #10801)
     216                        ((TaggingPresetItems.CheckGroup) o).checks.clear();
    202217                        ((TaggingPresetItems.CheckGroup) o).checks.addAll(checks);
    203218                        checks.clear();
     
    229244    }
    230245
     246    /**
     247     * Reads all tagging presets from the given source.
     248     * @param source a given filename, URL or internal resource
     249     * @param validate if {@code true}, XML validation will be performed
     250     * @return collection of tagging presets
     251     * @throws SAXException if any XML error occurs
     252     * @throws IOException if any I/O error occurs
     253     */
    231254    public static Collection<TaggingPreset> readAll(String source, boolean validate) throws SAXException, IOException {
    232255        Collection<TaggingPreset> tp;
  • trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java

    r7248 r7889  
    271271    }
    272272
     273    /**
     274     * Starts parsing from the given input reader, without validation.
     275     * @param in The input reader
     276     * @return iterable collection of objects
     277     * @throws SAXException if any XML or I/O error occurs
     278     */
    273279    public Iterable<Object> start(final Reader in) throws SAXException {
    274280        try {
     
    279285    }
    280286
     287    /**
     288     * Starts parsing from the given input reader, with XSD validation.
     289     * @param in The input reader
     290     * @param namespace default namespace
     291     * @param schemaSource XSD schema
     292     * @return iterable collection of objects
     293     * @throws SAXException if any XML or I/O error occurs
     294     */
    281295    public Iterable<Object> startWithValidation(final Reader in, String namespace, String schemaSource) throws SAXException {
    282296        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Note: See TracChangeset for help on using the changeset viewer.