org.codehaus.mojo.license.header.transformer
Class AbstractFileHeaderTransformer

java.lang.Object
  extended by org.codehaus.mojo.license.header.transformer.AbstractFileHeaderTransformer
All Implemented Interfaces:
FileHeaderTransformer
Direct Known Subclasses:
AptFileHeaderTransformer, FreeMarkerFileHeaderTransformer, JavaFileHeaderTransformer, JspFileHeaderTransformer, PhpFileHeaderTransformer, PropertiesFileHeaderTransformer, RstFileHeaderTransformer, SqlFileHeaderTransformer, XmlFileHeaderTransformer

public abstract class AbstractFileHeaderTransformer
extends Object
implements FileHeaderTransformer

Abstract implementation of FileHeaderTransformer.

Concrete implementation should only have to give comment configuration.

Since:
1.0
Author:
tchemit

Field Summary
protected  String commentEndTag
          comment end tag
protected  String commentLinePrefix
          comment line prefix (to add for header content)
protected  String commentStartTag
          comment start tag
protected static Pattern COPYRIGHT_PATTERN
          pattern of the copyright string representation : group(1) is Copyright prefix group(2) is Copyright first year group(3) is Copyright last year with prefix (can be null) group(4) is Copyright last year (can be null) group(5) is Copyright holder
protected  String description
          description of transfomer
protected  String name
          name of transformer
protected  String processEndTag
          end process tag
protected  String processStartTag
          start process tag
protected static Pattern REMOVE_SPACE_PATTERN
           
protected  String sectionDelimiter
          section delimiter
 
Fields inherited from interface org.codehaus.mojo.license.header.transformer.FileHeaderTransformer
DEFAULT_PROCESS_END_TAG, DEFAULT_PROCESS_START_TAG, DEFAULT_SECTION_DELIMITER, LINE_SEPARATOR, ROLE_NAME
 
Constructor Summary
protected AbstractFileHeaderTransformer(String name, String description, String commentStartTag, String commentEndTag, String commentLinePrefix)
           
 
Method Summary
 String addHeader(String header, String content)
          Adds the header.
 String boxComment(String header, boolean withTags)
          Box the given header in a comment.
 String boxProcessTag(String header)
          Box the given header between process tags.
 String getCommentEndTag()
           
 String getCommentLinePrefix()
           
 String getCommentStartTag()
           
 String getDescription()
           
 String getName()
           
 String getProcessEndTag()
          Obtain the process tag which indiciates the end of the header content.
 String getProcessStartTag()
          Obtains the process tag which indicates the begin of the header content.
 String getSectionDelimiter()
          The pattern used to separate sections of the header.
 boolean isCopyrightEquals(FileHeader header1, FileHeader header2)
          Tests if the copyright of the two models are equals.
 boolean isDescriptionEquals(FileHeader header1, FileHeader header2)
          Tests if the description of the two models are equals.
 boolean isLicenseEquals(FileHeader header1, FileHeader header2)
          Tests if the license of the two models are equals.
protected  String removeSpaces(String str)
           
 void setCommentEndTag(String commentEndTag)
          Changes the comment end tag.
 void setCommentLinePrefix(String commentLinePrefix)
          Changes the comment prefix line.
 void setCommentStartTag(String commentStartTag)
          Changes the comment start tag.
 void setDescription(String description)
          Chages the description of the transformer.
 void setName(String name)
          Changes the name of the transformer.
 void setProcessEndTag(String processEndTag)
          Changes the process end tag.
 void setProcessStartTag(String processStartTag)
          Changes the process start tag.
 void setSectionDelimiter(String sectionDelimiter)
          Sets the header section delimiter.
 FileHeader toFileHeader(String header)
          Build a FileHeader from an UNBOXED header content.
 String toHeaderContent(FileHeader model)
          Build a fully boxed header content from the given model.
 String toString(FileHeader model)
          Build a UNBOXED header content from the given model.
 String unboxComent(String header)
          Unbox the given boxed boxedHeader to obtain the header content.
 String unboxProcessTag(String boxedHeader)
          Unbox the process tag on the given boxed boxedHeader to obtain the brute header content.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.codehaus.mojo.license.header.transformer.FileHeaderTransformer
getDefaultAcceptedExtensions
 

Field Detail

COPYRIGHT_PATTERN

protected static final Pattern COPYRIGHT_PATTERN
pattern of the copyright string representation :


name

protected String name
name of transformer


description

protected String description
description of transfomer


sectionDelimiter

