Ant xmlvalidate cvc-elt.1.a: Cannot find the declaration of element 'topic' - ant

I've made an xsd that represent a restriction of docbook topic. Here is a basic xml example of that. The restriction should be valid within docbook namespace.
<?xml version="1.0" encoding="UTF-8"?>
<topic
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://docbook.org/ns/docbook"
xmlns:math="http://www.w3.org/2005/xpath-functions/math"
xml:id="TT_LONDON002-003CONTEN" role="imprint">
<title>title</title>
</topic>
The top of the xsd restriction looks like the following. In oxygen the xml validates nicely.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified"
targetNamespace="http://docbook.org/ns/docbook"
xmlns:docbook="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink">
<xs:import namespace="http://www.w3.org/1999/xlink"
schemaLocation="xlink.xsd"/>
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="xml.xsd"/>
<xs:element name="topic">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0"
maxOccurs="unbounded"
ref="docbook:title"/>
<xs:choice>
<xs:element ref="docbook:mediaobject"/>
<xs:element minOccurs="0"
maxOccurs="unbounded"
ref="docbook:para"/>
</xs:choice>
</xs:sequence>
However I'm trying to write the following ant script to validate a whole directory.
I get error output: cvc-elt.1.a: Cannot find the declaration of element 'topic'.
I've been searching online but can't find the solution.
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="dist" name="ANTProject">
<target name="dist">
<property name="xmlDir" value="../xml/"/>
<pathconvert dirsep="/" property="xsd.file">
<path>
<pathelement location="../xsd/topic.xsd"/>
</path>
</pathconvert>
<xmlvalidate lenient="true"
failonerror="false"
warn="true"
classname="org.apache.xerces.parsers.SAXParser"
classpath="../../lib/xercesImpl.jar">
<fileset dir="${xmlDir}" includes="**/*.xml"/>
<attribute name="http://xml.org/sax/features/validation"
value="true"/>
<attribute name="http://xml.org/sax/features/namespaces"
value="true"/>
<attribute name="http://apache.org/xml/features/validation/schema"
value="true"/>
<property name="http://apache.org/xml/properties/schema/external-schemaLocation"
value="${xsd.file}"/>
</xmlvalidate>
</target>
</project>
Any ideas?
Thanks
Conteh

Related

gsoap error : :ClientValidation constraint violation: invalid value in element

