ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steffen Schluff" <schl...@oio.de>
Subject AW: Merging XML files
Date Fri, 22 Aug 2003 08:10:37 GMT
Hello Will,

we did something similar once and even though XSLT is quite elegant it might
IMHO be a bit of overkill here (depending on what you want to do that is).

Here is the ANT code snipplet that we used to generate the XML filed to be
included into the final web.xml:

-------------------------------------------------------
<target name="jspc" depends="prepare">
    <taskdef classname="org.apache.jasper.JspC" name="jasper2" >
        <classpath refid="compile.classpath"/>
    </taskdef>
    <jasper2 validateXml="true"
            uriroot="${precompile-jsp.dir}"
            webXmlFragment="${build.precompile-jsp.webxml}"
            outputDir="${build.precompile-jsp.src}" />
</target>
-------------------------------------------------------

This created something like this:

-------------------------------------------------------
<!--
Automatically created by Tomcat JspC.
Place this fragement in the web.xml before all icon, display-name,
description, distributable, and context-param elements.
-->

	<servlet>
		<servlet-name>counter1_jsp</servlet-name>
		<servlet-class>counter1_jsp</servlet-class>
	</servlet>

...

	<servlet-mapping>
		<servlet-name>xmlJSP_jsp</servlet-name>
		<url-pattern>/xmlJSP.jsp</url-pattern>
	</servlet-mapping>

<!--
All session-config, mime-mapping, welcome-file-list, error-page, taglib,
resource-ref, security-constraint, login-config, security-role,
env-entry, and ejb-ref elements should follow this fragment.
-->
-------------------------------------------------------

Our original web.xml contained a token to be replaced with the just created
web.xml fragment and looked something like this:

-------------------------------------------------------
<web-app>

	<servlet>
		<servlet-name>HelloServlet</servlet-name>
		<servlet-class>de.oio.jserv.HelloServlet</servlet-class>
	</servlet>

	<!-- Jasper generated web.xml will go here -->
	@generated-web-xml-token@
	<!-- Jasper generated web.xml will go here -->

	<servlet-mapping>
		<servlet-name>HelloServlet</servlet-name>
		<url-pattern>/hello</url-pattern>
	</servlet-mapping>
</web-app>
-------------------------------------------------------

All that remained was to force Ant to replace this token with the respective
fragment which we did like this:

-------------------------------------------------------
<!-- Merge the Jasper generated web.xml with the user created one -->
<loadfile property="generated-web-xml"
srcFile="${build.precompile-jsp.webxml}" />
<copy file="${webinf.dir}/web.xml" todir="${build.precompile-jsp.metadata}">
	<filterset>
		<filter token="generated-web-xml-token" value="${generated-web-xml}"/>
	</filterset>
</copy>
-------------------------------------------------------

I admit not as elegant as using XSLT but sufficient for that kind of thing
:-)

Best regards

Steffen Schluff
Orientation in Objects GmbH
http://www.oio.de


-----Urspr√ľngliche Nachricht-----
Von: Will Hartung [mailto:willh@msoft.com]
Gesendet: Donnerstag, 21. August 2003 20:24
An: ant-user@jakarta.apache.org
Betreff: Merging XML files


Hi all, I'm kind of looking for a leg up here.

We have a Tomcat application and it has a generic, hand made web.xml file.

Tomcat has a facility to precompile its JSPs (using JSPC), and part of this
process is to create a new web.xml file that contains all of the servlet
mappings.

However, what it does NOT do is integrate this new web.xml with the one
already contained in the webapp.

So, I'm looking for pointers on a simple way to merge the JSPC generated
web.xml with the hand made web.xml.

I'm sure this can be done with a variety of methods (notably XSL, and
perhaps an ant task), but I'm completely unfamiliar with these methods. All
my previous attempts at using XSLT have been basic miserable disasters (I
haven't quite grokked it).

I was hoping someone had a more concrete suggestion with perhaps some
example code, rather than just "use XXX" and some theory. XSLT would be
peachy if I had the actual XSLT code to use.

At this point it would probably be faster for me to simply write a Java
class that merged the two files, but I was kind of hoping for something a
wee bit more elegant. I'm aware that I can use something like <ENTITY> with
the XML files themselves, used much like an include, but I would still have
to break the JSPC file apart into the 2 chunks that I need out of it before
that would be usable, and if I have to do that, I may as well merge the
whole thing anyway.

I'd like to know more of the deeper workings of these tools so I could
actually work this out on my own, but there's time pressure, and my previous
frustrations, so I can't really walk that path right now.

Thanx for any help.

Regards,

Will Hartung
(willh@msoft.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


Mime
View raw message