use of org.yaml.snakeyaml.error.YAMLException in project Bukkit by Bukkit.
the class YamlConfiguration method loadFromString.
@Override
public void loadFromString(String contents) throws InvalidConfigurationException {
Validate.notNull(contents, "Contents cannot be null");
Map<?, ?> input;
try {
input = (Map<?, ?>) yaml.load(contents);
} catch (YAMLException e) {
throw new InvalidConfigurationException(e);
} catch (ClassCastException e) {
throw new InvalidConfigurationException("Top level is not a Map.");
}
String header = parseHeader(contents);
if (header.length() > 0) {
options().header(header);
}
if (input != null) {
convertMapsToSections(input, this);
}
}
use of org.yaml.snakeyaml.error.YAMLException in project es6draft by anba.
the class Test262Info method readYaml.
private void readYaml(String descriptor, boolean lenient) throws MalformedDataException {
assert descriptor != null && !descriptor.isEmpty();
Yaml yaml = null;
if (lenient) {
yaml = yamlQueue.poll();
}
if (yaml == null) {
Constructor constructor = new Constructor(TestDescriptor.class);
if (lenient) {
PropertyUtils utils = new PropertyUtils();
utils.setSkipMissingProperties(true);
constructor.setPropertyUtils(utils);
}
yaml = new Yaml(constructor);
}
TestDescriptor desc;
try {
desc = yaml.loadAs(descriptor, TestDescriptor.class);
} catch (YAMLException e) {
throw new MalformedDataException(e.getMessage(), e);
}
if (lenient) {
yamlQueue.offer(yaml);
}
this.description = desc.getDescription();
this.includes = desc.getIncludes();
this.features = desc.getFeatures();
this.errorType = desc.getNegative();
this.negative = desc.getNegative() != null;
if (!desc.getFlags().isEmpty()) {
if (!lenient) {
for (String flag : desc.getFlags()) {
if (!allowedFlags.contains(flag)) {
throw new MalformedDataException(String.format("Unknown flag '%s'", flag));
}
}
}
this.negative |= desc.getFlags().contains("negative");
this.noStrict = desc.getFlags().contains("noStrict");
this.onlyStrict = desc.getFlags().contains("onlyStrict");
this.module = desc.getFlags().contains("module");
this.raw = desc.getFlags().contains("raw");
}
}
use of org.yaml.snakeyaml.error.YAMLException in project nifi-minifi by apache.
the class SchemaLoader method loadYamlAsMap.
public static Map<String, Object> loadYamlAsMap(InputStream sourceStream) throws IOException, SchemaLoaderException {
try {
Yaml yaml = new Yaml();
// Parse the YAML file
final Object loadedObject = yaml.load(sourceStream);
// Verify the parsed object is a Map structure
if (loadedObject instanceof Map) {
return (Map<String, Object>) loadedObject;
} else {
throw new SchemaLoaderException("Provided YAML configuration is not a Map");
}
} catch (YAMLException e) {
throw new IOException(e);
} finally {
sourceStream.close();
}
}
use of org.yaml.snakeyaml.error.YAMLException in project be5 by DevelopmentOnTheEdge.
the class Templates method getTemplatesProject.
public static Project getTemplatesProject() throws ReadException {
Project prj = new Project(TEMPLATES_PROJECT_NAME, true);
LoadContext lc = new LoadContext();
for (String template : TEMPLATES) {
URL url = Templates.class.getResource("templates/" + template + ".yaml");
Node content;
try (InputStream is = url.openStream()) {
content = new Yaml().compose(new InputStreamReader(is, StandardCharsets.UTF_8));
} catch (MarkedYAMLException e) {
throw new ReadException(new Exception((e.getProblemMark().getLine() + 1) + ":" + (e.getProblemMark().getColumn() + 1) + ": " + e.getMessage()), getPath(url), ReadException.LEE_INVALID_STRUCTURE);
} catch (YAMLException | IOException e) {
throw new ReadException(new Exception(e.getMessage()), getPath(url), ReadException.LEE_INVALID_STRUCTURE);
}
try {
Object obj = Serialization.derepresent(content);
@SuppressWarnings("unchecked") Map<String, Object> root = (Map<String, Object>) obj;
@SuppressWarnings("unchecked") Map<String, Object> entityContent = (Map<String, Object>) root.get(template);
DataElementUtils.saveQuiet(YamlDeserializer.readEntity(lc, template, entityContent, prj.getApplication()));
} catch (RuntimeException e) {
throw new ReadException(e, getPath(url), ReadException.LEE_INTERNAL_ERROR);
}
lc.check();
}
return prj;
}
use of org.yaml.snakeyaml.error.YAMLException in project TriggerReactor by wysohn.
the class CopyYamlConfiguration method loadFromString.
@Override
public void loadFromString(String contents) throws InvalidConfigurationException {
Validate.notNull(contents, "Contents cannot be null");
Map<?, ?> input;
try {
input = (Map<?, ?>) yaml.load(contents);
} catch (YAMLException e) {
throw new InvalidConfigurationException(e);
} catch (ClassCastException e) {
throw new InvalidConfigurationException("Top level is not a Map.");
}
String header = parseHeader(contents);
if (header.length() > 0) {
options().header(header);
}
if (input != null) {
convertMapsToSections(input, this);
}
}
Aggregations