Whenever I try to execute a service getContractHdr using online test tools like :
http://www.soapclient.com/soaptest.html
I get the error listed below. The type (of inTENANTREFNO ) is an INTEGER. Even when I place something like 33 in for the field inTENANTREFNO, I still get the error of "type mismatch". Additionally, the message states that the variable inTENANTREFNO is associated with the namespace of am but I do not see why gsoap is making this assignment.
Question
How can I fix this so that I no longer get the error? Is there a way to
configure this so that the namespaces are not used at all? Why am I
getting
it in the first place? I have seen this message here but it is not clear
as to whether or not implementing this would resolve the problem in
this case
Note: All works fine whenever I use the sample generated .xml files. I fill out the fields of course.The service runs and I get data (correct) back. I execute it with "ServerName < testfile.xml"
When I attempt to execute the service from one of the online testing areas (as mentioned above). It does not work citing a "type mismatch".
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns="urn:conmony">
<SOAP-ENV:Body>
<ns:getContractHdr>
<ns:inLogonID></ns:inLogonID>
<ns:inLogonPassword></ns:inLogonPassword>
<ns:inTENANTREFNO>0</ns:inTENANTREFNO>
<ns:incallhost></ns:incallhost>
<ns:incallpid>0</ns:incallpid>
<ns:incallfilename></ns:incallfilename>
<ns:incalllineno>0</ns:incalllineno>
</ns:getContractHdr>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Error message
SOAP-ENV:ClientValidation constraint violation: invalid value in
element 'am:inTENANTREFNO'
Error Message With SOAP Fault
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:am="urn:conmony" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Validation constraint violation: invalid value in element 'am:inTENANTREFNO'</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Ran soapcpp2 -c -n -pdukmony - AND - soapcpp2 -c on a file with the contents below
//gsoap am service name: conmony
//gsoap am service style: document
//gsoap am service encoding: literal
//gsoap am service location: http://99.33.23.2232:8075
//gsoap am schema namespace: urn:conmony
typedef char *xsd__string;
typedef char *xsd__anyURI;
typedef float xsd__float;
typedef long xsd__int;
typedef double xsd__double;
typedef unsigned long long xsd__positiveInteger;
typedef struct am__struct_DBCONTRACTHDR{
xsd__int TENANTREFNO;
xsd__string FirstName;
xsd__string MiddleName;
xsd__string LastName;
xsd__string EMail;
xsd__string CellPhoneNo;
xsd__string HomePhoneNo;
xsd__string AsgnLogonID;
xsd__string WebPicLocation;
xsd__int ReturnCode;
xsd__double KeyID;
xsd__string Message; };
typedef struct am__CONTRACTHDRItems {
struct am__struct_DBCONTRACTHDR *__ptr;
int __size;
int __offset; };
inTENANTREFNO
int am__getContractHdr(
xsd__int inTENANTREFNO,
xsd__string inLogonID,
xsd__string inLogonPassword,
xsd__string incallhost,
xsd__int incallpid,
xsd__string incallfilename,
xsd__int incalllineno,
struct am__CONTRACTHDRItems *DBListing);
The result is the conmony.wsdl file
<definitions xmlns:tns="urn:conmony/conmony.wsdl" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:am="urn:conmony" xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:HTTP="http://schemas.xmlsoap.org/wsdl/http/" xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/" xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" name="conmony" targetNamespace="urn:conmony/conmony.wsdl">
<types>
<schema xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:am="urn:conmony" xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:conmony" elementFormDefault="qualified" attributeFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="struct-DBCONTRACTHDR">
<!-- am__struct_DBCONTRACTHDR -->
<sequence>
<element name="TENANTREFNO" type="xsd:int" minOccurs="1" maxOccurs="1"/>
<!-- am__struct_DBCONTRACTHDR::TENANTREFNO -->
<element name="FirstName" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__struct_DBCONTRACTHDR::FirstName -->
<element name="MiddleName" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__struct_DBCONTRACTHDR::MiddleName -->
<element name="LastName" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__struct_DBCONTRACTHDR::LastName -->
<element name="EMail" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__struct_DBCONTRACTHDR::EMail -->
<element name="CellPhoneNo" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__struct_DBCONTRACTHDR::CellPhoneNo -->
<element name="HomePhoneNo" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__struct_DBCONTRACTHDR::HomePhoneNo -->
<element name="AsgnLogonID" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__struct_DBCONTRACTHDR::AsgnLogonID -->
<element name="WebPicLocation" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__struct_DBCONTRACTHDR::WebPicLocation -->
<element name="ReturnCode" type="xsd:int" minOccurs="1" maxOccurs="1"/>
<!-- am__struct_DBCONTRACTHDR::ReturnCode -->
<element name="KeyID" type="xsd:double" minOccurs="1" maxOccurs="1"/>
<!-- am__struct_DBCONTRACTHDR::KeyID -->
<element name="Message" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__struct_DBCONTRACTHDR::Message -->
</sequence>
</complexType>
<complexType name="CONTRACTHDRItems">
<!-- am__CONTRACTHDRItems -->
<sequence>
<element name="item" type="am:struct-DBCONTRACTHDR" minOccurs="0" maxOccurs="unbounded" nillable="false"/>
</sequence>
</complexType>
<!-- operation request element -->
<element name="getContractHdr">
<complexType>
<sequence>
<element name="inTENANTREFNO" type="xsd:int" minOccurs="1" maxOccurs="1"/>
<!-- am__getContractHdr::inTENANTREFNO -->
<element name="inLogonID" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__getContractHdr::inLogonID -->
<element name="inLogonPassword" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__getContractHdr::inLogonPassword -->
<element name="incallhost" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__getContractHdr::incallhost -->
<element name="incallpid" type="xsd:int" minOccurs="1" maxOccurs="1"/>
<!-- am__getContractHdr::incallpid -->
<element name="incallfilename" type="xsd:string" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__getContractHdr::incallfilename -->
<element name="incalllineno" type="xsd:int" minOccurs="1" maxOccurs="1"/>
<!-- am__getContractHdr::incalllineno -->
</sequence>
</complexType>
</element>
<!-- operation response element -->
<element name="getContractHdrResponse">
<complexType>
<sequence>
<element name="DBListing" type="am:CONTRACTHDRItems" minOccurs="0" maxOccurs="1" nillable="true"/>
<!-- am__getContractHdr::DBListing -->
</sequence>
</complexType>
</element>
</schema>
</types>
<message name="getContractHdrRequest">
<part name="Body" element="am:getContractHdr"/>
<!-- am__getContractHdr::am__getContractHdr -->
</message>
<message name="getContractHdrResponse">
<part name="Body" element="am:getContractHdrResponse"/>
</message>
<portType name="conmonyPortType">
<operation name="getContractHdr">
<documentation>Service definition of function am__getContractHdr</documentation>
<input message="tns:getContractHdrRequest"/>
<output message="tns:getContractHdrResponse"/>
</operation>
</portType>
<binding name="conmony" type="tns:conmonyPortType">
<SOAP:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getContractHdr">
<SOAP:operation soapAction=""/>
<input>
<SOAP:body parts="Body" use="literal"/>
</input>
<output>
<SOAP:body parts="Body" use="literal"/>
</output>
</operation>
</binding>
<service name="conmony">
<documentation>gSOAP 2.8.26 generated service definition</documentation>
<port name="conmony" binding="tns:conmony">
<SOAP:address location="http://99.33.23.2232:8075"/>
</port>
</service>
</definitions>
UPDATE:
Changed header portion of file that soapcpp2 is ran upon to:
//gsoap ns service name: conmony Special SOAP SErvices
//gsoap ns service protocol: SOAP
//gsoap ns service style: document
//gsoap ns service encoding: literal
//gsoap ns service namespace: http://99.33.23.2232:8075?conmony.wsdl
//gsoap ns service location: http://99.33.23.2232:8075
//gsoap ns schema namespace: urn:conmony
and still got the same issue
But still getting data when filling out the sample req.xml files generated
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="urn:conmony"><SOAP-ENV:Body><ns:getContractHdrResponse><ns:DBListing><ns:item><ns:TENANTREFNO>8288</ns:TENANTREFNO><ns:FirstName>Test</ns:FirstName><ns:MiddleName></ns:MiddleName><ns:LastName>Last</ns:LastName><ns:EMail>testing#last.com</ns:EMail><ns:CellPhoneNo>210-444-2212</ns:CellPhoneNo><ns:HomePhoneNo>210-444-2212</ns:HomePhoneNo><ns:AsgnLogonID>w10testing</ns:AsgnLogonID><ns:WebPicLocation>stuff</ns:WebPicLocation><ns:ReturnCode>0</ns:ReturnCode><ns:KeyID>0.000000</ns:KeyID><ns:Message> testing ...</ns:Message></ns:item></ns:DBListing></ns:getContractHdrResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Everything in the ".h file" and ".c" file was changed so that it used "ns" namespace and not the "am" namespace

