filetools.filegenerators
Class HelpFileIndexDBCompendiumGenerator

java.lang.Object
  extended by filetools.filegenerators.HelpFileIndexDBCompendiumGenerator
All Implemented Interfaces:
IFileGenerator
Direct Known Subclasses:
HelpFileWikiIndexGenerator

public abstract class HelpFileIndexDBCompendiumGenerator
extends java.lang.Object
implements IFileGenerator

Abstract base class for generating files with data from the matlab-helpfile-DB. This class encapsulates the DB-connection and provides general processing functionality and some tools.

Author:
osiris

Field Summary
private static java.lang.String DB_DBNAME_DEF
           
private static java.lang.String DB_DBNAME_KEY
          db connection data property names
private static java.lang.String DB_DRIVER
          db connection data
private static java.lang.String DB_HOSTNAME_DEF
          db connection data default values
private static java.lang.String DB_HOSTNAME_KEY
           
protected static java.lang.String DB_TABLENAME
           
private static java.lang.String DB_USERNAME_DEF
           
private static java.lang.String DB_USERNAME_KEY
           
private static java.lang.String DB_USERPWD_DEF
           
private static java.lang.String DB_USERPWD_KEY
           
private  java.sql.Statement dbStatement
           
protected static java.lang.String HTML_EXTENSION
           
protected  java.io.FileWriter outputFileWriter
           
protected  java.util.Properties properties
           
 
Constructor Summary
HelpFileIndexDBCompendiumGenerator()
           
 
Method Summary
protected  boolean connectToDB()
          Tries to get a connection with a MySQL DB specified by the properties
protected  void endProcessQuery(java.sql.ResultSet resultSet)
          This function is called for every query after the processing of its results.
 boolean generateFile(java.lang.String filename)
          Generate a file which contains data in a specific format.
protected  void includeFile(java.lang.String filename)
          Reads an ASCII file and writes its content into the target file.
protected abstract  void processRow(java.sql.ResultSet row)
          In this function concrete classes need to define what to do with a single row of the result of the last executed query.
protected abstract  void processTask()
          This function contains the code which manages the whole task.
static java.util.Properties readPropertiesFromFile(java.lang.String filename)
          Reads properties from a specified file and returns them as a java.util.Properties object
protected  void sendAndProcessQuery(java.lang.String query)
          Executes one specified query and manages the processing of the result.
 void setProperties(java.util.Properties properties)
          Set all relevant properties.
protected  void startProcessQuery(java.sql.ResultSet resultSet)
          This function is called for every query before the processing of its results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DB_HOSTNAME_DEF

private static final java.lang.String DB_HOSTNAME_DEF
db connection data default values

See Also:
Constant Field Values

DB_DBNAME_DEF

private static final java.lang.String DB_DBNAME_DEF
See Also:
Constant Field Values

DB_USERNAME_DEF

private static final java.lang.String DB_USERNAME_DEF
See Also:
Constant Field Values

DB_USERPWD_DEF

private static final java.lang.String DB_USERPWD_DEF
See Also:
Constant Field Values

DB_DBNAME_KEY

private static final java.lang.String DB_DBNAME_KEY
db connection data property names

See Also:
Constant Field Values

DB_USERNAME_KEY

private static final java.lang.String DB_USERNAME_KEY
See Also:
Constant Field Values

DB_USERPWD_KEY

private static final java.lang.String DB_USERPWD_KEY
See Also:
Constant Field Values

DB_HOSTNAME_KEY

private static final java.lang.String DB_HOSTNAME_KEY
See Also:
Constant Field Values

DB_DRIVER

private static final java.lang.String DB_DRIVER
db connection data

See Also:
Constant Field Values

DB_TABLENAME

protected static final java.lang.String DB_TABLENAME
See Also:
Constant Field Values

HTML_EXTENSION

protected static final java.lang.String HTML_EXTENSION
See Also:
Constant Field Values

dbStatement

private java.sql.Statement dbStatement

outputFileWriter

protected java.io.FileWriter outputFileWriter

properties

protected java.util.Properties properties
Constructor Detail

HelpFileIndexDBCompendiumGenerator

public HelpFileIndexDBCompendiumGenerator()
Method Detail

setProperties

public void setProperties(java.util.Properties properties)
Description copied from interface: IFileGenerator
Set all relevant properties.

Specified by:
setProperties in interface IFileGenerator
Parameters:
properties - Properties to set

readPropertiesFromFile

public static java.util.Properties readPropertiesFromFile(java.lang.String filename)
Reads properties from a specified file and returns them as a java.util.Properties object

Parameters:
filename - File which contains the properties. It has to be in a format which is compatible with java.util.Properties
Returns:
Generated java.util.Properties object, null if an error occured

generateFile

public boolean generateFile(java.lang.String filename)
Description copied from interface: IFileGenerator
Generate a file which contains data in a specific format.

Specified by:
generateFile in interface IFileGenerator
Parameters:
filename - Name of the file to generate
Returns:
true if file was successfully generated
See Also:
IFileGenerator.generateFile(java.lang.String)

connectToDB

protected boolean connectToDB()
Tries to get a connection with a MySQL DB specified by the properties

Returns:
true if a connection was established, false otherwise

sendAndProcessQuery

protected void sendAndProcessQuery(java.lang.String query)
                            throws java.sql.SQLException,
                                   java.io.IOException
Executes one specified query and manages the processing of the result.

Parameters:
query - Query to send
Throws:
java.sql.SQLException
java.io.IOException

includeFile

protected void includeFile(java.lang.String filename)
                    throws java.io.IOException
Reads an ASCII file and writes its content into the target file.

Parameters:
filename - File to include
Throws:
java.io.IOException

processTask

protected abstract void processTask()
This function contains the code which manages the whole task. Concrete classes have to override this function to define what to do.


processRow

protected abstract void processRow(java.sql.ResultSet row)
                            throws java.sql.SQLException,
                                   java.io.IOException
In this function concrete classes need to define what to do with a single row of the result of the last executed query.

Parameters:
row - ResultSet in which the row to process is the actual one. So one can get the results by using the get... functions of row
Throws:
java.sql.SQLException
java.io.IOException

startProcessQuery

protected void startProcessQuery(java.sql.ResultSet resultSet)
                          throws java.sql.SQLException,
                                 java.io.IOException
This function is called for every query before the processing of its results. Derived classes may override this function to implement some functionalities.

Parameters:
resultSet - ResultSet as it was returned from the query.
Throws:
java.sql.SQLException
java.io.IOException

endProcessQuery

protected void endProcessQuery(java.sql.ResultSet resultSet)
                        throws java.sql.SQLException,
                               java.io.IOException
This function is called for every query after the processing of its results. Derived classes may override this function to implement some functionalities.

Parameters:
resultSet - ResultSet after all rows of the result were processed.
Throws:
java.sql.SQLException
java.io.IOException