package eu.simstadt.nf; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import org.xml.sax.helpers.DefaultHandler; /** * This SAX handler scans a nF XML status report instance and searches for the nF job id and the status of a * nF job. * * @author Marcel Bruse */ public class ReportHandler extends DefaultHandler { /** The XML tag which tells you the status of a nF export job. */ public static final String STATUS_TAG = "status"; /** The XML tag which tells you the status of a nF import job. */ public static final String RESULT_STATUS_TAG = "ResultStatus"; /** The XML attribute which tells you the status of a nF import job. */ public static final String STATUS_ATTRIBUTE = "status"; /** The XML tag which holds the id of the nF job. */ public static final String JOB_ID = "jobId"; /** If there was a problem on the nF server, then this XML tag gives you some hints. */ public static final String SERVICE_EXCEPTION_TAG = "ServiceException"; /** The id of the status of the nF job. */ public Integer statusId = null; /** The id of the nF job. */ public Integer jobId = null; /** If there was any problem, then you will find an exception message here. */ public String serviceException = null; /** Scanned string will be stored here temporarily. */ private String currentString; @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equalsIgnoreCase(RESULT_STATUS_TAG)) { statusId = Integer.valueOf(attributes.getValue(STATUS_ATTRIBUTE)); } } /** * If a tag has been read, its contents will be tested here. If it contains either a status id, job id or * service exception messege, then the contents will be stored in the appropriate member variable. */ @Override public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equalsIgnoreCase(STATUS_TAG)) { statusId = Integer.valueOf(currentString); } else if (qName.equalsIgnoreCase(SERVICE_EXCEPTION_TAG)) { serviceException = currentString; } else if (qName.equalsIgnoreCase(JOB_ID)) { jobId = Integer.valueOf(currentString); } } /** * The scanner of the XML document. * * @see DefaultHandler */ @Override public void characters(char[] ch, int start, int length) { currentString = new String(ch, start, length); } }