builder.setParser(parser);
// get the message and parse
String msgText = ((TextMessage) message).getText();
parser.parse(new InputSource(new StringReader(msgText)));
XmlDocument doc = (XmlDocument) builder.getDocument();
Element root = doc.getDocumentElement();
if (root.getAttribute("message").equalsIgnoreCase("quit")) {
synchronized(this) {
quit = true;
this.notifyAll(); // Notify main thread to quit
}
} else {
System.out.println("\n\nYou have a message in you inbox!");
System.out.println("From: "+ root.getAttribute("sender"));
System.out.println("Message: "+ root.getAttribute("message"));
System.out.println("Status of message: "+ root.getAttribute("status"));
if (root.getAttribute("status").equals("pending approval")) {
boolean approved = false;
boolean denied = false;
do {
System.out.print("Approve (\"yes\" or \"no\"): ");
BufferedReader msgStream = new BufferedReader(new InputStreamReader(System.in));
String line=null;
line = msgStream.readLine();
if (line != null && line.trim().length() != 0) {
approved = line.equalsIgnoreCase("yes");
denied = line.equalsIgnoreCase("no");
if (approved || denied) {
msg.setStringProperty("messageTo", root.getAttribute("sender"));
// update the original xml doc
root.setAttribute("status", approved ? "approved" : "approval denied");
root.setAttribute("sender", "Admin");
// send xml doc back to JMS queue
StringWriter sw = new StringWriter();
doc.write(sw);
msg.setText(sw.toString());
System.out.println("Message status updated. Returning message to sender.");
qsender.send(msg);
}
}