Changeset 2124 in josm


Ignore:
Timestamp:
2009-09-13T22:46:45+02:00 (12 years ago)
Author:
Gubaer
Message:

See #3483: "Load list of changesets from the server" is broken for users with non-ASCII usernames

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

Legend:

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

    r2037 r2124  
    1414import java.nio.charset.Charset;
    1515import java.nio.charset.CharsetEncoder;
     16import java.util.logging.Logger;
    1617
    1718import javax.swing.JCheckBox;
     
    2324import org.openstreetmap.josm.Main;
    2425import org.openstreetmap.josm.gui.ExtendedDialog;
    25 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2626import org.openstreetmap.josm.tools.Base64;
    2727import org.openstreetmap.josm.tools.GBC;
     
    3434 */
    3535public class OsmConnection {
     36    private static final Logger logger = Logger.getLogger(OsmConnection.class.getName());
    3637
    3738    protected boolean cancel = false;
  • trunk/src/org/openstreetmap/josm/io/OsmServerChangesetReader.java

    r2115 r2124  
    77import org.openstreetmap.josm.data.osm.Changeset;
    88import org.openstreetmap.josm.data.osm.DataSet;
     9import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    910import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1011import static org.openstreetmap.josm.tools.I18n.tr;
     
    2122     */
    2223    public OsmServerChangesetReader(){
     24        setDoAuthenticate(false);
    2325    }
    2426
     
    3234    }
    3335
    34 
     36    /**
     37     * Queries a list
     38     * @param query  the query specification. Must not be null.
     39     * @param monitor a progress monitor. Set to {@see NullProgressMonitor#INSTANCE} if null
     40     * @return the list of changesets read from the server
     41     * @throws IllegalArgumentException thrown if query is null
     42     * @throws OsmTransferException
     43     */
    3544    public List<Changeset> queryChangesets(ChangesetQuery query, ProgressMonitor monitor) throws OsmTransferException {
     45        if (query == null)
     46            throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "query"));
     47        if (monitor == null) {
     48            monitor = NullProgressMonitor.INSTANCE;
     49        }
    3650        try {
    37             monitor.beginTask(tr("Reading changesetss..."));
     51            monitor.beginTask(tr("Reading changesets..."));
    3852            StringBuffer sb = new StringBuffer();
    3953            sb.append("changesets?").append(query.getQueryString());
     
    5367    }
    5468
     69    /**
     70     * Reads teh changeset with id <code>id</code> from the server
     71     *
     72     * @param id  the changeset id. id > 0 required.
     73     * @param monitor the progress monitor. Set to {@see NullProgressMonitor#INSTANCE} if null
     74     * @return the changeset read
     75     * @throws OsmTransferException thrown if something goes wrong
     76     * @throws IllegalArgumentException if id <= 0
     77     */
    5578    public Changeset readChangeset(long id, ProgressMonitor monitor) throws OsmTransferException {
     79        if (id <= 0)
     80            throw new IllegalArgumentException(tr("parameter ''{0}'' > 0 expected. Got {1}", "id", id));
     81        if (monitor == null) {
     82            monitor = NullProgressMonitor.INSTANCE;
     83        }
    5684        try {
    5785            monitor.beginTask(tr("Reading changeset {0} ...",id));
     
    6189            if (in == null)
    6290                return null;
    63             monitor.indeterminateSubTask(tr("Downloading changeset ..."));
     91            monitor.indeterminateSubTask(tr("Downloading changeset {0} ...", id));
    6492            List<Changeset> changesets = OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true));
    6593            if (changesets == null || changesets.isEmpty())
     
    75103    }
    76104
     105    /**
     106     * not implemented yet
     107     *
     108     * @param id
     109     * @param monitor
     110     * @return
     111     * @throws OsmTransferException
     112     */
    77113    public Changeset downloadChangeset(long id, ProgressMonitor monitor) throws OsmTransferException {
    78114        return null;
    79115    }
    80 
    81116}
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r2035 r2124  
    1010import java.net.MalformedURLException;
    1111import java.net.URL;
     12import java.nio.charset.CharacterCodingException;
    1213import java.util.zip.GZIPInputStream;
    1314import java.util.zip.Inflater;
     
    3031
    3132    private OsmApi api = OsmApi.getOsmApi();
     33    private boolean doAuthenticate = false;
    3234
    3335    /**
     
    6668            }
    6769
     70            try {
     71                if (doAuthenticate) {
     72                    addAuth(activeConnection);
     73                }
     74            } catch(CharacterCodingException e) {
     75                System.err.println(tr("Error: failed to add authentication credentials to the connection."));
     76                throw new OsmTransferException(e);
     77            }
    6878            if (Main.pref.getBoolean("osm-server.use-compression", true)) {
    6979                activeConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
     
    122132    public abstract DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException;
    123133
     134    /**
     135     * Returns true if this reader is adding authentication credentials to the read
     136     * request sent to the server.
     137     *
     138     * @return true if this reader is adding authentication credentials to the read
     139     * request sent to the server
     140     */
     141    public boolean isDoAuthenticate() {
     142        return doAuthenticate;
     143    }
     144
     145    /**
     146     * Sets whether this reader adds authentication credentials to the read
     147     * request sent to the server.
     148     *
     149     * @param doAuthenticate  true if  this reader adds authentication credentials to the read
     150     * request sent to the server
     151     */
     152    public void setDoAuthenticate(boolean doAuthenticate) {
     153        this.doAuthenticate = doAuthenticate;
     154    }
    124155}
  • trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java

    r2115 r2124  
    2424
    2525public class OsmServerUserInfoReader extends OsmServerReader {
     26
     27    public OsmServerUserInfoReader() {
     28        setDoAuthenticate(true);
     29    }
    2630
    2731    @Override
Note: See TracChangeset for help on using the changeset viewer.