You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by weiji <na...@hotmail.com> on 2009/08/11 08:48:01 UTC

help with filterchain: using regex filter...

Hi,

I'm trying to use Ant to convert an XML file from one format to another.  We
are using it this way in order to generate Flex manifest files for
compilation using the flex command-line compiler.  Basically we have a list
of classes to compile, but they're in one format and the manifest file is in
a slightly different format.  I'm able to do most of the conversion using
filterchains, but I'm stuck on the last portion and I'm hoping someone here
can help me out.

The input file structure looks like this:

.flexLibProperties:

<?xml version="1.0" encoding="UTF-8"?>
<flexLibProperties version="1">
  <includeClasses>
    <classEntry path="some.long.package.name.ClassA"/>
    <classEntry path="some.long.package.name.ClassB"/>
    <classEntry path="some.long.package.name.ClassC"/>
(more classes here)
  </includeClasses>
  <includeResources/>
  <namespaceManifests/>
</flexLibProperties>

The manifest.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<componentPackage>
    <component id="ClassA" class="some.long.package.name.ClassA"/>
    <component id="ClassB" class="some.long.package.name.ClassB"/>
    <component id="ClassC" class="some.long.package.name.ClassC"/>
(more classes here)
</componentPackage>

So far I have the following:

    <target name="testman" description="Convert a .flexLibProperties file
into a manifest file">
        <property name="tempfile" value="manifest.temp"/>
        <property name="outfile"  value="manifest.xml"/>
        <property name="flag.keepme" value="keepme"/>

        <delete file="${tempfile}"/>
        <delete file="${outfile}"/>
        <copy file=".flexLibProperties" tofile="${tempfile}">
            <filterchain>
                <replacestring from="xml version" to="xml ${flag.keepme}
version"/>
                <replacestring from="includeClasses" to="componentPackage
${flag.keepme}"/>
                <replacestring from="classEntry" to="component"/>
                <replacestring from="path=" to="${flag.keepme} id= class="/>
            </filterchain>
        </copy>
        <copy file="${tempfile}" tofile="${outfile}">
            <filterchain>
                <linecontains>
                    <contains value="${flag.keepme}"/>
                </linecontains>
                <replacestring from=" ${flag.keepme}" to=""/>
            </filterchain>
        </copy>
    </target>

This gets me pretty close; the output looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<componentPackage>
    <component id= class="some.long.package.name.ClassA"/>
    <component id= class="some.long.package.name.ClassB"/>
    <component id= class="some.long.package.name.ClassC"/>
(more classes here)
</componentPackage>

The only thing left is to get the class name inserted as the value of the id
attribute.  I can't figure out how to use the regex filters, or if that's
the correct one I should be using. Can anyone lend a hand?

Thanks,
KaJun
-- 
View this message in context: http://www.nabble.com/help-with-filterchain%3A-using-regex-filter...-tp24912535p24912535.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: AW: help with filterchain: using regex filter...

Posted by weiji <na...@hotmail.com>.
Hi Jan,

It does look easier... let me try it out and I'll let you know how it goes.

Thanks!
KaJun

-- 
View this message in context: http://www.nabble.com/help-with-filterchain%3A-using-regex-filter...-tp24912535p24922974.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: AW: help with filterchain: using regex filter...

Posted by weiji <na...@hotmail.com>.


Jan.Materne wrote:
> 
> Wouldnt be a XSLT easier?
> 
> Jan
> 
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet
>   version="1.0"
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 
> <xsl:template match="/">
> <xsl:comment>generated file - do not change</xsl:comment>
> <componentPackage>
>     <xsl:apply-templates/>
> </componentPackage>
> </xsl:template>
> 
> 
> <xsl:template match="classEntry">
>   <component class="{@path}">
>     <xsl:attribute name="id">
>       <xsl:call-template name="substring-after-last">
>         <xsl:with-param name="string" select="@path" />
>         <xsl:with-param name="delimiter" select="'.'" />
>       </xsl:call-template>
>     </xsl:attribute>
>   </component>
> </xsl:template>
> 
> 
> <xsl:template name="substring-after-last">
>   <xsl:param name="string" />
>   <xsl:param name="delimiter" />
>   <xsl:choose>
>     <xsl:when test="contains($string, $delimiter)">
>       <xsl:call-template name="substring-after-last">
>         <xsl:with-param name="string"
>           select="substring-after($string, $delimiter)" />
>         <xsl:with-param name="delimiter" select="$delimiter" />
>       </xsl:call-template>
>     </xsl:when>
>     <xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
>   </xsl:choose>
> </xsl:template>
> 
> </xsl:stylesheet> 
> 
> 


Jan - this worked perfectly!  It was actually very easy to set up.  My
target only uses a single task now:
        <xslt in=".flexLibProperties" out="manifest.xml"
