Example usage for org.jdom2 Element getName

List of usage examples for org.jdom2 Element getName

Introduction

In this page you can find the example usage for org.jdom2 Element getName.

Prototype

public String getName() 

Source Link

Document

Returns the (local) name of the element (without any namespace prefix).

Usage

From source file:nz.ac.massey.cs.guery.adapters.jungalt.io.graphml.GraphMLReader.java

License:Apache License

@Override
public synchronized DirectedGraph<V, E> readGraph() throws GraphIOException {

    Map<String, V> vertices = new HashMap<String, V>();
    Map<String, E> edges = new HashMap<String, E>();
    // parse//from  w  ww.  ja  v  a2s. co m
    SAXBuilder builder = new SAXBuilder();
    try {
        Namespace NS_GRAPHML = Namespace.getNamespace("http://graphml.graphdrawing.org/xmlns");
        Document doc = builder.build(reader);
        Element root = doc.getRootElement();
        assert "graphml".equals(root.getName());
        Element eGraph = root.getChild("graph", NS_GRAPHML);
        for (Object o : eGraph.getChildren("node", NS_GRAPHML)) {
            if (o instanceof Element) {
                buildVertex(vertices, (Element) o);
            }
        }
        for (Object o : eGraph.getChildren("edge", NS_GRAPHML)) {
            if (o instanceof Element) {
                E e = buildEdge(vertices, (Element) o);
                if (edges.containsKey(e.getId())) {
                    throw new GraphIOException(
                            "There are two edges with the same id " + e.getId() + " in the graph");
                }
                edges.put(e.getId(), e);
            }
        }

        // during parsing, composite edges can be created which replace simple edges, those simple edges must be removed from the buffer
        Collection<CompositeEdge<E>> composites = new HashSet<CompositeEdge<E>>();
        for (E e : edges.values()) {
            if (e instanceof CompositeEdge) {
                composites.add((CompositeEdge) e);
            }
        }
        // now remove 
        for (CompositeEdge<E> ce : composites) {
            Collection<E> parts = ce.getParts();
            for (E part : parts) {
                edges.remove(part.getId());
            }
        }

        // TODO: at this stage both the xml doc and the graph are in memory
        // we could gc the doc before we continue
        // build graph

    } catch (Exception e) {
        throw new GraphIOException(e);
    }
    DirectedGraph<V, E> graph = new DirectedSparseGraph<V, E>();
    for (V v : vertices.values()) {
        graph.addVertex(v);
    }
    for (E e : edges.values()) {
        graph.addEdge(e, e.getStart(), e.getEnd());
    }
    return graph;

}

From source file:open.dolphin.adm10.rest.AbstractResource.java

/**
 * ?????/*from  ww w.j av  a  2 s.c om*/
 * @param sb content??????StringBuilder
 * @param current XML?
 */
protected void writeChildren(StringBuilder sb, Element current) {

    int eType = -1;
    String eName = current.getName();

    if (eName.equals(PARAGRAPH_NAME)) {
        eType = TT_PARAGRAPH;
        startParagraph(sb, current.getAttributeValue(LOGICAL_STYLE_NAME),
                current.getAttributeValue(ALIGNMENT_NAME));

    } else if (eName.equals(CONTENT_NAME) && (current.getChild(TEXT_NAME) != null)) {
        eType = TT_CONTENT;
        startContent(sb, current.getAttributeValue(FOREGROUND_NAME), current.getAttributeValue(SIZE_NAME),
                current.getAttributeValue(BOLD_NAME), current.getAttributeValue(ITALIC_NAME),
                current.getAttributeValue(UNDERLINE_NAME), current.getChildText(TEXT_NAME));

    } else if (eName.equals(COMPONENT_NAME)) {
        eType = TT_COMPONENT;
        startComponent(sb, current.getAttributeValue(NAME_NAME), // compoenet=number
                current.getAttributeValue(COMPONENT_ELEMENT_NAME));

    } else if (eName.equals(ICON_NAME)) {
        eType = TT_ICON;
        startIcon(sb, current);

    } else if (eName.equals(PROGRESS_COURSE_NAME)) {
        eType = TT_PROGRESS_COURSE;
        startProgressCourse(sb);

    } else if (eName.equals(SECTION_NAME)) {
        eType = TT_SECTION;
        startSection(sb);

    } else {
        debug("Other element:" + eName);
    }

    //
    // ?: ????????
    //
    if (eType == TT_PARAGRAPH || eType == TT_PROGRESS_COURSE || eType == TT_SECTION) {

        java.util.List children = (java.util.List) current.getChildren();
        Iterator iterator = children.iterator();

        while (iterator.hasNext()) {
            Element child = (Element) iterator.next();
            writeChildren(sb, child);
        }
    }

    switch (eType) {

    case TT_PARAGRAPH:
        endParagraph(sb);
        break;

    case TT_CONTENT:
        endContent(sb);
        break;

    case TT_ICON:
        endIcon(sb);
        break;

    case TT_COMPONENT:
        endComponent(sb);
        break;

    case TT_PROGRESS_COURSE:
        endProgressCourse(sb);
        break;

    case TT_SECTION:
        endSection(sb);
        break;
    }
}

