com.panopset.flywheel
Class Flywheel

java.lang.Object
  extended by com.panopset.flywheel.Flywheel
All Implemented Interfaces:
MapProvider

public final class Flywheel
extends Object
implements MapProvider

Panopset Flywheel.

Commands

There are 7 commands that you may use in a Flywheel template. Commands have a default syntax that starts with ${@, followed by the letter associated with the command, followed by a space, followed by a parameter, followed by the default closing syntax of }.
f - File
 ${@f somefile.txt}
 
Output to the specified file, until the matching ${@q} is found.
p - Push

 ${@p variableName}
 
Everything following this command is pushed into a String buffer, until a q command is reached.
l - List
 ${@l someListFile.txt} or ${@l someFile.txt˜,}
 
Read the given file, and for each line execute the template from this list command up until its matching q command. If no token is defined as a variable, then each line will be stored in variable 1. If there is a token defined after a ~, the line will be split by that token, and stored in variables named after integers, in order.
q - Quit
 ${@q}
 
t - Template
 ${@t someTemplateFile.txt}
 
Continue execution using the supplied template script file.
Variable
There is no command associated with a variable, so you drop the @ directive indicator, and then you specify a variable just as you would in any ant script or unix shell. The variable must have been defined either in a map provided to the script through Script.Builder.mergeMap, or a Push command.
 ${variableName}
 
e - Execute
Excecute any static method. Parameters may be variable names only. Example:

 ${@p name}panopset${q}

 ${@e com.panopset.Strings.capitalize(name)}

 
The above script will output:

 Panopset

 

Author:
Karl Dinwiddie

Nested Class Summary
static class Flywheel.Builder
          Flywheel builder.
 
Method Summary
 void copyPackageResource(String resourcePath, String targetPath)
          Copy package resource.
 String exec()
          Execute this script.
 String get(String key)
          Get map value.
 Map<String,String> getAllValues()
           
 String getBaseDirectoryPath()
          Get the directory in which the script top template file resides.
 String getBaseRelativePath(String simpleFileName)
          Append simple file name to getBaseDirectoryPath.
 Control getControl()
          Get control.
 Map<String,Object> getRegisteredObjects()
           
protected  List<String[]> getReplacements()
           
 Command getResolvingCommand()
          Used for debugging.
 File getTargetDirectory()
           
 Template getTemplate()
           
 StringWriter getWriter()
          This method should only be used when a writer was specified in the builder.
 boolean isOutputEnabled()
           
 boolean isReplacementsSuppressed()
          Is replacements repressed.
 boolean isStopped()
          Used by debuggers.
 boolean isTargetDirectoryValid()
          Is target directory valid.
 String loadProperties(String relativePath)
          Load properties.
static void main(String... args)
           
 void mergeMap(Map<String,String> map)
          Merge a map into the script map.
 void put(String key, String value)
          Put map value, that will be available to future v commands.
 void setOutputEnabled(boolean value)
          Set whether or not Flywheel will write output to text files.
 void setRegisteredObjects(Map<String,Object> registeredObjects)
           
 void setWriter(StringWriter writer)
           
 void stop(String message)
          Called if something unexpected happens.
 void suppressReplacements(String value)
          Suppress replacements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTargetDirectory

public File getTargetDirectory()
Returns:
Target directory.

getResolvingCommand

public Command getResolvingCommand()
Used for debugging.

Returns:
Currently resolving command.

getAllValues

public Map<String,String> getAllValues()
Returns:
All map values.

main

public static void main(String... args)
Parameters:
args -
     [0] = script file name, args[1] = target directory name.
       or
     [0] = properties file name where these properties are required:
            com.panopset.flywheel.script=<your script file name>
 com.panopset.flywheel.target=<your target file name>
 

copyPackageResource

public void copyPackageResource(String resourcePath,
                                String targetPath)
                         throws IOException
Copy package resource.

Parameters:
resourcePath - Java source path resource.
targetPath - Target path, relative to Flywheel target directory.
Throws:
IOException - IO Exception.

isTargetDirectoryValid

public boolean isTargetDirectoryValid()
Is target directory valid.

Returns:
true if a valid, writable target directory has been specified.

getWriter

public StringWriter getWriter()
This method should only be used when a writer was specified in the builder. In other words, when you are using the templates to generate a text String, instead of files, then you would use this method to get the output.

Returns:
StringWriter holds script output.

setWriter

public void setWriter(StringWriter writer)
Parameters:
writer - Writer.

put

public void put(String key,
                String value)
Put map value, that will be available to future v commands.

Parameters:
key - Variable name.
value - Variable value.

loadProperties

public String loadProperties(String relativePath)
Load properties.

Parameters:
relativePath - Path is relative to the parent of the main Flywheel script file.
Returns:
empty String.

suppressReplacements

public void suppressReplacements(String value)
Suppress replacements. Usage
 ${@p foo}bar{@q}
 ${@e script.suppressReplacements(true)}
 A: ${@v foo}
 ${@e script.suppressReplacements(false)}
 B: ${@v foo}
 
Output

 A:
 B: bar

 

Parameters:
value - If true, all v commands will be not output anything.

get

public String get(String key)
Get map value.

Specified by:
get in interface MapProvider
Parameters:
key - Variable name.
Returns:
value or null if key not found.

mergeMap

public void mergeMap(Map<String,String> map)
Merge a map into the script map. Existing values are overwritten.

Parameters:
map - Map to merge into the script map.

exec

public String exec()
Execute this script.

Returns:
results, for unit tests and server side operations.

getTemplate

public Template getTemplate()
Returns:
Template.

stop

public void stop(String message)
Called if something unexpected happens. Diagnostic messages are logged, in addition to the message.

Parameters:
message - Log this message

isStopped

public boolean isStopped()
Used by debuggers.

Returns:
true if the stop method was called for any reason, usually some error condition.

getBaseDirectoryPath

public String getBaseDirectoryPath()
Get the directory in which the script top template file resides. This is used as a relative path base for all subsequent template files created with the template command: ${@t templateRelativePathName}.

Returns:
Full path of parent directory of the top script template file.

getReplacements

protected List<String[]> getReplacements()
Returns:
Replacements vector.

getBaseRelativePath

public String getBaseRelativePath(String simpleFileName)
Append simple file name to getBaseDirectoryPath.

Parameters:
simpleFileName - Simple file name (no path).
Returns:
Full relative path of simpleFileName

isReplacementsSuppressed

public boolean isReplacementsSuppressed()
Is replacements repressed.

Returns:
true if replacements suppressed flag is set.

setRegisteredObjects

public void setRegisteredObjects(Map<String,Object> registeredObjects)
Parameters:
registeredObjects - Registered objects.

getRegisteredObjects

public Map<String,Object> getRegisteredObjects()
Returns:
Registered objects for execute commands.

getControl

public Control getControl()
Get control.

Returns:
Flywheel Control.

isOutputEnabled

public boolean isOutputEnabled()
Returns:
True iff output to files is enabled, default is true.

setOutputEnabled

public void setOutputEnabled(boolean value)
Set whether or not Flywheel will write output to text files. Default is true, you might want to set to false if all you are doing is String manipulation in memory.

Parameters:
value - Value to set.


Copyright © 2012. All Rights Reserved.