style="build-manifest-style.xsl"/>

... where build-manifest-style.xsl contains the xml you provided.

Thanks again,
KaJun
-- 
View this message in context: http://www.nabble.com/help-with-filterchain%3A-using-regex-filter...-tp24912535p24923469.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: help with filterchain: using regex filter...

Posted by Ja...@rzf.fin-nrw.de.
Wouldnt be a XSLT easier?

Jan


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<xsl:comment>generated file - do not change</xsl:comment>
<componentPackage>
    <xsl:apply-templates/>
</componentPackage>
</xsl:template>


<xsl:template match="classEntry">
  <component class="{@path}">
    <xsl:attribute name="id">
      <xsl:call-template name="substring-after-last">
        <xsl:with-param name="string" select="@path" />
        <xsl:with-param name="delimiter" select="'.'" />
      </xsl:call-template>
    </xsl:attribute>
  </component>
</xsl:template>


<xsl:template name="substring-after-last">
  <xsl:param name="string" />
  <xsl:param name="delimiter" />
  <xsl:choose>
    <xsl:when test="contains($string, $delimiter)">
      <xsl:call-template name="substring-after-last">
        <xsl:with-param name="string"
          select="substring-after($string, $delimiter)" />
        <xsl:with-param name="delimiter" select="$delimiter" />
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet> 

>-----Ursprüngliche Nachricht-----
>Von: weiji [mailto:nabbleOp@hotmail.com] 
>Gesendet: Dienstag, 11. August 2009 08:48
>An: user@ant.apache.org
>Betreff: help with filterchain: using regex filter...
>
>
>Hi,
>
>I'm trying to use Ant to convert an XML file from one format 
>to another.  We
>are using it this way in order to generate Flex manifest files for
>compilation using the flex command-line compiler.  Basically 
>we have a list
>of classes to compile, but they're in one format and the 
>manifest file is in
>a slightly different format.  I'm able to do most of the 
>conversion using
>filterchains, but I'm stuck on the last portion and I'm hoping 
>someone here
>can help me out.
>
>The input file structure looks like this:
>
>.flexLibProperties:
>
><?xml version="1.0" encoding="UTF-8"?>
><flexLibProperties version="1">
>  <includeClasses>
>    <classEntry path="some.long.package.name.ClassA"/>
>    <classEntry path="some.long.package.name.ClassB"/>
>    <classEntry path="some.long.package.name.ClassC"/>
>(more classes here)
>  </includeClasses>
>  <includeResources/>
>  <namespaceManifests/>
></flexLibProperties>
>
>The manifest.xml file looks like this:
>
><?xml version="1.0" encoding="UTF-8"?>
><componentPackage>
>    <component id="ClassA" class="some.long.package.name.ClassA"/>
>    <component id="ClassB" class="some.long.package.name.ClassB"/>
>    <component id="ClassC" class="some.long.package.name.ClassC"/>
>(more classes here)
></componentPackage>
>
>So far I have the following:
>
>    <target name="testman" description="Convert a 
>.flexLibProperties file
>into a manifest file">
>        <property name="tempfile" value="manifest.temp"/>
>        <property name="outfile"  value="manifest.xml"/>
>        <property name="flag.keepme" value="keepme"/>
>
>        <delete file="${tempfile}"/>
>        <delete file="${outfile}"/>
>        <copy file=".flexLibProperties" tofile="${tempfile}">
>            <filterchain>
>                <replacestring from="xml version" to="xml 
>${flag.keepme}
>version"/>
>                <replacestring from="includeClasses" 
>to="componentPackage
>${flag.keepme}"/>
>                <replacestring from="classEntry" to="component"/>
>                <replacestring from="path=" to="${flag.keepme} 
>id= class="/>
>            </filterchain>
>        </copy>
>        <copy file="${tempfile}" tofile="${outfile}">
>            <filterchain>
>                <linecontains>
>                    <contains value="${flag.keepme}"/>
>                </linecontains>
>                <replacestring from=" ${flag.keepme}" to=""/>
>            </filterchain>
>        </copy>
>    </target>
>
>This gets me pretty close; the output looks like this:
>
><?xml version="1.0" encoding="UTF-8"?>
><componentPackage>
>    <component id= class="some.long.package.name.ClassA"/>
>    <component id= class="some.long.package.name.ClassB"/>
>    <component id= class="some.long.package.name.ClassC"/>
>(more classes here)
></componentPackage>
>
>The only thing left is to get the class name inserted as the 
>value of the id
>attribute.  I can't figure out how to use the regex filters, 
>or if that's
>the correct one I should be using. Can anyone lend a hand?
>
>Thanks,
>KaJun
>-- 
>View this message in context: 
>http://www.nabble.com/help-with-filterchain%3A-using-regex-filt
>er...-tp24912535p24912535.html
>Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org