/** * Parse the yaml content to {@link YamlValue}. */ public static YamlValue parse(Reader reader) throws YamlException { return YamlValue.of(decode(reader)); }
@Override public boolean readProperties(AppPropertyContext context, Resource resource) { String filename = resource.getFilename(); if(Strings.endsWithIgnoreCase(filename, ".yaml") || Strings.endsWithIgnoreCase(filename,".yml")) { String content = resource.getContent(); if(Strings.isEmpty(content)) { return true; } Map<String, Object> map = YAML.parse(content).asMap(); if(map.isEmpty()) { return true; } Map<String, String> props = Maps.toProperties(map); props.forEach((key, value) -> putProperty(context, resource, key, value)); return true; } return false; }
/** * Parse the yaml content to {@link YamlValue}. */ public static YamlValue parse(String string) throws YamlException { return YamlValue.of(decode(string)); }
public SwaggerDoc(String dir) { this.dir = leap.lang.path.Paths.suffixWithSlash(dir); Map map = null; File swaggerFile = Paths.get(dir).resolve("./swagger.json").toFile(); if(swaggerFile.exists()) { map = JSON.decodeMap(IO.readString(swaggerFile, Charsets.UTF_8)); }else { swaggerFile = Paths.get(dir).resolve("./swagger.yaml").toFile(); if(swaggerFile.exists()) { map = YAML.decode(Resources.createFileResource(swaggerFile).getContent()); } } if(null != map) { this.swagger = JsonObject.of(map); } }
@Override public ApiMetadataBuilder read(Reader reader) throws IOException { String content = IO.readString(reader).trim(); Map<String,Object> swagger; if(content.startsWith("{")) { swagger = JSON.decode(content); }else{ swagger = YAML.decode(content); } ApiMetadataBuilder m = new ApiMetadataBuilder(); readSwagger(swagger, m); return m; }
protected void readMessages(MessageContext context, Resource resource) { try { String localeName = Locales.extractFromFilename(resource.getFilename()); Locale locale = Strings.isEmpty(localeName) ? null : Locales.forName(localeName); Map<String, String> props; try (Reader reader = resource.getInputStreamReader(charset)) { Map map = YAML.decode(reader); if (null == map || map.isEmpty()) { return; } props = Maps.toProperties(map); } for (String key : props.keySet()) { readMessage(context, resource, locale, props, (String) key); } } catch (Exception e) { throw new AppConfigException("Error reading messages from properties resource [" + resource.getURLString() + "], " + e.getMessage(), e); } }