- Swush -- Overview Swush (pronounce s-woo-sh) is a simple data exchange language that is designed to be easy for people to read and manipulate (unlike XML, which is designed to be difficult for both people and for machines) A Swush file can be as simple as a key:value list, or a complex nested structure. -- Specification Swush ignore whitespaces. Each node is a list of Swush elements, each element can be: 1. a key-value pair, for example, this the following line key is format and the value is %s%t : format:%s%t 2. a String, for example, the following node is named drinks and contains 3 string elements: drinks{ Coffee Tea "Bloody marry" } 3. a name followed by a swush node inside curly brackets, fow example - the following swush node is named server, and contains a key:value pair: server{ host:localhost } A swush file must begin with an header line: @swush 1.0 encoding where encoding is optional and is the encoding of the file (default is utf-8) -- Comments Swush supports two types of comments: 1. C Multiline comments, for example: /* a multil line comment */ 2. C++/Bash style single line comments, for example: // Single line comment # Another single line comment key:value # Trailing single line comment -- Selectors Swush implementation supports a simple selector language that allow the user to easily access nested nodes. for example, given supposed we have the following swush file: @swush 1.0 addressbook{ entry{ name: "John dog" email: dog@john.com } entry{ name: "Jane bitch" email: jane@bitch.org } } the following selector will select the two entries: addressbook.entry an empty selector matches all the nodes in the root of the file. in the future, it's possible that the selectors language will become more powerful. -- Java Implementation The Java implmentation is released under the BSD license. Usage example: java -jar swush-x.y.jar swush.file selector Programmatic usage example: public class Example { public static void main(String[] args) throws SwushException, IOException { // You can construct a swush object in several ways: // by parsing a file Swush fromFile = new Swush(new File("test-data/test1/file.swush")); // straight from a string Swush fromString = Swush.fromString("swush:rocks node{a:b}"); // programatically Swush root = Swush.node("node1"); root.addPair("key","value"); Swush node2 = root.addNode("node2"); node2.addPair("key", "value1"); node2.addPair("key", "value2"); node2.addArray("array", "a", "b", "c"); // This will select the two key-value nodes and the array node in node2: List selected = root.select("node2.key"); // Selects the first key in node2 Swush first = root.selectFirst("node2.key"); // Selects the value of the first node2.key element ("value1") String value = root.selectProperty("node2.key"); } }