| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FileSystemReaderFactory |
|
| 1.0;1 |
| 1 | /* | |
| 2 | * Copyright (c) 2004 International Decision Systems, Inc. All Rights Reserved. | |
| 3 | * | |
| 4 | * By using this Software, You acknowledge that the Software is a valuable asset | |
| 5 | * and trade secret of either International Decision Systems, Inc. ("IDSI") or a | |
| 6 | * third party supplier of IDSI and constitutes confidential and proprietary | |
| 7 | * information. | |
| 8 | * | |
| 9 | * NEITHER IDSI NOR ANY AGENT OR PERSON ACTING FOR OR WITH IDSI HAS MADE OR DOES | |
| 10 | * MAKE ANY STATEMENTS, AFFIRMATIONS, REPRESENTATIONS OR WARRANTIES WHATSOEVER | |
| 11 | * TO YOU, WHETHER EXPRESS OR IMPLIED, AS TO THE SOFTWARE, THE QUALITY OR | |
| 12 | * CONDITION OF THE SOFTWARE, OR THE OPERATING CHARACTERISTICS OR RELIABILITY OF | |
| 13 | * THE SOFTWARE, OR ITS SUITABILITY FOR ANY GENERAL OR PARTICULAR PURPOSE, OR AS | |
| 14 | * TO ANY OTHER MATTER WHATSOEVER; ANY AND ALL OTHER WARRANTIES INCLUDING | |
| 15 | * WITHOUT LIMITATION ANY WARRANTIES IMPLIED BY LAW, SUCH AS THE IMPLIED | |
| 16 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND TITLE, | |
| 17 | * USE AND NON-INFRINGEMENT; ARE HEREBY EXPRESSLY DISCLAIMED AND EXCLUDED. | |
| 18 | */ | |
| 19 | package net.sourceforge.addam.ddlrun.utils; | |
| 20 | ||
| 21 | import java.io.File; | |
| 22 | ||
| 23 | ||
| 24 | /** | |
| 25 | * Used to retrieve a FileSystemReader. | |
| 26 | * | |
| 27 | * @author TIM3 | |
| 28 | * @since Mar 5, 2005 | |
| 29 | */ | |
| 30 | 0 | public class FileSystemReaderFactory implements ResourceReaderFactory { |
| 31 | ||
| 32 | /** | |
| 33 | * Constructs a FileSystemReaderFactory with a base path of CWD | |
| 34 | */ | |
| 35 | 0 | public FileSystemReaderFactory() { |
| 36 | 0 | basePath = new File("."); |
| 37 | 0 | } |
| 38 | ||
| 39 | /** | |
| 40 | * Constructs a FileSystemReaderFactory the provided base path | |
| 41 | * | |
| 42 | * @param basePath the path to prepend to relative paths passed to getReader | |
| 43 | */ | |
| 44 | public FileSystemReaderFactory(String basePath) { | |
| 45 | 0 | this(new File(basePath)); |
| 46 | 0 | } |
| 47 | ||
| 48 | /** | |
| 49 | * Constructs a FileSystemReaderFactory the provided base path | |
| 50 | * | |
| 51 | * @param basePath the path to prepend to relative paths passed to getReader | |
| 52 | */ | |
| 53 | 0 | public FileSystemReaderFactory(File basePath) { |
| 54 | 0 | this.basePath = basePath; |
| 55 | 0 | } |
| 56 | ||
| 57 | public ResourceReader getReader(String resource) { | |
| 58 | 0 | return this.getReader(".", resource); |
| 59 | } | |
| 60 | ||
| 61 | public ResourceReader getReader(String path, String resource) { | |
| 62 | 0 | File dirToUse = (path == null) ? basePath : new File(basePath, path); |
| 63 | 0 | File fileToRead = new File(dirToUse, resource); |
| 64 | 0 | return new FileSystemReader(fileToRead); |
| 65 | } | |
| 66 | ||
| 67 | private final File basePath; | |
| 68 | 0 | static private final String SEPARATOR = System.getProperty("file.separator"); |
| 69 | } |