Changeset 6695 in josm for trunk/src/org


Ignore:
Timestamp:
2014-01-15T23:39:56+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #9581 - Improve regular info message about "download user details" API request

Location:
trunk/src/org/openstreetmap/josm/io
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/MessageNotifier.java

    r6453 r6695  
    5959        public void run() {
    6060            try {
    61                 final UserInfo userInfo = new OsmServerUserInfoReader().fetchUserInfo(NullProgressMonitor.INSTANCE);
     61                final UserInfo userInfo = new OsmServerUserInfoReader().fetchUserInfo(NullProgressMonitor.INSTANCE, tr("get number of unread messages"));
    6262                final int unread = userInfo.getUnreadMessages();
    6363                if (unread > 0 && unread != lastUnreadCount) {
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r6643 r6695  
    4747     * @param urlStr The url to connect to.
    4848     * @param progressMonitor progress monitoring and abort handler
    49      * @return An reader reading the input stream (servers answer) or <code>null</code>.
     49     * @return A reader reading the input stream (servers answer) or <code>null</code>.
    5050     * @throws OsmTransferException thrown if data transfer errors occur
    5151     */
    5252    protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException  {
     53        return getInputStream(urlStr, progressMonitor, null);
     54    }
     55
     56    /**
     57     * Open a connection to the given url and return a reader on the input stream
     58     * from that connection. In case of user cancel, return <code>null</code>.
     59     * Relative URL's are directed to API base URL.
     60     * @param urlStr The url to connect to.
     61     * @param progressMonitor progress monitoring and abort handler
     62     * @param reason The reason to show on console. Can be {@code null} if no reason is given
     63     * @return A reader reading the input stream (servers answer) or <code>null</code>.
     64     * @throws OsmTransferException thrown if data transfer errors occur
     65     */
     66    protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor, String reason) throws OsmTransferException  {
    5367        try {
    5468            api.initialize(progressMonitor);
    55             urlStr = urlStr.startsWith("http") ? urlStr : (getBaseUrl() + urlStr);
    56             return getInputStreamRaw(urlStr, progressMonitor);
     69            String url = urlStr.startsWith("http") ? urlStr : (getBaseUrl() + urlStr);
     70            return getInputStreamRaw(url, progressMonitor, reason);
    5771        } finally {
    5872            progressMonitor.invalidate();
     
    6175
    6276    /**
    63      * Retrun the base URL for relative URL requests
     77     * Return the base URL for relative URL requests
    6478     * @return base url of API
    6579     */
     
    7791     */
    7892    protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException {
     93        return getInputStreamRaw(urlStr, progressMonitor, null);
     94    }
     95   
     96    /**
     97     * Open a connection to the given url and return a reader on the input stream
     98     * from that connection. In case of user cancel, return <code>null</code>.
     99     * @param urlStr The exact url to connect to.
     100     * @param progressMonitor progress monitoring and abort handler
     101     * @param reason The reason to show on console. Can be {@code null} if no reason is given
     102     * @return An reader reading the input stream (servers answer) or <code>null</code>.
     103     * @throws OsmTransferException thrown if data transfer errors occur
     104     */
     105    protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason) throws OsmTransferException {
    79106        try {
    80107            URL url = null;
     
    107134
    108135            try {
    109                 Main.info("GET " + url);
     136                if (reason != null && !reason.isEmpty()) {
     137                    Main.info("GET " + url + " (" + reason + ")");
     138                } else {
     139                    Main.info("GET " + url);
     140                }
    110141                activeConnection.connect();
    111142            } catch (Exception e) {
  • trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java

    r6365 r6695  
    144144    }
    145145
     146    /**
     147     * Fetches user info, without explicit reason.
     148     * @param monitor The progress monitor
     149     * @return The user info
     150     * @throws OsmTransferException if something goes wrong
     151     */
    146152    public UserInfo fetchUserInfo(ProgressMonitor monitor) throws OsmTransferException {
     153        return fetchUserInfo(monitor, null);
     154    }
     155
     156    /**
     157     * Fetches user info, with an explicit reason.
     158     * @param monitor The progress monitor
     159     * @param reason The reason to show on console. Can be {@code null} if no reason is given
     160     * @return The user info
     161     * @throws OsmTransferException if something goes wrong
     162     * @since 6695
     163     */
     164    public UserInfo fetchUserInfo(ProgressMonitor monitor, String reason) throws OsmTransferException {
    147165        try {
    148166            monitor.beginTask("");
    149167            monitor.indeterminateSubTask(tr("Reading user info ..."));
    150             InputStream in = getInputStream("user/details", monitor.createSubTaskMonitor(1, true));
     168            InputStream in = getInputStream("user/details", monitor.createSubTaskMonitor(1, true), reason);
    151169            return buildFromXML(
    152170                    DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(in)
Note: See TracChangeset for help on using the changeset viewer.