Changeset 5434 in josm


Ignore:
Timestamp:
2012-08-12T04:03:42+02:00 (12 years ago)
Author:
Don-vip
Message:

fix #6594 - Fetch user details with supplied OAuth credentials to download changesets without having to set user name in "Basic authentication" tab + fix a bug in languages parsing

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/JosmUserIdentityManager.java

    r5266 r5434  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Component;
    67import java.text.MessageFormat;
    78
     
    1112import org.openstreetmap.josm.data.Preferences.StringSetting;
    1213import org.openstreetmap.josm.data.osm.UserInfo;
     14import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
     15import org.openstreetmap.josm.io.OsmServerUserInfoReader;
     16import org.openstreetmap.josm.io.OsmTransferException;
    1317import org.openstreetmap.josm.io.auth.CredentialsManager;
    1418import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    3438 * of what the current JOSM instance knows about the current user. Other subsystems can
    3539 * let the global JosmUserStateManager know in case they fully identify the current user, see
    36  * {@link #setFullyIdentified(String, long)}.
     40 * {@link #setFullyIdentified}.
    3741 *
    3842 * The information kept by the JosmUserStateManager can be used to
    3943 * <ul>
    4044 *   <li>safely query changesets owned by the current user based on its user id, not on its user name</li>
    41  *   <li>safely search for objects last touched by the current user  based on its user id, not on its user name</li>
     45 *   <li>safely search for objects last touched by the current user based on its user id, not on its user name</li>
    4246 * </ul>
    4347 *
     
    166170        return userInfo;
    167171    }
    168     /**
    169      * Initializes the user identity manager from values in the {@link org.openstreetmap.josm.data.Preferences}
     172   
     173    /**
     174     * Initializes the user identity manager from Basic Authentication values in the {@link org.openstreetmap.josm.data.Preferences}
     175     * This method should be called if {@code osm-server.auth-method} is set to {@code basic}.
     176     * @see #initFromOAuth
    170177     */
    171178    public void initFromPreferences() {
     
    182189                // keep the state, be it partially or fully identified
    183190            }
     191        }
     192    }
     193
     194    /**
     195     * Initializes the user identity manager from OAuth request of user details.
     196     * This method should be called if {@code osm-server.auth-method} is set to {@code oauth}.
     197     * @param parent component relative to which the {@link PleaseWaitDialog} is displayed.
     198     * @see #initFromPreferences
     199     * @since 5434
     200     */
     201    public void initFromOAuth(Component parent) {
     202        try {
     203            UserInfo info = new OsmServerUserInfoReader().fetchUserInfo(NullProgressMonitor.INSTANCE);
     204            setFullyIdentified(info.getDisplayName(), info);
     205        } catch (IllegalArgumentException e) {
     206            e.printStackTrace();
     207        } catch (OsmTransferException e) {
     208            e.printStackTrace();
    184209        }
    185210    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManager.java

    r4864 r5434  
    532532        public void actionPerformed(ActionEvent arg0) {
    533533            JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
    534             im.initFromPreferences();
    535             if (im.isAnonymous()) {
    536                 alertAnonymousUser();
    537                 return;
     534            if (Main.pref.get("osm-server.auth-method").equals("oauth")) {
     535                im.initFromOAuth(ChangesetCacheManager.this);
     536            } else {
     537                im.initFromPreferences();
     538                if (im.isAnonymous()) {
     539                    alertAnonymousUser();
     540                    return;
     541                }
    538542            }
    539543            ChangesetQuery query = new ChangesetQuery();
  • trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java

    r3083 r5434  
    9797
    9898            // -- language list
    99             NodeList xmlNodeList = (NodeList)xpath.compile("/osm/user[1]/languages[1]/lang").evaluate(document, XPathConstants.NODESET);
     99            NodeList xmlNodeList = (NodeList)xpath.compile("/osm/user[1]/languages[1]/lang/text()").evaluate(document, XPathConstants.NODESET);
    100100            if (xmlNodeList != null) {
    101101                List<String> languages = new LinkedList<String>();
Note: See TracChangeset for help on using the changeset viewer.