edu.uci.ics.jung.io.graphml.parser.StringElementParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jung-io Show documentation
Show all versions of jung-io Show documentation
IO support classes for JUNG
The newest version!
/*
* Copyright (c) 2008, The JUNG Authors
*
* All rights reserved.
*
* This software is open-source under the BSD license; see either
* "license.txt" or
* https://github.com/jrtom/jung/blob/master/LICENSE for a description.
*/
package edu.uci.ics.jung.io.graphml.parser;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.events.Characters;
import javax.xml.stream.events.EndElement;
import javax.xml.stream.events.StartElement;
import javax.xml.stream.events.XMLEvent;
import edu.uci.ics.jung.graph.Hypergraph;
import edu.uci.ics.jung.io.GraphIOException;
import edu.uci.ics.jung.io.graphml.ExceptionConverter;
/**
* Parses an element that just contains text.
*
* @author Nathan Mittler - [email protected]
*/
public class StringElementParser,V,E> extends AbstractElementParser {
public StringElementParser(ParserContext parserContext) {
super(parserContext);
}
public String parse(XMLEventReader xmlEventReader, StartElement start)
throws GraphIOException {
try {
String str = null;
while (xmlEventReader.hasNext()) {
XMLEvent event = xmlEventReader.nextEvent();
if (event.isStartElement()) {
// Parse the unknown element.
getUnknownParser().parse(xmlEventReader, event
.asStartElement());
} else if (event.isEndElement()) {
EndElement end = (EndElement) event;
verifyMatch(start, end);
break;
} else if (event.isCharacters()) {
Characters characters = (Characters) event;
str = characters.getData();
}
}
return str;
} catch (Exception e) {
ExceptionConverter.convert(e);
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy