de.dv.sbu.filehandler.ftl.dataprovider.util
Class Util

java.lang.Object
  extended by de.dv.sbu.filehandler.ftl.dataprovider.DataProviderImpl
      extended by de.dv.sbu.filehandler.ftl.dataprovider.util.Util
All Implemented Interfaces:
IDataProvider

public class Util
extends DataProviderImpl

Various utility methods that can be used during templating.

Author:
Daniel Vogtland

Field Summary
 
Fields inherited from class de.dv.sbu.filehandler.ftl.dataprovider.DataProviderImpl
builderConfiguration, sourceFileInformation
 
Constructor Summary
Util()
           
 
Method Summary
static java.util.Date currentDate()
          Returns the current date.
static java.lang.String currentDate(java.lang.String formatPattern)
          Returns the current date in the given SimpleDateFormat compatible format definition.
static java.util.Map<java.lang.String,java.lang.String> extractAttributes(java.lang.String text)
          Creates attributes as mapping from name to value from some given text.
static java.io.File file(java.io.File parent, java.lang.String child)
          Creates a new File object via the related constructor.
static java.io.File file(java.lang.String path)
          Creates a new File object via the related constructor.
 java.lang.String resolvePath(java.lang.String path)
          Builds a target path respecting the current file information.
static java.lang.String resolveSourceFilePath(java.lang.String path, SourceFileInformation fileInfo)
          Builds a target path respecting the given file information.
 java.io.File resourceFile(java.lang.String relativePath)
          Returns the resource File object defined by the given relative path.
 java.io.File sourceFile(java.lang.String relativePath)
          Returns the source File object defined by the given relative path.
 java.io.File targetFile(java.lang.String relativePath)
          Returns the target File object defined by the given relative path.
static NodeModel xmlNodeModel(java.io.File file, java.lang.String encoding)
          Creates XML content from some given XML file.
static NodeModel xmlNodeModel(java.lang.String text)
          Creates XML content from some given text.
 
Methods inherited from class de.dv.sbu.filehandler.ftl.dataprovider.DataProviderImpl
init, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

resolvePath

public java.lang.String resolvePath(java.lang.String path)
Builds a target path respecting the current file information.
If the target starts with '/' it will be interpreted as source file reference, otherwise the original target will be returned.

Parameters:
path - The path to transform.
Returns:
The resulting target path.

resolveSourceFilePath

public static java.lang.String resolveSourceFilePath(java.lang.String path,
                                                     SourceFileInformation fileInfo)
Builds a target path respecting the given file information. If the target starts with '/' it will be interpreted as source file reference, otherwise the original target will be returned.

Parameters:
path - The path to transform.
fileInfo - The file information to use.
Returns:
The resulting target path.

sourceFile

public java.io.File sourceFile(java.lang.String relativePath)
Returns the source File object defined by the given relative path.

Parameters:
relativePath - The relative path.
Returns:
The resulting file.

targetFile

public java.io.File targetFile(java.lang.String relativePath)
Returns the target File object defined by the given relative path.

Parameters:
relativePath - The relative path.
Returns:
The resulting file.

resourceFile

public java.io.File resourceFile(java.lang.String relativePath)
Returns the resource File object defined by the given relative path.

Parameters:
relativePath - The relative path.
Returns:
The resulting file.

xmlNodeModel

public static NodeModel xmlNodeModel(java.lang.String text)
Creates XML content from some given text.

Parameters:
text - The text to use (must be valid).
Returns:
The resulting node model.

xmlNodeModel

public static NodeModel xmlNodeModel(java.io.File file,
                                     java.lang.String encoding)
                              throws java.io.FileNotFoundException,
                                     java.io.UnsupportedEncodingException
Creates XML content from some given XML file.

Parameters:
file - Path to the XML file.
encoding - The char set to use for encoding.
Returns:
The resulting node model.
Throws:
java.io.FileNotFoundException - The XML file was not found.
java.io.UnsupportedEncodingException

file

public static java.io.File file(java.lang.String path)
Creates a new File object via the related constructor.

Parameters:
path - The (absolute or work directory relative) path to the file.
Returns:
The corresponding file object.

file

public static java.io.File file(java.io.File parent,
                                java.lang.String child)
Creates a new File object via the related constructor.

Parameters:
parent - The parent of directory.
child - The child path from the parent.
Returns:
The corresponding file object.

extractAttributes

public static java.util.Map<java.lang.String,java.lang.String> extractAttributes(java.lang.String text)
Creates attributes as mapping from name to value from some given text. The format is: ="" ="" ...

Parameters:
text - The text to analyze.
Returns:
The parsed attributes.

currentDate

public static java.util.Date currentDate()
Returns the current date.

Returns:
The current date;

currentDate

public static java.lang.String currentDate(java.lang.String formatPattern)
Returns the current date in the given SimpleDateFormat compatible format definition.

Parameters:
formatPattern - The format pattern.
Returns:
The corresponding text representation of the current date.
See Also:
SimpleDateFormat