1
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
32 public enum MetaDataLocator {
33 TRANSIENT {
34 @Override
35 public File getReadLocation() {
36 return null;
37 }
38 @Override
39 public File getWriteLocation() {
40 return null;
41 }
42 },
43 JSWORD {
44 @Override
45 public File getReadLocation() {
46 URI[] dirs = CWProject.instance().getProjectResourceDirs();
47 if (dirs.length > 1) {
48 return getFile(dirs[1]);
49 }
50 return null;
51 }
52 @Override
53 public File getWriteLocation() {
54 URI[] dirs = CWProject.instance().getProjectResourceDirs();
55 if (dirs.length > 0) {
56 return getFile(dirs[0]);
57 }
58 return null;
59 }
60 },
61 FRONTEND {
62 @Override
63 public File getReadLocation() {
64 return getFile(CWProject.instance().getReadableFrontendProjectDir());
65 }
66 @Override
67 public File getWriteLocation() {
68 return getFile(CWProject.instance().getWritableFrontendProjectDir());
69 }
70 };
71
72
78 protected static File getFile(URI u) {
79 if (u == null) {
80 return null;
81 }
82
83 final File parent = new File(u);
84 final File override = new File(parent, DIR_CONF_OVERRIDE);
85 override.mkdirs();
86 return override;
87 }
88
89 public abstract File getReadLocation();
90 public abstract File getWriteLocation();
91
92
95 private static final String DIR_CONF_OVERRIDE = "jsword-mods.d";
96
97 }
98