WSO2 API Manager 2.0.0- Receive GET request and send POST to backend

I've created an RESTful API in wso2-am 2.0.0. But I'm face a problem and a would some help.
I have a resource wiht GET http method which receive an url param and I made a SOAP payload to send via POST to backend (backend is soap11).
For this, I used a custom 'in' sequence:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="JSONtoSOAP" trace="disable"
xmlns="http://ws.apache.org/ns/synapse">
<log description="Entrada" level="full" separator=",">
<property expression="get-property('uri.var.cpfCnpj')" name="cpfcnpj" />
<property name="trace"
value="IN LOG" />
</log>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING" />
<property name="messageType" scope="axis2" type="STRING"
value="application/soap+xml" />
<enrich>
<source type="inline">
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body />
</soap:Envelope>
</source>
<target action="replace" type="envelope" />
</enrich>
<payloadFactory media-type="xml">
<format>
<man:QueryCustomerDetailsRequestMessage
xmlns:man="http://www.algartelecom.com.br/SOA/Service/ManageCustomerInformationPortalClientesReqCS">
<man:documentNumber>$1</man:documentNumber>
<man:tagetCRM />
</man:QueryCustomerDetailsRequestMessage>
</format>
<args>
<arg evaluator="xml" expression="get-property('uri.var.cpfCnpj')" />
</args>
</payloadFactory>
<property name="REST_URL_POSTFIX" value="" scope="axis2" />
<header name="Action" scope="default" value="queryCustomerDetails" />
<log description="Saida" level="full" separator=",">
<property name="trace" value="DEBUG LOG" />
</log>
</sequence>
Until here, without problem.
But when I try to call the resource from any restClient (SOAPui for example or wso2-am store) result in Runtime exception, like this:
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<am:fault xmlns:am="http://wso2.org/apimanager">
<am:code/>
<am:type>Status report</am:type>
<am:message>Runtime Error</am:message>
<am:description/>
</am:fault>
</soap:Body>
</soap:Envelope>
Note that code and description tags are empty, and when I checked the server's log I found:
[2016-09-30 16:53:44,603] INFO - LogMediator STATUS = Executing default 'fault' sequence, ERROR_CODE = null, ERROR_MESSAGE = null
This is the correct way to produces a restful API and call a SOAP backend?
Anybody knows about this issue? (I believe, this feature works on WSO2 ESB).
You can try the following:
In the publisher, set your endpoint type to HTTP/SOAP endpoint
In your sequence don't set the REST_URL_POSTFIX to "", but remove the property completely

