There are multiple ways to parse a Mork database:
mork.MorkParser
and add your
mork.EventListener
to it. Use one of the parse() methods to start parsing a
resource containing your Mork database.
Your event listener will be notified for each parsed
item, which must then be parsed separately.
EventLister myHandler = ...;
MorkParser parser = new MorkParser();
parser.addEventListener(myHandler);
parser.parse(new File("abook.mab"));
Instantiate a
mork.MorkDocument
and use the load method to load your Mork database from
a resource. Then use the getters to access items such as
tables, rows or dictionaries.
Reader reader = new FileReader("abook.mab");
MorkDocument morkDocument = new MorkDocument(reader);
List<Dict> dicts = morkDocument.getDicts();
List<Row> rows= morkDocument.getRows();
The Mork library also provides some predefined implementations for Application-specific database formats, such as the Mozilla Thunderbird Address Book format.
InputStream inputStream = getClass().getResourceAsStream("/abook_single.mab")
AddressBook addressBook = new AddressBook();
addressBook.load(inputStream);
List<Address> addresses = addressBook.getAddresses();
If you wish to handle single Mork-entities on their own, separated from a whole database resource, you can do so by instantiate single entities.
Instantiating an entity such as a
mork.Dict
will automatically parse the syntax of the content,
including dereferencing object identifiers.
Dict dict = new Dict("< <a=c> (80=foo) >");
assertSame(ScopeTypes.COLUMN_SCOPE, dict.getDefaultScope());
assertEquals(1, dict.getAliasCount());
assertEquals("foo", dict.getValue("80"));
assertEquals("a", dict.getScopeName());
assertEquals("c", dict.getScopeValue());