aboutsummaryrefslogtreecommitdiff
path: root/examples/Translate.java
diff options
context:
space:
mode:
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");
+ }
}