Search in sources :

Example 6 with YamlReader

use of com.esotericsoftware.yamlbeans.YamlReader in project yamlbeans by EsotericSoftware.

the class YamlEnumTest method read.

public void read(String string) throws IOException {
    YamlReader reader = new YamlReader(string);
    reader.read(TestObject.class);
    reader.close();
}
Also used : YamlReader(com.esotericsoftware.yamlbeans.YamlReader)

Example 7 with YamlReader

use of com.esotericsoftware.yamlbeans.YamlReader in project StreetComplete by westnordost.

the class CreditsFragment method readTranslators.

private List<Map.Entry<String, String>> readTranslators() {
    try {
        InputStream is = getResources().openRawResource(R.raw.credits_translations);
        YamlReader reader = new YamlReader(new InputStreamReader(is));
        Map yml = (Map) reader.read();
        List<Map.Entry<String, String>> result = new ArrayList<>();
        for (Object e : yml.entrySet()) {
            result.add((Map.Entry<String, String>) e);
        }
        Collections.sort(result, (o1, o2) -> o1.getKey().compareTo(o2.getKey()));
        return result;
    } catch (YamlException e) {
        throw new RuntimeException(e);
    }
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) Map(java.util.Map)

Example 8 with YamlReader

use of com.esotericsoftware.yamlbeans.YamlReader in project StreetComplete by westnordost.

the class CountryInfos method loadCountryInfo.

