Coverage Report - org.crosswire.jsword.book.MetaDataLocator
 
Classes in this File Line Coverage Branch Coverage Complexity
MetaDataLocator
0%
0/10
0%
0/2
1.667
MetaDataLocator$1
0%
0/3
N/A
1.667
MetaDataLocator$2
0%
0/9
0%
0/4
1.667
MetaDataLocator$3
0%
0/3
N/A
1.667
 
 1  
 /**
 2  
  * Distribution License:
 3  
  * JSword is free software; you can redistribute it and/or modify it under
 4  
  * the terms of the GNU Lesser General Public License, version 2.1 or later
 5  
  * as published by the Free Software Foundation. This program is distributed
 6  
  * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 7  
  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 8  
  * See the GNU Lesser General Public License for more details.
 9  
  *
 10  
  * The License is available on the internet at:
 11  
  *      http://www.gnu.org/copyleft/lgpl.html
 12  
  * or by writing to:
 13  
  *      Free Software Foundation, Inc.
 14  
  *      59 Temple Place - Suite 330
 15  
  *      Boston, MA 02111-1307, USA
 16  
  *
 17  
  * © CrossWire Bible Society, 2015 - 2016
 18  
  */
 19  
 package org.crosswire.jsword.book;
 20  
 
 21  
 import java.io.File;
 22  
 import java.net.URI;
 23  
 
 24  
 import org.crosswire.common.util.CWProject;
 25  
 
 26  
 /**
 27  
  * A MetaDataLocator allows one to define where BookMetaData for a Book may be found.
 28  
  *
 29  
  * @see gnu.lgpl.License The GNU Lesser General Public License for details.
 30  
  * @author DM Smith
 31  
  */
 32  0
 public enum MetaDataLocator {
 33  0
     TRANSIENT {
 34  
         @Override
 35  
         public File getReadLocation() {
 36  0
             return null;
 37  
         }
 38  
         @Override
 39  
         public File getWriteLocation() {
 40  0
             return null;
 41  
         }
 42  
     },
 43  0
     JSWORD {
 44  
         @Override
 45  
         public File getReadLocation() {
 46  0
             URI[] dirs = CWProject.instance().getProjectResourceDirs();
 47  0
             if (dirs.length > 1) {
 48  0
                 return getFile(dirs[1]);
 49  
             }
 50  0
             return null;
 51  
         }
 52  
         @Override
 53  
         public File getWriteLocation() {
 54  0
             URI[] dirs = CWProject.instance().getProjectResourceDirs();
 55  0
             if (dirs.length > 0) {
 56  0
                 return getFile(dirs[0]);
 57  
             }
 58  0
             return null;
 59  
         }
 60  
     },
 61  0
     FRONTEND {
 62  
         @Override
 63  
         public File getReadLocation() {
 64  0
             return getFile(CWProject.instance().getReadableFrontendProjectDir());
 65  
         }
 66  
         @Override
 67  
         public File getWriteLocation() {
 68  0
             return getFile(CWProject.instance().getWritableFrontendProjectDir());
 69  
         }
 70  
     };
 71  
 
 72  
     /**
 73  
      * Safely creates the file location, or null if the parent can't exist
 74  
      *
 75  
      * @param u the parent URI
 76  
      * @return the file representing the config
 77  
      */
 78  
     protected static File getFile(URI u) {
 79  0
         if (u == null) {
 80  0
             return null;
 81  
         }
 82  
 
 83  0
         final File parent = new File(u);
 84  0
         final File override = new File(parent, DIR_CONF_OVERRIDE);
 85  0
         override.mkdirs();
 86  0
         return override;
 87  
     }
 88  
 
 89  
     public abstract File getReadLocation();
 90  
     public abstract File getWriteLocation();
 91  
 
 92  
     /**
 93  
      * The configuration directory for overrides
 94  
      */
 95  
     private static final String DIR_CONF_OVERRIDE = "jsword-mods.d";
 96  
 
 97  
 }