Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 211   Methods: 4
NCLOC: 54   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ApacheCatalogResolver.java - 65% 75% 66.7%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 
 55   
 package org.apache.tools.ant.types.resolver;
 56   
 
 57   
 import java.io.IOException;
 58   
 
 59   
 import java.net.MalformedURLException;
 60   
 import java.net.URL;
 61   
 
 62   
 import org.apache.tools.ant.BuildException;
 63   
 
 64   
 import org.apache.tools.ant.types.XMLCatalog;
 65   
 import org.apache.tools.ant.types.ResourceLocation;
 66   
 
 67   
 import org.apache.xml.resolver.Catalog;
 68   
 import org.apache.xml.resolver.CatalogManager;
 69   
 
 70   
 import org.apache.xml.resolver.tools.CatalogResolver;
 71   
 
 72   
 /**
 73   
  * <p>This class extends the CatalogResolver class provided by Norman
 74   
  * Walsh's resolver library in xml-commons.  It provides the bridge
 75   
  * between the Ant XMLCatalog datatype and the xml-commons Catalog
 76   
  * class.  XMLCatalog calls methods in this class using Reflection in
 77   
  * order to avoid requiring the xml-commons resolver library in the
 78   
  * path.</p>
 79   
  * 
 80   
  * <p>The {@link org.apache.tools.ant.types.resolver.ApacheCatalog
 81   
  * ApacheCatalog} class is used to parse external catalog files, which
 82   
  * can be in either <a
 83   
  * href="http://oasis-open.org/committees/entity/background/9401.html">
 84   
  * plain text format</a> or <a
 85   
  * href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html">
 86   
  * XML format</a>.</p>
 87   
  * 
 88   
  * <p>For each entry found in an external catalog file, if any, an
 89   
  * instance of {@link org.apache.tools.ant.types.ResourceLocation
 90   
  * ResourceLocation} is created and added to the controlling
 91   
  * XMLCatalog datatype.  In this way, these entries will be included
 92   
  * in XMLCatalog's lookup algorithm.  See XMLCatalog.java for more
 93   
  * details.</p>
 94   
  *
 95   
  * @see org.apache.tools.ant.types.XMLCatalog.CatalogResolver
 96   
  * @see org.apache.xml.resolver.CatalogManager
 97   
  * @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
 98   
  * @version $Id: ApacheCatalogResolver.java,v 1.6 2003/02/10 14:14:34 bodewig Exp $
 99   
  * @since Ant 1.6
 100   
  */
 101   
 
 102   
 public class ApacheCatalogResolver extends CatalogResolver {
 103   
 
 104   
     /** The XMLCatalog object to callback. */
 105   
     private XMLCatalog xmlCatalog = null;
 106   
     
 107   
     static
 108   
     {
 109   
         //
 110   
         // If you don't do this, you get all sorts of annoying
 111   
         // warnings about a missing properties file.  However, it
 112   
         // seems to work just fine with default values.  Ultimately,
 113   
         // we should probably include a "CatalogManager.properties"
 114   
         // file in the ant jarfile with some default property
 115   
         // settings.  See CatalogManager.java for more details.
 116   
         //
 117  1
         CatalogManager.getStaticManager().setIgnoreMissingProperties(true);
 118   
 
 119   
         //
 120   
         // Make sure CatalogResolver instantiates ApacheCatalog,
 121   
         // rather than a plain Catalog
 122   
         //
 123  1
         System.getProperties().put("xml.catalog.className",
 124   
                                    ApacheCatalog.class.getName());
 125   
 
 126  1
         CatalogManager.getStaticManager().setUseStaticCatalog(false);
 127   
 
 128   
         // debug
 129   
         // System.setProperty("xml.catalog.verbosity", "4");
 130   
     }
 131   
 
 132   
     /** Set the XMLCatalog object to callback. */
 133  22
     public void setXMLCatalog(XMLCatalog xmlCatalog) {
 134  22
         this.xmlCatalog = xmlCatalog;
 135   
     }
 136   
 
 137   
     /** 
 138   
      * XMLCatalog calls this to add an external catalog file for each
 139   
      * file within a <code>&lt;catalogfiles&gt;</code> fileset.
 140   
      */
 141  4
     public void parseCatalog(String file) {
 142   
 
 143  4
         ApacheCatalog catalog = (ApacheCatalog)getCatalog();
 144   
 
 145   
         // Pass in reference to ourselves so we can be called back.
 146  4
         catalog.setResolver(this);
 147   
 
 148  4
         try {
 149  4
             catalog.parseCatalog(file);
 150   
         }
 151   
         catch(MalformedURLException ex) {
 152  0
             throw new BuildException(ex);
 153   
         }
 154   
         catch(IOException ex) {
 155  0
             throw new BuildException(ex);
 156   
         }
 157   
     }
 158   
 
 159   
     /**
 160   
      * <p>Add a PUBLIC catalog entry to the controlling XMLCatalog instance.
 161   
      * ApacheCatalog calls this for each PUBLIC entry found in an external
 162   
      * catalog file.</p>
 163   
      *
 164   
      * @param publicid The public ID of the resource
 165   
      * @param systemid The system ID (aka location) of the resource
 166   
      * @param base The base URL of the resource.  If the systemid
 167   
      * specifies a relative URL/pathname, it is resolved using the
 168   
      * base.  The default base for an external catalog file is the
 169   
      * directory in which the catalog is located.
 170   
      * 
 171   
      */
 172  4
     public void addPublicEntry(String publicid, 
 173   
                                String systemid,
 174   
                                URL base) {
 175   
 
 176  4
         ResourceLocation dtd = new ResourceLocation();
 177  4
         dtd.setBase(base);
 178  4
         dtd.setPublicId(publicid);
 179  4
         dtd.setLocation(systemid);
 180   
         
 181  4
         xmlCatalog.addDTD(dtd);
 182   
     }
 183   
 
 184   
     /**
 185   
      * <p>Add a URI catalog entry to the controlling XMLCatalog instance.
 186   
      * ApacheCatalog calls this for each URI entry found in an external
 187   
      * catalog file.</p>
 188   
      *
 189   
      * @param URI The URI of the resource
 190   
      * @param altURI The URI to which the resource should be mapped
 191   
      * (aka the location)
 192   
      * @param base The base URL of the resource.  If the altURI
 193   
      * specifies a relative URL/pathname, it is resolved using the
 194   
      * base.  The default base for an external catalog file is the
 195   
      * directory in which the catalog is located.
 196   
      * 
 197   
      */
 198  0
     public void addURIEntry(String uri, 
 199   
                             String altURI,
 200   
                             URL base) {
 201   
 
 202  0
         ResourceLocation entity = new ResourceLocation();
 203  0
         entity.setBase(base);
 204  0
         entity.setPublicId(uri);
 205  0
         entity.setLocation(altURI);
 206   
         
 207  0
         xmlCatalog.addEntity(entity);
 208   
     }
 209   
 
 210   
 } //-- ApacheCatalogResolver
 211