Package net.solarnetwork.util
Class StringMerger
java.lang.Object
net.solarnetwork.util.StringMerger
Utility class for performing a simple mail-merge.
This class parses a String source and substitutes variables in the form of
${name} for a corresponding property in a specified data
object. The data object can be either a java.util.Map or an
arbitrary JavaBean. If the data object is a Map, the variable names will be
treated as keys in that map, the the corresponding value will be substituted
in the output String. Otherwise, reflection will be used to access JavaBean
getter methods, using the Struts naming conventions for bean property names
and nested names.
- Version:
- 1.1
- Author:
- matt
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringMerge from a file source, and return the merged output as a String.static StringmergeResource(org.springframework.core.io.Resource resource, Object data) Merge from a Resource, and return the merged output as a String.static StringmergeResource(org.springframework.core.io.Resource resource, Object data, String nullValue) Merge from a Resource, and return the merged output as a String.static voidmergeString(String src, Object data, String nullValue, StringBuilder buf) Merge from a String source into a StringBuilder.static StringmergeString(String src, String nullValue, Object data) Merge from a String source and return the result.
-
Method Details
-
mergeResource
public static String mergeResource(org.springframework.core.io.Resource resource, Object data) throws IOException Merge from a Resource, and return the merged output as a String.This method calls the
mergeResource(Resource, Object, String)method, passing an empty string fornullValue.- Parameters:
resource- the resourcedata- the data to merge with- Returns:
- merged string
- Throws:
IOException- if an error occurs
-
mergeResource
public static String mergeResource(org.springframework.core.io.Resource resource, Object data, String nullValue) throws IOException Merge from a Resource, and return the merged output as a String.This method will read the Resource as character data line by line, merging each line as it goes.
- Parameters:
resource- the resourcedata- the data to merge withnullValue- the value to substitute for null data elements- Returns:
- merged string
- Throws:
IOException- if an error occurs
-
merge
Merge from a file source, and return the merged output as a String.- Parameters:
filePath- path to the source filedata- theMapor JavaBean with merge data- Returns:
- the merged output
- Throws:
IOException- if an exception occurs
-
mergeString
Merge from a String source and return the result.- Parameters:
src- java.lang.StringnullValue- the value to substitute for null datadata- java.lang.Object- Returns:
- java.lang.String
-
mergeString
Merge from a String source into a StringBuilder.- Parameters:
src- the source String to substitute intodata- the data object to substitute withnullValue- the value to substitute for null databuf- the StringBuilder to append the output to
-