List of usage examples for javax.xml.stream XMLStreamReader hasName
public boolean hasName();
From source file:Main.java
private static void printName(XMLStreamReader xmlr, StringBuffer b) { if (xmlr.hasName()) { String prefix = xmlr.getPrefix(); String uri = xmlr.getNamespaceURI(); String localName = xmlr.getLocalName(); printName(prefix, uri, localName, b); }//from w w w . j a v a 2 s. c o m }
From source file:Main.java
private static void printName(XMLStreamReader xmlr, StringBuffer result) { if (xmlr.hasName()) { String prefix = xmlr.getPrefix(); String uri = xmlr.getNamespaceURI(); String localName = xmlr.getLocalName(); printName(prefix, uri, localName, result); }/* ww w . j a v a 2 s .c o m*/ }
From source file:Main.java
private static void printName(XMLStreamReader xmlr, int eventType) { if (xmlr.hasName()) { System.out.println("HAS NAME: " + xmlr.getLocalName()); } else {//from w ww.j a va 2s .c o m System.out.println("HAS NO NAME"); } }
From source file:Main.java
/** * Advance the reader to the next element after start element and return true. * Return false if next start element is not found * @param reader a XMLStreamReader//w w w . j a v a 2 s. co m * @param startElement Name of the start element. * @return True when successfully advanced the reader. * @throws XMLStreamException Exception when reading from the XMLStreamReader fails. */ public static boolean advanceToAfterStartElement(XMLStreamReader reader, String startElement) throws XMLStreamException { while (!(reader.getEventType() == XMLStreamConstants.START_ELEMENT && reader.hasName() && reader.getLocalName().equalsIgnoreCase(startElement))) { //String name = (reader.hasName()? reader.getLocalName() : ""); if (reader.hasNext()) { reader.next(); } else { // reach the end of elements in reader. Not found. return false; } } // found the startElement. Consume that start element also if (reader.hasNext()) { reader.next(); return true; } return false; }
From source file:edu.utah.further.core.api.xml.XmlUtil.java
/** * @param xmlReader/*from w ww .j a v a 2 s . co m*/ */ private static void printName(final PrintStream os, final XMLStreamReader xmlReader) { if (xmlReader.hasName()) { os.print(getName(xmlReader)); } }
From source file:edu.utah.further.core.api.xml.XmlUtil.java
/** * @param xmlReader//from w w w .java 2 s . c o m * @return */ public static String getName(final XMLStreamReader xmlReader) { if (xmlReader.hasName()) { final String prefix = xmlReader.getPrefix(); final String uri = xmlReader.getNamespaceURI(); final String localName = xmlReader.getLocalName(); return getName(prefix, uri, localName); } return null; }
From source file:edu.stanford.cfuller.colocalization3d.correction.Correction.java
/** * Reads a stored correction from disk./*from w w w . ja v a2 s. c o m*/ * * @param filename The name of the file containing the Correction that was previously written to disk. * @return The Correction contained in the file. * @throws java.io.IOException if the Correction cannot be successfully read. * @throws ClassNotFoundException if the file does not contain a Correction. */ public static Correction readFromDisk(String filename) throws java.io.IOException, ClassNotFoundException { File f = new File(filename); FileReader fr = new FileReader(f); XMLStreamReader xsr = null; String encBinData = null; try { xsr = XMLInputFactory.newFactory().createXMLStreamReader(fr); while (xsr.hasNext()) { int event = xsr.next(); if (event != XMLStreamReader.START_ELEMENT) continue; if (xsr.hasName() && xsr.getLocalName() == BINARY_DATA_ELEMENT) { encBinData = xsr.getElementText(); break; } } } catch (XMLStreamException e) { java.util.logging.Logger.getLogger(LOG_NAME) .severe("Exception encountered while reading XML correction: " + e.getMessage()); } byte[] binData = (new HexBinaryAdapter()).unmarshal(encBinData); ObjectInputStream oi = new ObjectInputStream(new ByteArrayInputStream(binData)); Object o = oi.readObject(); return (Correction) o; }
From source file:edu.indiana.d2i.htrc.portal.HTRCAgentClient.java
private boolean parseJobDeleteResponse(InputStream stream) throws XMLStreamException { XMLStreamReader parser = factory.createXMLStreamReader(stream); while (parser.hasNext()) { int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT) { if (parser.hasName()) { String localName = parser.getLocalName(); if (localName.equals("success")) return true; else { log.error(parser.getElementText()); return false; }/*from w ww.j av a 2s. com*/ } } } return false; }
From source file:edu.indiana.d2i.htrc.portal.HTRCAgentClient.java
private JobDetailsBean parseJobSubmit(InputStream stream) throws XMLStreamException { JobDetailsBean res = new JobDetailsBean(); XMLStreamReader parser = factory.createXMLStreamReader(stream); while (parser.hasNext()) { int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT) { if (parser.hasName()) { // only parse several attributes if (parser.getLocalName().equals(JobDetailsBean.STATUS)) { res.setJobStatus(parser.getAttributeValue(0)); } else if (parser.getLocalName().equals(JobDetailsBean.JOBID)) { res.setJobId(parser.getElementText()); } else if (parser.getLocalName().equals(JobDetailsBean.JOBNAME)) { res.setJobTitle(parser.getElementText()); } else if (parser.getLocalName().equals(JobDetailsBean.DATE)) { res.setLastUpdatedDate(parser.getElementText()); } else if (parser.getLocalName().equals(JobDetailsBean.USER)) { res.setUserName(parser.getElementText()); }//from w w w .j a v a2 s .com } } } return res; }
From source file:edu.indiana.d2i.htrc.portal.HTRCAgentClient.java
private Map<String, JobDetailsBean> parseJobDetailBeans(InputStream stream) throws XMLStreamException { Map<String, JobDetailsBean> res = new TreeMap<String, JobDetailsBean>(); XMLStreamReader parser = factory.createXMLStreamReader(stream); while (parser.hasNext()) { int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT) { if (parser.hasName()) { if (parser.getLocalName().equals("job_status")) { // one job status JobDetailsBean detail = new JobDetailsBean(); Map<String, String> jobParams = new HashMap<String, String>(); Map<String, String> results = new HashMap<String, String>(); int innerEvent = parser.next(); while (true) { if (innerEvent == XMLStreamConstants.END_ELEMENT && parser.getLocalName().equals("job_status")) { break; }/*from w w w .ja v a 2 s .c om*/ if (innerEvent == XMLStreamConstants.START_ELEMENT && parser.hasName()) { // single tag if (parser.getLocalName().equals("job_name")) { detail.setJobTitle(parser.getElementText()); } else if (parser.getLocalName().equals("user")) { detail.setUserName(parser.getElementText()); } else if (parser.getLocalName().equals("algorithm")) { detail.setAlgorithmName(parser.getElementText()); } else if (parser.getLocalName().equals("job_id")) { detail.setJobId(parser.getElementText()); } else if (parser.getLocalName().equals("date")) { detail.setLastUpdatedDate(parser.getElementText()); } // parameters if (parser.hasName() && parser.getLocalName().equals(JobDetailsBean.ONEPARAM)) { String name, value; name = value = ""; for (int i = 0; i < 3; i++) { if (parser.getAttributeName(i).toString().equals("name")) name = parser.getAttributeValue(i); if (parser.getAttributeName(i).toString().equals("value")) value = parser.getAttributeValue(i); } jobParams.put(name, value); } // status if (parser.hasName() && parser.getLocalName().equals(JobDetailsBean.STATUS)) { String status = parser.getAttributeValue(0); detail.setJobStatus(status); } // results if (parser.hasName() && parser.getLocalName().equals(JobDetailsBean.RESULT)) { String name = parser.getAttributeValue(0); String value = parser.getElementText(); results.put(name, value); } // message if (parser.hasName() && parser.getLocalName().equals(JobDetailsBean.MESSAGE)) { detail.setMessage(parser.getElementText()); } // saved or unsaved if (parser.hasName() && parser.getLocalName().equals(JobDetailsBean.SAVEDORNOT)) { detail.setJobSavedStr(parser.getElementText()); } } innerEvent = parser.next(); } detail.setJobParams(jobParams); detail.setResults(results); res.put(detail.getJobId(), detail); } } } } return res; }