Ignore:
Timestamp:
2009-11-01T10:20:23+01:00 (15 years ago)
Author:
stoecker
Message:

reworked user agent string to match established format

File:
1 edited

Legend:

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

    r2369 r2370  
    1414
    1515import org.openstreetmap.josm.Main;
     16import org.openstreetmap.josm.tools.LanguageInfo;
    1617
    1718/**
    1819 * Provides basic information about the currently used JOSM build.
    19  * 
     20 *
    2021 */
    2122public class Version {
     
    2324    static public final int JOSM_UNKNOWN_VERSION = 0;
    2425
    25     /** the unique instance */ 
     26    /** the unique instance */
    2627    private static Version instance;
    27    
     28
    2829    /**
    2930     * Load the specified resource as string.
    30      * 
     31     *
    3132     * @param resource the resource url to load
    32      * @return  the content of the resource file; null, if an error occurred 
     33     * @return  the content of the resource file; null, if an error occurred
    3334     */
    3435    static public String loadResourceFile(URL resource) {
     
    4849        return s;
    4950    }
    50    
    51     /**
    52      * Replies the unique instance of the version information 
    53      * 
     51
     52    /**
     53     * Replies the unique instance of the version information
     54     *
    5455     * @return the unique instance of the version information
    5556     */
    56    
     57
    5758    static public Version getInstance() {
    5859        if (instance == null) {
     
    6061            instance.init();
    6162        }
    62         return instance;           
    63     }
    64    
     63        return instance;
     64    }
     65
    6566    private int version;
    6667    private String revision;
    6768    private String time;
    6869    private boolean isLocalBuild;
    69    
     70
    7071    protected HashMap<String, String> parseManifestStyleFormattedString(String content) {
    7172        HashMap<String, String> properties = new HashMap<String, String>();
     
    8283        return properties;
    8384    }
    84    
    85     /**
    86      * Initializes the version infos from the revision resource file 
    87      * 
    88      * @param revisionInfo the revision info loaded from a revision resource file 
     85
     86    /**
     87     * Initializes the version infos from the revision resource file
     88     *
     89     * @param revisionInfo the revision info loaded from a revision resource file
    8990     */
    9091    protected void initFromRevisionInfo(String revisionInfo) {
     
    9394            this.version = JOSM_UNKNOWN_VERSION;
    9495            this.time = null;
    95             return;       
    96         }
    97        
     96            return;
     97        }
     98
    9899        HashMap<String, String> properties = parseManifestStyleFormattedString(revisionInfo);
    99100        String value = properties.get("Revision");
     
    109110            version = JOSM_UNKNOWN_VERSION;
    110111        }
    111                
    112         // the last changed data 
     112
     113        // the last changed data
    113114        //
    114115        time = properties.get("Last Changed Date");
     
    116117            time = properties.get("Build-Date");
    117118        }
    118        
     119
    119120        // is this a local build ?
    120121        //
    121         isLocalBuild = false; 
     122        isLocalBuild = false;
    122123        value = properties.get("Is-Local-Build");
    123124        if (value != null && value.trim().toLowerCase().equals("true"))  {
    124125            isLocalBuild = true;
    125126        }
    126        
     127
    127128        // the revision info
    128129        //
     
    132133        }
    133134        revision = sb.toString();
    134     }   
    135        
    136     public void init() {   
     135    }
     136
     137    public void init() {
    137138        URL u = Main.class.getResource("/REVISION");
    138139        if (u == null) {
     
    145146        System.out.println(revision);
    146147    }
    147    
    148     /**
    149      * Replies the version string. Either the SVN revision "1234" (as string) or the 
     148
     149    /**
     150     * Replies the version string. Either the SVN revision "1234" (as string) or the
    150151     * the I18n equivalent of "UNKNOWN".
    151      * 
    152      * @return the JOSM version 
     152     *
     153     * @return the JOSM version
    153154     */
    154155    public String getVersionString() {
    155156        return  version == 0 ? tr("UNKNOWN") : Integer.toString(version);
    156157    }
    157    
     158
    158159    /**
    159160     * Replies a text with the release attributes
    160      * 
     161     *
    161162     * @return a text with the release attributes
    162163     */
     
    166167
    167168    /**
    168      * Replies the build date as string 
    169      * 
    170      * @return the build date as string 
     169     * Replies the build date as string
     170     *
     171     * @return the build date as string
    171172     */
    172173    public String getTime() {
    173174        return time;
    174175    }
    175    
    176     /**
    177      * Replies the JOSM version. Replies {@see #JOSM_UNKNOWN_VERSION} if the version isn't known. 
     176
     177    /**
     178     * Replies the JOSM version. Replies {@see #JOSM_UNKNOWN_VERSION} if the version isn't known.
    178179     * @return the JOSM version
    179180     */
     
    184185    /**
    185186     * Replies true if this is a local build, i.e. an inofficial development build.
    186      * 
     187     *
    187188     * @return true if this is a local build, i.e. an inofficial development build.
    188189     */
     
    190191        return isLocalBuild;
    191192    }
     193
     194    public String getAgentString() {
     195        int v = getVersion();
     196        String s = (v == JOSM_UNKNOWN_VERSION) ? "UNKNOWN" : Integer.toString(v);
     197        if (isLocalBuild() && v != JOSM_UNKNOWN_VERSION) {
     198            s += " SVN";
     199        }
     200        return "JOSM/1.5 ("+ s+" "+LanguageInfo.getJOSMLocaleCode()+")";
     201    }
    192202}
Note: See TracChangeset for help on using the changeset viewer.