Class CustomConfigurator


  • public final class CustomConfigurator
    extends java.lang.Object
    Class to process configuration changes stored in XML can be used to modify preferences, store/delete files in .josm folders etc
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static boolean busy  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CustomConfigurator()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int askForOption​(java.lang.String text, java.lang.String opts)
      Simple function for choose window, may be used from JS API and from other code
      static java.lang.String askForText​(java.lang.String text)
      Ask the user for text
      static void deleteFile​(java.lang.String path, java.lang.String base)
      Delete a file
      static void deleteFileOrDirectory​(java.io.File f)
      Delete a file or a directory
      static void downloadAndUnpackFile​(java.lang.String address, java.lang.String path, java.lang.String base)
      Downloads file to one of JOSM standard folders and unpack it as ZIP/JAR file
      static void downloadFile​(java.lang.String address, java.lang.String path, java.lang.String base)
      Downloads file to one of JOSM standard folders
      static void exportPreferencesKeysByPatternToFile​(java.lang.String fileName, boolean append, java.lang.String pattern)
      This function exports part of user preferences to specified file.
      static void exportPreferencesKeysToFile​(java.lang.String filename, boolean append, java.lang.String... keys)
      This function exports part of user preferences to specified file.
      static void exportPreferencesKeysToFile​(java.lang.String filename, boolean append, java.util.Collection<java.lang.String> keys)
      Export specified preferences keys to configuration file
      private static java.lang.String getDirectoryByAbbr​(java.lang.String base)  
      static void messageBox​(java.lang.String type, java.lang.String text)
      Simple function to show messageBox, may be used from JS API and from other code
      static void pluginOperation​(java.lang.String install, java.lang.String uninstall, java.lang.String delete)
      Perform install, uninstall, and deletion operations on plugins
      static void processDownloadOperation​(java.lang.String address, java.lang.String path, java.lang.String parentDir, boolean mkdir, boolean unzip)
      Downloads file to arbitrary folder
      static void readXML​(java.io.File file)
      Read configuration script from XML file, modifying main preferences
      static void readXML​(java.io.File file, Preferences prefs)
      Read configuration script from XML file, modifying given preferences object
      static void readXML​(java.lang.String dir, java.lang.String fileName)
      Read configuration script from XML file, modifying main preferences
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • busy

        private static boolean busy
    • Method Detail

      • readXML

        public static void readXML​(java.lang.String dir,
                                   java.lang.String fileName)
        Read configuration script from XML file, modifying main preferences
        Parameters:
        dir - - directory
        fileName - - XML file name
      • readXML

        public static void readXML​(java.io.File file,
                                   Preferences prefs)
        Read configuration script from XML file, modifying given preferences object
        Parameters:
        file - - file to open for reading XML
        prefs - - arbitrary Preferences object to modify by script
      • readXML

        public static void readXML​(java.io.File file)
        Read configuration script from XML file, modifying main preferences
        Parameters:
        file - - file to open for reading XML
      • downloadFile

        public static void downloadFile​(java.lang.String address,
                                        java.lang.String path,
                                        java.lang.String base)
        Downloads file to one of JOSM standard folders
        Parameters:
        address - - URL to download
        path - - file path relative to base where to put downloaded file
        base - - only "prefs", "cache" and "plugins" allowed for standard folders
      • downloadAndUnpackFile

        public static void downloadAndUnpackFile​(java.lang.String address,
                                                 java.lang.String path,
                                                 java.lang.String base)
        Downloads file to one of JOSM standard folders and unpack it as ZIP/JAR file
        Parameters:
        address - - URL to download
        path - - file path relative to base where to put downloaded file
        base - - only "prefs", "cache" and "plugins" allowed for standard folders
      • processDownloadOperation

        public static void processDownloadOperation​(java.lang.String address,
                                                    java.lang.String path,
                                                    java.lang.String parentDir,
                                                    boolean mkdir,
                                                    boolean unzip)
        Downloads file to arbitrary folder
        Parameters:
        address - - URL to download
        path - - file path relative to parentDir where to put downloaded file
        parentDir - - folder where to put file
        mkdir - - if true, non-existing directories will be created
        unzip - - if true file wil be unzipped and deleted after download
      • messageBox

        public static void messageBox​(java.lang.String type,
                                      java.lang.String text)
        Simple function to show messageBox, may be used from JS API and from other code
        Parameters:
        type - - 'i','w','e','q','p' for Information, Warning, Error, Question, Message
        text - - message to display, HTML allowed
      • askForOption

        public static int askForOption​(java.lang.String text,
                                       java.lang.String opts)
        Simple function for choose window, may be used from JS API and from other code
        Parameters:
        text - - message to show, HTML allowed
        opts - -
        Returns:
        number of pressed button, -1 if cancelled
      • askForText

        @Nullable
        public static java.lang.String askForText​(java.lang.String text)
        Ask the user for text
        Parameters:
        text - The message for the user
        Returns:
        The text the user entered
      • exportPreferencesKeysToFile

        public static void exportPreferencesKeysToFile​(java.lang.String filename,
                                                       boolean append,
                                                       java.lang.String... keys)
        This function exports part of user preferences to specified file. Default values are not saved.
        Parameters:
        filename - - where to export
        append - - if true, resulting file cause appending to existing preferences
        keys - - which preferences keys you need to export ("imagery.entries", for example)
      • exportPreferencesKeysByPatternToFile

        public static void exportPreferencesKeysByPatternToFile​(java.lang.String fileName,
                                                                boolean append,
                                                                java.lang.String pattern)
        This function exports part of user preferences to specified file. Default values are not saved. Preference keys matching specified pattern are saved
        Parameters:
        fileName - - where to export
        append - - if true, resulting file cause appending to existing preferences
        pattern - - Regexp pattern for preferences keys you need to export (".*imagery.*", for example)
      • exportPreferencesKeysToFile

        public static void exportPreferencesKeysToFile​(java.lang.String filename,
                                                       boolean append,
                                                       java.util.Collection<java.lang.String> keys)
        Export specified preferences keys to configuration file
        Parameters:
        filename - - name of file
        append - - will the preferences be appended to existing ones when file is imported later. Elsewhere preferences from file will replace existing keys.
        keys - - collection of preferences key names to save
      • deleteFile

        public static void deleteFile​(java.lang.String path,
                                      java.lang.String base)
        Delete a file
        Parameters:
        path - The path to delete inside the base directory
        base - The base directory for the path
      • deleteFileOrDirectory

        public static void deleteFileOrDirectory​(java.io.File f)
        Delete a file or a directory
        Parameters:
        f - The file or directory to delete
      • pluginOperation

        public static void pluginOperation​(java.lang.String install,
                                           java.lang.String uninstall,
                                           java.lang.String delete)
        Perform install, uninstall, and deletion operations on plugins
        Parameters:
        install - The ; delimited list of plugins to install
        uninstall - The ; delimited list of plugins to uninstall
        delete - The ; delimited list of plugins to delete
      • getDirectoryByAbbr

        private static java.lang.String getDirectoryByAbbr​(java.lang.String base)