Class HeaderDefinition
- java.lang.Object
-
- com.google.code.mojo.license.header.HeaderDefinition
-
public final class HeaderDefinition extends java.lang.ObjectTheHeaderDefinitionclass defines what is needed to output a header text into the of the given file type and what is needed to match the first line as well as the last line of a previous header of the given file type.
Optionally you can define the lines you want to skip before outputting the header.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.BooleanallowBlankLinesprivate java.lang.StringbeforeEachLineprivate java.lang.StringendLineprivate java.lang.StringfirstLineprivate java.util.regex.PatternfirstLineDetectionPatternprivate java.lang.BooleanisMultilineprivate java.util.regex.PatternlastLineDetectionPatternprivate java.util.regex.PatternskipLinePatternprivate java.lang.Stringtype
-
Constructor Summary
Constructors Constructor Description HeaderDefinition(java.lang.String type)Constructs a newHeaderDefinitionwith only initializing the header type.HeaderDefinition(java.lang.String type, java.lang.String firstLine, java.lang.String beforeEachLine, java.lang.String endLine, java.lang.String skipLinePattern, java.lang.String firstLineDetectionPattern, java.lang.String lastLineDetectionPattern, boolean allowBlankLines, boolean isMultiline)Constructs a newHeaderDefinitionobject with every header definition properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallowBlankLines()private voidcheck(java.lang.String name, java.lang.Boolean value)private voidcheck(java.lang.String name, java.lang.String value)private voidcheck(java.lang.String name, java.util.regex.Pattern value)private java.util.regex.Patterncompile(java.lang.String regexp)booleanequals(java.lang.Object o)java.lang.StringgetBeforeEachLine()java.lang.StringgetEndLine()java.lang.StringgetFirstLine()protected java.util.regex.PatterngetSkipLinePattern()java.lang.StringgetType()inthashCode()private booleanisEmpty(java.lang.String s)booleanisFirstHeaderLine(java.lang.String line)Tells if the given content line is the first line of a possible header of this definition kind.booleanisLastHeaderLine(java.lang.String line)Tells if the given content line is the last line of a possible header of this definition kind.booleanisMultiLine()booleanisSkipLine(java.lang.String line)Tells if the given content line must be skipped according to this header definition.voidsetPropertyFromString(java.lang.String property, java.lang.String value)Sets header definition properties using its property name and its string value.
If you want to set a property to null you must not call this function.
This function is mainly used while parsing properties from the XML configuration file.java.lang.StringtoString()voidvalidate()Checks this header definition consistency, in other words if all the mandatory properties of the definition have been set.
-
-
-
Field Detail
-
type
private final java.lang.String type
-
firstLine
private java.lang.String firstLine
-
beforeEachLine
private java.lang.String beforeEachLine
-
endLine
private java.lang.String endLine
-
allowBlankLines
private java.lang.Boolean allowBlankLines
-
skipLinePattern
private java.util.regex.Pattern skipLinePattern
-
firstLineDetectionPattern
private java.util.regex.Pattern firstLineDetectionPattern
-
lastLineDetectionPattern
private java.util.regex.Pattern lastLineDetectionPattern
-
isMultiline
private java.lang.Boolean isMultiline
-
-
Constructor Detail
-
HeaderDefinition
public HeaderDefinition(java.lang.String type, java.lang.String firstLine, java.lang.String beforeEachLine, java.lang.String endLine, java.lang.String skipLinePattern, java.lang.String firstLineDetectionPattern, java.lang.String lastLineDetectionPattern, boolean allowBlankLines, boolean isMultiline)Constructs a newHeaderDefinitionobject with every header definition properties.- Parameters:
type- The type name for this header definition.firstLine- The string to output before the content of the first line of this header.beforeEachLine- The string to output before the content of each line of this header (except firstLine and endLine).endLine- The string to output before the content of the last line of this header.skipLinePattern- The pattern of lines to skip before being allowed to output this header or null if it can be outputted from the line of the file.firstLineDetectionPattern- The pattern to detect the first line of a previous header.lastLineDetectionPattern- The pattern to detect the last line of a previous header.- Throws:
java.lang.IllegalArgumentException- If the type name is null.
-
HeaderDefinition
public HeaderDefinition(java.lang.String type)
Constructs a newHeaderDefinitionwith only initializing the header type. You must then set all the other definitions properties manually in order to have a coherent object.- Parameters:
type- The type name for this header definition.- Throws:
java.lang.IllegalArgumentException- If the type name is null.- See Also:
check(String, String),setPropertyFromString(String, String)
-
-
Method Detail
-
compile
private java.util.regex.Pattern compile(java.lang.String regexp)
-
getFirstLine
public java.lang.String getFirstLine()
-
getBeforeEachLine
public java.lang.String getBeforeEachLine()
-
getEndLine
public java.lang.String getEndLine()
-
getType
public java.lang.String getType()
-
allowBlankLines
public boolean allowBlankLines()
-
isSkipLine
public boolean isSkipLine(java.lang.String line)
Tells if the given content line must be skipped according to this header definition. The header is outputted after any skipped line if any pattern defined on this point or on the first line if not pattern defined.- Parameters:
line- The line to test.- Returns:
- true if this line must be skipped or false.
-
isFirstHeaderLine
public boolean isFirstHeaderLine(java.lang.String line)
Tells if the given content line is the first line of a possible header of this definition kind.- Parameters:
line- The line to test.- Returns:
- true if the first line of a header have been recognized or false.
-
isLastHeaderLine
public boolean isLastHeaderLine(java.lang.String line)
Tells if the given content line is the last line of a possible header of this definition kind.- Parameters:
line- The line to test.- Returns:
- true if the last line of a header have been recognized or false.
-
getSkipLinePattern
protected java.util.regex.Pattern getSkipLinePattern()
-
setPropertyFromString
public void setPropertyFromString(java.lang.String property, java.lang.String value)Sets header definition properties using its property name and its string value.
If you want to set a property to null you must not call this function.
This function is mainly used while parsing properties from the XML configuration file.- Parameters:
property- The property name.value- The property value.- Throws:
java.lang.IllegalArgumentException- If the property value is null.
-
validate
public void validate()
Checks this header definition consistency, in other words if all the mandatory properties of the definition have been set.- Throws:
java.lang.IllegalStateException- If a mandatory property has not been set.
-
check
private void check(java.lang.String name, java.lang.Boolean value)
-
check
private void check(java.lang.String name, java.lang.String value)
-
check
private void check(java.lang.String name, java.util.regex.Pattern value)
-
isEmpty
private boolean isEmpty(java.lang.String s)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isMultiLine
public boolean isMultiLine()
-
-