org.pz.platypus.plugin.listing
Class Start

java.lang.Object
  extended by org.pz.platypus.plugin.listing.Start
All Implemented Interfaces:
IPlugin

public class Start
extends java.lang.Object
implements IPlugin

Simple, illustrative plugin for creating Platypus listing files in HTML. Note: Methods order: constructor, methods in alphabetical order, getters and setters Error-handling convention: Output plugins handle all their own error messages. Platypus is made aware of a problem only by the value returned from calling process(). However, it does not issue any user messages as a result of this.

Author:
alb, ask

Field Summary
private  boolean inCode
           
private  java.util.logging.Logger logger
           
 
Constructor Summary
Start()
          Start() is always called first by Platypus, followed by a call to process() Any plugin initialization code should go in here.
 
Method Summary
 void closeOuputFile(java.io.FileWriter outputFile, GDD gdd)
          Close the file
 void emitClosingHtml(java.io.FileWriter outputFile, GDD gdd)
          Emits the HTML closing code
 void emitHtmlHeader(java.lang.String inputFile, java.io.FileWriter outputFile, GDD gdd)
          Emit the HTML needed at the beginning of the listing file
 void emitListing(java.io.FileWriter outfile, GDD gdd)
          Where the content of the listing file is written out
 java.lang.String getHeaderHtml(GDD gdd, java.lang.String inputFile)
          Build the string of HTML needed as the prelude to output of the code
private  boolean isItANewHtmlLine(Token tok, int lineNumber)
          Should we start a new Html line? Every token carries with it the original source line number.
private  java.lang.String makeInitialSpacesHard(java.lang.String s)
           
 java.io.FileWriter openOutputFile(java.lang.String filename, GDD gdd)
          Get an instance of FileWriter, to which we will emit HTML output
private  void printToken(java.io.FileWriter outfile, GDD gdd, Token tok)
          Print the token contents with all the Html bells and whistles (colors, bold fonts, line breaks etc.) Get the Html string and output it to the output file.
 void process(GDD gdd, CommandLineArgs clArgs)
          This is the main line of the plug-in.
 void setLogger(java.util.logging.Logger newLogger)
           
private  int skipNextTokens(int currTokIndex, Token tok, TokenList tokensList)
          We skip next one or many tokens at times.
private  boolean skipThisToken(Token tok, TokenList tokensList, int i)
          Will the next record indicate the present command is a replacement? If so, don't print this command, just skip it.
private  int startANewHtmlLine(java.io.FileWriter outfile, GDD gdd, Token tok)
          Start a new Html line.
 int tokensToSkip(TokenList tokList, int tokenNumber)
          We skip all compound commands tokens.
private  void writeIt(java.io.FileWriter outfile, GDD gdd, HtmlListingStrategy strategy, java.lang.String s)
           
 java.lang.String writeStringToFile(java.io.FileWriter outfile, GDD gdd, java.lang.String s)
          Write a String to the output - deals with the business of actual writing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private java.util.logging.Logger logger

inCode

private boolean inCode
Constructor Detail

Start

public Start()
Start() is always called first by Platypus, followed by a call to process() Any plugin initialization code should go in here.

Method Detail

closeOuputFile

public void closeOuputFile(java.io.FileWriter outputFile,
                           GDD gdd)
                    throws java.io.IOException
Close the file

Parameters:
outputFile - file to close
gdd - the GDD. Only the literals are used
Throws:
java.io.IOException - in case of error

emitClosingHtml

public void emitClosingHtml(java.io.FileWriter outputFile,
                            GDD gdd)
                     throws java.io.IOException
Emits the HTML closing code

Parameters:
outputFile - the HTML is written to this file
gdd - GDD, only the literals are used in this method
Throws:
java.io.IOException - in the rare event the file cannot be written to

emitHtmlHeader

public void emitHtmlHeader(java.lang.String inputFile,
                           java.io.FileWriter outputFile,
                           GDD gdd)
                    throws java.io.IOException
Emit the HTML needed at the beginning of the listing file

Parameters:
inputFile - filename of the file being converted into a listing
outputFile - the file to write the HTML to
gdd - the GDD. Only the literals are used in this method
Throws:
java.io.IOException - in the rare event the file cannot be written to

emitListing

public void emitListing(java.io.FileWriter outfile,
                        GDD gdd)
                 throws java.io.IOException
Where the content of the listing file is written out

Parameters:
outfile - the file being written to
gdd - the GDD. Only the literals are used
Throws:
java.io.IOException - in the event the file can't be written to

