Skip to content

Commit a82a198

Browse files
committed
FINAL GOTO IN SAME VXML FILE
1 parent a2d7d0b commit a82a198

File tree

5 files changed

+35
-48
lines changed

5 files changed

+35
-48
lines changed

voicextt/src/main/java/com/sdiawara/voicextt/FormInterpretationAlgorithm.java

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public void run() {
226226
try {
227227
collect();
228228
} catch (VoiceXTTException e) {
229+
System.err.println("* "+ e +" *"+((GotoException)e).getGoto().getNext()+"=next expr="+((GotoException)e).getGoto().getExpr());
229230
throw new RuntimeException(e);
230231
}
231232
}

voicextt/src/main/java/com/sdiawara/voicextt/Interpreter.java

+31-42
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import org.xml.sax.SAXException;
1010

1111
import com.sdiawara.voicextt.exception.GotoException;
12-
import com.sdiawara.voicextt.exception.VoiceXTTException;
13-
import com.sdiawara.voicextt.node.VoiceXmlNode;
1412
import com.sdiawara.voicextt.node.Vxml;
1513

1614
public class Interpreter {
@@ -24,62 +22,53 @@ public class Interpreter {
2422
public Interpreter(String startFileName) throws ParserConfigurationException, IOException, SAXException {
2523
this.interpreterContext = new InterpreterContext(startFileName); // session
2624
this.speaker = new Speaker(userInput);
27-
this.vxml = new Vxml(interpreterContext.getDocumentAcces().get(startFileName, null)
28-
.getDocumentElement());
29-
resetFia(vxml.getFirstDialog());
30-
}
31-
32-
private void resetFia(VoiceXmlNode dialog) throws IOException, SAXException {
33-
this.fia = new FormInterpretationAlgorithm(dialog, interpreterContext.getScripting(), outPut, userInput);
34-
UncaughtExceptionHandler eh = new UncaughtExceptionHandler() {
35-
36-
public void uncaughtException(Thread t, Throwable e) {
37-
Throwable exception = e.getCause();
38-
System.err.println(exception);
39-
if (exception instanceof GotoException) {
40-
String next = ((GotoException) exception).getGoto().getNext();
41-
String expr = ((GotoException) exception).getGoto().getExpr();
42-
if (next == null && expr == null) {
43-
throw new RuntimeException("Semantic error");
44-
}
45-
System.err.println(next);
46-
next = ((next == null) ? ((String) interpreterContext.getScripting().eval(expr)) : next);
47-
if (next.startsWith("#")) {
48-
System.err.println("next " + next.replace("#", "") + " fia is a live= " + fia.isAlive()
49-
+ "test isinterrupt " + t.isInterrupted());
50-
fia.setCurrentDialog(vxml.getDialogById(next.replace("#", "")));
51-
System.err.println("next " + next.replace("#", "") + " fia is a live= " + fia.isAlive()
52-
+ "test isinterrupt " + t.isInterrupted());
53-
fia.run();
54-
System.err.println("after fia is a live= " + fia.isAlive()
55-
+ "test isinterrupt " + t.isInterrupted());
56-
fia.setUncaughtExceptionHandler(this);
57-
}
58-
}
59-
}
60-
61-
};
62-
fia.setUncaughtExceptionHandler(eh);
25+
this.vxml = new Vxml(interpreterContext.getDocumentAcces().get(startFileName, null).getDocumentElement());
26+
this.fia = new FormInterpretationAlgorithm(vxml.getFirstDialog(), interpreterContext.getScripting(), outPut, userInput);
27+
FormInterpretationAlgorithm.setDefaultUncaughtExceptionHandler(getDefaultUncaughtExceptionHandler());
6328
}
6429

6530
public void start() throws IOException, SAXException {
66-
// if (!fia.isAlive()) {
6731
this.fia.start();
6832
waitSpeaker();
69-
System.err.println("fin");
70-
// }
7133
}
7234

7335
private void waitSpeaker() {
7436
try {
7537
fia.join();
7638
speaker.join();
7739
} catch (InterruptedException e) {
78-
// System.err.println(e);
40+
System.err.println(e);
7941
}
8042
}
8143

8244
public List<String> getPrompts() {
8345
return outPut.getTTS();
8446
}
47+
48+
private UncaughtExceptionHandler getDefaultUncaughtExceptionHandler() {
49+
return new UncaughtExceptionHandler() {
50+
public void uncaughtException(Thread t, Throwable e) {
51+
Throwable exception = e.getCause();
52+
if (exception instanceof GotoException) {
53+
String next = ((GotoException) exception).getGoto().getNext();
54+
String expr = ((GotoException) exception).getGoto().getExpr();
55+
if (next == null && expr == null) {
56+
throw new RuntimeException("Semantic error");
57+
}
58+
next = ((next == null) ? ((String) interpreterContext.getScripting().eval(expr)) : next);
59+
if (next.contains("#")) {
60+
fia = new FormInterpretationAlgorithm(vxml.getDialogById(next.replace("#", "")), interpreterContext.getScripting(), outPut,
61+
userInput);
62+
try {
63+
fia.start();
64+
Interpreter.this.waitSpeaker();
65+
} catch (Exception e1) {
66+
System.err.println(e1);
67+
}
68+
}
69+
}
70+
}
71+
72+
};
73+
}
8574
}

voicextt/src/test/java/com/sdiawara/voicextt/FormInterpretationAlgorithmTest.java

-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ public void blockVisitor() throws ParserConfigurationException, IOException, SAX
7878
fia.initialize();
7979
fia.setSelectedFormItem(fia.select());
8080
fia.collect();
81-
//goto nextItem
82-
8381
fia.setSelectedFormItem(fia.select());
8482
fia.collect();
8583

voicextt/src/test/java/com/sdiawara/voicextt/InterpreterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public void testSimple() throws ParserConfigurationException, IOException, SAXEx
3030
assertEquals("simple prompt in block 3", interpreter.getPrompts().get(3));
3131
assertEquals("simple prompt in block 4", interpreter.getPrompts().get(4));
3232
assertEquals("simple prompt in block 5", interpreter.getPrompts().get(5));
33-
// assertEquals("simple prompt in another form", interpreter.getPrompts().get(6));
33+
//assertEquals("simple prompt in another form", interpreter.getPrompts().get(6));
3434
}
3535
}

voicextt/src/test/java/vxml/simple.vxml

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727
<form id="test">
2828
<block name="toto">
2929
<prompt>simple prompt in block 4</prompt>
30-
<prompt>simple prompt in block 5</prompt>
31-
<goto next="#test1"/>
30+
<goto expr="'#test1'"/>
3231
</block>
3332
</form>
3433
<form id="test1">
35-
<block name="toto2">
34+
<block name="toto">
3635
<prompt>simple prompt in block 5</prompt>
3736
</block>
3837
</form>

0 commit comments

Comments
 (0)