com.ccg.macros.at
Class Script

java.lang.Object
  extended by com.ccg.macros.at.Base
      extended by com.ccg.macros.at.Script

public class Script
extends Base

@macros useful for "script" style processing.

Since:
1.0
Version:
$Revision: 1.1.1.1 $
Author:
$Author: pkb $

Constructor Summary
Script()
          Constructs the object and readies it for installation.
 
Method Summary
 void atCopyFile(Output out, Vector args)
          @atCopyFile(SRC,DST) copy AND interpret one file to another.
 void atCopyToDir(Output out, Vector args)
          @atCopyToDir(MATCH0,MATCH1,...,DIR) copy AND interpret one or more files to directory.
 void copyFile(Output out, Vector args)
          @copyFile(SRC,DST) copy one file to another.
 void copyToDir(Output out, Vector args)
          @copyToDir(MATCH0,MATCH1,...,DIR) copy one or more files to directory.
 void ifFileExists(Output out, Vector args)
          @ifFileExists(NAME,IF_EXISTS,IF_NOT) determine if file exists.
 void loadTSV(Output out, Vector args)
          @loadTSV(NAME,SOURCE) load a tab separated table.
 
Methods inherited from class com.ccg.macros.at.Base
getAtMacros, getDoubleParameter, getIntParameter, getLongParameter, getStringParameter, install
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Script

public Script()
Constructs the object and readies it for installation.

Since:
1.0
See Also:
Base.install(com.ccg.macros.AtMacros)
Method Detail

loadTSV

public void loadTSV(Output out,
                    Vector args)
             throws IOException,
                    InterpretException
@loadTSV(NAME,SOURCE) load a tab separated table.

This macro is used to load the definition of a tab separated table. It doesn't actually read the contents of the database immediately, instead it defines a new macro named "NAME" and associates a SOURCE (typically a file or URL) where we should fetch the data from.

When you want to insert the data of the table into your output, you then use the "@NAME(FORMAT)" macro to read each line from the table and FORMAT the output of the table.

For example, if one created a table named phone.tsv like the following:

Last    First   Phone
Blankenbaker    Paul    555-555-5555
Brown   Megan   555-555-5555

And you used the following macros:

 @loadTSV("phoneTable","phone.tsv")
 @phoneTable("@phoneTableF(1),@phoneTableF(0),@phoneTableF(2)\n")
 

This will result in the output of one blank line followed by a comma seaparated list of just the data fields. This is shown below:


 Paul,Blankenbaker,555-555-5555
 Megan,Brown,555-555-5555
 

In the example, you'll notice that the macro used to process the table was called @phoneTable. When we used this macro, we accessed the specific columns within the table using a new macro @phoneTableF(COL). This macro is defined while processing each row of the table and allows one to access the column fields within a row of the table. You can specify the column either by its number (where 0 is the left most column), or it column heading. Using column headings to pull information from the table, we would have written the following:

 @loadTSV("phoneTable","phone.tsv")
 @phoneTable("@phoneTableF("First"),@phoneTableF("Last"),@phoneTableF("Phone")\n")
 

If you are producing HTML, you can use the table formatting tags to nicely format your table data.

Parameters:
out - The output device to write the results of processing the argument to.
args - A vector of arguments which were passed to the macro.
Throws:
IOException - If there is a problem writing to the output device
InterpretException - If a problem is encountered interpretting the arguments passed.
Since:
1.0

copyToDir

public void copyToDir(Output out,
                      Vector args)
               throws IOException,
                      InterpretException
@copyToDir(MATCH0,MATCH1,...,DIR) copy one or more files to directory.

This macro is used to copy 0 or more existing files to a output directory. If the directory doesn't exist, it will be created. You may use the "*" as a wildcard in each of the file name strings to match more than one file.

For example, to copy the ".at" and "*.properties" files from the "/etc/macros" directory to the "/home/user/etc/macros" directory, one could use the following:

@defnow("sdir","/etc/macros")
@copyToDir("@sdir()/*.at","@sdir()/*.properties","/home/user/etc/macros")

Parameters:
out - The output device to write the results of processing the argument to.
args - A vector of arguments which were passed to the macro.
Throws:
IOException - If there is a problem writing to the output device
InterpretException - If a problem is encountered interpretting the arguments passed.
Since:
1.0

