use of javax.xml.stream.events.Attribute in project contribution by checkstyle.
the class CheckstyleConfigurationsParser method processPropertyTag.
/**
* Parses single "property" tag.
*
* @param startElement
* start element of the tag.
* @param parent
* parent module instance.
*/
private static void processPropertyTag(StartElement startElement, ConfigurationModule parent) {
String propertyName = null;
String propertyValue = null;
final Iterator<Attribute> attributes = startElement.getAttributes();
while (attributes.hasNext()) {
final Attribute attribute = attributes.next();
final String attributeName = attribute.getName().toString();
if (attributeName.equals(NAME_ATTR)) {
propertyName = attribute.getValue();
} else if (attributeName.equals(VALUE_ATTR)) {
propertyValue = attribute.getValue();
}
}
parent.addProperty(propertyName, propertyValue);
}
use of javax.xml.stream.events.Attribute in project contribution by checkstyle.
the class CheckstyleReportsParser method parseErrorTag.
/**
* Parses "error" XML tag.
*
* @param startElement
* cursor of StAX parser pointed on the tag.
* @param statistics
* container accumulating statistics.
* @param index
* internal index of the parsed file.
* @param filename
* file name.
* @return parsed data as CheckstyleRecord instance.
*/
private static CheckstyleRecord parseErrorTag(StartElement startElement, Statistics statistics, int index, String filename) {
int line = -1;
int column = -1;
String source = null;
String message = null;
String severity = null;
final Iterator<Attribute> attributes = startElement.getAttributes();
while (attributes.hasNext()) {
final Attribute attribute = attributes.next();
final String attrName = attribute.getName().toString();
switch(attrName) {
case LINE_ATTR:
line = Integer.parseInt(attribute.getValue());
break;
case COLUMN_ATTR:
column = Integer.parseInt(attribute.getValue());
break;
case SEVERITY_ATTR:
severity = attribute.getValue();
statistics.addSeverityRecord(severity, index);
break;
case MESSAGE_ATTR:
message = attribute.getValue();
break;
case SOURCE_ATTR:
source = attribute.getValue();
statistics.addModuleRecord(source, index);
break;
default:
break;
}
}
return new CheckstyleRecord(index, line, column, severity, source, message, filename);
}
use of javax.xml.stream.events.Attribute in project jvarkit by lindenb.
the class WorldMapGenome method loadWorld.
private void loadWorld() throws IOException, XMLStreamException {
Source source;
LOG.warning("openingg " + svgMapUri);
if (IOUtils.isRemoteURI(svgMapUri)) {
source = new StreamSource(svgMapUri);
} else {
source = new StreamSource(new File(svgMapUri));
}
XMLInputFactory xif = XMLInputFactory.newFactory();
XMLEventReader xef = xif.createXMLEventReader(source);
while (xef.hasNext()) {
XMLEvent evt = xef.nextEvent();
if (!evt.isStartElement()) {
continue;
}
StartElement E = evt.asStartElement();
String localName = E.getName().getLocalPart();
if (!localName.equals("path"))
continue;
Attribute att = E.getAttributeByName(new QName("id"));
if (att == null)
continue;
String country = att.getValue().toLowerCase().replaceAll("[ ]+", "");
att = E.getAttributeByName(new QName("d"));
if (att == null)
continue;
GeneralPath path = null;
char op = '\0';
Scanner scanner = new Scanner(att.getValue().replaceAll("[ \t\n\r,]+", " "));
path = new GeneralPath();
while (scanner.hasNext()) {
if (op == '\0') {
op = scanner.next().charAt(0);
}
switch(op) {
case 'M':
path.moveTo(scanner.nextDouble(), scanner.nextDouble());
break;
case 'C':
path.curveTo(scanner.nextDouble(), scanner.nextDouble(), scanner.nextDouble(), scanner.nextDouble(), scanner.nextDouble(), scanner.nextDouble());
break;
case 'Z':
{
path.closePath();
break;
}
default:
throw new IOException("bad operator " + op);
}
if (scanner.hasNext("[MCZ]")) {
op = scanner.next().charAt(0);
}
}
scanner.close();
this.country2shape.put(country, scaleWorld(path));
}
xef.close();
}
use of javax.xml.stream.events.Attribute in project jvarkit by lindenb.
the class NgsStage method loadSnippets.
protected List<SnippetCode> loadSnippets() {
final String rsrc = getSnippetResourcePath();
if (rsrc == null || rsrc.isEmpty())
return Collections.emptyList();
final List<SnippetCode> snippets = new ArrayList<>();
InputStream in = null;
XMLEventReader r = null;
try {
in = getClass().getResourceAsStream(rsrc);
if (in != null) {
final XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
r = xif.createXMLEventReader(in);
final QName isFunctionAtt = new QName("is-function");
final QName scopeAtt = new QName("scope");
final QName labelAtt = new QName("label");
final QName nameAtt = new QName("name");
while (r.hasNext()) {
final XMLEvent evt = r.nextEvent();
if (!evt.isStartElement())
continue;
final StartElement start = evt.asStartElement();
if (!start.getName().getLocalPart().equals("code"))
continue;
final Attribute isFunction = start.getAttributeByName(isFunctionAtt);
final Attribute scope = start.getAttributeByName(scopeAtt);
Attribute attLabel = start.getAttributeByName(labelAtt);
if (attLabel == null)
attLabel = start.getAttributeByName(nameAtt);
if (attLabel != null && r.hasNext() && r.peek().isCharacters()) {
final SnippetCode snippet = new SnippetCode();
snippet.label = attLabel.getValue();
snippet.code = r.nextEvent().asCharacters().getData();
snippet.function = isFunction != null && isFunction.getValue().equals("true");
snippet.scope = (scope == null ? "" : scope.getValue());
snippets.add(snippet);
}
}
} else {
LOG.warning("Cannot read snippets " + rsrc);
}
} catch (Exception err) {
LOG.warning(err.getMessage());
} finally {
CloserUtil.close(r);
CloserUtil.close(in);
}
return snippets;
}
use of javax.xml.stream.events.Attribute in project jvarkit by lindenb.
the class TreePackApp method parseNode.
private Node parseNode(XMLEventReader r, StartElement E, Node parent) throws XMLStreamException {
Node node = new Node(parent);
Attribute att = E.getAttributeByName(new QName("label"));
node.label = (att != null ? att.getValue() : "");
while (r.hasNext()) {
XMLEvent evt = r.nextEvent();
if (evt.isStartElement()) {
QName qName = evt.asStartElement().getName();
if (qName.getLocalPart().equals("node")) {
Node child = parseNode(r, evt.asStartElement(), node);
if (node.children == null)
node.children = new HashMap<String, Node>();
node.children.put(node.label, child);
} else {
skip(r);
}
} else if (evt.isEndElement()) {
if (node.children == null || node.children.isEmpty()) {
att = E.getAttributeByName(new QName("weight"));
if (att == null) {
node.weight = 1.0;
} else {
node.weight = Double.parseDouble(att.getValue());
if (node.weight <= 0)
throw new XMLStreamException("bad @weight:" + node.weight, E.getLocation());
}
}
return node;
}
}
throw new IllegalStateException();
}
Aggregations