Class PlatformHookWindows
- java.lang.Object
-
- org.openstreetmap.josm.tools.PlatformHookWindows
-
- All Implemented Interfaces:
PlatformHook
public class PlatformHookWindows extends Object implements PlatformHook
PlatformHook
implementation for Microsoft Windows systems.- Since:
- 1023
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PlatformHookWindows.FontEntry
Simple data class to hold information about a font.-
Nested classes/interfaces inherited from interface org.openstreetmap.josm.tools.PlatformHook
PlatformHook.JavaExpirationCallback, PlatformHook.NativeOsCallback, PlatformHook.WebStartMigrationCallback
-
-
Field Summary
Fields Modifier and Type Field Description private static String
CURRENT_VERSION
private static Pattern
MS_VERSION_PATTERN
Pattern of Microsoft .NET and Powershell version numbers in registry.private String
oSBuildNumber
private static String
WINDOWS_ROOT
-
Fields inherited from interface org.openstreetmap.josm.tools.PlatformHook
CONSTRUCT_FROM_PLATFORM
-
-
Constructor Summary
Constructors Constructor Description PlatformHookWindows()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPrefStartupHook()
The afterPrefStartupHook will be called early, but after the preferences have been loaded and basic processing of command line arguments is finished.private static String
buildOSBuildNumber()
protected void
extendFontconfig(String templateFileName)
Add more fallback fonts to the Java runtime, in order to get support for more scripts.protected Collection<PlatformHookWindows.FontEntry>
getAdditionalFonts()
Get default list of additional fonts to add to the configuration.static String
getCurrentBuild()
Returns the Windows current build number from registry (example: "15063")File
getDefaultCacheDirectory()
Returns the platform-dependent default cache directory.File
getDefaultPrefDirectory()
Returns the platform-dependent default preferences directory.String
getDefaultStyle()
Returns the default LAF to be used on this platform to look almost as a native application.File
getDefaultUserDataDirectory()
Returns the platform-dependent default user data directory.protected Collection<String>
getInstalledFonts()
Get a list of fonts that are installed on the system.String
getOSBuildNumber()
Returns OS build number.String
getOSDescription()
Returns a detailed OS description (at least family + version).Platform
getPlatform()
Get the platform corresponding to this platform hook.Collection<String>
getPossiblePreferenceDirs()
Returns a set of possible platform specific directories where resources could be stored.static int
getPowerShellVersion()
Returns the major version number of PowerShell.static String
getProductName()
Returns the Windows product name from registry (example: "Windows 10 Pro")static String
getReleaseId()
Returns the Windows release identifier from registry (example: "1703")static KeyStore
getRootKeystore()
Loads Windows-ROOT keystore.X509Certificate
getX509Certificate(CertificateAmendment.NativeCertAmend certAmend)
Returns theX509Certificate
matching the given certificate amendment information.void
initSystemShortcuts()
The initSystemShortcuts hook will be called by the Shortcut class after the modifier groups have been read from the config, but before any shortcuts are read from it or registered from within the application.static boolean
isDotNet45Installed()
Determines if the .NET framework 4.5 (or later) is installed.void
openUrl(String url)
The openURL hook will be used to open an URL in the default web browser.boolean
rename(File from, File to)
Renames a file.File
resolveFileLink(File file)
Resolves a file link to its destination file.private static boolean
sha256matches(Certificate result, CertificateAmendment.NativeCertAmend certAmend, MessageDigest md)
void
startupHook(PlatformHook.JavaExpirationCallback javaCallback, PlatformHook.WebStartMigrationCallback webStartCallback)
The startupHook will be called early, but after the GUI setup has started.static String
webRequest(String uri)
Performs a web request using Windows CryptoAPI (through PowerShell).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.tools.PlatformHook
canFullscreen, checkExpiredJava, checkWebStartMigration, exec, getDefaultProj4NadshiftDirectories, getMenuShortcutKeyMaskEx, isHtmlSupportedInMenuTooltips, isOpenJDK, preStartupHook, setNativeOsCallback
-
-
-
-
Field Detail
-
MS_VERSION_PATTERN
private static final Pattern MS_VERSION_PATTERN
Pattern of Microsoft .NET and Powershell version numbers in registry.
-
WINDOWS_ROOT
private static final String WINDOWS_ROOT
- See Also:
- Constant Field Values
-
CURRENT_VERSION
private static final String CURRENT_VERSION
- See Also:
- Constant Field Values
-
oSBuildNumber
private String oSBuildNumber
-
-
Constructor Detail
-
PlatformHookWindows
public PlatformHookWindows()
-
-
Method Detail
-
getPlatform
public Platform getPlatform()
Description copied from interface:PlatformHook
Get the platform corresponding to this platform hook.- Specified by:
getPlatform
in interfacePlatformHook
- Returns:
- the platform corresponding to this platform hook
-
afterPrefStartupHook
public void afterPrefStartupHook()
Description copied from interface:PlatformHook
The afterPrefStartupHook will be called early, but after the preferences have been loaded and basic processing of command line arguments is finished. It is guaranteed to be called before the GUI setup has started.- Specified by:
afterPrefStartupHook
in interfacePlatformHook
-
startupHook
public void startupHook(PlatformHook.JavaExpirationCallback javaCallback, PlatformHook.WebStartMigrationCallback webStartCallback)
Description copied from interface:PlatformHook
The startupHook will be called early, but after the GUI setup has started. Reason: On OSX we need to register some callbacks with the OS, so we'll receive events from the system menu.- Specified by:
startupHook
in interfacePlatformHook
- Parameters:
javaCallback
- Java expiration callback, providing GUI feedbackwebStartCallback
- WebStart migration callback, providing GUI feedback
-
openUrl
public void openUrl(String url) throws IOException
Description copied from interface:PlatformHook
The openURL hook will be used to open an URL in the default web browser.- Specified by:
openUrl
in interfacePlatformHook
- Parameters:
url
- The URL to open- Throws:
IOException
- if any I/O error occurs
-
initSystemShortcuts
public void initSystemShortcuts()
Description copied from interface:PlatformHook
The initSystemShortcuts hook will be called by the Shortcut class after the modifier groups have been read from the config, but before any shortcuts are read from it or registered from within the application. Please note that you are not allowed to register any shortcuts from this hook, but only "systemCuts"! BTW: SystemCuts should be named "system:<whatever>", and it'd be best if you'd recycle the names already used by the Windows and OSX hooks. Especially the later has really many of them. You should also register any and all shortcuts that the operation system handles itself to block JOSM from trying to use them---as that would just not work. Call setAutomatic on them to prevent the keyboard preferences from allowing the user to change them.- Specified by:
initSystemShortcuts
in interfacePlatformHook
-
getDefaultStyle
public String getDefaultStyle()
Description copied from interface:PlatformHook
Returns the default LAF to be used on this platform to look almost as a native application.- Specified by:
getDefaultStyle
in interfacePlatformHook
- Returns:
- The default native LAF for this platform
-
rename
public boolean rename(File from, File to)
Description copied from interface:PlatformHook
Renames a file.- Specified by:
rename
in interfacePlatformHook
- Parameters:
from
- Source fileto
- Target file- Returns:
true
if the file has been renamed,false
otherwise
-
getOSDescription
public String getOSDescription()
Description copied from interface:PlatformHook
Returns a detailed OS description (at least family + version).- Specified by:
getOSDescription
in interfacePlatformHook
- Returns:
- A detailed OS description.
-
getProductName
public static String getProductName() throws IllegalAccessException, InvocationTargetException
Returns the Windows product name from registry (example: "Windows 10 Pro")- Returns:
- the Windows product name from registry
- Throws:
IllegalAccessException
- if Java language access control is enforced and the underlying method is inaccessibleInvocationTargetException
- if the underlying method throws an exception- Since:
- 12744
-
getReleaseId
public static String getReleaseId() throws IllegalAccessException, InvocationTargetException
Returns the Windows release identifier from registry (example: "1703")- Returns:
- the Windows release identifier from registry
- Throws:
IllegalAccessException
- if Java language access control is enforced and the underlying method is inaccessibleInvocationTargetException
- if the underlying method throws an exception- Since:
- 12744
-
getCurrentBuild
public static String getCurrentBuild() throws IllegalAccessException, InvocationTargetException
Returns the Windows current build number from registry (example: "15063")- Returns:
- the Windows current build number from registry
- Throws:
IllegalAccessException
- if Java language access control is enforced and the underlying method is inaccessibleInvocationTargetException
- if the underlying method throws an exception- Since:
- 12744
-
buildOSBuildNumber
private static String buildOSBuildNumber()
-
getOSBuildNumber
public String getOSBuildNumber()
Description copied from interface:PlatformHook
Returns OS build number.- Specified by:
getOSBuildNumber
in interfacePlatformHook
- Returns:
- OS build number.
-
getRootKeystore
public static KeyStore getRootKeystore() throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException
Loads Windows-ROOT keystore.- Returns:
- Windows-ROOT keystore
- Throws:
NoSuchAlgorithmException
- if the algorithm used to check the integrity of the keystore cannot be foundCertificateException
- if any of the certificates in the keystore could not be loadedIOException
- if there is an I/O or format problem with the keystore data, if a password is required but not givenKeyStoreException
- if no Provider supports a KeyStore implementation for the type "Windows-ROOT"- Since:
- 7343
-
getX509Certificate
public X509Certificate getX509Certificate(CertificateAmendment.NativeCertAmend certAmend) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException
Description copied from interface:PlatformHook
Returns theX509Certificate
matching the given certificate amendment information.- Specified by:
getX509Certificate
in interfacePlatformHook
- Parameters:
certAmend
- certificate amendment- Returns:
- the
X509Certificate
matching the given certificate amendment information, ornull
- Throws:
KeyStoreException
- in case of errorNoSuchAlgorithmException
- in case of errorCertificateException
- in case of errorIOException
- in case of error
-
sha256matches
private static boolean sha256matches(Certificate result, CertificateAmendment.NativeCertAmend certAmend, MessageDigest md) throws CertificateEncodingException
- Throws:
CertificateEncodingException
-
getDefaultCacheDirectory
public File getDefaultCacheDirectory()
Description copied from interface:PlatformHook
Returns the platform-dependent default cache directory.- Specified by:
getDefaultCacheDirectory
in interfacePlatformHook
- Returns:
- the platform-dependent default cache directory
-
getDefaultPrefDirectory
public File getDefaultPrefDirectory()
Description copied from interface:PlatformHook
Returns the platform-dependent default preferences directory.- Specified by:
getDefaultPrefDirectory
in interfacePlatformHook
- Returns:
- the platform-dependent default preferences directory
-
getDefaultUserDataDirectory
public File getDefaultUserDataDirectory()
Description copied from interface:PlatformHook
Returns the platform-dependent default user data directory.- Specified by:
getDefaultUserDataDirectory
in interfacePlatformHook
- Returns:
- the platform-dependent default user data directory
-
extendFontconfig
protected void extendFontconfig(String templateFileName)
Add more fallback fonts to the Java runtime, in order to get support for more scripts.
The font configuration in Java doesn't include some Indic scripts, even though MS Windows ships with fonts that cover these unicode ranges.
To fix this, the fontconfig.properties template is copied to the JOSM cache folder. Then, the additional entries are added to the font configuration. Finally the system property "sun.awt.fontconfig" is set to the customized fontconfig.properties file.
This is a crude hack, but better than no font display at all for these languages. There is no guarantee, that the template file ($JAVA_HOME/lib/fontconfig.properties.src) matches the default configuration (which is in a binary format). Furthermore, the system property "sun.awt.fontconfig" is undocumented and may no longer work in future versions of Java.
Related Java bug: JDK-8008572
- Parameters:
templateFileName
- file name of the fontconfig.properties template file
-
getInstalledFonts
protected Collection<String> getInstalledFonts()
Get a list of fonts that are installed on the system. Must be done without triggering the Java Font initialization. (SeeextendFontconfig(java.lang.String)
, have to set system property first, which is then read by sun.awt.FontConfiguration upon initialization.)- Returns:
- list of file names
-
getAdditionalFonts
protected Collection<PlatformHookWindows.FontEntry> getAdditionalFonts()
Get default list of additional fonts to add to the configuration. Java will choose thee first font in the list that can render a certain character.- Returns:
- list of FontEntry objects
-
isDotNet45Installed
public static boolean isDotNet45Installed()
Determines if the .NET framework 4.5 (or later) is installed. Windows 7 ships by default with an older version.- Returns:
true
if the .NET framework 4.5 (or later) is installed.- Since:
- 13463
-
getPowerShellVersion
public static int getPowerShellVersion()
Returns the major version number of PowerShell.- Returns:
- the major version number of PowerShell. -1 in case of error
- Since:
- 13465
-
webRequest
public static String webRequest(String uri) throws IOException
Performs a web request using Windows CryptoAPI (through PowerShell). This is useful to ensure Windows trust store will contain a specific root CA.- Parameters:
uri
- the web URI to request- Returns:
- HTTP response from the given URI
- Throws:
IOException
- if any I/O error occurs- Since:
- 13458
-
resolveFileLink
public File resolveFileLink(File file)
Description copied from interface:PlatformHook
Resolves a file link to its destination file.- Specified by:
resolveFileLink
in interfacePlatformHook
- Parameters:
file
- file (link or regular file)- Returns:
- destination file in case of a file link, file if regular
-
getPossiblePreferenceDirs
public Collection<String> getPossiblePreferenceDirs()
Description copied from interface:PlatformHook
Returns a set of possible platform specific directories where resources could be stored.- Specified by:
getPossiblePreferenceDirs
in interfacePlatformHook
- Returns:
- A set of possible platform specific directories where resources could be stored.
-
-