aboutsummaryrefslogtreecommitdiff
path: root/examples/Translate.java
diff options
context:
space:
mode:
authorjestin2004-07-27 16:21:24 +0000
committerjestin2004-07-27 16:21:24 +0000
commit9ab98e8b79688821f85649fa3a04137f83467b73 (patch)
treeec55f2feb85355cadaf901bd561cd37444ae83ba /examples/Translate.java
parent9eff9570e518daccec02dd62593294341f4c36b6 (diff)
downloadivy-java-9ab98e8b79688821f85649fa3a04137f83467b73.zip
ivy-java-9ab98e8b79688821f85649fa3a04137f83467b73.tar.gz
ivy-java-9ab98e8b79688821f85649fa3a04137f83467b73.tar.bz2
ivy-java-9ab98e8b79688821f85649fa3a04137f83467b73.tar.xz
clean up the examples to abide to the new API
Diffstat (limited to 'examples/Translate.java')
-rw-r--r--examples/Translate.java37
1 files changed, 25 insertions, 12 deletions
diff --git a/examples/Translate.java b/examples/Translate.java
index 738443c..43ed82f 100644
--- a/examples/Translate.java
+++ b/examples/Translate.java
@@ -5,16 +5,19 @@
*
* (c) CENA
*
+ * 1.2.6
+ * - goes apache jakarta regexp
+ *
*/
import fr.dgac.ivy.* ;
import java.io.* ;
-import gnu.regexp.* ;
+import org.apache.regexp.* ;
class Translate {
private Ivy bus;
- Translate(String filename) {
+ Translate(String filename) throws IvyException {
bus = new Ivy("Translater","Hello le monde",null);
parseFile(filename);
bus.bindMsg("^Bye$",new IvyMessageListener() {
@@ -33,16 +36,18 @@ class Translate {
try {
BufferedReader in = new BufferedReader(new FileReader(new File(filename)));
String s;
- RE regexp;
- regexp = new RE("\"([^\"]*)\" \"([^\"]*)\"");
+ RE re = new RE("\"([^\"]*)\" \"([^\"]*)\"");
while ( (s=in.readLine()) != null ) {
- REMatch result = regexp.getMatch(s);
- bus.bindMsg(result.toString(1),new TALK(result.toString(2)));
+ if (re.match(s)) {
+ System.out.println("binding " +re.getParen(1)+" and translating to " + re.getParen(2));
+ try {
+ bus.bindMsg(re.getParen(1),new TALK(re.getParen(2)));
+ } catch (IvyException ie) {
+ System.out.println(re.getParen(1)+" is not a valid PCRE regex");
+ }
+ }
}
in.close();
- } catch (REException ree) {
- System.out.println("regexp error");
- System.exit(-1);
} catch (FileNotFoundException fnfe) {
System.out.println("file "+filename+" not found. Good bye !");
System.exit(-1);
@@ -56,13 +61,21 @@ class Translate {
private String go;
TALK(String s) {go=s;}
public void receive(IvyClient client, String[] args) {
- bus.sendMsg(go);
+ try {
+ bus.sendMsg(go);
+ } catch (IvyException ie) {
+ }
}
}
public void receive(IvyClient client, String[] args) {
- bus.sendMsg("Bonjour"+((args.length>0)?args[0]:""));
+ try {
+ bus.sendMsg("Bonjour"+((args.length>0)?args[0]:""));
+ } catch (IvyException ie) {
+ }
}
- public static void main(String args[]) { new Translate("translation.txt"); }
+ public static void main(String args[]) throws IvyException {
+ new Translate("translation.txt");
+ }
}