Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/ConfigFile.java @ 331:a37ce7145c3f
Access to repository configuration
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Sat, 05 Nov 2011 04:21:18 +0100 |
| parents | 981f9f50bb6c |
| children | 9fb990c8a724 |
comparison
equal
deleted
inserted
replaced
| 330:9747a786a34d | 331:a37ce7145c3f |
|---|---|
| 25 import java.util.LinkedHashMap; | 25 import java.util.LinkedHashMap; |
| 26 import java.util.List; | 26 import java.util.List; |
| 27 import java.util.Map; | 27 import java.util.Map; |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * | 30 * .ini / .rc file reader |
| 31 * @author Artem Tikhomirov | 31 * @author Artem Tikhomirov |
| 32 * @author TMate Software Ltd. | 32 * @author TMate Software Ltd. |
| 33 */ | 33 */ |
| 34 public class ConfigFile { | 34 public class ConfigFile { |
| 35 | 35 |
| 42 public void addLocation(File path) throws IOException { | 42 public void addLocation(File path) throws IOException { |
| 43 read(path); | 43 read(path); |
| 44 } | 44 } |
| 45 | 45 |
| 46 public boolean hasSection(String sectionName) { | 46 public boolean hasSection(String sectionName) { |
| 47 return sections == null ? false : sections.indexOf(sectionName) == -1; | 47 return sections == null ? false : sections.indexOf(sectionName) != -1; |
| 48 } | |
| 49 | |
| 50 // XXX perhaps, should be moved to subclass HgRepoConfig, as it is not common operation for any config file | |
| 51 public boolean hasEnabledExtension(String extensionName) { | |
| 52 int x = sections != null ? sections.indexOf("extensions") : -1; | |
| 53 if (x == -1) { | |
| 54 return false; | |
| 55 } | |
| 56 String value = content.get(x).get(extensionName); | |
| 57 return value != null && !"!".equals(value); | |
| 58 } | 48 } |
| 59 | 49 |
| 60 public List<String> getSectionNames() { | 50 public List<String> getSectionNames() { |
| 61 return sections == null ? Collections.<String>emptyList() : Collections.unmodifiableList(sections); | 51 return sections == null ? Collections.<String>emptyList() : Collections.unmodifiableList(sections); |
| 62 } | 52 } |
| 90 return value == null ? defaultValue : value; | 80 return value == null ? defaultValue : value; |
| 91 } | 81 } |
| 92 | 82 |
| 93 // TODO handle %include and %unset directives | 83 // TODO handle %include and %unset directives |
| 94 // TODO "" and lists | 84 // TODO "" and lists |
| 85 // XXX perhaps, single string to keep whole section with substrings for keys/values to minimize number of arrays (String.value) | |
| 95 private void read(File f) throws IOException { | 86 private void read(File f) throws IOException { |
| 96 if (f == null || !f.canRead()) { | 87 if (f == null || !f.canRead()) { |
| 97 return; | 88 return; |
| 98 } | 89 } |
| 99 if (sections == null) { | 90 if (sections == null) { |
