org.barracudamvc.taskdefs
Class CopyAndReplace

java.lang.Object
  extended byorg.apache.tools.ant.ProjectComponent
      extended byorg.apache.tools.ant.Task
          extended byorg.apache.tools.ant.taskdefs.Copy
              extended byorg.barracudamvc.taskdefs.CopyAndReplace

public class CopyAndReplace
extends org.apache.tools.ant.taskdefs.Copy

A consolidated copy and replace task that extends the basic Ant Copy taskdef.

In addition, once files have been copied, a replace function is also run on them. This replace will only affect the files that actually get copied; it will not affect any other files in the directory.

The replace occurs using a simply properties file, rather than specifying replace parameters via the xml. The format of this file looks something like this:

As you can see, the format is flexible. Tokens are identified with "token=" and values are identified by "value=". The actual token/value delimiters are taken to be the first character following the = sign. This could be a double quote, single quote, or any other character (ie. if the text you wish to replace contains both double and single quotes, you might want to use a ~ delimiter or something like that).

Note also that this taskdef supports SSI replacement, which can be quite useful. By default, the copied files are NOT processed for SSIs; if you want to use this, turn is on using the 'ssi=true' attribute. SSI replacement occurs BEFORE the token replacement (ensuring that the text contained in the SSI gets processed for tokens as well).

If SSI replacement is turned on, you can also exclude blocks of code using #exclude_start and #exclude_end tags (as many as you want in the template). This allows you to drop code from the mockups when you copy across. For example:

blah blah blah
will result in this after copying:

As a final note, doing SSI replacement on a hierarchy of directories can easily cause broken link references (ie. if your SSI is in the root directory, and it refers to images/foo.gif, then when you suck that SSI into a file several directories deep (eg. /foo/bar/blah.html), then that ssi reference really needs to get changed to ../../images/foo.gif. You can do this by specifying a relative dir constant in your options.mappings file:
token=^"images/^ value=^"@REL_PATH@images/^

Author:
Christian Cryder [christianc@granitepeaks.com]

Nested Class Summary
static class CopyAndReplace.BooleanAttribute
           
 
Field Summary
protected  File mappingsFile
           
static String REL_PATH_TOKEN
           
protected  boolean ssi
           
 
Fields inherited from class org.apache.tools.ant.taskdefs.Copy
completeDirMap, destDir, destFile, dirCopyMap, file, fileCopyMap, filesets, filtering, flatten, forceOverwrite, includeEmpty, mapperElement, preserveLastModified, verbosity
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
CopyAndReplace()
           
 
Method Summary
protected  void doFileOperations()
          Actually does the file (and possibly empty directory) copies.
 byte[] getFile(File targetFile, File fromDir)
           
protected  void processReplace(String fromFile, String toFile, List tokenList, List valueList)
          perform the token-value based replacement.
protected  void processSSI(String fromFile, String toFile)
          processSSI is the result of a code refactoring due to changes in Ant 1.5 to Ant 1.6 Ant 1.6 supports multiple target file, therefore processSSI might be called n-times
 void setMappings(File mappingsFile)
          Sets the mappings file.
 void setSsi(CopyAndReplace.BooleanAttribute issi)
          Process files copied for ssi
 
Methods inherited from class org.apache.tools.ant.taskdefs.Copy
addFileset, buildMap, createFilterChain, createFilterSet, createMapper, execute, getEncoding, getFileUtils, getFilterChains, getFilterSets, getOutputEncoding, getPreserveLastModified, isEnableMultipleMapping, scan, setEnableMultipleMappings, setEncoding, setFailOnError, setFile, setFiltering, setFlatten, setIncludeEmptyDirs, setOutputEncoding, setOverwrite, setPreserveLastModified, setPreserveLastModified, setTodir, setTofile, setVerbose, validateAttributes
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REL_PATH_TOKEN

public static final String REL_PATH_TOKEN
See Also:
Constant Field Values

mappingsFile

protected File mappingsFile

ssi

protected boolean ssi
Constructor Detail

CopyAndReplace

public CopyAndReplace()
Method Detail

setMappings

public void setMappings(File mappingsFile)
Sets the mappings file.


setSsi

public void setSsi(CopyAndReplace.BooleanAttribute issi)
Process files copied for ssi

Parameters:
issi - set "true" to process copied files for ssi

processSSI

protected void processSSI(String fromFile,
                          String toFile)
processSSI is the result of a code refactoring due to changes in Ant 1.5 to Ant 1.6 Ant 1.6 supports multiple target file, therefore processSSI might be called n-times

Parameters:
fromFile -
toFile -

processReplace

protected void processReplace(String fromFile,
                              String toFile,
                              List tokenList,
                              List valueList)
perform the token-value based replacement. This method was introduced due to changes from Ant 1.5 to Ant 1.6. It might be called multiple times

Parameters:
fromFile -
toFile -
tokenList -
valueList -

doFileOperations

protected void doFileOperations()

Actually does the file (and possibly empty directory) copies. This is a good method for subclasses to override.

Note that all the copy functionality occurs by simply deferring to the superclass implementation. The replace functionality follows:


getFile

public byte[] getFile(File targetFile,
                      File fromDir)


Copyright © 2004 BarracudaMVC.org All Rights Reserved.