List of usage examples for javax.xml.stream XMLStreamReader hasName
public boolean hasName();
From source file:edu.indiana.d2i.htrc.portal.HTRCPersistenceAPIClient.java
private AlgorithmDetailsBean parseAlgorithmDetailBean(InputStream stream) throws XMLStreamException { AlgorithmDetailsBean res = new AlgorithmDetailsBean(); XMLStreamReader parser = factory.createXMLStreamReader(stream); List<AlgorithmDetailsBean.Parameter> parameters = new ArrayList<AlgorithmDetailsBean.Parameter>(); List<String> authors = new ArrayList<String>(); while (parser.hasNext()) { int event = parser.next(); if (event == XMLStreamConstants.START_ELEMENT) { if (parser.hasName()) { // only parse the info tag! if (parser.getLocalName().equals(AlgorithmDetailsBean.NAME)) { res.setName(parser.getElementText()); } else if (parser.getLocalName().equals(AlgorithmDetailsBean.VERSION)) { res.setVersion(parser.getElementText()); } else if (parser.getLocalName().equals(AlgorithmDetailsBean.DESCRIPTION)) { res.setDescription(parser.getElementText()); } else if (parser.getLocalName().equals(AlgorithmDetailsBean.SUPPORTURL)) { res.setSupportUrl(parser.getElementText()); } else if (parser.getLocalName().equals(AlgorithmDetailsBean.PARAMETER)) { AlgorithmDetailsBean.Parameter parameter = new AlgorithmDetailsBean.Parameter(); int count = parser.getAttributeCount(); for (int i = 0; i < count; i++) { if (parser.getAttributeLocalName(i).equals("required")) parameter.setRequired(Boolean.valueOf(parser.getAttributeValue(i))); if (parser.getAttributeLocalName(i).equals("type")) parameter.setType(parser.getAttributeValue(i)); if (parser.getAttributeLocalName(i).equals("name")) parameter.setName(parser.getAttributeValue(i)); if (parser.getAttributeLocalName(i).equals("defaultValue")) parameter.setDefaultValue(parser.getAttributeValue(i)); if (parser.getAttributeLocalName(i).equals("validation")) parameter.setValidation(parser.getAttributeValue(i)); if (parser.getAttributeLocalName(i).equals("validationError")) parameter.setValidationError(parser.getAttributeValue(i)); if (parser.getAttributeLocalName(i).equals("readOnly")) parameter.setReadOnly(Boolean.parseBoolean(parser.getAttributeValue(i))); }//w w w.j av a 2 s . c o m parser.nextTag(); if (parser.getLocalName().equals("label")) parameter.setLabel(parser.getElementText()); parser.nextTag(); if (parser.getLocalName().equals("description")) parameter.setDescription(parser.getElementText()); parameters.add(parameter); } else if (parser.getLocalName().equals(AlgorithmDetailsBean.AUTHOR)) { int count = parser.getAttributeCount(); for (int i = 0; i < count; i++) { if (parser.getAttributeLocalName(i).equals("name")) authors.add(parser.getAttributeValue(i)); } } } } } res.setParameters(parameters); res.setAuthors(authors); return res; }