com.ccg.macros.at
Class Core

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

public class Core
extends Base

Set of core macros which provide some standard basic features.

 class Example {
   public void main(String[] args) {
     com.ccg.macros.at.Core o = new com.ccg.macros.at.Core();
          System.out.println(o);
   }
 }
 

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

Constructor Summary
Core()
          Constructs the object and readies it for installation.
 
Method Summary
 void debug(Output out, Vector args)
          @debug(LEVEL,TEXT) macro - debug output.
 void decrement(Output out, Vector args)
          @decrement(NAME) decrements value of integer macro by 1.
 void define(Output out, Vector args)
          @define(NAME,VAL[,OPT]) macro - define a new macro.
 void definition(Output out, Vector args)
          @definition(NAME) macro - fetch definition of a macro.
 void dumpDefinitions(Output out, Vector args)
          @dumpDefinitions() macro - dump definition of all macros.
 void fnb(Output out, Vector args)
          @fnb(V0[,V1[,V2[,...]) macro - find first "non-blank" value.
 void formatMillis(Output out, Vector args)
          @formatMillis([MILLIS][,DATE_FMT[,TIME_FMT]],[TZ]) macro - format a Java millisecond count.
 String getLineSeparator()
          Get the string used to separate lines on the current platform
 void ifDefined(Output out, Vector args)
          @ifDefined(MACRO,YES,NO) macro - branch if macro is defined.
 void ifEqual(Output out, Vector args)
          @ifEqual(V1,V2,E,NE) macro - branching macro.
 void include(Output out, Vector args)
          @include(SOURCE,[IGNERR],[NOOUT]) insert and process other file(s).
 void increment(Output out, Vector args)
          @increment(NAME) increments value of integer macro by 1.
 void param(Output out, Vector args)
          @param(N[,t|f]) macro - get parameter value This macro is typically used in the definition of run time macros (in the VAL parameter of "@define(NAME,VAL)".
 void quote(Output out, Vector args)
          @quote(TEXT) macro - output text verbatim This macro is invoked in the form "@quote(TEXT)".
 void setDocumentInfo(Output out, Vector args)
          @setDocumentInfo(TYPE,INFO,yyyy-MM-dd) set information about the document.
 void setLineSeparator(String val)
          Set the string used to separate lines on the current platform
 void systemProperty(Output out, Vector args)
          @systemProperty(NAME[,DEF]) macro - fetch a specific system property.
 
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

Core

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

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

setLineSeparator

public void setLineSeparator(String val)
Set the string used to separate lines on the current platform

Parameters:
val - New String value to assign - note, if you pass null, we will attempt to reset it based on the "line.separator" system property.
See Also:
getLineSeparator()

getLineSeparator

public String getLineSeparator()
Get the string used to separate lines on the current platform

Returns:
Current String value assigned.
See Also:
setLineSeparator(java.lang.String)

ifEqual

public void ifEqual(Output out,
                    Vector args)
             throws IOException,
                    InterpretException
@ifEqual(V1,V2,E,NE) macro - branching macro.

This macro is used to compare two values (V1 and V2). If the evaluation of the two values results in identical values, then the equal statement (E) is evaluated, else the false statement "NE" is evaluated.

 @define(name,fred)@ifEqual("@name","barney","betty","wilma")
 

The above should result in the output of "wilma".

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

increment

public void increment(Output out,
                      Vector args)
               throws IOException,
                      InterpretException
@increment(NAME) increments value of integer macro by 1.

This macro is used to increment the value of the macro "NAME" by 1. If the macro does not exist or has a non numeric value, it is created and initialized with a value of '1'.

 @increment(cnt)@cnt,@increment(cnt)@cnt
 

The above should result in the output of "1,2".

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

decrement

public void decrement(Output out,
                      Vector args)
               throws IOException,
                      InterpretException
@decrement(NAME) decrements value of integer macro by 1.

This macro is used to decrement the value of the macro "NAME" by 1. If the macro does not exist or has a non numeric value, it is created and initialized with a value of '1'.

 @define(cnt,4)@decrement(cnt)@cnt,@decrement(cnt)@cnt
 

The above should result in the output of "3,2".

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

ifDefined

public void ifDefined(Output out,
                      Vector args)
               throws IOException,
                      InterpretException
@ifDefined(MACRO,YES,NO) macro - branch if macro is defined.

This macro is evaluates the MACRO name passed. If the evaluated value of the MACRO is a defined macro, then the YES clause is evaluated. Otherwise the NO clause is evaluated.

The following determines if the @name() macro is defined. If not, it defines it to "fred".

 @ifDefined("name",,"@define("name","fred")")
 

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

fnb

public void fnb(Output out,
                Vector args)
         throws IOException,
                InterpretException
@fnb(V0[,V1[,V2[,...]) macro - find first "non-blank" value.

This macro returns the first parameter that evaluates to something other than white space (or no space). It is particularily useful when defining macros where you want to provide a default value if the user omits one. Here's an example that defines "pkb" to print "Paul Blankenbaker (574-7964)" unless a alternate phone number is passed:

 @define("pkb","Paul Blankenbaker (@fnb("@param(0)","574-7964"))")
 

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

param

public void param(Output out,
                  Vector args)
           throws IOException,
                  InterpretException
@param(N[,t|f]) macro - get parameter value This macro is typically used in the definition of run time macros (in the VAL parameter of "@define(NAME,VAL)". It allows a user defined macro (run time defined) to reference the parameter passed to its invocation. Take a look at the following:
 @define(email,"<a href=\"mailto:@param(0)\">@param(0)</a>")
 @email("paul@mekwin.com")
 

The above defines a new run time macro "@email", the new "@email" macro allows the user to pass an argument which is subsitutes in two places. This provides a means to make some pretty powerful run time macros.

Note, the second parameter indicates whether you want the value of the parameter to be interpretted or not. You can get the exact value passed (instead of the default interrpretted results), by passing "f".

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

quote

public void quote(Output out,
                  Vector args)
           throws IOException,
                  InterpretException
@quote(TEXT) macro - output text verbatim This macro is invoked in the form "@quote(TEXT)". This macro only looks at the first argument (additional arguments are ignored). The text of the first argument is written verbatim to the output device. This allows one to output macro names. For example: @quote("@quote(TEXT)") would result in @quote(TEXT) in the output stream.

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

setDocumentInfo

public void setDocumentInfo(Output out,
                            Vector args)
                     throws IOException,
                            InterpretException
@setDocumentInfo(TYPE,INFO,yyyy-MM-dd) set information about the document.

Often it is desirable to have a consistent set of macros to retrieve information about the document being processed (such as its last revision date, copyright, etc). This macro is used to generate these values.

You typically use this macro at the start of your document in the following form:

 @setDocumentInfo("cvsId","$Id: Core.java,v 1.1.1.1 2004/01/26 20:46:18 pkb Exp $","2001-12-25")
 

The following parameters are recognized:

TYPE
This is the type of information from which we are to get the document info from. This describes the format of the INFO field. Currently, the only recognized type is "cvsId" which means the info corresponds to the CVS Id value.
INFO
This is the text string which provides information about the document.
yyyy-MM-dd
This is the copyright date associated with the document. It must be in the format shown.

This takes the information passed to it and then defines the following macros:

@docLastModifiedMillis()
Will be the Java millisecond count that the document was last modified - if unable to determine from the information passed, the current time will be used.
@docVersion()
Will be the version number associated with the document, if unable to determine, this will default to "0.0.1".
@copyRightYear()
Will be the year field from the copy right.
@copyRightDate()
Will be the copy right date.
@copyRightMillis()
Will be the copy right date as a Java millisecond time value.

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

formatMillis

public void formatMillis(Output out,
                         Vector args)
                  throws IOException,
                         InterpretException
@formatMillis([MILLIS][,DATE_FMT[,TIME_FMT]],[TZ]) macro - format a Java millisecond count.

This macro is invoked in the form "@millis(MILLIS)". This macro accepts up to four arguments (how to format the date/time and the time zone). Refer to the SimpleDateFormat class if you want to specify your own custom format (like: "yyyy-MM-dd").

The four optional parameters to this macro accepts include:

MILLIS
This value can be the Java millisecond count of the time to be formatted. If omitted, the current system time is used.
DATE_FMT
This parameter can be one of the Java specific formats (like: "long", "short", etc - described below). Or, it can be a full date/time format using the characters recognized by the SimpleDateFormat class (like "yyyy-MMM-dd hh:mm:ss").
TIME_FMT
This parameter is only used if you want to specify the locale specific formats supported by the Java run time.
TZ
You only need to pass this parameter if you want to force a particular time zone. It may be any string value (it will be interpretted first) recognized as a valid parameter to TimeZone.getTimeZone(String). For example: "UTC", "America/Los_Angeles", or "GMT+10". If you pass a unrecognized timezone, we will ignore your request (we will log a debug message) and use the default time zone for the JVM.

If you want to use one of the built in local formats, pass use one of the following keywords for the DATE_FMT and/or TIME_FMT parameters:

none
Don't include (only one of the parameters should be set to this value).
short
Use the DateFormat.SHORT format for this portion.
medium
Use the DateFormat.MEDIUM format for this portion.
long
Use the DateFormat.LONG format for this portion.
full
Use the DateFormat.FULL format for this portion.

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

debug

public void debug(Output out,
                  Vector args)
           throws IOException,
                  InterpretException
@debug(LEVEL,TEXT) macro - debug output. This macro is invoked in the form "@debug(LEVEL,TEXT)". If the current debug level is enabled for the LEVEL specified, the text is interpretted and debug output is generated. This can be VERY useful when tracking down problems in your source file.

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

define

public void define(Output out,
                   Vector args)
            throws IOException,
                   InterpretException
@define(NAME,VAL[,OPT]) macro - define a new macro. This macro is invoked in the form "@define(NAME,VAL[,OPT])". This macro is used to define new text replacement macros. The first argument NAME is the name of the new macro to define (do not include the leading "@" sign). The second argument VAL is the text which is to be subsituted. The third arguments allows for some specialized options during the definition. For example:
 @define(pkb_email,"@quote(paul@mekwin.com)")
 

After interpretting the above, one could then use "@pkb_email()" in the document and have "paul@mekwin.com" appear. It should be noted, that the "VAL" area can contain references to other macros. For example:

 @define(pkb,"Paul Blankenbaker (@pkb_email)")
 

There are two important concepts to understand with the above. One is that the @pkb macro just defined contains a reference to another macro. This is handled properly and the contained @pkb_email reference will be expanded each time the @pkb macro is used. The second concept is that the expansion occurs at the time the @pkb macro is used, not at the time it is defined. In other words, if someone changed the definition of the @pkb_email macro, then it would affect subsequent invocations of the @pkb macro.

The third parameter to this macro is optional, and can be extremely useful in some circumstances. The third parameter can be one of the following:

ifnew
The "ifnew" option means that the definition should only be accepted if a definition does not already exist. This can be a very handy way to provide default values.
now
The "now" option means that the value should be interpretted immediately (right now). This can be more efficient and prevents future changes from having affects.

To get an idea of how these behave, try running the the following through to see what comes out:

 @define("name","Joe Schmoe")
 @define("phone","333-333-3333")
 @define("pname","@name @phone")
 @define("nname","@name @phone","now")
 @define("phone","444-444-4444")
 @define("phone","555-555-5555","ifnew")
 @quote("@pname=")@pname
 @quote("@nname=")@nname
 

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

definition

public void definition(Output out,
                       Vector args)
                throws IOException,
                       InterpretException
@definition(NAME) macro - fetch definition of a macro. This macro is mainly used for debugging purposes, it returns the current definition of a macro. You pass the NAME of the macro (without the leading "@" symbol) which you want to retrieve the definition for. The current definition of the macro is returned as a text string. If the macro was created with the "@define(NAME,VAL)" macro, then the returned text will be "VAL". If the macro is a built-in macro (such as "@definition(NAME)", then the returned value will be the name of the Java class/method used to handle the macro.

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

systemProperty

public void systemProperty(Output out,
                           Vector args)
                    throws IOException,
                           InterpretException
@systemProperty(NAME[,DEF]) macro - fetch a specific system property. This macro is evaluates the "NAME" parameter and then tries to fetch the "system property" it identifies. If the system property is successfully retrieved, it is returned. Otherwise, if the system property is not available (or attempts to retrieve it result in some sort of error), the optional DEF parameter is evaluated and returned.

Here are some sample (and useful definitions) out of "Core.At" which area available and make use of this:

 @define("userName","@systemProperty("user.name","unknown")","now")
 @define("userHome","@systemProperty("user.home",".")","now")
 

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

dumpDefinitions

public void dumpDefinitions(Output out,
                            Vector args)
                     throws IOException,
                            InterpretException
@dumpDefinitions() macro - dump definition of all macros.

This macro is mainly used for debugging purposes. It dumps the definition of ALL defined macros.

NOTE: You may optionally pass a single argument to this method. If passed, the argument will be expanded for each definition in our macro dictionary. The following macros will be available:

@dumpDefName()
The name of the macro the definition refers to.
@dumpDefValue()
The string value of the macro (this may be the name of the Java method used to evaluate it.

Here is an example which produces the same results as the default output:

 @dumpDefinitions("@dumpDefName()=@dumpDefValue()
 ")
 

Here's an example which provides a little fancier output in HTML:

 @dumpDefinitions("<h2>@quote(@)@dumpDefName()</h2>
 <pre>
 @htmlEscape("@dumpDefValue()")
 </pre>
 ")
 

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

include

public void include(Output out,
                    Vector args)
             throws IOException,
                    InterpretException
@include(SOURCE,[IGNERR],[NOOUT]) insert and process other file(s).

This macro is used to load and process the contents of another file. Currently the full or relative path to the source must be specified (in the future, path searching may be added).

It should be noted however, that the CLASSPATH and/or JAR files are searched. For example, the file "/com/ccg/macros/at/Jnlp.At" would be found as its included with the distribution. Check the "/com/ccg/macros/at" directory for "*.At" files which are available.

For example, to include the file "/opt/include/atmacros/companies.atmacros", one could use the following command:

@include("/etc/hosts")

The second parameter IGNERR is optional. It may be set to either "true" or "false" (only first letter is checked). If omitted, it defaults to a value of "false". When set to "true", then no error will be thrown if the file is not found. If set to "false" (or omitted), then an error will be thrown if the desired SOURCE could not be found.

The third parameter DISOUT is optional. It may be set to either "true", "false", "cdata" or "definitions" (only first letter is checked). If omitted, it defaults to a value of "false". When set to "true", then no output will be produced while interpretting the file included (this allows one to load definition files). When set to "false" (or omitted), any output produced as a result of interpretting the file will be written to the current output device. When set to "definition" (or "d"), no output will be generated, AND the file will only be included if it has not be included in the past (this is useful when you don't want to bother processing macro definition files more than once).

When the third parameter is set to "cdata" (or "c"), the contents of the file are treated as character data (similar to XML) and placed in the output verbatim.

When using this directive to include definition files, it is often handy to set the DISOUT value to "definition" (or "d") to disable any output as a result of interpretting the definition file (this allows one to enter comments in their definition files). It also prevents the same definitions from being loaded more than once during a run.

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.