ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nswob...@clip.dia.fi.upm.es
Subject Re: Using Java xml properties file with Ant
Date Fri, 20 Jul 2007 17:38:03 GMT
Thanks for the short term solution, it works like a charm.

Nik

> In the meantime one can write a custom task, or use <script> or <scriptdef>
> for example:
>      <scriptdef name="load-xml-properties" language="beanshell">
>           <attribute name="file"/>
>           <attribute name="prefix"/>
>          import java.io.*;
>          import java.util.*;
>          prefix = attributes.get("prefix") + ".";
>          is = new FileInputStream(attributes.get("file"));
>          Properties props = new Properties();
>          props.loadFromXML(is);
>          for (e = props.propertyNames(); e.hasMoreElements();) {
>              key = e.nextElement();
>              project.setNewProperty(prefix + key, props.getProperty(key));
>          }
>          is.close();
>       </scriptdef>
>       <load-xml-properties file="${basedir}/p.xml" prefix="temp"/>
>       <echo>appname ${temp.appName}</echo>
> 
> Peter
> >
> > Nik
> >
> > > > ----- Original Message -----
> > > > From: nswoboda@clip.dia.fi.upm.es
> > > > To: user@ant.apache.org
> > > > Subject: Using Java xml properties file with Ant
> > > > Date: Fri, 20 Jul 2007 16:05:19 +0200 (CEST)
> > > >=20
> > > >=20
> > > > We are building a piece of software which has a number of Java
> > > > properties files in xml format (the kind which are read with
> > > > Properties.loadFromXML).  An example:
> > > >=20
> > > > <?xml version=3D"1.0" encoding=3D"UTF-8"?>
> > > > <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
> > > >=20
> > > > <properties>
> > > >    <entry key=3D"appName">Name</entry>
> > > >    <entry key=3D"startBean">Something</entry>
> > > >    <entry key=3D"versionNumber">2.5</entry>
> > > > </properties>
> > > >=20
> > > > I would like to be able to read these files and use their properties from
> > > > within ant.  The property task doesn't seem to handle properties files
> > > > in xml so I have been trying to use the xmlproperty task:
> > > >=20
> > > > <xmlproperty file=3D"temp.properties.xml" prefix=3D"temp" />
> > > >=20
> > > > But then all the values get thrown into the temp.properties.entry
> > > > property:
> > > >=20
> > > > <echo> using Prop=3D${temp.properties.entry} </echo>
> > > >=20
> > > > gives:
> > > >=20
> > > >       [echo]  using Prop=3DName,Something,2.5
> > > >=20
> > > > I assume that this should be trivial but I can't find a good solution
to
> > > > get it to do the obvious thing (load three separate properties).
> > > > Suggestions?
> > > >=20
> > > > Second question, since the Sun dtd specifies SYSTEM (not a publicid),
is
> > > > it possible to use xmlcatalog?
> > > >=20
> > > > Thanks,
> > > >=20
> > > > Nik
> > > > ____________________________________________________
> > > >=20
> > > > Conversation, n.:
> > > >     A vocal competition in which the one who is catching his breath
> > > >     is called the listener.
> > > >=20
> > > > ---------------------------------------------------------------------
> > > > 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
> > >
> > >
> >
> >
> > ____________________________________________________
> >
> > "I am ready to meet my Maker.  Whether my Maker is prepared for the
> > great ordeal of meeting me is another matter."
> >                 -- Winston Churchill
> >
> > ---------------------------------------------------------------------
> > 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
> 
> 


____________________________________________________

Computer, n.:
	An electronic entity which performs sequences of useful steps in a
	totally understandable, rigorously logical manner.  If you believe
	this, see me about a bridge I have for sale in Manhattan.

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


Mime
View raw message