Look at the code snippet below, this is just enough to pump
internationalized tips into user interface, according to the selected locale.
Meta[] tips = meta.getMetaArray("tips/tip", locale); for (Meta tip : tips) { String title = tip.getStringAttribute("title"); String text = tip.getString(); JEditorPane tipPane = new JEditorPane("text/html", text); tipPane.setEditable(false); tipsPane.addTab(title, tipPane); }This snippet is from tutor/meta/Brief.java
And the XML content for default locale is like this:
<tips> <tip title="Tips"> <![CDATA[ In this panel you get tips about how to play with this demo, see other tips under each Tab. <br> Tip tabs here are populated by meta array <code>tips/tip</code> inside <code>tutor/meta/Brief.meta</code> ]]> </tip> <tip title="Navigating"> ..... ..... ..... ..... ..... ..... ..... ..... <tip title="Hot Reloading"> <![CDATA[ If you are running this demo locally, try add, remove, or modify those <em>.meta</em> files in local classpath, then press <b>[Reload MetaBundles]</b> button. You'll see your changes take effect immediately.]]> </tip> </tips>This snippet is from tutor/meta/Brief.meta
Let's look at the first line of code:
Meta[] tips = meta.getMetaArray("tips/tip", locale);
"tips/tip" is the essential XPath expression to fetch all
the tip nodes as an array of Meta objects.
Then tip.getStringAttribute("title") will get a tip
node's title attribute, and tip.getString() will get
all XML text nested inside this tip node.
String title = tip.getStringAttribute("title");
String text = tip.getString();
The rest code just construct a JEditorPane
to render the tip text as html, and add it to the JTabbedPane
tipsPane.