Search in sources :

Example 1 with YAMLException

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);
    }
}
Also used : YAMLException(org.yaml.snakeyaml.error.YAMLException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Example 2 with YAMLException

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");
    }
}
Also used : PropertyUtils(org.yaml.snakeyaml.introspector.PropertyUtils) Constructor(org.yaml.snakeyaml.constructor.Constructor) YAMLException(org.yaml.snakeyaml.error.YAMLException) Yaml(org.yaml.snakeyaml.Yaml)

Example 3 with YAMLException

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();
    }
}
Also used : YAMLException(org.yaml.snakeyaml.error.YAMLException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml) SchemaLoaderException(org.apache.nifi.minifi.commons.schema.exception.SchemaLoaderException)

Example 4 with YAMLException

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Node(org.yaml.snakeyaml.nodes.Node) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) YAMLException(org.yaml.snakeyaml.error.YAMLException) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) IOException(java.io.IOException) URL(java.net.URL) Yaml(org.yaml.snakeyaml.Yaml) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) YAMLException(org.yaml.snakeyaml.error.YAMLException) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) Map(java.util.Map)

Example 5 with YAMLException

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);
    }
}
Also used : YAMLException(org.yaml.snakeyaml.error.YAMLException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Aggregations

YAMLException (org.yaml.snakeyaml.error.YAMLException)15 Yaml (org.yaml.snakeyaml.Yaml)8 IOException (java.io.IOException)7 InputStream (java.io.InputStream)5 Map (java.util.Map)4 Constructor (org.yaml.snakeyaml.constructor.Constructor)4 Metrics (com.earth2me.essentials.metrics.Metrics)2 PermissionsHandler (com.earth2me.essentials.perm.PermissionsHandler)2 Method (java.lang.reflect.Method)2 HashMap (java.util.HashMap)2 ISettings (net.ess3.api.ISettings)2 LegacyPotionMetaProvider (net.ess3.nms.legacy.LegacyPotionMetaProvider)2 LegacySpawnEggProvider (net.ess3.nms.legacy.LegacySpawnEggProvider)2 LegacySpawnerProvider (net.ess3.nms.legacy.LegacySpawnerProvider)2 ReflSpawnEggProvider (net.ess3.nms.refl.ReflSpawnEggProvider)2 BasePotionDataProvider (net.ess3.nms.updatedmeta.BasePotionDataProvider)2 BlockMetaSpawnerProvider (net.ess3.nms.updatedmeta.BlockMetaSpawnerProvider)2 net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider (net.ess3.nms.v1_8_R1.v1_8_R1SpawnerProvider)2 net.ess3.nms.v1_8_R2.v1_8_R2SpawnerProvider (net.ess3.nms.v1_8_R2.v1_8_R2SpawnerProvider)2 ProviderFactory (net.ess3.providers.ProviderFactory)2