Class PlatformHookWindows
- java.lang.Object
-
- org.openstreetmap.josm.tools.PlatformHookWindows
-
- All Implemented Interfaces:
PlatformHook
public class PlatformHookWindows extends java.lang.Object implements PlatformHook
PlatformHookimplementation for Microsoft Windows systems.- Since:
- 1023
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPlatformHookWindows.FontEntrySimple data class to hold information about a font.-
Nested classes/interfaces inherited from interface org.openstreetmap.josm.tools.PlatformHook
PlatformHook.JavaExpirationCallback, PlatformHook.NativeOsCallback, PlatformHook.SanityCheckCallback
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCURRENT_VERSIONprivate static java.util.regex.PatternMS_VERSION_PATTERNPattern of Microsoft .NET and Powershell version numbers in registry.private java.lang.StringoSBuildNumberprivate static java.lang.StringWINDOWS_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 voidafterPrefStartupHook()The afterPrefStartupHook will be called early, but after the preferences have been loaded and basic processing of command line arguments is finished.private static java.lang.StringbuildOSBuildNumber()protected voidextendFontconfig(java.lang.String templateFileName)Add more fallback fonts to the Java runtime, in order to get support for more scripts.protected java.util.Collection<PlatformHookWindows.FontEntry>getAdditionalFonts()Get default list of additional fonts to add to the configuration.static java.lang.StringgetCurrentBuild()Returns the Windows current build number from registry (example: "15063")java.io.FilegetDefaultCacheDirectory()Returns the platform-dependent default cache directory.java.io.FilegetDefaultPrefDirectory()Returns the platform-dependent default preferences directory.java.lang.StringgetDefaultStyle()Returns the default LAF to be used on this platform to look almost as a native application.java.io.FilegetDefaultUserDataDirectory()Returns the platform-dependent default user data directory.static java.lang.StringgetDisplayVersion()Returns the Windows display version from registry (example: "22H2")protected java.util.Collection<java.lang.String>getInstalledFonts()Get a list of fonts that are installed on the system.java.lang.StringgetOSBuildNumber()Returns OS build number.java.lang.StringgetOSDescription()Returns a detailed OS description (at least family + version).PlatformgetPlatform()Get the platform corresponding to this platform hook.java.util.Collection<java.lang.String>getPossiblePreferenceDirs()Returns a set of possible platform specific directories where resources could be stored.static intgetPowerShellVersion()Returns the major version number of PowerShell.static java.lang.StringgetProductName()Returns the Windows product name from registry (example: "Windows 10 Pro")static java.lang.StringgetReleaseId()Returns the Windows release identifier from registry (example: "1703")static java.security.KeyStoregetRootKeystore()Loads Windows-ROOT keystore.java.security.cert.X509CertificategetX509Certificate(CertificateAmendment.NativeCertAmend certAmend)Returns theX509Certificatematching the given certificate amendment information.voidinitSystemShortcuts()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 booleanisDotNet45Installed()Determines if the .NET framework 4.5 (or later) is installed.voidopenUrl(java.lang.String url)The openURL hook will be used to open a URL in the default web browser.booleanrename(java.io.File from, java.io.File to)Renames a file.java.io.FileresolveFileLink(java.io.File file)Resolves a file link to its destination file.private static booleansha256matches(java.security.cert.Certificate result, CertificateAmendment.NativeCertAmend certAmend, java.security.MessageDigest md)voidstartupHook(PlatformHook.JavaExpirationCallback javaCallback, PlatformHook.SanityCheckCallback sanityCheckCallback)The startupHook will be called early, but after the GUI setup has started.static java.lang.StringwebRequest(java.lang.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, exec, getDefaultProj4NadshiftDirectories, getJavaUrl, getMenuShortcutKeyMaskEx, isHtmlSupportedInMenuTooltips, isOpenJDK, preStartupHook, setNativeOsCallback, startupSanityChecks, warnSoonToBeUnsupportedJava
-
-
-
-
Field Detail
-
MS_VERSION_PATTERN
private static final java.util.regex.Pattern MS_VERSION_PATTERN
Pattern of Microsoft .NET and Powershell version numbers in registry.
-
WINDOWS_ROOT
private static final java.lang.String WINDOWS_ROOT
- See Also:
- Constant Field Values
-
CURRENT_VERSION
private static final java.lang.String CURRENT_VERSION
- See Also:
- Constant Field Values
-
oSBuildNumber
private java.lang.String oSBuildNumber
-
-
Constructor Detail
-
PlatformHookWindows
public PlatformHookWindows()
-
-
Method Detail
-
getPlatform
public Platform getPlatform()
Description copied from interface:PlatformHookGet the platform corresponding to this platform hook.- Specified by:
getPlatformin interfacePlatformHook- Returns:
- the platform corresponding to this platform hook
-
afterPrefStartupHook
public void afterPrefStartupHook()
Description copied from interface:PlatformHookThe 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:
afterPrefStartupHookin interfacePlatformHook
-
startupHook
public void startupHook(PlatformHook.JavaExpirationCallback javaCallback, PlatformHook.SanityCheckCallback sanityCheckCallback)
Description copied from interface:PlatformHookThe 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:
startupHookin interfacePlatformHook- Parameters:
javaCallback- Java expiration callback, providing GUI feedbacksanityCheckCallback- Sanity check callback, providing GUI feedback
-
openUrl
public void openUrl(java.lang.String url) throws java.io.IOException
Description copied from interface:PlatformHookThe openURL hook will be used to open a URL in the default web browser.- Specified by:
openUrlin interfacePlatformHook- Parameters:
url- The URL to open- Throws:
java.io.IOException- if any I/O error occurs
-
initSystemShortcuts
public void initSystemShortcuts()
Description copied from interface:PlatformHookThe 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 latter has really many of them.
You should also register any and all shortcuts that the operating 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:
initSystemShortcutsin interfacePlatformHook
-
getDefaultStyle
public java.lang.String getDefaultStyle()
Description copied from interface:PlatformHookReturns the default LAF to be used on this platform to look almost as a native application.- Specified by:
getDefaultStylein interfacePlatformHook- Returns:
- The default native LAF for this platform
-
rename
public boolean rename(java.io.File from, java.io.File to)
Description copied from interface:PlatformHookRenames a file.- Specified by:
renamein interfacePlatformHook- Parameters:
from- Source fileto- Target file- Returns:
trueif the file has been renamed,falseotherwise
-
getOSDescription
public java.lang.String getOSDescription()
Description copied from interface:PlatformHookReturns a detailed OS description (at least family + version).- Specified by:
getOSDescriptionin interfacePlatformHook- Returns:
- A detailed OS description.
-
getProductName
public static java.lang.String getProductName() throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Returns the Windows product name from registry (example: "Windows 10 Pro")- Returns:
- the Windows product name from registry
- Throws:
java.lang.IllegalAccessException- if Java language access control is enforced and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException- if the underlying method throws an exception- Since:
- 12744
-
getReleaseId
public static java.lang.String getReleaseId() throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Returns the Windows release identifier from registry (example: "1703")- Returns:
- the Windows release identifier from registry
- Throws:
java.lang.IllegalAccessException- if Java language access control is enforced and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException- if the underlying method throws an exception- Since:
- 12744
-
getDisplayVersion
public static java.lang.String getDisplayVersion() throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Returns the Windows display version from registry (example: "22H2")- Returns:
- the Windows display version from registry
- Throws:
java.lang.IllegalAccessException- if Java language access control is enforced and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException- if the underlying method throws an exception- Since:
- 19041
-
getCurrentBuild
public static java.lang.String getCurrentBuild() throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
Returns the Windows current build number from registry (example: "15063")- Returns:
- the Windows current build number from registry
- Throws:
java.lang.IllegalAccessException- if Java language access control is enforced and the underlying method is inaccessiblejava.lang.reflect.InvocationTargetException- if the underlying method throws an exception- Since:
- 12744
-
buildOSBuildNumber
private static java.lang.String buildOSBuildNumber()
-
getOSBuildNumber
public java.lang.String getOSBuildNumber()
Description copied from interface:PlatformHookReturns OS build number.- Specified by:
getOSBuildNumberin interfacePlatformHook- Returns:
- OS build number.
-
getRootKeystore
public static java.security.KeyStore getRootKeystore() throws java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.io.IOException, java.security.KeyStoreException
Loads Windows-ROOT keystore.- Returns:
- Windows-ROOT keystore
- Throws:
java.security.NoSuchAlgorithmException- if the algorithm used to check the integrity of the keystore cannot be foundjava.security.cert.CertificateException- if any of the certificates in the keystore could not be loadedjava.io.IOException- if there is an I/O or format problem with the keystore data, if a password is required but not givenjava.security.KeyStoreException- if no Provider supports a KeyStore implementation for the type "Windows-ROOT"- Since:
- 7343
-
getX509Certificate
public java.security.cert.X509Certificate getX509Certificate(CertificateAmendment.NativeCertAmend certAmend) throws java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.io.IOException
Description copied from interface:PlatformHookReturns theX509Certificatematching the given certificate amendment information.- Specified by:
getX509Certificatein interfacePlatformHook- Parameters:
certAmend- certificate amendment- Returns:
- the
X509Certificatematching the given certificate amendment information, ornull - Throws:
java.security.KeyStoreException- in case of errorjava.security.NoSuchAlgorithmException- in case of errorjava.security.cert.CertificateException- in case of errorjava.io.IOException- in case of error
-
sha256matches
private static boolean sha256matches(java.security.cert.Certificate result, CertificateAmendment.NativeCertAmend certAmend, java.security.MessageDigest md) throws java.security.cert.CertificateEncodingException
- Throws:
java.security.cert.CertificateEncodingException
-
getDefaultCacheDirectory
public java.io.File getDefaultCacheDirectory()
Description copied from interface:PlatformHookReturns the platform-dependent default cache directory.- Specified by:
getDefaultCacheDirectoryin interfacePlatformHook- Returns:
- the platform-dependent default cache directory
-
getDefaultPrefDirectory
public java.io.File getDefaultPrefDirectory()
Description copied from interface:PlatformHookReturns the platform-dependent default preferences directory.- Specified by:
getDefaultPrefDirectoryin interfacePlatformHook- Returns:
- the platform-dependent default preferences directory
-
getDefaultUserDataDirectory
public java.io.File getDefaultUserDataDirectory()
Description copied from interface:PlatformHookReturns the platform-dependent default user data directory.- Specified by:
getDefaultUserDataDirectoryin interfacePlatformHook- Returns:
- the platform-dependent default user data directory
-
extendFontconfig
protected void extendFontconfig(java.lang.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 java.util.Collection<java.lang.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 java.util.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:
trueif 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 java.lang.String webRequest(java.lang.String uri) throws java.io.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:
java.io.IOException- if any I/O error occurs- Since:
- 13458
-
resolveFileLink
public java.io.File resolveFileLink(java.io.File file)
Description copied from interface:PlatformHookResolves a file link to its destination file.- Specified by:
resolveFileLinkin interfacePlatformHook- Parameters:
file- file (link or regular file)- Returns:
- destination file in case of a file link, file if regular
-
getPossiblePreferenceDirs
public java.util.Collection<java.lang.String> getPossiblePreferenceDirs()
Description copied from interface:PlatformHookReturns a set of possible platform specific directories where resources could be stored.- Specified by:
getPossiblePreferenceDirsin interfacePlatformHook- Returns:
- A set of possible platform specific directories where resources could be stored.
-
-