protected String sectionDelimiter
section delimiter


processStartTag

protected String processStartTag
start process tag


processEndTag

protected String processEndTag
end process tag


commentStartTag

protected String commentStartTag
comment start tag


commentEndTag

protected String commentEndTag
comment end tag


commentLinePrefix

protected String commentLinePrefix
comment line prefix (to add for header content)


REMOVE_SPACE_PATTERN

protected static final Pattern REMOVE_SPACE_PATTERN
Constructor Detail

AbstractFileHeaderTransformer

protected AbstractFileHeaderTransformer(String name,
                                        String description,
                                        String commentStartTag,
                                        String commentEndTag,
                                        String commentLinePrefix)
Method Detail

getName

public String getName()
Specified by:
getName in interface FileHeaderTransformer
Returns:
the name of the transformer

setName

public void setName(String name)
Description copied from interface: FileHeaderTransformer
Changes the name of the transformer.

Specified by:
setName in interface FileHeaderTransformer
Parameters:
name - the new name of the transformer

getDescription

public String getDescription()
Specified by:
getDescription in interface FileHeaderTransformer
Returns:
the description of the transformer

setDescription

public void setDescription(String description)
Description copied from interface: FileHeaderTransformer
Chages the description of the transformer.

Specified by:
setDescription in interface FileHeaderTransformer
Parameters:
description - the new description of the transformer

getSectionDelimiter

public String getSectionDelimiter()
Description copied from interface: FileHeaderTransformer
The pattern used to separate sections of the header.

By default, (says if you do not explicitly invoke the FileHeaderTransformer.setSectionDelimiter(String) method), will use the FileHeaderTransformer.DEFAULT_SECTION_DELIMITER.

Specified by:
getSectionDelimiter in interface FileHeaderTransformer
Returns:
the delimiter used to separate sections in the header.

setSectionDelimiter

public void setSectionDelimiter(String sectionDelimiter)
Description copied from interface: FileHeaderTransformer
Sets the header section delimiter.

By default, will use the FileHeaderTransformer.DEFAULT_SECTION_DELIMITER.

Specified by:
setSectionDelimiter in interface FileHeaderTransformer
Parameters:
sectionDelimiter - the new delimiter

getProcessStartTag

public String getProcessStartTag()
Description copied from interface: FileHeaderTransformer
Obtains the process tag which indicates the begin of the header content.

By default, (says if you do not explicitly invoke the FileHeaderTransformer.setProcessStartTag(String) method), will use the FileHeaderTransformer.DEFAULT_PROCESS_START_TAG

Specified by:
getProcessStartTag in interface FileHeaderTransformer
Returns:
the starting header tag

setProcessStartTag

public void setProcessStartTag(String processStartTag)
Description copied from interface: FileHeaderTransformer
Changes the process start tag.

Specified by:
setProcessStartTag in interface FileHeaderTransformer
Parameters:
processStartTag - the new start tag

getProcessEndTag

public String getProcessEndTag()
Description copied from interface: FileHeaderTransformer
Obtain the process tag which indiciates the end of the header content.

By default, (says if you do not explicitly invoke the FileHeaderTransformer.setProcessEndTag(String) method), will use the FileHeaderTransformer.DEFAULT_PROCESS_END_TAG.

Specified by:
getProcessEndTag in interface FileHeaderTransformer
Returns:
the ending header tag

setProcessEndTag

public void setProcessEndTag(String processEndTag)
Description copied from interface: FileHeaderTransformer
Changes the process end tag.

Specified by:
setProcessEndTag in interface FileHeaderTransformer
Parameters:
processEndTag - the new endtag

getCommentStartTag

public String getCommentStartTag()
Specified by:
getCommentStartTag in interface FileHeaderTransformer
Returns:
the start tag of a comment

setCommentStartTag

public void setCommentStartTag(String commentStartTag)
Description copied from interface: FileHeaderTransformer
Changes the comment start tag.

Specified by:
setCommentStartTag in interface FileHeaderTransformer
Parameters:
commentStartTag - the new comment start tag

getCommentEndTag

public String getCommentEndTag()
Specified by:
getCommentEndTag in interface FileHeaderTransformer
Returns:
the end tag of a comment

setCommentEndTag

public void setCommentEndTag(String commentEndTag)
Description copied from interface: FileHeaderTransformer
Changes the comment end tag.

Specified by:
setCommentEndTag in interface FileHeaderTransformer
Parameters:
commentEndTag - the new comment end tag

getCommentLinePrefix

