>>>>> "Al" == Al Tingley <[EMAIL PROTECTED]> writes:
Al> Hello, Al> We are trying to automate the pre-compilation of our JSP files with JspC and Al> the inclusion of the generated "webinc.xml" file in our application Al> "web.xml" file. We have constructed an application web.xml as shown below. Al> Both "web.xml" and "webinc.xml" are local to the Al> .../webapps/<application>/WEB-INF/ directory. Al> Our problem is that Tomcat complains when starting up with the message: Al> org.xml.sax.SAXParseException: Relative URI "webinc.xml"; can not Al> be resolved without a base URI. Al> Note the local reference to "webinc.xml" below in the DOCTYPE tag. I got the complete precompilation process to work, but I gave up on trying to reference the include file with an entity reference. It just doesn't work. What I was able to do was write an XSLT stylesheet that takes the main "web.xml" and the generated include file and generates a new "web.xml" that incorporates both files. It uses the Ant "style" task to do the transformation. A slight wrinkle is that the generated include file is not a fully "well-formed" XML file, in that it doesn't have a "root" element. So, in order for the XML parser (used by Ant) to grok it, I had to write a simple well-formed wrapper that references the include file with an entity reference. It's ironic that I'm using the same mechanism in this process that I gave up with using inside of Tomcat. I'll show all the pieces of my solution here. This is the excerpt from my "build-war" Ant target related to this: ------------------------- <delete dir="jspc"/> <mkdir dir="jspc"/> <java classname="org.apache.jasper.JspC" fork="yes"> <arg line="-v -d jspc -p org.apache.jsp -uriroot build -webinc web-inf/webinc.xml -webapp build "/> <classpath> <pathelement location="${catalina.home}/common/lib/jasper-compiler.jar"/> <pathelement location="${catalina.home}/common/lib/jasper-runtime.jar"/> <pathelement location="weblib/servlet.jar"/> </classpath> </java> <!-- Here, run a "style" task to merge the two "web.xml" pieces. --> <style basedir="build/WEB-INF" in="web-inf/web.xml" out="build/WEB-INF/web2.xml" style="web-inf/webmerge.xsl"> <param name="includeFile" expression="includeWrapper.xml"/> </style> <move file="build/WEB-INF/web2.xml" tofile="build/WEB-INF/web.xml"/> <javac srcdir="jspc" destdir="classes" debug="on" optimize="off" deprecation="on"> <classpath> <pathelement location="${catalina.home}/common/lib/jasper-compiler.jar"/> <pathelement location="${catalina.home}/common/lib/jasper-runtime.jar"/> <fileset dir="weblib"> <include name="*.jar"/> </fileset> </classpath> <include name="**/*.java"/> </javac> <copy todir="build/WEB-INF/classes"> <fileset dir="webprops"> <include name="**/*.properties"/> </fileset> <fileset dir="classes"> <include name="com/intsoft/strutstest/**/*.class"/> <include name="org/apache/jsp/**/*.class"/> </fileset> </copy> <jar jarfile="deploy/strutstest.war"> <fileset dir="build"> <include name="**"/> <exclude name="*.jsp"/> </fileset> </jar> ------------------------- Following this is the "includeWrapper.xml" file, which references the generated include file. Note that I have to reference a path of "web-inf/webinc.xml", which is the path to the generated file in my build tree (not my deploy tree). I'm using Ant 1.4. In Ant 1.5.1, there is apparently some new features in the "style" task that allow the specification of an alternate EntityResolver that would allow me to avoid hardcoding the name of the directory the file is in. ------------------------- <?xml version="1.0"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" [ <!ENTITY webinc PUBLIC "webinc" "file:web-inf/webinc.xml"> ] > <web-app> &webinc; </web-app> ------------------------- And finally, here is the stylesheet (webmerge.xsl) that does the transformation: ------------------------- <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- This takes a parameter indicating the name of the secondary file to merge in. When we've matched the "web-app" element, we will first insert the "servlet" elements of the include file, then the "servlet" elements of the main file, then the "servlet-mapping" elements of the include file, then the "servlet-mapping" elements of the main file, and then all the remaining elements of the main file (which will be specified explicitly by element type. --> <xsl:output method="xml" indent="yes" doctype-public="-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" doctype-system="http://java.sun.com/dtd/web-app_2_3.dtd"/> <xsl:param name="includeFile"/> <!-- get the required elements of "web-app", in their defined order, according to the DTD. --> <xsl:template match="/web-app"> <web-app> <xsl:apply-templates select="icon"/> <xsl:apply-templates select="display-name"/> <xsl:apply-templates select="description"/> <xsl:apply-templates select="distributable"/> <xsl:apply-templates select="context-param"/> <xsl:apply-templates select="filter"/> <xsl:apply-templates select="filter-mapping"/> <xsl:apply-templates select="listener"/> <xsl:apply-templates select="servlet"/> <xsl:copy-of select="document($includeFile)/web-app/servlet"/> <xsl:apply-templates select="servlet-mapping"/> <xsl:copy-of select="document($includeFile)/web-app/servlet-mapping"/> <xsl:apply-templates select="session-config"/> <xsl:apply-templates select="mime-mapping"/> <xsl:apply-templates select="welcome-file-list"/> <xsl:apply-templates select="error-page"/> <xsl:apply-templates select="taglib"/> <xsl:apply-templates select="resource-env-ref"/> <xsl:apply-templates select="resource-ref"/> <xsl:apply-templates select="security-constraint"/> <xsl:apply-templates select="login-config"/> <xsl:apply-templates select="security-role"/> <xsl:apply-templates select="env-entry"/> <xsl:apply-templates select="ejb-ref"/> <xsl:apply-templates select="ejb-local-ref"/> </web-app> </xsl:template> <xsl:template match="*"> <xsl:for-each select="@*"> <xsl:attribute name="{.}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:for-each> <xsl:copy-of select="."/> </xsl:template> </xsl:stylesheet> ------------------------- -- =================================================================== David M. Karr ; Java/J2EE/XML/Unix/C++ [EMAIL PROTECTED] -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>