Changeset 7704 in josm


Ignore:
Timestamp:
2014-11-04T02:33:20+01:00 (9 years ago)
Author:
Don-vip
Message:

see #10701 - parsing support of changeset discussions

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Changeset.java

    r7700 r7704  
    22package org.openstreetmap.josm.data.osm;
    33
     4import java.util.ArrayList;
    45import java.util.Collection;
     6import java.util.Collections;
    57import java.util.Date;
    68import java.util.HashMap;
     9import java.util.List;
    710import java.util.Map;
    811
     
    3942    /** the map of tags */
    4043    private Map<String,String> tags;
    41     /** indicates whether this changeset is incomplete. For an
    42      * incomplete changeset we only know its id
    43      */
     44    /** indicates whether this changeset is incomplete. For an incomplete changeset we only know its id */
    4445    private boolean incomplete;
    4546    /** the changeset content */
    4647    private ChangesetDataSet content = null;
     48    /** the changeset discussion */
     49    private List<ChangesetDiscussionComment> discussion = null;
    4750
    4851    /**
     
    328331        this.content = content;
    329332    }
     333
     334    /**
     335     * Replies the list of comments in the changeset discussion, if any.
     336     * @return the list of comments in the changeset discussion. May be empty but never null
     337     * @since 7704
     338     */
     339    public synchronized final List<ChangesetDiscussionComment> getDiscussion() {
     340        if (discussion == null) {
     341            return Collections.emptyList();
     342        }
     343        return new ArrayList<>(discussion);
     344    }
     345
     346    /**
     347     * Adds a comment to the changeset discussion.
     348     * @param comment the comment to add. Ignored if null
     349     * @since 7704
     350     */
     351    public synchronized final void addDiscussionComment(ChangesetDiscussionComment comment) {
     352        if (comment == null) {
     353            return;
     354        }
     355        if (discussion == null) {
     356            discussion = new ArrayList<>();
     357        }
     358        discussion.add(comment);
     359    }
    330360}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java

    r7434 r7704  
    181181        model.addPropertyChangeListener(pnlChangesetContent);
    182182
     183        // -- add the panel for the changeset discussion
     184        ChangesetDiscussionPanel pnlChangesetDiscussion = new ChangesetDiscussionPanel();
     185        tp.add(pnlChangesetDiscussion);
     186        model.addPropertyChangeListener(pnlChangesetDiscussion);
     187
    183188        tp.setTitleAt(0, tr("Properties"));
    184189        tp.setToolTipTextAt(0, tr("Display the basic properties of the changeset"));
     
    187192        tp.setTitleAt(2, tr("Content"));
    188193        tp.setToolTipTextAt(2, tr("Display the objects created, updated, and deleted by the changeset"));
     194        tp.setTitleAt(3, tr("Discussion"));
     195        tp.setToolTipTextAt(3, tr("Display the public discussion around this changeset"));
    189196
    190197        pnl.add(tp, BorderLayout.CENTER);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentDownloadTask.java

    r7005 r7704  
    135135            reader = new OsmServerChangesetReader();
    136136        }
    137         Changeset cs = reader.readChangeset(changesetId, getProgressMonitor().createSubTaskMonitor(0, false));
     137        Changeset cs = reader.readChangeset(changesetId, false, getProgressMonitor().createSubTaskMonitor(0, false));
    138138        synchronized(this) {
    139139            reader = null;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java

    r7509 r7704  
    5353
    5454/**
    55  * The panel which displays the content of a changeset in a scollable table.
     55 * The panel which displays the content of a changeset in a scrollable table.
    5656 *
    5757 * It listens to property change events for {@link ChangesetCacheManagerModel#CHANGESET_IN_DETAIL_VIEW_PROP}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetHeaderDownloadTask.java

    r7005 r7704  
    8484    private Exception lastException;
    8585    private Set<Changeset> downloadedChangesets;
     86    private final boolean includeDiscussion;
    8687
    8788    protected void init(Collection<Integer> ids) {
     
    112113        super(tr("Download changesets"), false /* don't ignore exceptions */);
    113114        init(ids);
     115        this.includeDiscussion = false;
    114116    }
    115117
     
    125127     */
    126128    public ChangesetHeaderDownloadTask(Component dialogParent, Collection<Integer> ids) throws IllegalArgumentException{
    127         super(dialogParent,tr("Download changesets"), false /* don't ignore exceptions */);
     129        this(dialogParent, ids, false);
     130    }
     131
     132    /**
     133     * Creates the download task for a collection of changeset ids, with possibility to download changeset discussion.
     134     * Uses a {@link org.openstreetmap.josm.gui.PleaseWaitDialog} whose parent is the parent window of <code>dialogParent</code>.
     135     *
     136     * Null ids or or ids &lt;= 0 in the id collection are ignored.
     137     *
     138     * @param dialogParent the parent reference component for the {@link org.openstreetmap.josm.gui.PleaseWaitDialog}. Must not be null.
     139     * @param ids the collection of ids. Empty collection assumed if null.
     140     * @param includeDiscussion determines if discussion comments must be downloaded or not
     141     * @throws IllegalArgumentException thrown if dialogParent is null
     142     * @since 7704
     143     */
     144    public ChangesetHeaderDownloadTask(Component dialogParent, Collection<Integer> ids, boolean includeDiscussion)
     145            throws IllegalArgumentException {
     146        super(dialogParent, tr("Download changesets"), false /* don't ignore exceptions */);
    128147        init(ids);
     148        this.includeDiscussion = includeDiscussion;
    129149    }
    130150
     
    180200            }
    181201            downloadedChangesets = new HashSet<>();
    182             downloadedChangesets.addAll(reader.readChangesets(idsToDownload, getProgressMonitor().createSubTaskMonitor(0, false)));
     202            downloadedChangesets.addAll(reader.readChangesets(idsToDownload, includeDiscussion,
     203                    getProgressMonitor().createSubTaskMonitor(0, false)));
    183204        } catch(OsmTransferException e) {
    184205            if (canceled)
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java

    r7700 r7704  
    88import java.nio.charset.StandardCharsets;
    99import java.text.MessageFormat;
     10import java.util.Date;
    1011import java.util.LinkedList;
    1112import java.util.List;
     
    1617import org.openstreetmap.josm.data.coor.LatLon;
    1718import org.openstreetmap.josm.data.osm.Changeset;
     19import org.openstreetmap.josm.data.osm.ChangesetDiscussionComment;
    1820import org.openstreetmap.josm.data.osm.User;
    1921import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    7072        private Changeset current = null;
    7173
     74        /** The current comment */
     75        private ChangesetDiscussionComment comment = null;
     76
     77        /** The current comment text */
     78        private StringBuilder text = null;
     79
    7280        protected void parseChangesetAttributes(Changeset cs, Attributes atts) throws XmlParsingException {
    7381            // -- id
     
    7886            current.setId(parseNumericAttribute(value, 1));
    7987
    80             // -- user
    81             String user = atts.getValue("user");
    82             String uid = atts.getValue("uid");
    83             current.setUser(createUser(uid, user));
     88            // -- user / uid
     89            current.setUser(createUser(atts));
    8490
    8591            // -- created_at
     
    155161        }
    156162
     163        private void parseCommentAttributes(Attributes atts) throws XmlParsingException {
     164            // -- date
     165            String value = atts.getValue("date");
     166            Date date = null;
     167            if (value != null) {
     168                date = DateUtils.fromString(value);
     169            }
     170
     171            comment = new ChangesetDiscussionComment(date, createUser(atts));
     172        }
     173
    157174        private int parseNumericAttribute(String value, int minAllowed) throws XmlParsingException {
    158175            int att = 0;
     
    193210                current.put(key, value);
    194211                break;
     212            case "discussion":
     213                break;
     214            case "comment":
     215                parseCommentAttributes(atts);
     216                break;
     217            case "text":
     218                text = new StringBuilder();
     219                break;
    195220            default:
    196221                throwException(tr("Undefined element ''{0}'' found in input stream. Aborting.", qName));
     222            }
     223        }
     224
     225        @Override
     226        public void characters(char[] ch, int start, int length) throws SAXException {
     227            if (text != null) {
     228                text.append(ch, start, length);
    197229            }
    198230        }
     
    202234            if ("changeset".equals(qName)) {
    203235                changesets.add(current);
    204             }
    205         }
    206 
    207         protected User createUser(String uid, String name) throws XmlParsingException {
     236                current = null;
     237            } else if ("comment".equals(qName)) {
     238                current.addDiscussionComment(comment);
     239                comment = null;
     240            } else if ("text".equals(qName)) {
     241                comment.setText(text.toString());
     242                text = null;
     243            }
     244        }
     245
     246        protected User createUser(Attributes atts) throws XmlParsingException {
     247            String name = atts.getValue("user");
     248            String uid = atts.getValue("uid");
    208249            if (uid == null) {
    209250                if (name == null)
  • trunk/src/org/openstreetmap/josm/io/OsmServerChangesetReader.java

    r7033 r7704  
    2929
    3030    /**
    31      * constructor
    32      *
    33      */
    34     public OsmServerChangesetReader(){
     31     * Constructs a new {@code OsmServerChangesetReader}.
     32     */
     33    public OsmServerChangesetReader() {
    3534        setDoAuthenticate(false);
    3635    }
     
    3837    /**
    3938     * don't use - not implemented!
    40      *
    4139     */
    4240    @Override
    4341    public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException {
    4442        return null;
     43    }
     44
     45    protected final InputStream getChangesetInputStream(long id, boolean includeDiscussion, ProgressMonitor monitor)
     46            throws OsmTransferException {
     47        StringBuilder sb = new StringBuilder();
     48        sb.append("changeset/").append(id);
     49        if (includeDiscussion) {
     50            sb.append("?include_discussion=true");
     51        }
     52        return getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true));
    4553    }
    4654
     
    8290
    8391    /**
    84      * Reads the changeset with id <code>id</code> from the server
     92     * Reads the changeset with id <code>id</code> from the server.
    8593     *
    86      * @param id  the changeset id. id &gt; 0 required.
     94     * @param id the changeset id. id &gt; 0 required.
     95     * @param includeDiscussion determines if discussion comments must be downloaded or not
    8796     * @param monitor the progress monitor. Set to {@link NullProgressMonitor#INSTANCE} if null
    8897     * @return the changeset read
    8998     * @throws OsmTransferException thrown if something goes wrong
    9099     * @throws IllegalArgumentException if id &lt;= 0
    91      */
    92     public Changeset readChangeset(long id, ProgressMonitor monitor) throws OsmTransferException {
     100     * @since 7704
     101     */
     102    public Changeset readChangeset(long id, boolean includeDiscussion, ProgressMonitor monitor) throws OsmTransferException {
    93103        if (id <= 0)
    94104            throw new IllegalArgumentException(MessageFormat.format("Parameter ''{0}'' > 0 expected. Got ''{1}''.", "id", id));
     
    99109        try {
    100110            monitor.beginTask(tr("Reading changeset {0} ...",id));
    101             StringBuilder sb = new StringBuilder();
    102             sb.append("changeset/").append(id);
    103             try (InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true))) {
     111            try (InputStream in = getChangesetInputStream(id, includeDiscussion, monitor)) {
    104112                if (in == null)
    105113                    return null;
     
    123131
    124132    /**
    125      * Reads the changeset with id <code>id</code> from the server
     133     * Reads the changesets with id <code>ids</code> from the server.
    126134     *
    127      * @param ids  the list of ids. Ignored if null. Only load changesets for ids &gt; 0.
     135     * @param ids the list of ids. Ignored if null. Only load changesets for ids &gt; 0.
     136     * @param includeDiscussion determines if discussion comments must be downloaded or not
    128137     * @param monitor the progress monitor. Set to {@link NullProgressMonitor#INSTANCE} if null
    129138     * @return the changeset read
    130139     * @throws OsmTransferException thrown if something goes wrong
    131140     * @throws IllegalArgumentException if id &lt;= 0
    132      */
    133     public List<Changeset> readChangesets(Collection<Integer> ids, ProgressMonitor monitor) throws OsmTransferException {
     141     * @since 7704
     142     */
     143    public List<Changeset> readChangesets(Collection<Integer> ids, boolean includeDiscussion, ProgressMonitor monitor) throws OsmTransferException {
    134144        if (ids == null)
    135145            return Collections.emptyList();
     
    147157                }
    148158                i++;
    149                 StringBuilder sb = new StringBuilder();
    150                 sb.append("changeset/").append(id);
    151                 try (InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true))) {
     159                try (InputStream in = getChangesetInputStream(id, includeDiscussion, monitor)) {
    152160                    if (in == null)
    153161                        return null;
Note: See TracChangeset for help on using the changeset viewer.