public String getCommentLinePrefix()
Specified by:
getCommentLinePrefix in interface FileHeaderTransformer
Returns:
the line prefix of every line insed the comment

addHeader

public String addHeader(String header,
                        String content)
Description copied from interface: FileHeaderTransformer
Adds the header.

Specified by:
addHeader in interface FileHeaderTransformer
Parameters:
header - header to add
content - content of original file
Returns:
the new full file content beginning with header

setCommentLinePrefix

public void setCommentLinePrefix(String commentLinePrefix)
Description copied from interface: FileHeaderTransformer
Changes the comment prefix line.

Specified by:
setCommentLinePrefix in interface FileHeaderTransformer
Parameters:
commentLinePrefix - the new comment prefix line

toFileHeader

public FileHeader toFileHeader(String header)
Description copied from interface: FileHeaderTransformer
Build a FileHeader from an UNBOXED header content.

Specified by:
toFileHeader in interface FileHeaderTransformer
Parameters:
header - unboxed header content
Returns:
The model of the header content

toString

public String toString(FileHeader model)
                throws NullPointerException
Description copied from interface: FileHeaderTransformer
Build a UNBOXED header content from the given model.

Specified by:
toString in interface FileHeaderTransformer
Parameters:
model - the model of the file header
Returns:
the UNBOXED header content
Throws:
NullPointerException - if model is null

toHeaderContent

public String toHeaderContent(FileHeader model)
                       throws NullPointerException
Description copied from interface: FileHeaderTransformer
Build a fully boxed header content from the given model.

Specified by:
toHeaderContent in interface FileHeaderTransformer
Parameters:
model - the model of the file header
Returns:
the fully boxed header content
Throws:
NullPointerException - if model is null

boxComment

public String boxComment(String header,
                         boolean withTags)
Description copied from interface: FileHeaderTransformer
Box the given header in a comment.

Specified by:
boxComment in interface FileHeaderTransformer
Parameters:
header - the header content WITHOUT any comment boxing
withTags - flag to add start and end comment tags.
Returns:
the header content WITH comment boxing

unboxComent

public String unboxComent(String header)
Description copied from interface: FileHeaderTransformer
Unbox the given boxed boxedHeader to obtain the header content.

Specified by:
unboxComent in interface FileHeaderTransformer
Parameters:
header - the boxed header
Returns:
the unboxed header.

boxProcessTag

public String boxProcessTag(String header)
Description copied from interface: FileHeaderTransformer
Box the given header between process tags.

Specified by:
boxProcessTag in interface FileHeaderTransformer
Parameters:
header - the header content WITHOUT any comment boxing
Returns:
the header content boxed between process tags
See Also:
FileHeaderTransformer.getProcessStartTag(), FileHeaderTransformer.getProcessEndTag()

unboxProcessTag

public String unboxProcessTag(String boxedHeader)
Description copied from interface: FileHeaderTransformer
Unbox the process tag on the given boxed boxedHeader to obtain the brute header content.

Specified by:
unboxProcessTag in interface FileHeaderTransformer
Parameters:
boxedHeader - the boxed header
Returns:
the brute header content.
See Also:
FileHeaderTransformer.getProcessStartTag(), FileHeaderTransformer.getProcessEndTag()

isDescriptionEquals

public boolean isDescriptionEquals(FileHeader header1,
                                   FileHeader header2)
Description copied from interface: FileHeaderTransformer
Tests if the description of the two models are equals.

Specified by:
isDescriptionEquals in interface FileHeaderTransformer
Parameters:
header1 - the first header
header2 - the second header
Returns:
true if headers description are stricly the same

isCopyrightEquals

public boolean isCopyrightEquals(FileHeader header1,
                                 FileHeader header2)
Description copied from interface: FileHeaderTransformer
Tests if the copyright of the two models are equals.

Specified by:
isCopyrightEquals in interface FileHeaderTransformer
Parameters:
header1 - the first header
header2 - the second header
Returns:
true if headers copyright are stricly the same

isLicenseEquals

public boolean isLicenseEquals(FileHeader header1,
                               FileHeader header2)
Description copied from interface: FileHeaderTransformer
Tests if the license of the two models are equals.

Specified by:
isLicenseEquals in interface FileHeaderTransformer
Parameters:
header1 - the first header
header2 - the second header
Returns:
true if headers license are stricly the same (WITHOUT ANY space)

removeSpaces

protected String removeSpaces(String str)


Copyright © 2010-2012 The Kuali Foundation. All Rights Reserved.