Document pollDoc;
try {
pollDoc = XmlUtil.getDomFromInputStream(mPollDocument.getInputStream());
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new ToxicityException(pIn, e);
}
//
// increase count on selected item (if any)
//
XPath xpath = XmlUtil.newXPath();
xpath.setNamespaceContext(new NamespaceContext("http://toxicity.sf.net/ns/examples/nuke/poll", "p"));
if(mSelectedPollItem != null) {
Element pollItem = pollDoc.getElementById(mSelectedPollItem);
try {
pollItem = (Element) xpath.evaluate("/p:poll-collection/p:poll/p:item[@id='" + mSelectedPollItem + "']",
pollDoc, XPathConstants.NODE);
} catch (XPathExpressionException e) {
log.error(e.getMessage(), e);
throw new ToxicityException(pIn, e);
}
String scount = pollItem.getAttribute("count");
int count = Integer.parseInt(scount);
pollItem.setAttribute("count", String.valueOf(count+1));
}
//
// return the requested poll
//
// 1) import all nodes of the selected poll
// 2) hide actual poll result until the user submited an option
// if this example would be productive you could also make this
// decisions based on a ip-addrr. mapping or on the user session
//
Document ret = XmlUtil.getNewDocument();
Element pollRoot = null;
try {
pollRoot = (Element) xpath.evaluate("/p:poll-collection/p:poll[@id='" + mPollId + "']",
pollDoc, XPathConstants.NODE);
} catch (XPathExpressionException e) {
log.error(e.getMessage(), e);
throw new ToxicityException(pIn, e);
}
pollRoot = (Element)ret.importNode(pollRoot, true);
if(mSelectedPollItem == null) {
NodeList nl = pollRoot.getChildNodes();