Search in sources :

Example 51 with Attribute

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);
    }
}
Also used : Attribute(javax.xml.stream.events.Attribute) EndElement(javax.xml.stream.events.EndElement) StartElement(javax.xml.stream.events.StartElement) Iterator(java.util.Iterator) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 52 with Attribute

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;
}
Also used : Attribute(javax.xml.stream.events.Attribute)

Example 53 with Attribute

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;
}
Also used : Attribute(javax.xml.stream.events.Attribute) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader)

Example 54 with Attribute

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;
}
Also used : Attribute(javax.xml.stream.events.Attribute)

Example 55 with Attribute

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;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Attribute(javax.xml.stream.events.Attribute) Sememe(ruc.irm.similarity.word.hownet2.sememe.Sememe) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) GZIPInputStream(java.util.zip.GZIPInputStream) StartElement(javax.xml.stream.events.StartElement) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) XMLInputFactory(javax.xml.stream.XMLInputFactory)

Aggregations

Attribute (javax.xml.stream.events.Attribute)144 QName (javax.xml.namespace.QName)73 StartElement (javax.xml.stream.events.StartElement)63 XMLEvent (javax.xml.stream.events.XMLEvent)54 XMLEventReader (javax.xml.stream.XMLEventReader)30 EndElement (javax.xml.stream.events.EndElement)26 Namespace (javax.xml.stream.events.Namespace)26 ArrayList (java.util.ArrayList)23 XMLStreamException (javax.xml.stream.XMLStreamException)20 XMLInputFactory (javax.xml.stream.XMLInputFactory)18 InputStream (java.io.InputStream)14 IOException (java.io.IOException)12 Iterator (java.util.Iterator)11 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 HashSet (java.util.HashSet)6 Characters (javax.xml.stream.events.Characters)6 QNm (org.brackit.xquery.atomic.QNm)5