Package ortus.boxlang.runtime.util
Class PropertyFile
java.lang.Object
ortus.boxlang.runtime.util.PropertyFile
A fluent API for managing property files in BoxLang.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor - initializes a new PropertyFile instance Sets default values for maxLineWidth (150), empty lines list, and uses system line separator -
Method Summary
Modifier and TypeMethodDescriptionAdds a blank line to the property fileaddComment(String comment) Adds a comment line to the property fileclear()Clears everything including comments and whitespaceClears all properties while preserving comments and whitespacebooleanChecks if a property existsstatic PropertyFilefromIStruct(IStruct properties) Creates a new PropertyFile from an IStructstatic PropertyFileCreates a new PropertyFile from a MapGets a property value by nameGets a property value by name with a default valuegetAsMap()Gets all properties as a standard Java Map Properties are returned in the order they appear in the fileGets all properties as a BoxLang IStruct Uses LinkedStruct to preserve property order as they appear in the filegetLines()Gets the list of all lines (comments, whitespace, and properties) in the fileintGets the maximum line width for formatting long property valuesgetPath()Gets the file path of this property fileGets all property namesbooleanChecks if the property file has any propertiesLoads a property file from the specified path using BoxLang FileSystemUtilMerges properties from a Map into this PropertyFilemergeStruct(IStruct incomingStruct) Merges properties from an IStruct into this PropertyFileRemoves a propertyremoveMulti(Array names) Removes multiple properties at onceSets a property valueSets the list of all lines in the filesetMaxLineWidth(int maxLineWidth) Sets the maximum line width for formatting long property valuesSets multiple property values at once from a MapSets multiple property values at onceSets the file path of this property fileintsize()Gets the number of properties in the filestore()Stores the property file to the currently loaded pathStores the property file to the specified path, if it doesn't exist, it will create the directory structure.toJSON()JSON representation of the property filetoString()To String representation of the property file as a struct
-
Constructor Details
-
PropertyFile
public PropertyFile()Constructor - initializes a new PropertyFile instance Sets default values for maxLineWidth (150), empty lines list, and uses system line separator
-
-
Method Details
-
fromMap
Creates a new PropertyFile from a Map- Parameters:
properties- The properties as a Map- Returns:
- A new PropertyFile instance
-
fromIStruct
Creates a new PropertyFile from an IStruct- Parameters:
properties- The properties as an IStruct- Returns:
- A new PropertyFile instance
-
load
Loads a property file from the specified path using BoxLang FileSystemUtil- Parameters:
path- A fully qualified path to a property file- Returns:
- This PropertyFile instance for method chaining
- Throws:
BoxRuntimeException- If the file does not exist or cannot be read
-
store
Stores the property file to the specified path, if it doesn't exist, it will create the directory structure.- Parameters:
path- The path to store the file (optional, uses loaded path if not provided)- Returns:
- This PropertyFile instance for method chaining
-
store
Stores the property file to the currently loaded path- Returns:
- This PropertyFile instance for method chaining
-
get
Gets a property value by name- Parameters:
name- The property name- Returns:
- The property value
- Throws:
IllegalArgumentException- If the key doesn't exist
-
get
Gets a property value by name with a default value- Parameters:
name- The property namedefaultValue- The default value if the key doesn't exist- Returns:
- The property value or default value
-
addComment
Adds a comment line to the property file- Parameters:
comment- The comment text (without # prefix)- Returns:
- This PropertyFile instance for method chaining
-
addBlankLine
Adds a blank line to the property file- Returns:
- This PropertyFile instance for method chaining
-
set
Sets a property value- Parameters:
name- The property namevalue- The property value- Returns:
- This PropertyFile instance for method chaining
-
setMulti
Sets multiple property values at once- Parameters:
properties- An IStruct containing key-value pairs to set- Returns:
- This PropertyFile instance for method chaining
-
setMulti
Sets multiple property values at once from a Map- Parameters:
properties- A Map containing key-value pairs to set- Returns:
- This PropertyFile instance for method chaining
-
remove
Removes a property- Parameters:
name- The property name to remove- Returns:
- This PropertyFile instance for method chaining
-
removeMulti
Removes multiple properties at once- Parameters:
names- The property names to remove- Returns:
- This PropertyFile instance for method chaining
-
exists
Checks if a property exists- Parameters:
name- The property name- Returns:
- true if the property exists, false otherwise
-
hasProperties
public boolean hasProperties()Checks if the property file has any properties- Returns:
- true if the property file contains at least one property, false otherwise
-
size
public int size()Gets the number of properties in the file- Returns:
- The count of properties
-
clearProperties
Clears all properties while preserving comments and whitespace- Returns:
- This PropertyFile instance for method chaining
-
clear
Clears everything including comments and whitespace- Returns:
- This PropertyFile instance for method chaining
-
getAsStruct
Gets all properties as a BoxLang IStruct Uses LinkedStruct to preserve property order as they appear in the file- Returns:
- An IStruct containing all properties with insertion order preserved
-
getAsMap
Gets all properties as a standard Java Map Properties are returned in the order they appear in the file- Returns:
- A LinkedHashMap containing all properties with insertion order preserved
-
mergeStruct
Merges properties from an IStruct into this PropertyFile- Parameters:
incomingStruct- The IStruct containing properties to merge- Returns:
- This PropertyFile instance for method chaining
-
mergeMap
Merges properties from a Map into this PropertyFile- Parameters:
incomingMap- The Map containing properties to merge- Returns:
- This PropertyFile instance for method chaining
-
getPropertyNames
Gets all property names- Returns:
- An array of property names
-
toString
To String representation of the property file as a struct -
toJSON
JSON representation of the property file -
getPath
Gets the file path of this property file- Returns:
- The fully qualified path to the property file
-
setPath
Sets the file path of this property file- Parameters:
path- The fully qualified path to the property file- Returns:
- This PropertyFile instance for method chaining
-
getLines
Gets the list of all lines (comments, whitespace, and properties) in the file- Returns:
- List of IStruct objects representing the file structure
-
setLines
Sets the list of all lines in the file- Parameters:
lines- List of IStruct objects representing the file structure- Returns:
- This PropertyFile instance for method chaining
-
getMaxLineWidth
public int getMaxLineWidth()Gets the maximum line width for formatting long property values- Returns:
- The maximum line width in characters
-
setMaxLineWidth
Sets the maximum line width for formatting long property values- Parameters:
maxLineWidth- The maximum line width in characters- Returns:
- This PropertyFile instance for method chaining
-