commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Weinstein <jasonweinst...@hotmail.com>
Subject New Tag - Looking for Comments (Maintain user code during regeneration of files)
Date Fri, 17 Jul 2009 09:11:34 GMT


A common problem with templating systems is that they overwrite changes made to the generated
files, when things are regenerated.

This simple tag eliminates a portion of this problem.

A simple example:

Template:

<?xml version="1.0"?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:s="jelly:slot">
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;

public class ${className} extends TagSupport {
    public void doTag(XMLOutput output) throws JellyTagException {
        <s:slot id="//[[100]] - user code" overwrite="false" evaluate="true" buffer="${fileText}">
        getBody().run(context, output);
        </s:slot>
    }
}
</j:jelly>

Outputs:

import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;

public class FooTag extends TagSupport {
    public void doTag(XMLOutput output) throws JellyTagException {
        //[[100]] - user code
        getBody().run(context, output);
        //[[100]] - user code
    }
}

If the user now changes this file and adds a print statement the statement will survive regeneration.

    public void doTag(XMLOutput output) throws JellyTagException {

        //[[100]] - user code
        System.out.println("entering doTag");

        getBody().run(context, output);

        //[[100]] - user code

    }



This tag allows the user to make changes in between unique id tags in the generated file and
to have those changes persist after regeneration. Obvious issues exist in the above example
when parameter names or numbers change. However if a generate and compile step are combined
this will give an early clue that the user code will need to be changed.

Basically it is using the generated file as a Context (Key, Vals) for regenerated files.

        <s:slot id="//[[100]] - user code" overwrite="false" evaluate="true" buffer="${fileText}">

        getBody().run(context, output);

        </s:slot>


The id is the key, overwrite indicates whether the code in between should be overwritten,
evaluate indicates whether the code in between should be evaled as a script (only for new
files) and the buffer contains the original text of the file being regenerated.

If anyone has any ideas on improving this simple code i'd be glad to hear suggestions. The
code was done very quickly so even simple suggestions may be helpful. Changes to inputs, names,
types, etc...

_________________________________________________________________
Lauren found her dream laptop. Find the PC that’s right for you.
http://www.microsoft.com/windows/choosepc/?ocid=ftp_val_wl_290
Mime
View raw message