Ignore:
Timestamp:
2011-01-25T10:29:01+01:00 (13 years ago)
Author:
stoecker
Message:

fixes for applet

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

Legend:

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

    r3795 r3815  
    645645    }
    646646
     647    /* old style conversion, replace by above call after some transition time */
     648    /* remove this function, when no more old-style preference collections in the code */
     649    @Deprecated
     650    synchronized public Collection<String> getCollectionOld(String key, String sep) {
     651        putCollectionDefault(key, null);
     652        String s = get(key);
     653        if (s != null && s.length() != 0) {
     654            if(!s.contains("\u001e") && s.contains(sep)) {
     655                s = s.replace(sep, "\u001e");
     656                put(key, s);
     657            }
     658            return Arrays.asList(s.split("\u001e"));
     659        }
     660        return Collections.emptyList();
     661    }
     662
    647663    synchronized public void removeFromCollection(String key, String value) {
    648664        List<String> a = new ArrayList<String>(getCollection(key, Collections.<String>emptyList()));
  • trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java

    r3528 r3815  
    2020import java.util.StringTokenizer;
    2121import java.util.Map.Entry;
    22 import java.util.logging.Logger;
     22//import java.util.logging.Logger;
    2323
    2424import javax.swing.JOptionPane;
     
    3838 */
    3939public class ServerSidePreferences extends Preferences {
    40     static private final Logger logger = Logger.getLogger(ServerSidePreferences.class.getName());
     40    //static private final Logger logger = Logger.getLogger(ServerSidePreferences.class.getName());
     41
     42    public class MissingPassword extends Exception{
     43        public String realm;
     44        public MissingPassword(String r) {
     45            realm = r;
     46        }
     47    }
    4148
    4249    private final Connection connection;
     
    4754            this.serverUrl = serverUrl;
    4855        }
    49         public String download() {
     56        public String download() throws MissingPassword {
    5057            try {
    5158                System.out.println("reading preferences from "+serverUrl);
    5259                URLConnection con = serverUrl.openConnection();
    53                 if (con instanceof HttpURLConnection) {
    54                     addAuth((HttpURLConnection) con);
     60                String username = get("applet.username");
     61                String password = get("applet.password");
     62                if(password.isEmpty() && username.isEmpty())
     63                    con.addRequestProperty("Authorization", "Basic "+Base64.encode(username+":"+password));
     64                con.connect();
     65                if(username.isEmpty() && con instanceof HttpURLConnection
     66                    && ((HttpURLConnection) con).getResponseCode()
     67                    == HttpURLConnection.HTTP_UNAUTHORIZED) {
     68                    String t = ((HttpURLConnection) con).getHeaderField("WWW-Authenticate");
     69                    t = t.replace("Basic realm=\"","").replace("\"","");
     70                    throw new MissingPassword(t);
    5571                }
    56                 con.connect();
    5772                BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
    5873                StringBuilder b = new StringBuilder();
     
    6782            } catch (IOException e) {
    6883                e.printStackTrace();
    69             } catch(OsmTransferException e) {
    70                 e.printStackTrace();
    7184            }
    7285            return null;
     
    7790                System.out.println("uploading preferences to "+u);
    7891                HttpURLConnection con = (HttpURLConnection)u.openConnection();
    79                 // FIXME:
    80                 // - doesn't work if CredentialManager isn't JosmPreferencesCredentialManager
    81                 // - doesn't work for OAuth
    82 
    83                 con.addRequestProperty("Authorization", "Basic "+Base64.encode(get("osm-server.username")+":"+get("osm-server.password")));
     92                String username = get("applet.username");
     93                String password = get("applet.password");
     94                if(password.isEmpty() && username.isEmpty())
     95                    con.addRequestProperty("Authorization", "Basic "+Base64.encode(username+":"+password));
    8496                con.setRequestMethod("POST");
    8597                con.setDoOutput(true);
     
    146158
    147159    public void download(String userName, String password) {
    148         if (!properties.containsKey("osm-server.username") && userName != null) {
    149             properties.put("osm-server.username", userName);
    150         }
    151         if (!properties.containsKey("osm-server.password") && password != null) {
    152             properties.put("osm-server.password", password);
    153         }
    154         download();
    155     }
    156 
    157     public boolean download() {
     160        if (!properties.containsKey("applet.username") && userName != null) {
     161            properties.put("applet.username", userName);
     162        }
     163        if (!properties.containsKey("applet.password") && password != null) {
     164            properties.put("applet.password", password);
     165        }
     166        try {
     167            download();
     168        } catch (MissingPassword e) {
     169        }
     170    }
     171
     172    public boolean download() throws MissingPassword {
    158173        resetToDefault();
    159174        String cont = connection.download();
Note: See TracChangeset for help on using the changeset viewer.