use of javax.xml.stream.events.Attribute in project structr by structr.
the class XMLHandler method startElement.
public void startElement(final StartElement element) {
final String tagName = element.getName().toString();
current = new Element(current, tagName);
final Map<String, Object> typeHandler = (Map) configuration.get(current.getPath());
if (typeHandler != null) {
final Map<String, Object> properties = (Map) typeHandler.get(PROPERTIES);
final String action = (String) typeHandler.get(ACTION);
final Object isRoot = typeHandler.get(ISROOT);
final Map<String, Object> data = new LinkedHashMap<>();
current.isRoot = Boolean.TRUE.equals(isRoot);
// only process attributes if createNode is selected,
if (CREATE_NODE.equals(action)) {
for (final Iterator it = element.getAttributes(); it.hasNext(); ) {
final Object attr = it.next();
if (attr instanceof Attribute) {
final Attribute attribute = (Attribute) attr;
final String name = attribute.getName().toString();
final String value = attribute.getValue();
if (properties != null && properties.containsKey(name)) {
final String mappedName = (String) properties.get(name);
data.put(mappedName, value);
} else {
data.put(name, value);
}
}
}
}
current.setData(data);
}
}
use of javax.xml.stream.events.Attribute in project rpki-validator-3 by RIPE-NCC.
the class RrdpParser method getAttr.
private String getAttr(final StartElement startElement, final String attrName) {
final Iterator<?> attributes = startElement.getAttributes();
while (attributes.hasNext()) {
final Attribute next = (Attribute) attributes.next();
final String name = next.getName().getLocalPart();
if (attrName.equals(name)) {
return next.getValue();
}
}
return null;
}
use of javax.xml.stream.events.Attribute in project service-proxy by membrane.
the class WSDLUtil method getXSDs.
public static List<String> getXSDs(String wsdl) throws XMLStreamException {
List<String> result = new ArrayList<String>();
XMLEventReader parser;
synchronized (xmlInputFactory) {
parser = xmlInputFactory.createXMLEventReader(new StringReader(wsdl));
}
while (parser.hasNext()) {
XMLEvent event = parser.nextEvent();
if (event.isStartElement()) {
String name = event.asStartElement().getName().getLocalPart();
if (name.equals("import") || name.equals("include")) {
Attribute a = event.asStartElement().getAttributeByName(new QName("schemaLocation"));
if (a != null)
result.add(a.getValue());
}
}
}
return result;
}
use of javax.xml.stream.events.Attribute in project LibreraReader by foobnix.
the class StreamReader method build.
/**
* This is used to build the attributes that are to be used to
* populate the start event. Populating the start event with the
* attributes it contains is required so that each element will
* contain its associated attributes. Only attributes that are
* not reserved will be added to the start event.
*
* @param event this is the start event that is to be populated
*
* @return this returns a start event with its attributes
*/
private Start build(Start event) {
Iterator<Attribute> list = event.getAttributes();
while (list.hasNext()) {
Attribute node = list.next();
Entry entry = attribute(node);
if (!entry.isReserved()) {
event.add(entry);
}
}
return event;
}
use of javax.xml.stream.events.Attribute in project xsimilarity by iamxiatian.
the class SememeTreeUI method load.
/**
* 加载义原到Multimap中,并创建树的节点
*
* @return
* @throws IOException
*/
private static DefaultMutableTreeNode load() throws IOException {
/**
* 存放parentId和该parentId所隶属的义原,即Key为parentId,value为子义原
*/
Multimap<String, Sememe> sememes = ArrayListMultimap.create();
logger.info("Try to load hownet/sememe.xml.gz from resources");
InputStream input = SememeTreeUI.class.getResourceAsStream("/data/sememe.xml.gz");
input = new GZIPInputStream(input);
System.out.println("[" + SememeTreeUI.class.getSimpleName() + "]loading sememes into sememe tree...");
long time = System.currentTimeMillis();
try {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLEventReader xmlEventReader = inputFactory.createXMLEventReader(input);
while (xmlEventReader.hasNext()) {
XMLEvent event = xmlEventReader.nextEvent();
if (event.isStartElement()) {
StartElement startElement = event.asStartElement();
if (startElement.getName().toString().equals("sememe")) {
String en = startElement.getAttributeByName(QName.valueOf("en")).getValue();
String cn = startElement.getAttributeByName(QName.valueOf("cn")).getValue();
String id = startElement.getAttributeByName(QName.valueOf("id")).getValue();
Attribute attr = startElement.getAttributeByName(QName.valueOf("define"));
String define = (attr == null ? null : attr.getValue());
Sememe sememe = new Sememe(id, en, cn, define);
int pos = id.lastIndexOf("-");
String parentId = "root";
if (pos > 0) {
parentId = id.substring(0, pos);
}
sememes.put(parentId, sememe);
}
}
}
input.close();
} catch (Exception e) {
throw new IOException(e);
}
time = System.currentTimeMillis() - time;
System.out.println("complete. time elapsed: " + (time / 1000) + "s");
DefaultMutableTreeNode top = new DefaultMutableTreeNode("知网义原层次关系树");
createNodes(sememes, top, "root");
return top;
}
Aggregations