java.lang.Object
de.funfried.netbeans.plugins.external.formatter.eclipse.xml.EclipseFormatterUtils

public class EclipseFormatterUtils extends Object
Author:
bahlef
  • Field Details

  • Method Details

    • getEclipseFormatterFile

      public static String getEclipseFormatterFile(Preferences preferences, Document document, String configFileLocationKey, String useProjectPrefsKey, String projectPrefFile)
      Returns the Eclipse formatter file for the given Document from the given Preferences. If the value behind useProjectPrefsKey is true in the given Preferences, it will be automatically checked if there is a project specific formatter configuration file available.
      Parameters:
      preferences - the Preferences where to load from
      document - the Document
      configFileLocationKey - the preferences key for the configuration file location
      useProjectPrefsKey - the preferences key whether to use project preferences
      projectPrefFile - the expected Eclipse project specific formatter configuration file name
      Returns:
      the Eclipse formatter file for the given Document from the given Preferences. If the value behind useProjectPrefsKey is true in the given Preferences, it will be automatically checked if there is a project specific formatter configuration file available.
    • isProjectSetting

      public static boolean isProjectSetting(String filename, String projectPrefFile)
      Returns true if the given filename ends with the given projectPrefFile.
      Parameters:
      filename - the filename to check
      projectPrefFile - the expected Eclipse project specific formatter configuration file name
      Returns:
      true if the given filename ends with org.eclipse.jdt.core.prefs, otherwise false
    • isWorkspaceMechanicFile

      public static boolean isWorkspaceMechanicFile(String filename)
      Returns true if the given filename ends with the workspace mechanic file extension epf.
      Parameters:
      filename - the filename to check
      Returns:
      true if the given filename ends with the workspace mechanic file extension epf, otherwise false
    • isXMLConfigurationFile

      public static boolean isXMLConfigurationFile(String filename)
      Returns true if the given filename ends with the XML file extension.
      Parameters:
      filename - the filename to check
      Returns:
      true if the given filename ends with the XML file extension, otherwise false
    • parseConfig

      public static Map<String,String> parseConfig(String formatterFile, String formatterProfile, Map<String,String> defaultProperties, Map<String,String> additionalProperties, String workspaceMechanicPrefix, String projectPrefFile) throws ProfileNotFoundException, ConfigReadException, CannotLoadConfigurationException
      Parses the configuration parameters from the given formatterProfile of the given formatterFile and returns it as a Map containing the configuration as key value pairs.
      Parameters:
      formatterFile - the path to the formatter configuration file
      formatterProfile - the name of the formatter configuration profile
      defaultProperties - the default properties
      additionalProperties - optional additional properties
      workspaceMechanicPrefix - the workspace mechanic prefix
      projectPrefFile - the expected Eclipse project specific formatter configuration file name
      Returns:
      a Map containing the configuration as key value pairs
      Throws:
      ConfigReadException - if there is an issue parsing the formatter configuration
      ProfileNotFoundException - if the given profile could not be found
      CannotLoadConfigurationException - if there is any issue accessing or reading the formatter configuration
    • readPropertiesFromConfigurationFile

      @NonNull public static Map<String,String> readPropertiesFromConfigurationFile(String filePath) throws IOException
      Parses and returns properties of the given filePath into a key value Map.
      Parameters:
      filePath - a configuration file path
      Returns:
      properties of the given file as a key value Map
      Throws:
      IOException - if there is an issue accessing the given configuration file
    • toMap

      public static Map<String,String> toMap(Properties properties, String prefix)
      Collect the given properties into a map and optionall filter the property keys by the given optional prefix.
      Parameters:
      properties - The Properties to filter and collect.
      prefix - An optional prefix to filter the keys.
      Returns:
      A map containing the keys and their respective values