Java ResourceBundle for YAML format
Java
Switch branches/tags
Nothing to show
Clone or download
Latest commit 7e60925 Dec 16, 2015
Permalink
Failed to load latest commit information.
src Modify example. Aug 29, 2015
.gitignore Make project. Aug 14, 2015
README.md README: Add maven-badges Dec 16, 2015
circle.yml CircleCI: Collect artifacts. Aug 29, 2015
pom.xml Set the release version: v1.1 Dec 16, 2015

README.md

YamlResourceBundle

Java ResourceBundle for YAML format.

Status

Maven Central Circle CI

Usage

Maven dependency:

<dependency>
    <groupId>net.rakugakibox.util</groupId>
    <artifactId>yaml-resource-bundle</artifactId>
    <version>1.1</version>
</dependency>

YAML file (example.yaml):

fruits:
  apple: Apple
  orange: Orange
  grape: Grape
colors:
  - Red
  - Orange
  - Purple

Java code:

import java.util.ResourceBundle;
import net.rakugakibox.util.YamlResourceBundle;

public class YamlResourceBundleExample {

    public static void main(String[] args) {

        // Specify the "YamlResourceBundle.Control.INSTANCE" to "ResourceBundle.Control".
        ResourceBundle r = ResourceBundle.getBundle(
                "net.rakugakibox.util.YamlResourceBundleExample.example",
                YamlResourceBundle.Control.INSTANCE
        );

        // Support the "ResourceBundle#getString(String)" for yaml string.
        System.out.println(r.getString("fruits.apple"));    // => "Apple"
        System.out.println(r.getString("fruits.orange"));   // => "Orange"
        System.out.println(r.getString("fruits.grape"));    // => "Grape"

        // Support the "ResourceBundle#getString(String)" for yaml array.
        System.out.println(r.getString("colors[0]"));       // => "Red"
        System.out.println(r.getString("colors[1]"));       // => "Orange"
        System.out.println(r.getString("colors[2]"));       // => "Purple"

        // Support the "ResourceBundle#getStringArray(String)".
        for (String s : r.getStringArray("colors")) {
            System.out.println(s);
        }       // => "Red", "Orange", "Purple"

        // Support the "ResourceBundle#keySet()".
        for (String s: r.keySet()) {
            System.out.println(s);
        }       // => "fruits.apple", "fruits.orange", "fruits.grape",
                //    "colors[0]", "colors[1]", "colors[2]", "colors" (not sorted)

    }

}

License

Licensed under the Apache License, Version 2.0.