Wouldn't this be better as an XSLT file?  Just a thought.

-----Original Message-----
From: Paul Fisher [mailto:[EMAIL PROTECTED] 
Sent: Monday, April 10, 2006 2:07 AM
To: tapestry-user@jakarta.apache.org
Subject: Magic Tapestry Upgrade Ant Script

I decided to try to upgrade our Tapestry 3.03 Application to Tapestry
4.01 this weekend, and in the process wrote up a simple Ant Task that
converts the .page and .jwc files to be Tapestry 4 compliant. The
task uses Regex Replace and group substitution to somewhat
intelligently find the changed items in the XML files and replace
them accordingly. It should also figure out whether a binding
expression starts with listeners, beans, or is a static-binding and
replace that with the appropriate binding expression using either the
literal, listener, or bean prefix.

I whipped this up fairly quickly, so please use this at your own
risk. I would highly recommend checking in all your current work, or
doing a back-up before giving this task a whirl. By default, it
attempts to change all .page and .jwc files that exist under any
subdirectory from the ${web.root} directory : you'll need to specify
web.root as your root web directory to get this to work.

Anyway, here it is. If you have any suggestions, please let me know.
I really am thinking this could be a good starting point that might
prove helpful to those wanting to upgrade to Tapestry 4, but don't
want to spend a lot of time doing it (of course, the existing 3.0 xml
files should still work in 4, but if you want to take advantage of 4
features, you'll need to upgrade the xml files at some point!).

Ant Task (place in your build script):

<!--Start -->
      <target name="upgradeTapestry4">

           <replaceregexp byline="true">
          <regexp pattern="(binding name=&quot;\w+&quot;)
expression=&quot;listeners\."/>
          <substitution expression="\1 value=&quot;listener:"/>
          <fileset dir="${web.root}">
              <include name="**/*.page" />
               <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>



             <replaceregexp byline="true">
          <regexp pattern="(binding name=&quot;\w+&quot;)
expression=&quot;beans\."/>
          <substitution expression="\1 value=&quot;bean:"/>
          <fileset dir="${web.root}">
               <include name="**/*.page" />
               <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>


          <replaceregexp byline="true">
          <regexp pattern="(binding name=&quot;\w+&quot;)
expression=&quot;"/>
          <substitution expression="\1 value=&quot;ognl:"/>
          <fileset dir="${web.root}">
              <include name="**/*.page" />
               <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>

          <replaceregexp byline="true">
          <regexp pattern="persistent=&quot;yes&quot;"/>
          <substitution expression="persist=&quot;session&quot;"/>
          <fileset dir="${web.root}">
              <include name="**/*.page" />
               <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>



           <replaceregexp byline="true">
          <regexp pattern="Tapestry Specification 3.0//EN"/>
          <substitution expression="Tapestry Specification 4.0//EN"/>
          <fileset dir="${web.root}">
              <include name="**/*.page" />
               <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>

            <replaceregexp byline="true">
          <regexp pattern="tapestry/dtd/Tapestry_3_0.dtd"/>
          <substitution expression="tapestry/dtd/Tapestry_4_0.dtd"/>
          <fileset dir="${web.root}">
               <include name="**/*.page" />
               <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>

          <replaceregexp byline="true">
          <regexp pattern="(static-binding name=)(&quot;\w+&quot;)
(value=&quot;)"/>
          <substitution expression="binding name=\2 \3literal:"/>
          <fileset dir="${web.root}">
              <include name="**/*.page" />
               <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>

          <replaceregexp byline="true">
          <regexp pattern="&lt;set-property (name=&quot;\w+&quot;)
(expression=)"/>
          <substitution expression="&lt;set \1 value="/>
          <fileset dir="${web.root}">
              <include name="**/*.page" />
               <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>

            <replaceregexp byline="true">
          <regexp pattern="&lt;context-asset"/>
          <substitution expression="&lt;asset"/>
          <fileset dir="${web.root}">
              <include name="**/*.page" />
               <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>

              <replaceregexp byline="true">
          <regexp pattern="&lt;property-specification (name=&quot;\w
+&quot;) (type=&quot;.*?&quot;)(.*?&gt;)"/>
          <substitution expression="&lt;property \1 \3"/>
          <fileset dir="${web.root}">
              <include name="**/*.page" />
               <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>

          <replaceregexp byline="true">
          <regexp pattern="&lt;parameter (name=&quot;\w+&quot;)
(direction=&quot;\w&quot;) (type=&quot;\w&quot;)(.*?&gt;)"/>
          <substitution expression="&lt;parameter \1 \4"/>
          <fileset dir="${web.root}">
              <include name="**/*.jwc" />
          </fileset>
          </replaceregexp>

       </target>

<!-- Finish -->

Please let me know your thoughts!

Thanks,

Paul

Paul Fisher


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to