2009/04/15 - Apache HiveMind has been retired.

For more information, please explore the Attic.

Clover coverage report - Code Coverage for hivemind release 1.2.1
Coverage timestamp: Fri Feb 10 2006 16:33:43 PST
file stats: LOC: 93   Methods: 7
NCLOC: 56   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FileResource.java 100% 88.9% 100% 93.1%
coverage coverage
 1    // Copyright 2004, 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.hivemind.util;
 16   
 17    import java.io.File;
 18    import java.net.MalformedURLException;
 19    import java.net.URL;
 20    import java.util.Locale;
 21   
 22    import org.apache.commons.logging.Log;
 23    import org.apache.commons.logging.LogFactory;
 24    import org.apache.hivemind.Resource;
 25   
 26    /**
 27    * An implementation of {@link org.apache.hivemind.Resource} built around
 28    * {@link java.io.File}.
 29    *
 30    * @author Howard Lewis Ship
 31    */
 32    public class FileResource extends AbstractResource
 33    {
 34    private static final Log LOG = LogFactory.getLog(FileResource.class);
 35   
 36  14 public FileResource(String path)
 37    {
 38  14 super(path);
 39    }
 40   
 41  1 public FileResource(String path, Locale locale)
 42    {
 43  1 super(path, locale);
 44    }
 45   
 46  1 protected Resource newResource(String path)
 47    {
 48  1 return new FileResource(path);
 49    }
 50   
 51  9 private File getFile()
 52    {
 53  9 return new File(getPath());
 54    }
 55   
 56  9 public URL getResourceURL()
 57    {
 58  9 File file = getFile();
 59   
 60  9 try
 61    {
 62  9 if (file == null || !file.exists())
 63  2 return null;
 64   
 65  7 return file.toURL();
 66    }
 67    catch (MalformedURLException ex)
 68    {
 69  0 LOG.error(UtilMessages.badFileURL(getPath(), ex), ex);
 70  0 return null;
 71    }
 72    }
 73   
 74  3 public Resource getLocalization(Locale locale)
 75    {
 76  3 LocalizedFileResourceFinder f = new LocalizedFileResourceFinder();
 77   
 78  3 String path = getPath();
 79   
 80  3 String finalPath = f.findLocalizedPath(path, locale);
 81   
 82  3 if (finalPath.equals(path))
 83  2 return this;
 84   
 85  1 return newResource(finalPath);
 86    }
 87   
 88  3 public String toString()
 89    {
 90  3 return getPath();
 91    }
 92   
 93    }