From source file:open.dolphin.impl.mml.MMLHelper23.java

/**
 * ?????/*from   www. j  av  a 2 s. c o  m*/
 */
private void parseChildren(Element current) {

    // Element???
    List children = current.getChildren();

    // Leaf ??
    if (children == null || children.isEmpty()) {
        return;
    }

    // ??
    for (Iterator iterator = children.iterator(); iterator.hasNext();) {

        Element child = (Element) iterator.next();
        //String qname = child.getQualifiedName();
        String ename = child.getName();
        //Namespace ns = child.getNamespace();
        //debug(ename);

        if (ename.equals("paragraph")) {
            // ????<xhtml:br/>??
            // ???????
            if (paragraphBuilder != null) {
                freeExp.append(paragraphBuilder.toString());
                freeExp.append("<xhtml:br/>\n");
            }
            paragraphBuilder = new StringBuilder();

        } else if (ename.equals("content")) {
            // ?????

        } else if (ename.equals("component")) {

            String name = child.getAttributeValue("name");
            int number = Integer.parseInt(child.getAttributeValue("component"));

            if (name.equals("schemaHolder")) {
                // Schema ???extRef???
                paragraphBuilder.append(getSchemaInfo(schemas.get(number)));

            } else if (name.equals("stampHolder")) {
                // ???<br>?toString()
                //paragraphBuilder.append(getStampInfo(pModules.get(number)));
            }

        } else if (ename.equals("text")) {
            // ????????trim()???
            //paragraphBuilder.append(child.getTextTrim());
            paragraphBuilder.append(child.getText());
        }

        // ??
        parseChildren(child);
    }
}

From source file:open.dolphin.message.MMLHelper.java

/**
 * ?????/*  www  . j a  va  2s  .  co m*/
 */
private void parseChildren(Element current) {

    // Element???
    List children = current.getChildren();

    // Leaf ??
    if (children == null || children.isEmpty()) {
        return;
    }

    // ??
    for (Iterator iterator = children.iterator(); iterator.hasNext();) {

        Element child = (Element) iterator.next();
        //String qname = child.getQualifiedName();
        String ename = child.getName();
        //Namespace ns = child.getNamespace();
        //debug(ename);

        if (ename.equals("paragraph")) {
            // ????<xhtml:br/>??
            // ???????
            if (paragraphBuilder != null) {
                freeExp.append(paragraphBuilder.toString());
                freeExp.append("<xhtml:br/>\n");
            }
            paragraphBuilder = new StringBuilder();

        } else if (ename.equals("content")) {
            // ?????

        } else if (ename.equals("component")) {

            String name = child.getAttributeValue("name");
            int number = Integer.parseInt(child.getAttributeValue("component"));

            if (name.equals("schemaHolder")) {
                // Schema ???extRef???
                paragraphBuilder.append(getSchemaInfo(schemas.get(number)));

            } else if (name.equals("stampHolder")) {
                // ???<br>?toString()
                paragraphBuilder.append(getStampInfo(pModules.get(number)));
            }

        } else if (ename.equals("text")) {
            // ????????trim()???
            //paragraphBuilder.append(child.getTextTrim());
            paragraphBuilder.append(child.getText());
        }

        // ??
        parseChildren(child);
    }
}

From source file:org.ambientdynamix.contextplugins.foaf.FoafPluginRuntime.java

License:Apache License

