use of org.yaml.snakeyaml.Yaml in project infoarchive-sip-sdk by Enterprise-Content-Management.
the class YamlConfiguration method expand.
@SuppressWarnings("unchecked")
private void expand(InputStream input) {
Map<String, Object> source = new HashMap<>();
for (Object data : new Yaml().loadAll(input)) {
source.putAll((Map<String, Object>) data);
}
expand(source);
}
use of org.yaml.snakeyaml.Yaml in project spring-boot by spring-projects.
the class OriginTrackedYamlLoader method createYaml.
@Override
protected Yaml createYaml() {
BaseConstructor constructor = new OriginTrackingConstructor();
Representer representer = new Representer();
DumperOptions dumperOptions = new DumperOptions();
LimitedResolver resolver = new LimitedResolver();
return new Yaml(constructor, representer, dumperOptions, resolver);
}
use of org.yaml.snakeyaml.Yaml in project spring-framework by spring-projects.
the class YamlPropertiesFactoryBeanTests method testYaml.
@SuppressWarnings("unchecked")
@Test
public void testYaml() {
Yaml yaml = new Yaml();
Map<String, ?> map = yaml.loadAs("foo: bar\nspam:\n foo: baz", Map.class);
assertThat(map.get("foo"), equalTo((Object) "bar"));
assertThat(((Map<String, Object>) map.get("spam")).get("foo"), equalTo((Object) "baz"));
}
use of org.yaml.snakeyaml.Yaml 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.Yaml in project siddhi by wso2.
the class DocumentationUtils method updateAPIPagesInMkdocsConfig.
/**
* This add a new page to the list of pages in the mkdocs configuration
*
* @param mkdocsConfigFile The mkdocs configuration file
* @param documentationBaseDirectory The base directory of the documentation
* @throws FileNotFoundException If mkdocs configuration file is not found
*/
public static void updateAPIPagesInMkdocsConfig(File mkdocsConfigFile, String documentationBaseDirectory) throws FileNotFoundException {
// Retrieving the documentation file names
File documentationDirectory = new File(documentationBaseDirectory + File.separator + Constants.API_SUB_DIRECTORY);
String[] documentationFiles = documentationDirectory.list((directory, fileName) -> fileName.endsWith(Constants.MARKDOWN_FILE_EXTENSION));
List<String> apiDirectoryContent;
if (documentationFiles == null) {
apiDirectoryContent = new ArrayList<>();
} else {
apiDirectoryContent = Arrays.asList(documentationFiles);
apiDirectoryContent.sort(new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
String[] s1s = s1.split("\\D+");
String[] s2s = s2.split("\\D+");
int i = 0;
while (s1s.length > i || s2s.length > i) {
String s1a = "0";
String s2a = "0";
if (s1s.length > i) {
s1a = s1s[i];
}
if (s2s.length > i) {
s2a = s2s[i];
}
int s1aInt = Integer.parseInt(s1a);
int s2aInt = Integer.parseInt(s2a);
if (s2aInt > s1aInt) {
return 1;
} else if (s2aInt < s1aInt) {
return -1;
}
i++;
}
return 0;
}
});
}
String latestVersionFile = null;
if (apiDirectoryContent.size() > 1) {
String first = apiDirectoryContent.get(0);
String second = apiDirectoryContent.get(1);
if (first.equals(Constants.LATEST_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION)) {
latestVersionFile = second;
}
}
// Creating yaml parser
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
// Reading the mkdocs configuration
Map<String, Object> yamlConfig = (Map<String, Object>) yaml.load(new InputStreamReader(new FileInputStream(mkdocsConfigFile), Constants.DEFAULT_CHARSET));
// Getting the pages list
List<Map<String, Object>> yamlConfigPagesList = (List<Map<String, Object>>) yamlConfig.get(Constants.MKDOCS_CONFIG_PAGES_KEY);
// Creating the new api pages list
List<Map<String, Object>> apiPagesList = new ArrayList<>();
for (String apiFile : apiDirectoryContent) {
String pageName = apiFile.substring(0, apiFile.length() - Constants.MARKDOWN_FILE_EXTENSION.length());
Map<String, Object> newPage = new HashMap<>();
if (latestVersionFile != null && pageName.equals(Constants.LATEST_FILE_NAME)) {
pageName = "Latest (" + latestVersionFile.substring(0, latestVersionFile.length() - Constants.MARKDOWN_FILE_EXTENSION.length()) + ")";
}
newPage.put(pageName, Constants.API_SUB_DIRECTORY + Constants.MKDOCS_FILE_SEPARATOR + apiFile);
apiPagesList.add(newPage);
}
// Setting the new api pages
Map<String, Object> yamlConfigAPIPage = null;
for (Map<String, Object> yamlConfigPage : yamlConfigPagesList) {
if (yamlConfigPage.get(Constants.MKDOCS_CONFIG_PAGES_API_KEY) != null) {
yamlConfigAPIPage = yamlConfigPage;
break;
}
}
if (yamlConfigAPIPage == null) {
yamlConfigAPIPage = new HashMap<>();
yamlConfigPagesList.add(yamlConfigAPIPage);
}
yamlConfigAPIPage.put(Constants.MKDOCS_CONFIG_PAGES_API_KEY, apiPagesList);
// Saving the updated configuration
yaml.dump(yamlConfig, new OutputStreamWriter(new FileOutputStream(mkdocsConfigFile), Constants.DEFAULT_CHARSET));
}
Aggregations