本文整理汇总了Java中org.yaml.snakeyaml.constructor.SafeConstructor类的典型用法代码示例。如果您正苦于以下问题:Java SafeConstructor类的具体用法?Java SafeConstructor怎么用?Java SafeConstructor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SafeConstructor类属于org.yaml.snakeyaml.constructor包,在下文中一共展示了SafeConstructor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
private void initialize(InputStream regexYaml) {
Yaml yaml = new Yaml(new SafeConstructor());
Map<String,List> regexConfig = (Map<String,List>) yaml.load(regexYaml);
List<Map> uaParserConfigs = regexConfig.get("user_agent_parsers");
if (uaParserConfigs == null) {
throw new IllegalArgumentException("user_agent_parsers is missing from yaml");
}
uaParser = UserAgentParser.fromList(uaParserConfigs);
List<Map> osParserConfigs = regexConfig.get("os_parsers");
if (osParserConfigs == null) {
throw new IllegalArgumentException("os_parsers is missing from yaml");
}
osParser = OSParser.fromList(osParserConfigs);
List<Map> deviceParserConfigs = regexConfig.get("device_parsers");
if (deviceParserConfigs == null) {
throw new IllegalArgumentException("device_parsers is missing from yaml");
}
deviceParser = DeviceParser.fromList(deviceParserConfigs);
}
示例2: checkQuotes
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
private void checkQuotes(boolean isBlock, String expectation) {
DumperOptions options = new DumperOptions();
options.setIndent(4);
if (isBlock) {
options.setDefaultFlowStyle(FlowStyle.BLOCK);
}
Representer representer = new Representer();
Yaml yaml = new Yaml(new SafeConstructor(), representer, options);
LinkedHashMap<String, Object> lvl1 = new LinkedHashMap<String, Object>();
lvl1.put("steak:cow", "11");
LinkedHashMap<String, Object> root = new LinkedHashMap<String, Object>();
root.put("cows", lvl1);
String output = yaml.dump(root);
assertEquals(expectation + "\n", output);
// parse the value back
@SuppressWarnings("unchecked")
Map<String, Object> cows = (Map<String, Object>) yaml.load(output);
@SuppressWarnings("unchecked")
Map<String, String> cow = (Map<String, String>) cows.get("cows");
assertEquals("11", cow.get("steak:cow"));
}
示例3: testListSafeConstructor
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testListSafeConstructor() {
List value = new ArrayList();
value.add(value);
value.add("test");
value.add(new Integer(1));
Yaml yaml = new Yaml(new SafeConstructor());
String output1 = yaml.dump(value);
assertEquals("&id001\n- *id001\n- test\n- 1\n", output1);
List value2 = (List) yaml.load(output1);
assertEquals(3, value2.size());
assertEquals(value.size(), value2.size());
assertSame(value2, value2.get(0));
// we expect self-reference as 1st element of the list
// let's remove self-reference and check other "simple" members of the
// list. otherwise assertEquals will lead us to StackOverflow
value.remove(0);
value2.remove(0);
assertEquals(value, value2);
}
示例4: readConfigFile
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
private static Map readConfigFile(String filename) throws IOException {
Map ret;
Yaml yaml = new Yaml(new SafeConstructor());
InputStream inputStream = new FileInputStream(new File(filename));
try {
ret = (Map)yaml.load(inputStream);
} finally {
inputStream.close();
}
if(ret == null) {
ret = new HashMap();
}
return new HashMap(ret);
}
示例5: readConfigFile
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public static Map readConfigFile(String file, boolean mustExist) {
Yaml yaml = new Yaml(new SafeConstructor());
Map ret = null;
InputStream input = IOUtils.getInputStream(file);
if (input != null) {
ret = (Map) yaml.load(new InputStreamReader(input));
LOG.info("Loaded " + file);
try {
input.close();
} catch (IOException e) {
LOG.error("IOException: " + e.getMessage());
}
} else if (mustExist) {
LOG.error("Config file " + file + " was not found!");
}
if ((ret == null) && (mustExist)) {
throw new RuntimeException("Config file " + file + " was not found!");
}
return ret;
}
示例6: initialize
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
private void initialize(InputStream regexYaml) {
Yaml yaml = new Yaml(new SafeConstructor());
@SuppressWarnings("unchecked")
Map<String,List<Map<String,String>>> regexConfig = (Map<String,List<Map<String,String>>>) yaml.load(regexYaml);
List<Map<String,String>> uaParserConfigs = regexConfig.get("user_agent_parsers");
if (uaParserConfigs == null) {
throw new IllegalArgumentException("user_agent_parsers is missing from yaml");
}
uaParser = UserAgentParser.fromList(uaParserConfigs);
List<Map<String,String>> osParserConfigs = regexConfig.get("os_parsers");
if (osParserConfigs == null) {
throw new IllegalArgumentException("os_parsers is missing from yaml");
}
osParser = OSParser.fromList(osParserConfigs);
List<Map<String,String>> deviceParserConfigs = regexConfig.get("device_parsers");
if (deviceParserConfigs == null) {
throw new IllegalArgumentException("device_parsers is missing from yaml");
}
deviceParser = DeviceParser.fromList(deviceParserConfigs);
}
示例7: readConfigFile
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
public static Map readConfigFile(String filename) throws IOException {
Map ret;
Yaml yaml = new Yaml(new SafeConstructor());
InputStream inputStream = new FileInputStream(new File(filename));
try {
ret = (Map)yaml.load(inputStream);
} finally {
inputStream.close();
}
if(ret == null) {
ret = new HashMap();
}
return new HashMap(ret);
}
示例8: testConstruct
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void testConstruct() {
String doc = "- 5\n- Person\n- true";
Yaml yaml = new Yaml(new SafeConstructor());
List<Object> list = (List<Object>) yaml.load(doc);
assertEquals(3, list.size());
assertEquals(new Integer(5), list.get(0));
assertEquals("Person", list.get(1));
assertEquals(Boolean.TRUE, list.get(2));
}
示例9: testSafeConstruct
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
public void testSafeConstruct() {
String doc = "- 5\n- !org.yaml.snakeyaml.constructor.Person\n firstName: Andrey\n age: 99\n- true";
Yaml yaml = new Yaml(new SafeConstructor());
try {
yaml.load(doc);
fail("Custom Java classes should not be created.");
} catch (Exception e) {
assertEquals(
"could not determine a constructor for the tag !org.yaml.snakeyaml.constructor.Person\n"
+ " in 'string', line 2, column 3:\n"
+ " - !org.yaml.snakeyaml.constructor. ... \n" + " ^\n",
e.getMessage());
}
}
示例10: testDictSafeConstructor
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testDictSafeConstructor() {
Map value = new TreeMap();
value.put("abc", "www");
value.put("qwerty", value);
Yaml yaml = new Yaml(new SafeConstructor());
String output1 = yaml.dump(value);
assertEquals("&id001\nabc: www\nqwerty: *id001\n", output1);
Map value2 = (Map) yaml.load(output1);
assertEquals(2, value2.size());
assertEquals("www", value2.get("abc"));
assertTrue(value2.get("qwerty") instanceof Map);
Map value3 = (Map) value2.get("qwerty");
assertTrue(value3.get("qwerty") instanceof Map);
}
示例11: SpongeConfig
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
public SpongeConfig(File fh, Logger logger) {
this.file = fh;
this.yaml = new Yaml(new SafeConstructor());
this.reload();
logger.info(String.format("Data: %s", this.data));
}
示例12: loadString
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
public ObjectNode loadString(String content)
throws IOException
{
// here doesn't use jackson-dataformat-yaml so that snakeyaml calls Resolver
// and Composer. See also YamlTagResolver.
Yaml yaml = new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(), new YamlTagResolver());
ObjectNode object = normalizeValidateObjectNode(yaml.load(content));
return object;
}
示例13: externalGroupsService
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
@Bean
@Autowired
public ExternalGroupsService externalGroupsService(
@Value("${externalProviders.config.path}") final String configFileLocation) throws IOException {
Yaml yaml = new Yaml(new SafeConstructor());
@SuppressWarnings("unchecked")
Map<String, List<Map<String, Object>>> config = (Map<String, List<Map<String, Object>>>) yaml.load(resourceLoader.getResource(configFileLocation).getInputStream());
final List<Map<String, Object>> externalGroupProviders = config.get("externalGroupProviders");
final List<Provider> groupClients = externalGroupProviders.stream().map(entryMap -> {
final String type = (String) entryMap.get("type");
final String url = StringUtils.trimTrailingCharacter((String) entryMap.get("url"), '/');
final String schacHomeOrganization = (String) entryMap.get("schacHomeOrganization");
final String name = (String) entryMap.get("name");
final Integer timeoutMillis = (Integer) entryMap.get("timeoutMillis");
@SuppressWarnings("unchecked") final Map<String, Object> rawCredentials = (Map<String, Object>) entryMap.get("credentials");
String username = (String) rawCredentials.get("username");
String secret = (String) rawCredentials.get("secret");
GroupProviderType groupProviderType = GroupProviderType.valueOf(type.toUpperCase());
final Provider.Configuration configuration = new Provider.Configuration(groupProviderType, url, new Provider.Configuration.Credentials(username, secret), timeoutMillis, schacHomeOrganization, name);
switch (groupProviderType) {
case VOOT2:
return new Voot2Provider(configuration);
case OPEN_SOCIAL:
return new OpenSocialClient(configuration);
case TEAMS:
return new TeamsProviderClient(configuration);
case OPEN_SOCIAL_MEMBERS:
return new OpenSocialMembersClient(configuration);
default:
throw new IllegalArgumentException("Unknown external provider-type: " + type);
}
}).collect(Collectors.toList());
return new ExternalGroupsService(groupClients, supportLinkedGrouperExternalGroups);
}
示例14: createConstructor
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
private static SafeConstructor createConstructor() {
try {
return constructor.getDeclaredConstructor().newInstance();
} catch(Exception e) {
ModuleManager.getLogger().log(Level.SEVERE, "Could not create YAML constructor.", e);
return null;
}
}
示例15: APTranslator
import org.yaml.snakeyaml.constructor.SafeConstructor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public APTranslator(InputStream APDBYAML, boolean full_apname) {
this.full_apname = full_apname;
// Load yaml database
Yaml yaml = new Yaml(new SafeConstructor());
Map<String,Object> regexConfig = (Map<String,Object>) yaml.load(APDBYAML);
APNameDB = (Map<String, Map<String, String>>) regexConfig.get("apprefix_sjtu");
}