public static void updateFoafFile() {
    String foafurl = settings.get(Constants.FOAFURL);
    foafurl = "http://galileo1.zapto.org/tvluke.rdf";
    final SAXBuilder builder = new SAXBuilder();
    try {// www  .  j a  v a 2s.c o  m
        Document doc = builder.build(foafurl);
        Element root = doc.getRootElement();
        List<Element> children = root.getChildren();
        Iterator<Element> childrenIterator = children.iterator();
        while (childrenIterator.hasNext()) {
            Element child = childrenIterator.next();
            List<Element> grandchildren = child.getChildren();
            Iterator<Element> grandchildrenIterator = grandchildren.iterator();
            while (grandchildrenIterator.hasNext()) {
                Element grandchild = grandchildrenIterator.next();
                if (grandchild.getName().equals("foaf:name")) {
                    foafname = grandchild.getText();
                }
            }
        }
    } catch (Exception e) {

    }
}

From source file:org.ambientdynamix.contextplugins.lastfm.LastFMPluginRuntime.java

License:Apache License

public static Song checkForCurrentSong(String uid) {
    Log.d(TAG, "checkforCurrentSong");
    Song x = null;/*from   w w w .j  a va  2  s.  c o  m*/

    String url = "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=" + uid + "&api_key="
            + Constants.API_KEY;
    final SAXBuilder builder = new SAXBuilder();
    try {
        Document doc = builder.build(url);
        Element root = doc.getRootElement();
        List<Element> children = root.getChildren();
        Iterator<Element> childrenIterator = children.iterator();
        while (childrenIterator.hasNext()) {
            Element child = childrenIterator.next();
            //Log.d(TAG, ""+child.getName());
            List<Element> grandchildren = child.getChildren();
            Iterator<Element> grandchildrenIterator = grandchildren.iterator();
            boolean gotit = false;
            while (grandchildrenIterator.hasNext()) {
                Element grandchild = grandchildrenIterator.next();
                if (grandchild.getName().equals("track") && grandchild.hasAttributes()) {
                    List<Element> ggclist = grandchild.getChildren();
                    Iterator<Element> ggcit = ggclist.iterator();
                    String artist = "";
                    String name = "";
                    while (ggcit.hasNext()) {
                        Element ggc = ggcit.next();
                        if (ggc.getName().equals("artist")) {
                            artist = ggc.getText();
                        }
                        if (ggc.getName().equals("name")) {
                            name = ggc.getText();
                        }
                        if (ggc.getName().equals("mbid")) {
                            if (ggc.getText().equals("")) {
                                Log.e(TAG, "mbid is empty for some reason. This should be impossible...");
                            }
                            x = songinfo(ggc.getText());
                        }
                        if (ggc.getName().equals("album")) {
                            if (x != null) {

                            } else {
                                x = new Song(name, artist, -999, ggc.getText(), "", "");
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "exception: " + e.getMessage());
    }
    return x;
}

From source file:org.ambientdynamix.contextplugins.lastfm.LastFMPluginRuntime.java

License:Apache License

private static Song songinfo(String mbidx) {
    Song x = null;//from  ww  w.  java  2s. c o m
    String url = "http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=" + Constants.API_KEY
            + "+&mbid=" + mbidx;
    String title = "";
    String id = "";
    String artist = "";
    String album = "";
    int duration = 0;
    String tags = "";
    final SAXBuilder builder = new SAXBuilder();
    try {
        Document doc = builder.build(url);
        Element root = doc.getRootElement();
        List<Element> children = root.getChildren();
        Iterator<Element> childrenIterator = children.iterator();
        while (childrenIterator.hasNext()) {
            Element child = childrenIterator.next();
            //Log.d(TAG, ""+child.getName());
            List<Element> grandchildren = child.getChildren();
            Iterator<Element> grandchildrenIterator = grandchildren.iterator();
            while (grandchildrenIterator.hasNext()) {
                Element grandchild = grandchildrenIterator.next();
                //Log.d(TAG, ""+grandchild.getName());
                if (grandchild.getName().equals("id")) {
                    Log.d(TAG, grandchild.getText());
                    id = grandchild.getText();
                }
                if (grandchild.getName().equals("name")) {
                    Log.d(TAG, grandchild.getText());
                    title = grandchild.getText();
                }
                if (grandchild.getName().equals("duration")) {
                    if (!grandchild.getText().equals("")) {
                        Log.d(TAG, grandchild.getText());
                        Log.d(TAG, "trytoparse");
                        duration = Integer.parseInt(grandchild.getText());
                        Log.d(TAG, "duration=" + duration);
                    }
                }
                if (grandchild.getName().equals("artist")) {
                    Log.d(TAG, grandchild.getText());
                    artist = grandchild.getChild("name").getText();
                }
                if (grandchild.getName().equals("album")) {
                    Log.d(TAG, grandchild.getText());
                    album = grandchild.getChild("title").getText();
                }
                if (grandchild.getName().equals("toptags")) {
                    //Log.d(TAG, grandchild.getText());
                    Log.d(TAG, "toptags...");
                    List<Element> ggclist = grandchild.getChildren();
                    Iterator<Element> ggcit = ggclist.iterator();
                    while (ggcit.hasNext()) {
                        Element ggg = ggcit.next();
                        tags = tags + " " + ggg.getChild("name").getText();
                    }
                }
            }
        }
        x = new Song(title, artist, duration, album, tags, id);
    } catch (Exception e) {
        Log.d(TAG, "-->");
        Log.e(TAG, "exception: " + e.getMessage());
    }
    return x;
}

From source file:org.ambientdynamix.contextplugins.lastfm.LastFMPluginRuntime.java

License:Apache License

public static ArrayList<Song> getTop100Tracks(String uid) {
    ArrayList<Song> top100tracks = new ArrayList<Song>();
    String url = "http://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=" + uid + "&api_key="
            + Constants.API_KEY + "&limit=100";
    final SAXBuilder builder = new SAXBuilder();
    try {/* ww  w .ja  v a 2s. c o  m*/
        Log.d(TAG, "Try");
        Document doc = builder.build(url);
        Log.d(TAG, "2");
        Element root = doc.getRootElement();
        Log.d(TAG, "3");
        List<Element> children = root.getChildren();
        Log.d(TAG, "4");
        Iterator<Element> childrenIterator = children.iterator();
        Log.d(TAG, "5");
        while (childrenIterator.hasNext()) {
            Element child = childrenIterator.next();
            Log.d(TAG, "" + child.getName());
            List<Element> grandchildren = child.getChildren();
            Log.d(TAG, "6");
            Iterator<Element> grandchildrenIterator = grandchildren.iterator();
            while (grandchildrenIterator.hasNext()) {
                Log.d(TAG, "7");
                Element grandchild = grandchildrenIterator.next();
                if (grandchild.getName().equals("track") && grandchild.hasAttributes()) {
                    List<Element> ggclist = grandchild.getChildren();
                    Log.d(TAG, "8");
                    Iterator<Element> ggcit = ggclist.iterator();
                    Log.d(TAG, "9");
                    String artist = "";
                    String name = "";
                    int playcount = 0;
                    Log.d(TAG, "10");
                    while (ggcit.hasNext()) {
                        Element ggc = ggcit.next();
                        if (ggc.getName().equals("artist")) {
                            Log.d(TAG, "11");
                            artist = ggc.getChild("name").getText();
                            Log.d(TAG, "Artist=" + artist);
                            top100tracks.add(new Song(name, artist, -999, ggc.getText(), "", playcount, ""));
                        }
                        if (ggc.getName().equals("name")) {
                            Log.d(TAG, "12");
                            name = ggc.getText();
                        }
                        if (ggc.getName().equals("playcount")) {
                            Log.d(TAG, "14 " + ggc.getText());
                            playcount = Integer.parseInt(ggc.getText());
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.d(TAG, "-->");
        Log.e(TAG, "exception: " + e.getMessage());
    }
    return top100tracks;
}

From source file:org.apache.ctakes.temporal.ae.DeepPheAnaforaXMLReader.java

License:Apache License

private static void processXmlFile(JCas jCas, File xmlFile) throws AnalysisEngineProcessException {
    // load the XML
    Element dataElem;/*  w  w  w .j  a  v a 2 s.c o  m*/
    try {
        dataElem = new SAXBuilder().build(xmlFile.toURI().toURL()).getRootElement();
    } catch (MalformedURLException e) {
        throw new AnalysisEngineProcessException(e);
    } catch (JDOMException e) {
        throw new AnalysisEngineProcessException(e);
    } catch (IOException e) {
        throw new AnalysisEngineProcessException(e);
    }

    int curEventId = 1;
    int docLen = jCas.getDocumentText().length();

    for (Element annotationsElem : dataElem.getChildren("annotations")) {

        for (Element entityElem : annotationsElem.getChildren("entity")) {
            String id = removeSingleChildText(entityElem, "id", null);
            Element spanElem = removeSingleChild(entityElem, "span", id);
            String type = removeSingleChildText(entityElem, "type", id);
            String parType = removeSingleChildText(entityElem, "parentsType", id);
            Element propertiesElem = removeSingleChild(entityElem, "properties", id);

            // UIMA doesn't support disjoint spans, so take the span enclosing
            // everything
            int begin = Integer.MAX_VALUE;
            int end = Integer.MIN_VALUE;
            for (String spanString : spanElem.getText().split(";")) {
                String[] beginEndStrings = spanString.split(",");
                if (beginEndStrings.length != 2) {
                    error("span not of the format 'number,number'", id);
                }
                int spanBegin = Integer.parseInt(beginEndStrings[0]);
                int spanEnd = Integer.parseInt(beginEndStrings[1]);
                if (spanBegin < begin) {
                    begin = spanBegin;
                }
                if (spanEnd > end) {
                    end = spanEnd;
                }
            }
            if (begin < 0 || end >= docLen) {
                error("Illegal begin or end boundary", id);
                continue;
            }

            if (!type.equals("Anatomical_site") && parType.equals("UMLSEntities")
                    || parType.equals("Metastasis_Entities")) {
                String docTimeRel = removeSingleChildText(propertiesElem, "DocTimeRel", id);
                if (docTimeRel == null) {
                    error("no docTimeRel, assuming OVERLAP", id);
                    //            docTimeRel = "OVERLAP";
                    continue;
                }
                EventMention eventMention = new EventMention(jCas, begin, end);
                Event event = new Event(jCas);
                EventProperties eventProperties = new EventProperties(jCas);
                eventProperties.setDocTimeRel(docTimeRel);
                eventProperties.setCategory(type);
                eventProperties.addToIndexes();
                event.setConfidence(1.0f);
                event.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION);
                event.setProperties(eventProperties);
                event.setMentions(new FSArray(jCas, 1));
                event.setMentions(0, eventMention);
                event.addToIndexes();
                eventMention.setId(curEventId++);
                eventMention.setConfidence(1.0f);
                eventMention.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION);
                eventMention.setEvent(event);
                eventMention.addToIndexes();
            }
            //        else if (type.equals("TIMEX3")) {
            //          String timeClass = removeSingleChildText(propertiesElem, "Class", id);
            //          TimeMention timeMention = new TimeMention(jCas, begin, end);
            //          timeMention.setId(curTimexId++);
            //          timeMention.setTimeClass(timeClass);
            //          timeMention.addToIndexes();
            //          annotation = timeMention;
            //
            //        } else if (type.equals("DOCTIME")) {
            //          TimeMention timeMention = new TimeMention(jCas, begin, end);
            //          timeMention.setId(curTimexId++);
            //          timeMention.setTimeClass(type);
            //          timeMention.addToIndexes();
            //          annotation = timeMention;
            //
            //        } else if (type.equals("SECTIONTIME")) {
            //          TimeMention timeMention = new TimeMention(jCas, begin, end);
            //          timeMention.setId(curTimexId++);
            //          timeMention.setTimeClass(type);
            //          timeMention.addToIndexes();
            //          annotation = timeMention;
            //
            //        } else if (type.equals("Markable")) {
            //          while(end >= begin && (jCas.getDocumentText().charAt(end-1) == '\n' || jCas.getDocumentText().charAt(end-1) == '\r')){
            //            end--;
            //          }
            //          Markable markable = new Markable(jCas, begin, end);
            //          markable.addToIndexes();
            //          annotation = markable;
            //
            //        } else if (type.equals("DUPLICATE")) {
            //          LOGGER.warn("Ignoring duplicate sections in annotations.");
            //          continue;
            //        } 
            //        else {
            //          throw new UnsupportedOperationException("unsupported entity type: " + type);
            //        }
            //
            //        // match the annotation to it's ID for later use
            //        idToAnnotation.put(id, annotation);

            // make sure all XML has been consumed
            removeSingleChild(entityElem, "parentsType", id);
            if (!propertiesElem.getChildren().isEmpty() || !entityElem.getChildren().isEmpty()) {
                List<String> children = Lists.newArrayList();
                for (Element child : propertiesElem.getChildren()) {
                    children.add(child.getName());
                }
                for (Element child : entityElem.getChildren()) {
                    children.add(child.getName());
                }
                error("unprocessed children " + children, id);
            }
        }
    }
}