Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 159   Methods: 3
NCLOC: 41   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ApacheCatalog.java 25% 44.4% 66.7% 41.4%
 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 org.apache.xml.resolver.Catalog;
 58   
 import org.apache.xml.resolver.CatalogEntry;
 59   
 
 60   
 import org.apache.xml.resolver.helpers.Debug;
 61   
 import org.apache.xml.resolver.helpers.PublicId;
 62   
 
 63   
 /**
 64   
  * This class extends the Catalog class provided by Norman Walsh's
 65   
  * resolver library in xml-commons in order to add classpath entity
 66   
  * and URI resolution.  Since XMLCatalog already does classpath
 67   
  * resolution, we simply add all CatalogEntry instances back to the
 68   
  * controlling XMLCatalog instance.  This is done via a callback
 69   
  * mechanism.  ApacheCatalog is <em>only</em> used for external
 70   
  * catalog files.  Inline entries (currently <code>&lt;dtd&gt;</code>
 71   
  * and <code>&lt;entity&gt;</code>) are not added to ApacheCatalog.
 72   
  * See XMLCatalog.java for the details of the entity and URI
 73   
  * resolution algorithms.
 74   
  *
 75   
  * @see org.apache.tools.ant.types.XMLCatalog.CatalogResolver
 76   
  * @author <a href="mailto:cstrong@arielpartners.com">Craeg Strong</a>
 77   
  * @version $Id: ApacheCatalog.java,v 1.5 2003/02/10 14:14:34 bodewig Exp $
 78   
  * @since Ant 1.6
 79   
  */
 80   
 public class ApacheCatalog extends Catalog {
 81   
 
 82   
     /** The resolver object to callback. */
 83   
     private ApacheCatalogResolver resolver = null;
 84   
 
 85   
     /**
 86   
      * <p>Create a new ApacheCatalog instance.</p>
 87   
      *
 88   
      * <p>This method overrides the superclass method of the same name
 89   
      *  in order to set the resolver object for callbacks.  The reason
 90   
      *  we have to do this is that internally Catalog creates a new
 91   
      *  instance of itself for each external catalog file processed.
 92   
      *  That is, if two external catalog files are processed, there
 93   
      *  will be a total of two ApacheCatalog instances, and so on.</p>
 94   
      */
 95  0
     protected Catalog newCatalog() {
 96  0
         ApacheCatalog cat = (ApacheCatalog)super.newCatalog();
 97  0
         cat.setResolver(resolver);
 98  0
         return cat;
 99   
     }
 100   
     
 101   
     /** Set the resolver object to callback. */
 102  4
     public void setResolver(ApacheCatalogResolver resolver) {
 103  4
         this.resolver = resolver;
 104   
     }
 105   
     
 106   
     /**
 107   
      * <p>This method overrides the superclass method of the same name
 108   
      * in order to add catalog entries back to the controlling
 109   
      * XMLCatalog instance.  In this way, we can add classpath lookup
 110   
      * for these entries.</p>
 111   
      *
 112   
      * <p>When we add an external catalog file, the entries inside it
 113   
      * get parsed by this method.  Therefore, we override it to add
 114   
      * each of them back to the controlling XMLCatalog instance.  This
 115   
      * is done by performing a callback to the ApacheCatalogResolver,
 116   
      * which in turn calls the XMLCatalog.</p>
 117   
      *
 118   
      * <p>XMLCatalog currently only understands <code>PUBLIC</code>
 119   
      * and <code>URI</code> entry types, so we ignore the other types.</p>
 120   
      *
 121   
      * @param entry The CatalogEntry to process.
 122   
      */
 123  4
     public void addEntry(CatalogEntry entry) {
 124   
 
 125  4
         int type = entry.getEntryType();
 126   
 
 127  4
         if (type == PUBLIC) {
 128   
 
 129  4
             String publicid = PublicId.normalize(entry.getEntryArg(0));
 130  4
             String systemid = normalizeURI(entry.getEntryArg(1));
 131   
 
 132  4
             if (resolver == null) {
 133  0
                 catalogManager.debug
 134   
                     .message(1, "Internal Error: null ApacheCatalogResolver");
 135   
             }
 136   
             else {
 137  4
                 resolver.addPublicEntry(publicid, systemid, base);
 138   
             }
 139   
 
 140  0
         } else if (type == URI) {
 141   
             
 142  0
             String uri = normalizeURI(entry.getEntryArg(0));
 143  0
             String altURI = normalizeURI(entry.getEntryArg(1));
 144   
 
 145  0
             if (resolver == null) {
 146  0
                 catalogManager.debug
 147   
                     .message(1, "Internal Error: null ApacheCatalogResolver");
 148   
             }
 149   
             else {
 150  0
                 resolver.addURIEntry(uri, altURI, base);
 151   
             }
 152   
 
 153   
         }
 154   
         
 155  4
         super.addEntry(entry);
 156   
     }
 157   
 
 158   
 } //- ApacheCatalog
 159