From d23e26197c375071459bbd6c5aa3d09c27020c31 Mon Sep 17 00:00:00 2001 From: jestin Date: Tue, 1 Aug 2006 08:13:06 +0000 Subject: ajout d'un exemple --- examples/TranslateXML.java | 115 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 examples/TranslateXML.java (limited to 'examples/TranslateXML.java') diff --git a/examples/TranslateXML.java b/examples/TranslateXML.java new file mode 100644 index 0000000..b7ec8fb --- /dev/null +++ b/examples/TranslateXML.java @@ -0,0 +1,115 @@ +/** + * TranslateXML, an Ivy tranlater based on xml rules + * + * @author Yannick Jestin + * @author + * + * (c) CENA Centre d'Etudes de la Navigation Aerienne + * this program is LGPL ... etc etc + * + * New: + * 1.2.6 + * get compatible with new Ivy version + * 1.2.3 + * use of Vector.addElement instead of add() and the old Properties + * model + * + */ +import fr.dgac.ivy.* ; +import java.io.* ; +import net.n3.nanoxml.*; +import java.util.*; +import gnu.getopt.Getopt; + +class TranslateXML { + + private Ivy bus; + + TranslateXML(String domain, String name, String filename) throws IvyException { + bus = new Ivy(name,"Hello le monde",null); + parseFile(filename); + bus.bindMsg("^Bye$",new IvyMessageListener() { + // callback for "Bye" message + public void receive(IvyClient client, String[] args) {System.exit(0);} + }); + try { + // starts the bus on the default domain or IVY_DOMAIN property + bus.start(domain); + } catch (IvyException ie) { + System.err.println("can't run the Ivy bus" + ie.getMessage()); + } + } + + private void parseFile(String filename) { + try { + IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); + IXMLReader reader = StdXMLReader.fileReader(filename); + parser.setReader(reader); + IXMLElement xml = (IXMLElement) parser.parse(); + // checks if everything is OK + // XMLWriter writer = new XMLWriter(System.out); + // writer.write(xml); + Vector translations = xml.getChildrenNamed("translate"); + for (int i=0;i0)?args[0]:"")); + } catch (IvyException ie) { + } + } + + public static final String helpmsg = "usage: java TranslateXML [options]\n\t-f filename.xml\tspecifies the XML file with tranlations\n\t-b BUS\tspecifies the Ivy bus domain (can be overriden by XML file)\n\t-n ivyname (default TranslateXML)\n\t-d\tdebug\n\t-h\thelp\n"; + + public static void main(String args[]) throws IvyException { + Getopt opt = new Getopt("TranslateXML",args,"f:n:b:dht"); + int c; + String domain=Ivy.getDomain(null); + String name="TranslateXML"; + String filename="translation.xml"; + while ((c = opt.getopt()) != -1) switch (c) { + case 'f': + filename=opt.getOptarg(); + break; + case 'b': + domain=opt.getOptarg(); + break; + case 'n': + name=opt.getOptarg(); + break; + case 'd': + java.util.Properties sysProp = System.getProperties(); + sysProp.put("IVY_DEBUG","yes"); + break; + case 'h': + default: + System.out.println(helpmsg); + System.exit(0); + } // getopt + new TranslateXML(domain,name,filename); + } +} -- cgit v1.1