How to regenrate java classes from xjc ant while xsd's are up to date

If xsd are up to date , then xjc are not generating the class.
I want classes always to be generated..
<target name="jaxbSource" description="Generate jaxb objects">
<echo message="Generate jaxb objects for CategoryAPIRequest..." />
<xjc source="2.0" schema="${basedir}/schemas/categoryAPI/CategoryAPIRequest.xsd" package="com.myrio.tm.company.categories.util.request"
destdir="${basedir}/src" binding="${basedir}/schemas/categoryAPI/binding.xml">
<produces dir="${basedir}/src" includes="**/*.java" />
<arg value="-extension" />
</xjc>
<echo message="Generate jaxb objects for CategoryAPIReturn..." />
<xjc source="2.0" schema="${basedir}/schemas/categoryAPI/CategoryAPIReturn.xsd" package="com.myrio.tm.company.categories.util.response"
destdir="${basedir}/src" binding="${basedir}/schemas/categoryAPI/binding.xml">
<produces dir="${basedir}/src" includes="**/*.java" />
<arg value="-extension" />
</xjc>
</target>
-- My Binding xml is :
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:version="2.1">
<jaxb:globalBindings>
<xjc:serializable/>
</jaxb:globalBindings>
</jaxb:bindings>

maven-antrun-plugin generating emty ddl file