private CountryInfo loadCountryInfo(String countryCodeIso3166) throws IOException {
    String filename = countryCodeIso3166 + ".yml";
    InputStream is = null;
    try {
        is = assetManager.open(BASEPATH + File.separator + filename);
        Reader reader = new InputStreamReader(is, "UTF-8");
        YamlReader yamlReader = new YamlReader(reader);
        yamlReader.getConfig().setPrivateFields(true);
        CountryInfo result = yamlReader.read(CountryInfo.class);
        result.countryCode = countryCodeIso3166;
        return result;
    } finally {
        if (is != null)
            try {
                is.close();
            } catch (IOException e) {
            }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) IOException(java.io.IOException)

Example 9 with YamlReader

use of com.esotericsoftware.yamlbeans.YamlReader in project audit4j-core by audit4j.

the class YAMLConfigProvider method readConfig.

/**
 * {@inheritDoc}
 *
 * @see org.audit4j.core.ConfigProvider#readConfig(java.lang.String)
 */
@SuppressWarnings("unchecked")
@Override
public T readConfig(String filePath) throws ConfigurationException {
    try {
        YamlReader reader = new YamlReader(new FileReader(filePath));
        reader.getConfig().setClassTag(clazz.getSimpleName(), clazz);
        return (T) reader.read();
    } catch (FileNotFoundException e) {
        throw new ConfigurationException("Configuration Exception", "CONF_001", e);
    } catch (YamlException e) {
        throw new ConfigurationException("Configuration Exception", "CONF_002", e);
    }
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) ConfigurationException(org.audit4j.core.exception.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) YamlReader(com.esotericsoftware.yamlbeans.YamlReader)

Example 10 with YamlReader

use of com.esotericsoftware.yamlbeans.YamlReader in project ecs-dashboard by carone1.

the class KibanaEmailer method loadConfig.

/*
	 * Utility method to load and parse emailer's configuration data
	 */
@SuppressWarnings("unchecked")
private static void loadConfig() {
    try {
        FileReader fr;
        fr = new FileReader(kibanaConfigFile);
        logger.info("Loading configuration from config file: " + kibanaConfigFile);
        YamlReader reader = new YamlReader(fr);
        Object object = reader.read();
        if (object == null) {
            logger.info("Can't load config data from: " + kibanaConfigFile + " exiting...");
            System.out.println("Can't load config data from: " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        Map<?, ?> map = (Map<?, ?>) object;
        if (map == null) {
            logger.info("Can't load config data from: " + kibanaConfigFile + " exiting...");
            System.out.println("Can't load config data from: " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // chromedriver
        Object driverPathObj = map.get(CHROME_DRIVER_CONFIG);
        if (driverPathObj != null && driverPathObj instanceof String) {
            chromeDriverPath = (String) driverPathObj;
        } else {
            logger.info("Can't find: " + CHROME_DRIVER_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + CHROME_DRIVER_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // chromebrowser
        Object browserPathObj = map.get(CHROME_BROWSER_CONFIG);
        if (browserPathObj != null && browserPathObj instanceof String) {
            chromeBrowserPath = (String) browserPathObj;
        } else {
            logger.info("Can't find: " + CHROME_BROWSER_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + CHROME_BROWSER_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        Object captureDelayObj = map.get(SCREEN_CAPTURE_DELAY);
        if (captureDelayObj != null && captureDelayObj instanceof String) {
            screenCaptureDelay = Integer.valueOf((String) captureDelayObj);
        } else {
            logger.info("Can't find: " + SCREEN_CAPTURE_DELAY + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SCREEN_CAPTURE_DELAY + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // Kibana Urls
        Object urls = map.get(KIBANA_URLS_CONFIG);
        if (urls != null && urls instanceof ArrayList<?>) {
            kibanaUrls = (ArrayList<Map<String, String>>) urls;
        } else {
            logger.info("Can't find: " + KIBANA_URLS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + KIBANA_URLS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // destination path to save screen captures
        Object destinationObj = map.get(DESTINATION_PATH_CONFIG);
        if (destinationObj != null && destinationObj instanceof String) {
            destinationPath = (String) destinationObj;
        } else {
            logger.info("Can't find: " + DESTINATION_PATH_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + DESTINATION_PATH_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // == smtp config ==
        // smtp.host
        Object smtpHostObj = map.get(SMTP_HOST_CONFIG);
        if (smtpHostObj != null && smtpHostObj instanceof String) {
            smtpHost = (String) smtpHostObj;
        } else {
            logger.info("Can't find: " + SMTP_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SMTP_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // smtp.port
        Object smtpPortObj = map.get(SMTP_PORT_CONFIG);
        if (smtpPortObj != null && smtpPortObj instanceof String) {
            smtpPort = (String) smtpHostObj;
        } else {
            logger.info("Can't find: " + SMTP_PORT_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SMTP_PORT_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // smtp.username
        Object smtpUsernameObj = map.get(SMTP_USERNAME_CONFIG);
        if (smtpUsernameObj != null && smtpUsernameObj instanceof String) {
            smtpUsername = (String) smtpUsernameObj;
        } else {
            logger.info("Can't find: " + SMTP_USERNAME_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SMTP_USERNAME_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // smtp.password
        Object smtpPasswordObj = map.get(SMTP_PASSWORD_CONFIG);
        if (smtpPasswordObj != null && smtpPasswordObj instanceof String) {
            smtpPassword = (String) smtpPasswordObj;
        } else {
            logger.info("Can't find: " + SMTP_PASSWORD_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SMTP_PASSWORD_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // smtp.security "tls|ssl"
        Object smtpSecurityObj = map.get(SMTP_SECURITY_CONFIG);
        if (smtpSecurityObj != null && smtpSecurityObj instanceof String) {
            smtpSecurity = (String) smtpSecurityObj;
        } else {
            logger.info("Can't find: " + SMTP_SECURITY_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SMTP_SECURITY_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // source.host
        Object sourceHostObj = map.get(SOURCE_HOST_CONFIG);
        if (sourceHostObj != null && sourceHostObj instanceof String) {
            sourceHost = (String) sourceHostObj;
        } else {
            logger.info("Can't find: " + SOURCE_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SOURCE_HOST_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // e-mail addresses configuration
        // source.mail
        Object sourceAddressObj = map.get(SOURCE_ADDRESS_CONFIG);
        if (sourceAddressObj != null && sourceAddressObj instanceof String) {
            sourceAddress = (String) sourceAddressObj;
        } else {
            logger.info("Can't find: " + SOURCE_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + SOURCE_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // destination.addresses
        Object destinations = map.get(DESTINATION_ADDRESS_CONFIG);
        if (destinations != null && destinations instanceof ArrayList<?>) {
            destinationAddressList = (ArrayList<String>) destinations;
        } else {
            logger.info("Can't find: " + DESTINATION_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + DESTINATION_ADDRESS_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // e-mail content
        // mail.title
        Object mailTitleObj = map.get(MAIL_TITLE_CONFIG);
        if (mailTitleObj != null && mailTitleObj instanceof String) {
            mailTitle = (String) mailTitleObj;
        } else {
            logger.info("Can't find: " + MAIL_TITLE_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + MAIL_TITLE_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
        // mail.body
        Object mailBodyObj = map.get(MAIL_BODY_CONFIG);
        if (mailBodyObj != null && mailBodyObj instanceof String) {
            mailBody = (String) mailBodyObj;
        } else {
            logger.info("Can't find: " + MAIL_BODY_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.out.println("Can't find: " + MAIL_BODY_CONFIG + " in " + kibanaConfigFile + " exiting...");
            System.exit(0);
        }
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (YamlException e) {
        throw new RuntimeException(e);
    }
    logger.info("Loaded config details: " + SMTP_HOST_CONFIG + ": `" + smtpHost + "`, " + SMTP_PORT_CONFIG + ": `" + smtpPort.toString() + "`, " + SMTP_USERNAME_CONFIG + ": `" + smtpUsername + "`, " + SOURCE_HOST_CONFIG + ": `" + sourceHost + "`, " + SOURCE_ADDRESS_CONFIG + ": `" + sourceAddress + "`, " + DESTINATION_ADDRESS_CONFIG + ": `" + destinationAddressList.toString() + "`, " + MAIL_TITLE_CONFIG + ": `" + mailTitle + "`, " + MAIL_BODY_CONFIG + ": `" + mailBody);
    logger.info("Loaded config details: " + KIBANA_URLS_CONFIG + ": " + kibanaUrls.toString());
}
Also used : YamlException(com.esotericsoftware.yamlbeans.YamlException) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

YamlReader (com.esotericsoftware.yamlbeans.YamlReader)11 YamlException (com.esotericsoftware.yamlbeans.YamlException)5 InputStreamReader (java.io.InputStreamReader)5 Map (java.util.Map)4 FileReader (java.io.FileReader)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ConfigurationException (org.audit4j.core.exception.ConfigurationException)2 Test (org.junit.Test)2 YamlConfig (com.esotericsoftware.yamlbeans.YamlConfig)1 YamlWriter (com.esotericsoftware.yamlbeans.YamlWriter)1 File (java.io.File)1 Reader (java.io.Reader)1 StringWriter (java.io.StringWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Point2d (javax.vecmath.Point2d)1