Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 80570 invoked from network); 3 Mar 2002 22:19:20 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 3 Mar 2002 22:19:20 -0000 Received: (qmail 8543 invoked by uid 97); 3 Mar 2002 22:19:20 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 8527 invoked by uid 97); 3 Mar 2002 22:19:20 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 8516 invoked from network); 3 Mar 2002 22:19:19 -0000 Message-ID: <3C833BA4.40902@multitask.com.au> Date: Mon, 04 Mar 2002 20:17:24 +1100 From: dIon Gillard User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8+) Gecko/20020226 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Ant Developers List Subject: [PATCH] XCatalog - Fixed bugs in XCatalog.java References: <3C81B046.7050405@multitask.com.au> X-MIMETrack: Itemize by SMTP Server on gateway/Multitask Consulting/AU(Release 5.0.8 |June 18, 2001) at 03/04/2002 09:26:00 AM, Serialize by Router on gateway/Multitask Consulting/AU(Release 5.0.8 |June 18, 2001) at 03/04/2002 09:26:03 AM, Serialize complete at 03/04/2002 09:26:03 AM Content-Type: multipart/mixed; boundary="------------020001050106000109020301" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N --------------020001050106000109020301 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii; format=flowed Found a bug or two :) in XCatalog during testing. I've started the test cases for it, as well as the XSLTProcess task. Once I get them to a reasonable state, I'll submit those as well. -- dIon Gillard, Multitask Consulting http://adslgateway.multitask.com.au/developers --------------020001050106000109020301 Content-Transfer-Encoding: 7bit Content-Type: text/plain; name="XCatalog.java" Content-Disposition: inline; filename="XCatalog.java" /* * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Ant", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ package org.apache.tools.ant.types; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.IOException; import java.net.URL; import java.util.Iterator; import java.util.Vector; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** * This object represents a path as used by CLASSPATH or PATH * environment variable. *

* * <sometask>
*   <catalog>
*     <dtd publicId="" location="/path/to/file.jar" />
*     <dtd publicId location="/path/to/file2.jar" /gt;
*     <entity publicId="" location="/path/to/file3.jar" />
*     <entity publicId="" location="/path/to/file4.jar" />
*   </catalog>
* </sometask>
*
*

* The object implemention sometask must provide a method called * createCatalog which returns an instance of XCatalog. * Nested dtd and entity definitions are handled by the XCatalog object and * must be labeled dtd and entity respectively.

* *

Possible future extension could allow a catalog file instead of nested * elements, or use Norman Walsh's entity resolver from xml-commons

* * @author dIon Gillard * @version $Id$ */ public class XCatalog extends DataType implements Cloneable, EntityResolver { //-- Fields ---------------------------------------------------------------- /** holds dtd/entity objects until needed */ private Vector elements = new Vector(); //-- Methods --------------------------------------------------------------- /** * @return the elements of the catalog - dtd objects */ private Vector getElements() { return elements; } private void setElements(Vector aVector) { elements = aVector; } private void addElement(DTD aDTD) { getElements().add(aDTD); } // need methods to create DTD and entity elements and add to the map // not sure why I should be coding a add vs create method - I'm choosing // create as the DTD class may not be known(?) by ant. /** * Creates the nested <dtd> element. */ public DTD createDtd() throws BuildException { if (isReference()) { throw noChildrenAllowed(); } DTD dtd = new DTD(); getElements().add(dtd); return dtd; } /** * Creates the nested <entity> element */ public DTD createEntity() throws BuildException { return createDtd(); } /** * Makes this instance in effect a reference to another XCatalog instance. * *

You must not set another attribute or nest elements inside * this element if you make it a reference.

*/ public void setRefid(Reference r) throws BuildException { if (!elements.isEmpty()) { throw tooManyAttributes(); } // change this to get the objects from the other reference Object o = r.getReferencedObject(getProject()); // we only support references to other XCatalogs if (o instanceof XCatalog) { // set all elements from referenced catalog to this one XCatalog catalog = (XCatalog) o; setElements(catalog.getElements()); } else { String msg = r.getRefId()+" doesn\'t refer to an XCatalog"; throw new BuildException(msg); } super.setRefid(r); } public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { InputSource source = null; DTD matchingDTD = findMatchingDTD(publicId); if (matchingDTD != null) { // check if publicId is mapped to a file log("Matching DTD found for publicId: '" + publicId + "' location: '" + matchingDTD.getLocation() + "'", Project.MSG_DEBUG); File dtdFile = new File(matchingDTD.getLocation()); if (dtdFile.exists() && dtdFile.canRead()) { source = new InputSource( new FileInputStream(dtdFile) ); source.setSystemId(dtdFile.toURL().toExternalForm()); log("matched a readable file", Project.MSG_DEBUG); } else { // check if publicId is a resource // FIXME: ClassLoader: should this be context? ClassLoader loader = Thread.currentThread().getContextClassLoader(); InputStream is = loader.getResourceAsStream( matchingDTD.getLocation() ); if (is != null) { source = new InputSource(is); source.setSystemId(loader.getResource( matchingDTD.getLocation()).toExternalForm()); log("matched a resource", Project.MSG_DEBUG); } else { // check if it's a URL try { URL dtdUrl = new URL(matchingDTD.getLocation()); InputStream dtdIs = dtdUrl.openStream(); if (dtdIs != null) { source = new InputSource(dtdIs); source.setSystemId(dtdUrl.toExternalForm()); log("matched as a URL", Project.MSG_DEBUG); } else { log("No match, parser will use: '" + systemId + "'", Project.MSG_DEBUG); } } catch ( IOException ioe) { //ignore } } } } else { log("No match, parser will use: '" + systemId + "'", Project.MSG_DEBUG); } // else let the parser handle it as a URI as we don't know what to // do with it return source; } private DTD findMatchingDTD(String publicId) { Iterator elements = getElements().iterator(); DTD element = null; while (elements.hasNext()) { element = (DTD)elements.next(); if (element.getPublicId().equals(publicId)) { return element; } } return null; } //-- Inner classes --------------------------------------------------------- /** * Helper class to handle the DTD and Entity nested elements * Shamelessly stolen from the EjbJar task and documented * * @author Tim Fennell * @author dIon Gillard */ public static class DTD { /** publicId of the dtd/entity */ private String publicId = null; /** location of the dtd/entity - a file/resource/URL*/ private String location = null; /** * @param publicId uniquely identifies the resource */ public void setPublicId(String publicId) { this.publicId = publicId; } /** * @param location the location of the resource associated with the * publicId */ public void setLocation(String location) { this.location = location; } /** * @return the publicId */ public String getPublicId() { return publicId; } /** * @return the location of the resource identified by the publicId */ public String getLocation() { return location; } } } --------------020001050106000109020301 Content-Type: text/plain; charset=us-ascii -- To unsubscribe, e-mail: For additional commands, e-mail: --------------020001050106000109020301--