printToken

private void printToken(java.io.FileWriter outfile,
                        GDD gdd,
                        Token tok)
                 throws java.io.IOException
Print the token contents with all the Html bells and whistles (colors, bold fonts, line breaks etc.) Get the Html string and output it to the output file.

Parameters:
outfile -
gdd -
tok -
Throws:
java.io.IOException

writeIt

private void writeIt(java.io.FileWriter outfile,
                     GDD gdd,
                     HtmlListingStrategy strategy,
                     java.lang.String s)
              throws java.io.IOException
Throws:
java.io.IOException

makeInitialSpacesHard

private java.lang.String makeInitialSpacesHard(java.lang.String s)

startANewHtmlLine

private int startANewHtmlLine(java.io.FileWriter outfile,
                              GDD gdd,
                              Token tok)
                       throws java.io.IOException
Start a new Html line. This amounts to outputting an Html
  • token.

    Parameters:
    outfile -
    gdd -
    tok -
    Returns:
    the new / next line number.
    Throws:
    java.io.IOException

  • isItANewHtmlLine

    private boolean isItANewHtmlLine(Token tok,
                                     int lineNumber)
    Should we start a new Html line? Every token carries with it the original source line number. If it changes, we start a new HTML line.

    Parameters:
    tok - the token we're processing
    lineNumber - the line number
    Returns:
    whether we should start a new HTML line

    skipThisToken

    private boolean skipThisToken(Token tok,
                                  TokenList tokensList,
                                  int i)
    Will the next record indicate the present command is a replacement? If so, don't print this command, just skip it. The next token (containing the original command) will be printed on the next loop cycle.

    Parameters:
    tok - the command token, the next token is/isn't a replacement command
    tokensList - list of input tokens
    i - which token in the token list
    Returns:
    whether to skip the current token in favor of the replacement token

    skipNextTokens

    private int skipNextTokens(int currTokIndex,
                               Token tok,
                               TokenList tokensList)
                        throws java.io.IOException
    We skip next one or many tokens at times. For example, we process the explicit newline command i.e. "[]", and output a newline. If this token appears at the end of a line (i.e. next immediate token is "[cr]"), we don't want to output one more Html newline.

    Parameters:
    currTokIndex - where we are in the token list
    tok - current token
    tokensList - list of input tokens
    Returns:
    the number of tokens to skip
    Throws:
    java.io.IOException

    getHeaderHtml

    public java.lang.String getHeaderHtml(GDD gdd,
                                          java.lang.String inputFile)
    Build the string of HTML needed as the prelude to output of the code

    Parameters:
    gdd - the GDD. Only the literals are used
    inputFile - filename of the file being converted into a listing
    Returns:
    the string of HTML to emit

    openOutputFile

    public java.io.FileWriter openOutputFile(java.lang.String filename,
                                             GDD gdd)
                                      throws java.io.IOException
    Get an instance of FileWriter, to which we will emit HTML output

    Parameters:
    filename - of file to open (obtained from the command line)
    gdd - GDD. Only the literals are used in this method.
    Returns:
    the open FileWriter
    Throws:
    java.io.IOException - in the event the file can't be opened

    writeStringToFile

    public java.lang.String writeStringToFile(java.io.FileWriter outfile,
                                              GDD gdd,
                                              java.lang.String s)
                                       throws java.io.IOException
    Write a String to the output - deals with the business of actual writing. If any exceptions happen while writing - are logged and rethrown.

    Parameters:
    outfile - output file
    gdd - global document data
    s - string to write to ouput
    Returns:
    the string written out. Needed?
    Throws:
    java.io.IOException

    tokensToSkip

    public int tokensToSkip(TokenList tokList,
                            int tokenNumber)
                     throws java.io.IOException
    We skip all compound commands tokens.

    Parameters:
    tokList - list of tokens
    tokenNumber - which token in the input stream tok is
    Returns:
    how many tokens to skip over for this command.
    Throws:
    java.io.IOException - in event of exception in writing to file

    process

    public void process(GDD gdd,
                        CommandLineArgs clArgs)
    This is the main line of the plug-in. Platypus calls only the Start constructor and this method.

    Specified by:
    process in interface IPlugin
    Parameters:
    gdd - The Global Document Data
    clArgs - command-line arguments in a hash map (key = argument, value = parameters)

    setLogger

    public void setLogger(java.util.logging.Logger newLogger)


    Copyright © 2008-10 Pacific Data Works LLC