Added new FileConfigurationOptions.copyHeader, defaulting to true. Copies the header from default config, if there is one.

This commit is contained in:
Nathan Adams
2011-10-12 13:24:57 +01:00
parent ab46572125
commit 98633dfddf
6 changed files with 153 additions and 54 deletions

View File

@@ -39,13 +39,14 @@ public class YamlConfiguration extends FileConfiguration {
serializeValues(output, getValues(false));
String header = buildHeader();
String dump = yaml.dump(output);
if (dump.equals(BLANK_CONFIG)) {
dump = "";
}
return buildHeader() + dump;
return header + dump;
}
@Override
@@ -61,7 +62,12 @@ public class YamlConfiguration extends FileConfiguration {
throw new InvalidConfigurationException("Specified contents is not a valid Configuration", ex);
}
options().header(parseHeader(contents));
String header = parseHeader(contents);
if (header.length() > 0) {
options().header(header);
}
deserializeValues(input, this);
}
@@ -159,6 +165,19 @@ public class YamlConfiguration extends FileConfiguration {
protected String buildHeader() {
String header = options().header();
if (options().copyHeader()) {
Configuration def = getDefaults();
if ((def != null) && (def instanceof FileConfiguration)) {
FileConfiguration filedefaults = (FileConfiguration)def;
String defaultsHeader = filedefaults.buildHeader();
if ((defaultsHeader != null) && (defaultsHeader.length() > 0)) {
return defaultsHeader;
}
}
}
if (header == null) {
return "";
}