Changeset 18830 in josm for trunk/src


Ignore:
Timestamp:
2023-09-18T20:27:46+02:00 (13 months ago)
Author:
taylor.smock
Message:

Fix #23111: Hoist the common acceptsDocumentationSummary DownloadTask method definition into the interface

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTask.java

    r17333 r18830  
    88import org.openstreetmap.josm.data.ProjectionBounds;
    99import org.openstreetmap.josm.io.UrlPattern;
    10 import org.openstreetmap.josm.io.XmlWriter;
    1110
    1211/**
     
    9695    }
    9796
    98     @Override
    99     public String acceptsDocumentationSummary() {
    100         StringBuilder buff = new StringBuilder(128)
    101             .append("<tr><td>")
    102             .append(getTitle())
    103             .append(":</td><td>");
    104         String[] patterns = getPatterns();
    105         if (patterns.length > 0) {
    106             buff.append("<ul>");
    107             for (String pattern: patterns) {
    108                 buff.append("<li>")
    109                     .append(XmlWriter.encode(pattern))
    110                     .append("</li>");
    111             }
    112             buff.append("</ul>");
    113         }
    114         buff.append("</td></tr>");
    115         return buff.toString();
    116     }
    117 
    11897    /**
    11998     * Determines if the given URL is accepted by {@link #getPatterns}.
     
    128107    /**
    129108     * Check / decide if the task is safe for remotecontrol.
    130      *
     109     * <p>
    131110     * Keep in mind that a potential attacker has full control over the content
    132111     * of the file that will be downloaded.
    133112     * If it is possible to run arbitrary code or write to the local file
    134113     * system, then the task is (obviously) not save for remote execution.
    135      *
     114     * <p>
    136115     * The default value is false = unsafe. Override in a subclass to
    137116     * allow running the task via remotecontol.
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java

    r17330 r18830  
    1111import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1212import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     13import org.openstreetmap.josm.io.XmlWriter;
    1314import org.openstreetmap.josm.tools.ExceptionUtil;
    1415
     
    2021    /**
    2122     * Asynchronously launches the download task for a given bounding box.
    22      *
     23     * <p>
    2324     * Set <code>progressMonitor</code> to null, if the task should create, open, and close a progress monitor.
    2425     * Set progressMonitor to {@link NullProgressMonitor#INSTANCE} if progress information is to
    2526     * be discarded.
    26      *
     27     * <p>
    2728     * You can wait for the asynchronous download task to finish by synchronizing on the returned
    2829     * {@link Future}, but make sure not to freeze up JOSM. Example:
     
    6061    /**
    6162     * Asynchronously launches the download task for a given bounding URL.
    62      *
     63     * <p>
    6364     * Set progressMonitor to null, if the task should create, open, and close a progress monitor.
    6465     * Set progressMonitor to {@link NullProgressMonitor#INSTANCE} if progress information is to
     
    9394     * @since 6031
    9495     */
    95     String acceptsDocumentationSummary();
     96    default String acceptsDocumentationSummary() {
     97        StringBuilder buff = new StringBuilder(128)
     98                .append("<tr><td>")
     99                .append(getTitle())
     100                .append(":</td><td>");
     101        String[] patterns = getPatterns();
     102        if (patterns.length > 0) {
     103            buff.append("<ul>");
     104            for (String pattern: patterns) {
     105                buff.append("<li>")
     106                        .append(XmlWriter.encode(pattern))
     107                        .append("</li>");
     108            }
     109            buff.append("</ul>");
     110        }
     111        buff.append("</td></tr>");
     112        return buff.toString();
     113    }
    96114
    97115    /**
     
    111129    /**
    112130     * Replies the error objects of the task. Empty list, if no error messages are available.
    113      *
     131     * <p>
    114132     * Error objects are either {@link String}s with error messages or {@link Exception}s.
    115133     *
     
    131149                return ExceptionUtil.explainException((Exception) o).replace("<html>", "").replace("</html>", "");
    132150            } else {
    133                 return (String) null;
     151                return null;
    134152            }
    135153        }).filter(Objects::nonNull).collect(Collectors.toList());
Note: See TracChangeset for help on using the changeset viewer.