atCopyToDir

public void atCopyToDir(Output out,
                        Vector args)
                 throws IOException,
                        InterpretException
@atCopyToDir(MATCH0,MATCH1,...,DIR) copy AND interpret one or more files to directory.

This macro is used to copy 0 or more existing files to a output directory. If the directory doesn't exist, it will be created. You may use the "*" as a wildcard in each of the file name strings to match more than one file.

There is a HUGE difference between this command and the "@copyToDir". This command interprets each file that it copies and evaluates any "@macros" which it contains. This can be a VERY useful way to install HTML documents to their final location and do some subsitutions during the installation process.

It should be noted that any definitions (or redefinitions) made by the files processed WILL AFFECT all subsequent files processed (I may add a version of this macro which saves/restores the macros for each file processed).

To see the power of this function, take a look at the atcopy.atmacros "script". It does the following:

If you have the source code installed such that the "ccg" top level directory can be found under the "$COMHOME" environment variable, you should be able to try this out via:

 java com.ccg.macros.At -Dcomhome=$COMHOME -Dhtmlroot=$HOME/public_html \
   -in $COMHOME/ccg/macros/doc-files/atcopy.atmacros
 

Parameters:
out - The output device to write the results of processing the argument to.
args - A vector of arguments which were passed to the macro.
Throws:
IOException - If there is a problem writing to the output device
InterpretException - If a problem is encountered interpretting the arguments passed.
Since:
1.0

atCopyFile

public void atCopyFile(Output out,
                       Vector args)
                throws IOException,
                       InterpretException
@atCopyFile(SRC,DST) copy AND interpret one file to another.

This macro is used to copy exactly one file from one location to another. If the DST is a directory, then the same file name will be preserved, if DST does not include a directory, then the same directory as the SRC will be assumed. The final DST must not be the same as the SRC (or we will report an error and skip the copy). If the destination directory doesn't exist, it will be created.

There is a HUGE difference between this command and the "@copyFile". This command interprets each file that it copies and evaluates any "@macros" which it contains. This can be a VERY useful way to install HTML (or other text) documents to their final location and do some subsitutions during the installation process.

It should be noted that any definitions (or redefinitions) made by the files processed WILL AFFECT all subsequent files processed (I may add a version of this macro which saves/restores the macros for each file processed).

Parameters:
out - The output device to write the results of processing the argument to.
args - A vector of arguments which were passed to the macro.
Throws:
IOException - If there is a problem writing to the output device
InterpretException - If a problem is encountered interpretting the arguments passed.
Since:
1.0

copyFile

public void copyFile(Output out,
                     Vector args)
              throws IOException,
                     InterpretException
@copyFile(SRC,DST) copy one file to another.

This macro is used to copy exactly one file from one location to another. If the DST is a directory, then the same file name will be preserved, if DST does not include a directory, then the same directory as the SRC will be assumed. The final DST must not be the same as the SRC (or we will report an error and skip the copy). If the destination directory doesn't exist, it will be created.

There is a HUGE difference between this command and the "@atCopyFile". This command does no interpretation (it simply copies the bytes from the source file to the destination file). This makes it well suited for transferring images (or any file where interpretation of the file contents doesn't make sense).

Parameters:
out - The output device to write the results of processing the argument to.
args - A vector of arguments which were passed to the macro.
Throws:
IOException - If there is a problem writing to the output device
InterpretException - If a problem is encountered interpretting the arguments passed.
Since:
1.0

ifFileExists

public void ifFileExists(Output out,
                         Vector args)
                  throws IOException,
                         InterpretException
@ifFileExists(NAME,IF_EXISTS,IF_NOT) determine if file exists.

This macro is used to make a decistion based upon whether a file exists or not. If the file specified byte NAME exists, then the IF_EXISTS clause is evaluated. If not, then the IF_NOT clause is evaluated.

Parameters:
out - The output device to write the results of processing the argument to.
args - A vector of arguments which were passed to the macro.
Throws:
IOException - If there is a problem writing to the output device
InterpretException - If a problem is encountered interpretting the arguments passed.
Since:
1.0


Copyright 1998-1998-2006 null. All Rights Reserved.