|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.neeve.util.UtlTailoring
public class UtlTailoring
Utility class facilitating tailoring of textual content from provided properties.
This class IS NOT intended to be used by end users.
Nested Class Summary | |
---|---|
static interface |
UtlTailoring.PropertySource
Allows callers to plug in different property sources. |
static class |
UtlTailoring.STYLE
Enumerates possible tailoring styles. |
static class |
UtlTailoring.TailoringException
Indicates that an error occured tailoring String content |
Field Summary | |
---|---|
static boolean |
ENABLE_NEW_SPRING_STYLE_SUBSTITUTION_PARSER
|
static String |
ENABLE_NEW_SPRING_STYLE_SUBSTITUTION_PARSER_PROP
Defines the property name used to control whether or not the new 3.5 spring-style parser is enabled when calling substitute(String, PropertySource) |
static String |
ENABLE_SPRING_STYLE_SUBSTITUTION_PROP
Defines the property name used to control whether or not UtlTailoring.STYLE.SPRING style substitution
is enabled when calling substitute(String, PropertySource) |
static UtlTailoring.PropertySource |
ENV_SUBSTITUTION_RESOLVER
The environment based substitution resolver. |
Constructor Summary | |
---|---|
UtlTailoring()
|
Method Summary | |
---|---|
boolean |
isAppendUnreplacedProperties()
|
boolean |
isLeaveReplacementComments()
|
static boolean |
isPropFileComment(String line)
Tests if the line is a comment line from a prop file. |
static void |
main(String[] args)
|
static String |
propFileScanAndReplace(File target,
Properties props,
boolean appendUreplacedValues,
boolean leaveReplaceComment)
Convenience method equivalent to propFileScanAndReplace(String, Properties, boolean, boolean) except that the
File is read in as a string and tailored. |
static String |
propFileScanAndReplace(String propFileContent,
Properties replacementProps,
boolean appendUreplacedValues,
boolean leaveReplaceComment)
Scans the provided String as a properties file looking for lines of the form propName=propVal replacing them with the value in the provided properties if such a property exists. |
void |
setAppendUnreplacedProperties(boolean appendUnreplacedProperties)
Indicates that unreplaced properties should be appended at the end of the file being tailored. |
void |
setLeaveReplacementComments(boolean leaveReplacementComments)
Indicates that when a property line is replaced a comment containing the original line should be left in the file. |
static String |
springScanAndReplace(File f,
Properties props)
Same as springScanAndReplace(String, Properties) except that the given File is
read in as a string and tailored. |
static String |
springScanAndReplace(String string,
Properties props)
Scans the provided String looking for replacements sequences of the form ${toReplace} replacing them with the value specified by "toReplace" in the provided properties if such a property exists. |
static String |
springScanAndReplace(String string,
Properties props,
boolean preserveDefaults)
Scans the provided String looking for replacements sequences of the form ${toReplace} replacing them with the value specified by "toReplace" in the provided properties if such a property exists. |
static String |
springScanAndReplace(String string,
UtlTailoring.PropertySource props)
Scans the provided String looking for replacements sequences of the form ${toReplace} replacing them with the value specified by "toReplace" in the provided properties if such a property exists. |
static String |
springScanAndReplace(String string,
UtlTailoring.PropertySource props,
boolean preserveDefaults)
Scans the provided String looking for replacements sequences of the form ${toReplace} replacing them with the value specified by "toReplace" in the provided properties if such a property exists. |
static String |
substitute(String str,
UtlTailoring.PropertySource props)
Checks if a string contains subst(...). |
static String |
substituteFromEnv(String str)
Performs substitute(String, PropertySource) using the UtlProps.getEnvProps()
as the property source. |
static String |
substScanAndReplace(File f,
Properties props)
Same as substScanAndReplace(String, Properties) except that the given File is
read in as a string and tailored. |
static String |
substScanAndReplace(String string,
Properties props)
Same as substScanAndReplace(String, PropertySource) using the given Properties
as the UtlTailoring.PropertySource |
static String |
substScanAndReplace(String str,
UtlTailoring.PropertySource props)
Scans the provided String looking for replacements sequences of the form: $subst(%toReplace::defaultValue%)
replacing them with the value specified by "toReplace" in the provided properties if such a property exists or the defaultValue if the property does not exist. |
static void |
tailorFile(File f,
Properties props,
UtlTailoring.STYLE style)
Tailors the given file with the specified properties. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String ENABLE_SPRING_STYLE_SUBSTITUTION_PROP
UtlTailoring.STYLE.SPRING
style substitution
is enabled when calling substitute(String, PropertySource)
public static final String ENABLE_NEW_SPRING_STYLE_SUBSTITUTION_PARSER_PROP
substitute(String, PropertySource)
public static final boolean ENABLE_NEW_SPRING_STYLE_SUBSTITUTION_PARSER
public static final UtlTailoring.PropertySource ENV_SUBSTITUTION_RESOLVER
Constructor Detail |
---|
public UtlTailoring()
Method Detail |
---|
public static final void tailorFile(File f, Properties props, UtlTailoring.STYLE style) throws IOException
f
- The file or directory.props
- The replacement properties.
IOException
- If there is an error tailoring.public static String springScanAndReplace(File f, Properties props) throws IOException
springScanAndReplace(String, Properties)
except that the given File
is
read in as a string and tailored. If substitutions are made then the file is rewritten with the
new content.
IOException
- if there is an error reading the file.public static String springScanAndReplace(String string, Properties props)
${toReplace}
${toReplace,defaultValue}
${toReplace,defaultValue}
will be
replaced with defaultValue"
.
string
- The string to tailorprops
- The properties to used for replacements.
public static String springScanAndReplace(String string, Properties props, boolean preserveDefaults)
${toReplace}
${toReplace,defaultValue}
${toReplace,defaultValue}
will be
replaced with defaultValue"
.
string
- The string to tailorprops
- The properties to used for replacements.preserveDefaults
- When true if a value is not specified in the properties the default
will be left in place.
public static String springScanAndReplace(String string, UtlTailoring.PropertySource props) throws UtlTailoring.TailoringException
${toReplace}
${toReplace::defaultValue}
${toReplace,defaultValue}
will be
replaced with defaultValue"
.
string
- The string to tailorprops
- The property source to used for replacements.
UtlTailoring.TailoringException
public static String springScanAndReplace(String string, UtlTailoring.PropertySource props, boolean preserveDefaults) throws UtlTailoring.TailoringException
${toReplace}
${toReplace::defaultValue}
${toReplace,defaultValue}
will be
replaced with defaultValue"
.
string
- The string to tailorprops
- The property source to used for replacements.preserveDefaults
- When true if a value is not specified in the properties the default
will be left in place.
UtlTailoring.TailoringException
public static String substScanAndReplace(File f, Properties props) throws IOException
substScanAndReplace(String, Properties)
except that the given File
is
read in as a string and tailored. If substitutions are made then the file is rewritten with the
new content.
IOException
- if there is an error reading the file.public static String substScanAndReplace(String string, Properties props) throws Exception
substScanAndReplace(String, PropertySource)
using the given Properties
as the UtlTailoring.PropertySource
Exception
public static String substScanAndReplace(String str, UtlTailoring.PropertySource props) throws Exception
$subst(%toReplace::defaultValue%)
This substitution method requires supports escaping of special characters inside the $subst(...)
Exception
public static String propFileScanAndReplace(File target, Properties props, boolean appendUreplacedValues, boolean leaveReplaceComment) throws IOException
propFileScanAndReplace(String, Properties, boolean, boolean)
except that the
File
is read in as a string and tailored. If substitutions are made then the file is
rewritten with the new content.
target
- The property file contentprops
- The replacementProps propertiesappendUreplacedValues
- if True values that are not replaced are appended to the end of the file.leaveReplaceComment
- if True values that are not replaced are appended to the end of the file.
IOException
- if there is an error reading the file.public static String propFileScanAndReplace(String propFileContent, Properties replacementProps, boolean appendUreplacedValues, boolean leaveReplaceComment)
propName=propVal
propFileContent
- The propety file contentreplacementProps
- The replacementProps propertiesappendUreplacedValues
- if True values that are not replaced are appended to the end of the file.leaveReplaceComment
- Leaves a comment indicating what was replaced
public static final boolean isPropFileComment(String line)
line
- The line to check
public void setAppendUnreplacedProperties(boolean appendUnreplacedProperties)
Applies to UtlTailoring.STYLE.PROPFILE
tailoring.
appendUnreplacedProperties
- true to if unreplaced properties should be appended to the end of the filepublic boolean isAppendUnreplacedProperties()
public void setLeaveReplacementComments(boolean leaveReplacementComments)
Applies to UtlTailoring.STYLE.PROPFILE
tailoring.
leaveReplacementComments
- Whether or not to leave comments about replacementspublic boolean isLeaveReplacementComments()
public static final String substitute(String str, UtlTailoring.PropertySource props) throws Exception
ENABLE_SPRING_STYLE_SUBSTITUTION_PROP
property.
Exception
public static final String substituteFromEnv(String str) throws Exception
substitute(String, PropertySource)
using the UtlProps.getEnvProps()
as the property source.
str
- The String on which to perform substitution.
UtlTailoring.TailoringException
- If there is an error making substitutions.
Exception
public static final void main(String[] args) throws Exception
Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |