- Timestamp:
- 2010-09-14T14:11:25+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java
r2748 r3528 146 146 147 147 public void download(String userName, String password) { 148 resetToDefault();149 148 if (!properties.containsKey("osm-server.username") && userName != null) { 150 149 properties.put("osm-server.username", userName); … … 153 152 properties.put("osm-server.password", password); 154 153 } 154 download(); 155 } 156 157 public boolean download() { 158 resetToDefault(); 155 159 String cont = connection.download(); 156 if (cont == null) return; 160 if (cont == null) return false; 157 161 Reader in = new StringReader(cont); 162 boolean res = false; 158 163 try { 159 164 XmlObjectParser.Uniform<Prop> parser = new XmlObjectParser.Uniform<Prop>(in, "tag", Prop.class); 160 165 for (Prop p : parser) { 166 res = true; 161 167 properties.put(p.key, p.value); 162 168 } … … 164 170 e.printStackTrace(); 165 171 } 172 return res; 166 173 } 167 174 … … 187 194 connection.upload(b.toString()); 188 195 } 189 190 @Override public Collection<Bookmark> loadBookmarks() {191 URL url = null;192 try {193 Collection<Bookmark> bookmarks;194 bookmarks = new LinkedList<Bookmark>();195 url = new URL("http://"+connection.serverUrl.getHost()+"/josm/bookmarks");196 BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));197 198 for (String line = in.readLine(); line != null; line = in.readLine()) {199 StringTokenizer st = new StringTokenizer(line, ",");200 if (st.countTokens() != 5) {201 System.err.println(tr("Error: Unexpected line ''{0}'' in bookmark list from server",line));202 continue;203 }204 Bookmark b = new Bookmark();205 b.setName(st.nextToken());206 double[] values= new double[4];207 for (int i = 0; i < 4; ++i) {208 String token = st.nextToken();209 try {210 values[i] = Double.parseDouble(token);211 } catch(NumberFormatException e) {212 System.err.println(tr("Error: Illegal double value ''{0}'' on line ''{1}'' in bookmark list from server",token,line));213 continue;214 }215 }216 b.setArea(new Bounds(values));217 bookmarks.add(b);218 }219 in.close();220 return bookmarks;221 } catch (MalformedURLException e) {222 e.printStackTrace();223 } catch (IllegalArgumentException e) {224 e.printStackTrace();225 } catch (IOException e) {226 e.printStackTrace();227 } catch(SecurityException e) {228 e.printStackTrace();229 logger.warning(tr("Failed to load bookmarks from ''{0}'' for security reasons. Exception was: {1}", url == null ? "null" : url.toExternalForm(), e.toString()));230 }231 return Collections.emptyList();232 }233 234 @Override public void saveBookmarks(Collection<Bookmark> bookmarks) {235 }236 196 } -
trunk/src/org/openstreetmap/josm/gui/MainApplet.java
r3252 r3528 82 82 83 83 @Override public void start() { 84 String username = args.containsKey("username") ? args.get("username").iterator().next() : null;85 String password = args.containsKey("password") ? args.get("password").iterator().next() : null;86 if (username == null || password == null) {87 JPanel p = new JPanel(new GridBagLayout());88 p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,20,0));89 JTextField user = new JTextField(username == null ? "" : username);90 p.add(user, GBC.eol().fill(GBC.HORIZONTAL));91 p.add(new JLabel(tr("Password")), GBC.std().insets(0,0,20,0));92 JPasswordField pass = new JPasswordField(password == null ? "" : password);93 p.add(pass, GBC.eol().fill(GBC.HORIZONTAL));94 JOptionPane.showMessageDialog(null, p);95 username = user.getText();96 password = new String(pass.getPassword());97 args.put("password", Arrays.asList(new String[]{password}));98 }99 100 84 // initialize the plaform hook, and 101 85 Main.determinePlatformHook(); 102 // call the really early hook before we anything else 86 // call the really early hook before we do anything else 103 87 Main.platform.preStartupHook(); 104 88 … … 106 90 107 91 Main.pref = new ServerSidePreferences(getCodeBase()); 108 ((ServerSidePreferences)Main.pref).download(username, password); 92 if(!((ServerSidePreferences)Main.pref).download()) { 93 String username = args.containsKey("username") ? args.get("username").iterator().next() : null; 94 String password = args.containsKey("password") ? args.get("password").iterator().next() : null; 95 if (username == null || password == null) { 96 JPanel p = new JPanel(new GridBagLayout()); 97 p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,20,0)); 98 JTextField user = new JTextField(username == null ? "" : username); 99 p.add(user, GBC.eol().fill(GBC.HORIZONTAL)); 100 p.add(new JLabel(tr("Password")), GBC.std().insets(0,0,20,0)); 101 JPasswordField pass = new JPasswordField(password == null ? "" : password); 102 p.add(pass, GBC.eol().fill(GBC.HORIZONTAL)); 103 JOptionPane.showMessageDialog(null, p); 104 username = user.getText(); 105 password = new String(pass.getPassword()); 106 args.put("password", Arrays.asList(new String[]{password})); 107 } 108 ((ServerSidePreferences)Main.pref).download(username, password); 109 } 110 109 111 Main.preConstructorInit(args); 110 112 Main.parent = frame;
Note:
See TracChangeset
for help on using the changeset viewer.