I would like to generate schema sql script with maven.
Here is my persistance file :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="mypersistance"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"></property>
<property name="hibernate.archive.autodetection" value="class"></property>
</properties>
<description>Persistance descriptor</description>
<class>test.sofiane.beans.Code</class>
</persistence-unit>
</persistence>
hibernate configuration file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="mySessionFactory">
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/test</property>
<property name="hibernate.connection.username">postgres</property>
<property name="hibernate.default_schema">public</property>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
</session-factory>
</hibernate-configuration>
plugin in the pom
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<!-- Hibernatetool will generate everything before running tests -->
<phase>compile</phase>
<configuration>
<target>
<echo message="Ant target, through maven-antrun-plugin, started" />
<property name="maven_compile_classpath" refid="maven.compile.classpath" />
<property name="maven_test_classpath" refid="maven.test.classpath" />
<path id="hibernatetool.path">
<pathelement path="${maven_compile_classpath}" />
<pathelement path="${maven_test_classpath}" />
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="hibernatetool.path" />
<property name="generatedByHibernate.outputDirectory"
value="${project.build.directory}/generated/hibernatetool" />
<mkdir dir="${generatedByHibernate.outputDirectory}" />
<hibernatetool destdir="${generatedByHibernate.outputDirectory}">
<classpath>
<path location="${project.build.directory}/classes/test/sofiane/beans" />
</classpath>
<configuration
configurationfile="${project.build.directory}/classes/hibernate.cfg.xml" />
<hbm2ddl export="true" drop="true" create="true"
outputfilename="helloworld.ddl" format="true" />
</hibernatetool>
<echo message="Ant target, through maven-antrun-plugin, terminated" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The pom works fine and generate helloworld.ddl but empty unfortunately !
Any idea please ?
My first advice is that you should better use the hibernate3-maven-plugin instead of the maven-antrun-plugin because it includes everything that you need and is a lot more simple to use than all the configuration that you had to write with the maven-antrun-plugin (see here for more information about the hibernate3-maven-plugin).
And then, to fix your problem, I think that you can find the answer to your problem in this post and in the answer because it seems that all the elements given will lead you to make your configuration work good.
And don't forget to bind the run of the hibernate3-maven-plugin after the compile phase, on the process-classes phase for example (see Lifecycle Reference) and then just run mvn process-classes.

how to replace all matches with ant script

How can i replace all matching lines? I wanna replace all matching lines in *xml file.
Script snippet which is below just only replace one line
Thanks in advance.
brgds
<?xml version="1.0" encoding="windows-1252" ?>
<project default="init" basedir=".">
<property file="build.properties"/>
<target name="init">
<tstamp/>
<loadfile property="jndiurl"
srcfile="${src.model}/META-INF/persistence.xml">
<filterchain>
<linecontains>
<contains value="hibernate.jndi.url"></contains>
</linecontains>
</filterchain>
</loadfile>
<replace file="${src.model}/META-INF/persistence.xml" token="${jndiurl}"
value="${hibernate.jndi.url.live}${line.separator}"/>
<echo>${hibernate.jndi.url.live}</echo>
<loadfile property="providerurl"
srcfile="${src.structure}/com/arsivist/structure/connection.properties">
<filterchain>
<linecontains>
<contains value="providerurl"></contains>
</linecontains>
</filterchain>
</loadfile>
<replace file="${src.structure}/com/arsivist/structure/connection.properties"
token="${providerurl}"
value="${providerurl.live}${line.separator}"/>
<echo>${providerurl.live}</echo>
<loadfile property="ucmusername"
srcfile="${src.roketsanutil}/com/arsivist/util/ucmConnection.properties">
<filterchain>
<linecontains>
<contains value="username"></contains>
</linecontains>
</filterchain>
</target>
</project>
Instead of trying to edit files in place, wouldn't it be simpler to use the copy task as a templating system, it supports a filterset which can be used to substitute production values.
Example
.
├── build.xml
└── src
└── resources
└── persistence.xml
build.xml
<project name="demo" default="template">
<target name="template">
<copy todir="build/META-INF">
<fileset dir="src/resources" includes="*.xml"/>
<filterset>
<filter token="HIBERNATE.HBM2DDL.AUTO" value="create-drop"/>
</filterset>
</copy>
</target>
<target name="clean">
<delete dir="build"/>
</target>
</project>
persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="sample">
<jta-data-source>java:/DefaultDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="#HIBERNATE.HBM2DDL.AUTO#"/>
</properties>
</persistence-unit>
</persistence>
That snippet works for me:
<?xml version="1.0" encoding="windows-1252" ?>
<project default="init" basedir=".">
<property file="build.properties"/>
<target name="init">
<tstamp/>
<loadfile property="jndiurl"
srcfile="${src.model}/META-INF/persistence.xml">
<filterchain>
<linecontains>
<contains value="hibernate.jndi.url"></contains>
</linecontains>
<headfilter lines="1"/>
</filterchain>
</loadfile>
<echo>${jndiurl}</echo>
<replace file="${src.model}/META-INF/persistence.xml" token="${jndiurl}"
value="${hibernate.jndi.url.live}${line.separator}"/>
<echo>${hibernate.jndi.url.live}</echo>
</project>

Resources