Class EclipseFormatterUtils
java.lang.Object
de.funfried.netbeans.plugins.external.formatter.eclipse.xml.EclipseFormatterUtils
- Author:
- bahlef
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getEclipseFormatterFile
(Preferences preferences, Document document, String configFileLocationKey, String useProjectPrefsKey, String projectPrefFile) Returns the Eclipse formatter file for the givenDocument
from the givenPreferences
.static boolean
isProjectSetting
(String filename, String projectPrefFile) Returnstrue
if the givenfilename
ends with the givenprojectPrefFile
.static boolean
isWorkspaceMechanicFile
(String filename) Returnstrue
if the givenfilename
ends with the workspace mechanic file extension epf.static boolean
isXMLConfigurationFile
(String filename) Returnstrue
if the givenfilename
ends with the XML file extension.parseConfig
(String formatterFile, String formatterProfile, Map<String, String> defaultProperties, Map<String, String> additionalProperties, String workspaceMechanicPrefix, String projectPrefFile) Parses the configuration parameters from the givenformatterProfile
of the givenformatterFile
and returns it as aMap
containing the configuration as key value pairs.readPropertiesFromConfigurationFile
(String filePath) Parses and returns properties of the givenfilePath
into a key valueMap
.toMap
(Properties properties, String prefix) Collect the given properties into a map and optionall filter the property keys by the given optional prefix.
-
Field Details
-
EPF_FILE_EXTENSION
EPF file extension- See Also:
-
XML_FILE_EXTENSION
XML file extension- See Also:
-
-
Method Details
-
getEclipseFormatterFile
public static String getEclipseFormatterFile(Preferences preferences, Document document, String configFileLocationKey, String useProjectPrefsKey, String projectPrefFile) Returns the Eclipse formatter file for the givenDocument
from the givenPreferences
. If the value behinduseProjectPrefsKey
istrue
in the givenPreferences
, it will be automatically checked if there is a project specific formatter configuration file available.- Parameters:
preferences
- thePreferences
where to load fromdocument
- theDocument
configFileLocationKey
- the preferences key for the configuration file locationuseProjectPrefsKey
- the preferences key whether to use project preferencesprojectPrefFile
- the expected Eclipse project specific formatter configuration file name- Returns:
- the Eclipse formatter file for the given
Document
from the givenPreferences
. If the value behinduseProjectPrefsKey
istrue
in the givenPreferences
, it will be automatically checked if there is a project specific formatter configuration file available.
-
isProjectSetting
Returnstrue
if the givenfilename
ends with the givenprojectPrefFile
.- Parameters:
filename
- the filename to checkprojectPrefFile
- the expected Eclipse project specific formatter configuration file name- Returns:
true
if the givenfilename
ends withorg.eclipse.jdt.core.prefs
, otherwisefalse
-
isWorkspaceMechanicFile
Returnstrue
if the givenfilename
ends with the workspace mechanic file extension epf.- Parameters:
filename
- the filename to check- Returns:
true
if the givenfilename
ends with the workspace mechanic file extension epf, otherwisefalse
-
isXMLConfigurationFile
Returnstrue
if the givenfilename
ends with the XML file extension.- Parameters:
filename
- the filename to check- Returns:
true
if the givenfilename
ends with the XML file extension, otherwisefalse
-
parseConfig
public static Map<String,String> parseConfig(String formatterFile, String formatterProfile, Map<String, String> defaultProperties, Map<String, throws ProfileNotFoundException, ConfigReadException, CannotLoadConfigurationExceptionString> additionalProperties, String workspaceMechanicPrefix, String projectPrefFile) Parses the configuration parameters from the givenformatterProfile
of the givenformatterFile
and returns it as aMap
containing the configuration as key value pairs.- Parameters:
formatterFile
- the path to the formatter configuration fileformatterProfile
- the name of the formatter configuration profiledefaultProperties
- the default propertiesadditionalProperties
- optional additional propertiesworkspaceMechanicPrefix
- the workspace mechanic prefixprojectPrefFile
- 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 configurationProfileNotFoundException
- if the givenprofile
could not be foundCannotLoadConfigurationException
- 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 givenfilePath
into a key valueMap
.- Parameters:
filePath
- a configuration file path- Returns:
- properties of the given
file
as a key valueMap
- Throws:
IOException
- if there is an issue accessing the given configuration file
-
toMap
Collect the given properties into a map and optionall filter the property keys by the given optional prefix.- Parameters:
properties
- TheProperties
to filter and collect.prefix
- An optional prefix to filter the keys.- Returns:
- A map containing the keys and their respective values
-