Commit b4402faa authored by Martin LOISEAU's avatar Martin LOISEAU 🎄
Browse files

Fix xml parser

parent 5ce9979e
......@@ -87,8 +87,6 @@ public class MainActivity extends AppCompatActivity {
SetUpListener();
Atoms = new ArrayList<Atom>();
Atoms.add(new ItemAtom(0));
EveryNode = new ArrayList<Node>();
OpenNodes = new ArrayList<Node>();
......@@ -105,7 +103,7 @@ public class MainActivity extends AppCompatActivity {
e.printStackTrace();
}
// OpenNodes.add(EveryNode.get(0));
OpenNodes.add(EveryNode.get(0));
}
public void CheckOpenNodes() {
......
......@@ -72,7 +72,7 @@ public class ScenarioLoader {
private ArrayList<Node> readList(XmlPullParser parser) throws IOException, XmlPullParserException {
ScenarioNodes = new ArrayList<Node>();
// s
parser.require(XmlPullParser.START_TAG, ns, "liste");
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
......@@ -85,7 +85,6 @@ public class ScenarioLoader {
Log.d("Debug2", "Node tag detected");
ScenarioNodes.add(readNode(parser));
Log.d("Debug2", "Added node to scenario");
} else {
throw new Error("A non-node tag was found in list. name: " + name);
}
......@@ -103,6 +102,7 @@ public class ScenarioLoader {
int ID = 0;
while (parser.next() != XmlPullParser.END_TAG) {
Log.d("Debug2", "Coucou");
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
......@@ -113,14 +113,17 @@ public class ScenarioLoader {
Log.d("Debug2", "ID read in XML: " + Integer.toString(ID));
} else if (name.equals("required_atoms")) {
Log.d("Debug2", "Conditions found in node " + Integer.toString(ID) + " in XML");
//Conditions = readAtoms(parser);
Conditions = readAtoms(parser);
} else if (name.equals("action_list")) {
Log.d("Debug2", "Actions found in node " + Integer.toString(ID) + " in XML");
//Actions = readActions(parser, ID);
Actions = readActions(parser, ID);
} else {
Log.d("Debug2", "Juste avant le throw error");
throw new Error("An unexpected tag was found in node " + Integer.toString(ID) + " XML definition");
}
Log.d("Debug2", "Coucou fin");
}
parser.require(XmlPullParser.END_TAG, ns, "node");
Log.d("Debug2", "finished reading node " + Integer.toString(ID) + ": " + Integer.toString(Conditions.size()) + " atoms and " + Actions.size() + " actions");
return new Node(mainActivity, ID, Actions, Conditions);
}
......@@ -129,31 +132,48 @@ public class ScenarioLoader {
parser.require(XmlPullParser.START_TAG, ns, "action_list");
ArrayList<Action> Actions = new ArrayList<Action>();
while (parser.next() != XmlPullParser.END_TAG) {
Log.d("Debug2", "readAction while loop begin");
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("AddAtom")) {
Log.d("Debug2", "action name read in xml: " + name);
if (name.equals("atom")) {
Log.d("Debug2", "AddAtom action tag detected");
Actions.add(new AddAtom(mainActivity, nodeID, readAtom(parser)));
Log.d("Debug2", "AddAtom action added");
// parser.next();
}
else if (name.equals("TTSReading")) {
Actions.add(new TTSReading(mainActivity, nodeID, readText(parser, "text_to_read")));
Log.d("Debug2", "TTSReading action tag detected");
Actions.add(new TTSReading(mainActivity, nodeID, readText(parser, "TTSReading")));
Log.d("Debug2", "TTSReading action added");
// parser.next();
}
else if (name.equals("ClearNodes")) {
Log.d("Debug2", "ClearNodes action tag detected");
Actions.add(new ClearNodes(mainActivity, nodeID));
parser.nextTag();
while (parser.next() != XmlPullParser.END_TAG);
Log.d("Debug2", "ClearNodes action added");
}
else if (name.equals("AddNode")) {
Actions.add(new AddNode(mainActivity, nodeID, readInt(parser, "node_id")));
Log.d("Debug2", "AddNode action tag detected");
Actions.add(new AddNode(mainActivity, nodeID, readInt(parser, "AddNode")));
Log.d("Debug2", "AddNode action added");
// parser.next();
} else {
throw new Error("Unexpected action tag found in node " + Integer.toString(nodeID) + " XML definition");
// skip(parser);
}
}
Log.d("Debug2", "end of readAction reading");
parser.require(XmlPullParser.END_TAG, ns, "action_list");
return Actions;
}
......@@ -175,29 +195,35 @@ public class ScenarioLoader {
return Atoms;
}
private Atom readAtom(XmlPullParser parser) throws IOException, XmlPullParserException {
parser.require(XmlPullParser.START_TAG, ns, "atom");
String type = "", Content = "";
while (parser.next() != XmlPullParser.END_TAG) {
Log.d("Debug2", "Begin atom while loop");
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("content")) {
Log.d("Debug2", "atom content tag detected in XML");
Content = readText(parser, "content");
Log.d("Debug2", "atom ID read in XML: " + Content);
Log.d("Debug2", "atom content read in XML: " + Content);
} else if (name.equals("type")) {
Log.d("Debug2", "atom type tag detected in XML");
type = readText(parser, "type");
Log.d("Debug2", "atom type read in XML: " + type);
}
else
{
throw new Error("An unexpected tag was found in an atom definition (other than type or content)");
}
Log.d("Debug2", "End atom while loop");
}
parser.require(XmlPullParser.END_TAG, ns, "atom");
if(type.equals("QRAtom")) return new QRAtom(Content);
else if(type.equals("SpeechAtom")) return new SpeechAtom(Content);
else return new ItemAtom(Integer.parseInt(Content));
......
......@@ -7,19 +7,13 @@
</required_atoms>
<action_list>
<TTSReading>
<text_to_read>Bonjour<text_to_read>
</TTSReading>
<TTSReading>Bonjour</TTSReading>
<ClearNodes> </ClearNodes>
<AddAtom>
<atom>
<type>ItemAtom</type>
<content>12</content>
</atom>
</AddAtom>
<AddNode>
<node_id>24</node_id>
</AddNode>
<atom>
<type>ItemAtom</type>
<content>12</content>
</atom>
<AddNode>24</AddNode>
</action_list>
</node>
......@@ -31,16 +25,11 @@
<type>ItemAtom</type>
<content>12</content>
</atom>
<atom>
<type>QRAtom</type>
<content>13</content>
</atom>
</required_atoms>
<action_list>
<TTSReading>
<text_to_read>Au revoir<text_to_read>
</TTSReading>
<TTSReading>Au revoir</TTSReading>
<ClearNodes></ClearNodes>
</action_list>
</node>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment