Changeset 6349 in josm
- Timestamp:
- 2013-10-31T22:52:58+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/UserInfo.java
r3083 r6349 22 22 /** the list of preferred languages */ 23 23 private List<String> languages; 24 /** the number of unread messages */ 25 private int unreadMessages; 24 26 27 /** 28 * Constructs a new {@code UserInfo}. 29 */ 25 30 public UserInfo() { 26 31 id = 0; … … 71 76 this.homeZoom = homeZoom; 72 77 } 78 79 /** 80 * Replies the number of unread messages 81 * @return the number of unread messages 82 * @since 6349 83 */ 84 public final int getUnreadMessages() { 85 return unreadMessages; 86 } 87 88 /** 89 * Sets the number of unread messages 90 * @param unreadMessages the number of unread messages 91 * @since 6349 92 */ 93 public final void setUnreadMessages(int unreadMessages) { 94 this.unreadMessages = unreadMessages; 95 } 73 96 } -
trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
r6070 r6349 20 20 import org.openstreetmap.josm.io.IllegalDataException; 21 21 import org.openstreetmap.josm.io.MissingOAuthAccessTokenException; 22 import org.openstreetmap.josm.io.OsmApi; 22 23 import org.openstreetmap.josm.io.OsmApiException; 23 24 import org.openstreetmap.josm.io.OsmApiInitializationException; … … 244 245 } 245 246 246 private static boolean isOAuth() {247 return Main.pref.get("osm-server.auth-method", "basic").equals("oauth");248 }249 250 247 /** 251 248 * Explains a {@link OsmApiException} which was thrown because the authentication at … … 256 253 public static void explainAuthenticationFailed(OsmApiException e) { 257 254 String msg; 258 if ( isOAuth()) {255 if (OsmApi.isUsingOAuth()) { 259 256 msg = ExceptionUtil.explainFailedOAuthAuthentication(e); 260 257 } else { … … 293 290 msg = tr("Access to redacted version ''{0}'' of {1} {2} is forbidden.", 294 291 version, tr(type), id); 295 } else if ( isOAuth()) {292 } else if (OsmApi.isUsingOAuth()) { 296 293 msg = ExceptionUtil.explainFailedOAuthAuthorisation(e); 297 294 } else { -
trunk/src/org/openstreetmap/josm/gui/JosmUserIdentityManager.java
r6296 r6349 14 14 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder; 15 15 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 16 import org.openstreetmap.josm.io.OsmApi; 16 17 import org.openstreetmap.josm.io.OsmServerUserInfoReader; 17 18 import org.openstreetmap.josm.io.OsmTransferException; … … 60 61 if (instance == null) { 61 62 instance = new JosmUserIdentityManager(); 62 if ( Main.pref.get("osm-server.auth-method").equals("oauth") && OAuthAccessTokenHolder.getInstance().containsAccessToken()) {63 if (OsmApi.isUsingOAuth() && OAuthAccessTokenHolder.getInstance().containsAccessToken()) { 63 64 try { 64 65 instance.initFromOAuth(Main.parent); … … 272 273 accessTokenKeyChanged = false; 273 274 accessTokenSecretChanged = false; 274 if ( Main.pref.get("osm-server.auth-method").equals("oauth")) {275 if (OsmApi.isUsingOAuth()) { 275 276 try { 276 277 instance.initFromOAuth(Main.parent); -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r6248 r6349 42 42 import org.openstreetmap.josm.gui.util.GuiHelper; 43 43 import org.openstreetmap.josm.io.DefaultProxySelector; 44 import org.openstreetmap.josm.io.MessageNotifier; 44 45 import org.openstreetmap.josm.io.auth.CredentialsManager; 45 46 import org.openstreetmap.josm.io.auth.DefaultAuthenticator; … … 443 444 RemoteControl.start(); 444 445 } 446 447 if (MessageNotifier.PROP_NOTIFIER_ENABLED.get()) { 448 MessageNotifier.start(); 449 } 445 450 446 451 if (Main.pref.getBoolean("debug.edt-checker.enable", Version.getInstance().isLocalBuild())) { -
trunk/src/org/openstreetmap/josm/gui/preferences/server/AuthenticationPreferencesPanel.java
r6248 r6349 41 41 /** the panel for the OAuth authentication parameters */ 42 42 private OAuthAuthenticationPreferencesPanel pnlOAuthPreferences; 43 /** the panel for messages notifier preferences */ 44 private MessagesNotifierPanel pnlMessagesPreferences; 43 45 44 46 /** … … 74 76 bg.add(rbOAuth); 75 77 76 //-- add the panel which will h ld the authentication parameters78 //-- add the panel which will hold the authentication parameters 77 79 gc.gridx = 0; 78 80 gc.gridy = 1; … … 84 86 pnlAuthenticationParameteters.setLayout(new BorderLayout()); 85 87 86 //-- the two panel for authentication parameters88 //-- the two panels for authentication parameters 87 89 pnlBasicAuthPreferences = new BasicAuthenticationPreferencesPanel(); 88 90 pnlOAuthPreferences = new OAuthAuthenticationPreferencesPanel(); … … 90 92 rbBasicAuthentication.setSelected(true); 91 93 pnlAuthenticationParameteters.add(pnlBasicAuthPreferences, BorderLayout.CENTER); 94 95 //-- the panel for messages preferences 96 gc.gridy = 2; 97 gc.fill = GridBagConstraints.NONE; 98 add(pnlMessagesPreferences = new MessagesNotifierPanel(), gc); 92 99 } 93 100 101 /** 102 * Constructs a new {@code AuthenticationPreferencesPanel}. 103 */ 94 104 public AuthenticationPreferencesPanel() { 95 105 build(); … … 97 107 } 98 108 109 /** 110 * Initializes the panel from preferences 111 */ 99 112 public void initFromPreferences() { 100 113 String authMethod = Main.pref.get("osm-server.auth-method", "basic"); … … 109 122 pnlBasicAuthPreferences.initFromPreferences(); 110 123 pnlOAuthPreferences.initFromPreferences(); 124 pnlMessagesPreferences.initFromPreferences(); 111 125 } 112 126 127 /** 128 * Saves the current values to preferences 129 */ 113 130 public void saveToPreferences() { 114 131 // save the authentication method … … 131 148 pnlOAuthPreferences.saveToPreferences(); 132 149 } 150 // save message notifications preferences. To be done after authentication preferences. 151 pnlMessagesPreferences.saveToPreferences(); 133 152 } 134 153 -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r6317 r6349 564 564 } 565 565 566 protected boolean isUsingOAuth() { 567 String authMethod = Main.pref.get("osm-server.auth-method", "basic"); 568 return authMethod.equals("oauth"); 566 /** 567 * Determines if JOSM is configured to access OSM API via OAuth 568 * @return {@code true} if JOSM is configured to access OSM API via OAuth, {@code false} otherwise 569 * @since 6349 570 */ 571 public static final boolean isUsingOAuth() { 572 return "oauth".equals(Main.pref.get("osm-server.auth-method", "basic")); 569 573 } 570 574 -
trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java
r5434 r6349 29 29 } 30 30 31 static public UserInfo buildFromXML(Document document) throws OsmDataParsingException{ 31 /** 32 * Parses the given XML data and returns the associated user info. 33 * @param document The XML contents 34 * @return The user info 35 * @throws OsmDataParsingException if parsing goes wrong 36 */ 37 static public UserInfo buildFromXML(Document document) throws OsmDataParsingException { 32 38 try { 33 39 XPathFactory factory = XPathFactory.newInstance(); … … 105 111 userInfo.setLanguages(languages); 106 112 } 113 114 // -- messages 115 xmlNode = (Node)xpath.compile("/osm/user[1]/messages/received").evaluate(document, XPathConstants.NODE); 116 if (xmlNode != null) { 117 v = getAttribute(xmlNode, "unread"); 118 if (v == null) 119 throw new OsmDataParsingException(tr("Missing attribute ''{0}'' on XML tag ''{1}''.", "unread", "received")); 120 try { 121 userInfo.setUnreadMessages(Integer.parseInt(v)); 122 } catch(NumberFormatException e) { 123 throw new OsmDataParsingException(tr("Illegal value for attribute ''{0}'' on XML tag ''{1}''. Got {2}.", "unread", "received", v)); 124 } 125 } 126 107 127 return userInfo; 108 128 } catch(XPathException e) { … … 111 131 } 112 132 133 /** 134 * Constructs a new {@code OsmServerUserInfoReader}. 135 */ 113 136 public OsmServerUserInfoReader() { 114 137 setDoAuthenticate(true); -
trunk/src/org/openstreetmap/josm/io/auth/CredentialsManager.java
r6070 r6349 9 9 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 10 10 import org.openstreetmap.josm.io.OsmApi; 11 import org.openstreetmap.josm.tools.CheckParameterUtil; 11 12 import org.openstreetmap.josm.tools.Utils; 12 13 … … 15 16 * 16 17 * Currently, it defaults to replying an instance of {@link JosmPreferencesCredentialAgent}. 17 * 18 * @since 2641 18 19 */ 19 20 public class CredentialsManager implements CredentialsAgent { … … 56 57 } 57 58 58 /***** 59 * non-static fields and methods 59 /* non-static fields and methods */ 60 61 /** 62 * The credentials agent doing the real stuff 60 63 */ 61 62 64 private CredentialsAgent delegate; 63 65 66 /** 67 * Constructs a new {@code CredentialsManager}. 68 * @param delegate The credentials agent backing this credential manager. Must not be {@code null} 69 */ 64 70 public CredentialsManager(CredentialsAgent delegate) { 71 CheckParameterUtil.ensureParameterNotNull(delegate, "delegate"); 65 72 this.delegate = delegate; 66 73 } 74 75 /** 76 * Returns type of credentials agent backing this credentials manager. 77 * @return The type of credentials agent 78 */ 79 public final Class<? extends CredentialsAgent> getCredentialsAgentClass () { 80 return delegate.getClass(); 81 } 67 82 83 /** 84 * Returns the username for OSM API 85 * @return the username for OSM API 86 */ 68 87 public String getUsername() { 69 88 return getUsername(OsmApi.getOsmApi().getHost()); 70 89 } 71 90 91 /** 92 * Returns the username for a given host 93 * @param host The host for which username is wanted 94 * @return The username for {@code host} 95 */ 72 96 public String getUsername(String host) { 73 97 String username = null; -
trunk/src/org/openstreetmap/josm/io/auth/DefaultAuthenticator.java
r5266 r6349 7 7 import java.util.Map; 8 8 9 import org.openstreetmap.josm. Main;9 import org.openstreetmap.josm.io.OsmApi; 10 10 11 11 /** … … 43 43 if (getRequestorType().equals(Authenticator.RequestorType.SERVER)) { 44 44 // if we are working with OAuth we don't prompt for a password 45 // 46 String authMethod = Main.pref.get("osm-server.auth-method", "basic"); 47 if (authMethod.equals("oauth")) 45 if (OsmApi.isUsingOAuth()) 48 46 return null; 49 47 }
Note:
See TracChangeset
for help on using the changeset viewer.