Changeset 3815 in josm
- Timestamp:
- 2011-01-25T10:29:01+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r3715 r3815 6 6 import java.awt.Component; 7 7 import java.awt.Dimension; 8 import java.awt.GridBagConstraints; 9 import java.awt.GridBagLayout; 8 10 import java.awt.Rectangle; 9 11 import java.awt.Toolkit; … … 31 33 import javax.swing.JComponent; 32 34 import javax.swing.JFrame; 35 import javax.swing.JLabel; 33 36 import javax.swing.JOptionPane; 34 37 import javax.swing.JPanel; 38 import javax.swing.JTextArea; 35 39 import javax.swing.KeyStroke; 36 40 import javax.swing.UIManager; … … 717 721 ((JFrame)parent).addWindowStateListener(new WindowPositionSizeListener()); 718 722 } 723 724 public static void checkJava6() { 725 String version = System.getProperty("java.version"); 726 if (version != null) { 727 if (version.startsWith("1.6") || version.startsWith("6") || 728 version.startsWith("1.7") || version.startsWith("7")) 729 return; 730 if (version.startsWith("1.5") || version.startsWith("5")) { 731 JLabel ho = new JLabel("<html>"+ 732 tr("<h2>JOSM requires Java version 6.</h2>"+ 733 "Detected Java version: {0}.<br>"+ 734 "You can <ul><li>update your Java (JRE) or</li>"+ 735 "<li>use an earlier (Java 5 compatible) version of JOSM.</li></ul>"+ 736 "More Info:", version)+"</html>"); 737 JTextArea link = new JTextArea("http://josm.openstreetmap.de/wiki/Help/SystemRequirements"); 738 link.setEditable(false); 739 link.setBackground(panel.getBackground()); 740 JPanel panel = new JPanel(new GridBagLayout()); 741 GridBagConstraints gbc = new GridBagConstraints(); 742 gbc.gridwidth = GridBagConstraints.REMAINDER; 743 gbc.anchor = GridBagConstraints.WEST; 744 gbc.weightx = 1.0; 745 panel.add(ho, gbc); 746 panel.add(link, gbc); 747 final String EXIT = tr("Exit JOSM"); 748 final String CONTINUE = tr("Continue, try anyway"); 749 int ret = JOptionPane.showOptionDialog(null, panel, tr("Error"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new String[] {EXIT, CONTINUE}, EXIT); 750 if (ret == 0) { 751 System.exit(0); 752 } 753 return; 754 } 755 } 756 System.err.println("Error: Could not recognize Java Version: "+version); 757 } 719 758 } -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r3795 r3815 645 645 } 646 646 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 647 663 synchronized public void removeFromCollection(String key, String value) { 648 664 List<String> a = new ArrayList<String>(getCollection(key, Collections.<String>emptyList())); -
trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java
r3528 r3815 20 20 import java.util.StringTokenizer; 21 21 import java.util.Map.Entry; 22 import java.util.logging.Logger;22 //import java.util.logging.Logger; 23 23 24 24 import javax.swing.JOptionPane; … … 38 38 */ 39 39 public 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 } 41 48 42 49 private final Connection connection; … … 47 54 this.serverUrl = serverUrl; 48 55 } 49 public String download() {56 public String download() throws MissingPassword { 50 57 try { 51 58 System.out.println("reading preferences from "+serverUrl); 52 59 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); 55 71 } 56 con.connect();57 72 BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream())); 58 73 StringBuilder b = new StringBuilder(); … … 67 82 } catch (IOException e) { 68 83 e.printStackTrace(); 69 } catch(OsmTransferException e) {70 e.printStackTrace();71 84 } 72 85 return null; … … 77 90 System.out.println("uploading preferences to "+u); 78 91 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)); 84 96 con.setRequestMethod("POST"); 85 97 con.setDoOutput(true); … … 146 158 147 159 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 { 158 173 resetToDefault(); 159 174 String cont = connection.download(); -
trunk/src/org/openstreetmap/josm/gui/MainApplet.java
r3545 r3815 29 29 import org.openstreetmap.josm.data.ServerSidePreferences; 30 30 import org.openstreetmap.josm.tools.GBC; 31 import org.openstreetmap.josm.tools.I18n; 31 32 import org.openstreetmap.josm.tools.Shortcut; 32 33 … … 82 83 83 84 @Override public void start() { 84 // initialize the plaform hook, and 85 I18n.init(); 86 Main.checkJava6(); 87 88 // initialize the platform hook, and 85 89 Main.determinePlatformHook(); 86 90 // call the really early hook before we do anything else … … 88 92 89 93 Main.pref = new ServerSidePreferences(getCodeBase()); 90 if(!((ServerSidePreferences)Main.pref).download()) { 94 try 95 { 96 ((ServerSidePreferences)Main.pref).download(); 97 } catch (ServerSidePreferences.MissingPassword e) { 91 98 String username = args.containsKey("username") ? args.get("username").iterator().next() : null; 92 99 String password = args.containsKey("password") ? args.get("password").iterator().next() : null; 93 100 if (username == null || password == null) { 94 101 JPanel p = new JPanel(new GridBagLayout()); 102 p.add(new JLabel(tr(e.realm)), GBC.eol().fill(GBC.HORIZONTAL)); 95 103 p.add(new JLabel(tr("Username")), GBC.std().insets(0,0,20,0)); 96 104 JTextField user = new JTextField(username == null ? "" : username); … … 101 109 JOptionPane.showMessageDialog(null, p); 102 110 username = user.getText(); 111 if("".equals(username)) 112 username = null; 103 113 password = new String(pass.getPassword()); 104 args.put("password", Arrays.asList(new String[]{password})); 114 if("".equals(password)) 115 password = null; 105 116 } 106 ((ServerSidePreferences)Main.pref).download(username, password); 117 if (username != null && password != null) { 118 ((ServerSidePreferences)Main.pref).download(username, password); 119 } 107 120 } 108 121 -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r3715 r3815 5 5 import static org.openstreetmap.josm.tools.I18n.trn; 6 6 7 import java.awt.GridBagConstraints;8 import java.awt.GridBagLayout;9 7 import java.awt.Toolkit; 10 8 import java.awt.event.WindowAdapter; … … 25 23 26 24 import javax.swing.JFrame; 27 import javax.swing.JLabel;28 import javax.swing.JOptionPane;29 import javax.swing.JPanel;30 import javax.swing.JTextArea;31 25 import javax.swing.SwingUtilities; 32 26 … … 141 135 public static void main(final String[] argArray) { 142 136 I18n.init(); 143 checkJava6();137 Main.checkJava6(); 144 138 Main.pref = new Preferences(); 145 139 … … 166 160 System.setProperty("sun.awt.exception.handler", BugReportExceptionHandler.class.getName()); 167 161 168 // initialize the pla form hook, and162 // initialize the platform hook, and 169 163 Main.determinePlatformHook(); 170 164 // call the really early hook before we anything else … … 302 296 } 303 297 } 304 305 private static void checkJava6() {306 String version = System.getProperty("java.version");307 if (version != null) {308 if (version.startsWith("1.6") || version.startsWith("6") ||309 version.startsWith("1.7") || version.startsWith("7"))310 return;311 if (version.startsWith("1.5") || version.startsWith("5")) {312 JLabel ho = new JLabel("<html>"+313 tr("<h2>JOSM requires Java version 6.</h2>"+314 "Detected Java version: {0}.<br>"+315 "You can <ul><li>update your Java (JRE) or</li>"+316 "<li>use an earlier (Java 5 compatible) version of JOSM.</li></ul>"+317 "More Info:", version)+"</html>");318 JTextArea link = new JTextArea("http://josm.openstreetmap.de/wiki/Help/SystemRequirements");319 link.setEditable(false);320 link.setBackground(panel.getBackground());321 JPanel panel = new JPanel(new GridBagLayout());322 GridBagConstraints gbc = new GridBagConstraints();323 gbc.gridwidth = GridBagConstraints.REMAINDER;324 gbc.anchor = GridBagConstraints.WEST;325 gbc.weightx = 1.0;326 panel.add(ho, gbc);327 panel.add(link, gbc);328 final String EXIT = tr("Exit JOSM");329 final String CONTINUE = tr("Continue, try anyway");330 int ret = JOptionPane.showOptionDialog(null, panel, tr("Error"), JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE, null, new String[] {EXIT, CONTINUE}, EXIT);331 if (ret == 0) {332 System.exit(0);333 }334 return;335 }336 }337 System.err.println("Error: Could not recognize Java Version: "+version);338 }339 298 } -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r3344 r3815 11 11 import java.nio.charset.Charset; 12 12 import java.nio.charset.CharsetEncoder; 13 import java.util.logging.Logger;13 //import java.util.logging.Logger; 14 14 15 15 import oauth.signpost.OAuthConsumer; … … 32 32 public class OsmConnection { 33 33 @SuppressWarnings("unused") 34 private static final Logger logger = Logger.getLogger(OsmConnection.class.getName());34 //private static final Logger logger = Logger.getLogger(OsmConnection.class.getName()); 35 35 36 36 protected boolean cancel = false;
Note:
See TracChangeset
for help on using the changeset viewer.