Example usage for org.jdom2 Element getChildText

List of usage examples for org.jdom2 Element getChildText

Introduction

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

Prototype

public String getChildText(final String cname) 

Source Link

Document

Returns the textual content of the named child element, or null if there's no such child.

Usage

From source file:Content.java

public void showPlaylist(String playlistName) {
    if (playlistName.equals("Library")) {
        setRightClick(true);/*from  w w  w .  j  av  a 2 s.c o m*/
    } else {
        setRightClick(false);
    }

    if (nowPlayingInfo != null) {
        try {
            nowPlayingInfo.setVisible(false);
            remove(nowPlayingInfo);
        } catch (Exception e) {
        }
    }

    currentPlaylist = playlistName;
    eventEnabled = false;

    int count = model.getRowCount();
    for (int n = 0; n < count; n++) {
        model.removeRow(0);
    }

    if (playlistName.equals("Now Playing")) {
        playlist.setVisible(false);

        if (mediaPlayer != null) {
            try {
                String loc = mediaPlayer.getMedia().getSource();

                for (int i = 0; i < Library.getLib().size(); i++) {
                    if (("file:///" + ((Element) Library.getLib().get(i)).getChildText("url")).equals(loc)) {
                        Element el = ((Element) Library.getLib().get(i));
                        nowPlayingSong = new JLabel(el.getChildText("name"));
                        nowPlayingArtist = new JLabel(el.getChildText("artist"));
                        nowPlayingAlbum = new JLabel(el.getChildText("album"));
                        nowPlayingInfo = new JPanel();

                        nowPlayingInfo.setLayout(new BoxLayout(nowPlayingInfo, BoxLayout.PAGE_AXIS));
                        nowPlayingInfo.add(nowPlayingSong);
                        nowPlayingInfo.add(nowPlayingArtist);
                        nowPlayingInfo.add(nowPlayingAlbum);
                        nowPlayingInfo.setVisible(true);
                        add(nowPlayingInfo, BorderLayout.CENTER);

                        break;
                    }
                }

            } catch (Exception e) {
            }
        }
    } else if (playlistName.equals("Library")) {
        playlist.setVisible(true);
        List lib = Library.getLib();

        for (int i = 0; i < lib.size(); i++) {
            Element song = (Element) lib.get(i);

            Vector<String> row = new Vector<String>();
            row.add(song.getChildText("name"));
            row.add(song.getChildText("artist"));
            row.add(song.getChildText("album"));

            model.addRow(row);
        }
    } else {
        playlist.setVisible(true);
        List list = Library.getList();

        for (int i = 0; i < list.size(); i++) {
            Element node = (Element) list.get(i);

            if (node.getAttributeValue("id") == playlistName) {
                List children = node.getChildren();

                for (int j = 0; j < children.size(); j++) {
                    Element entry = (Element) children.get(j);
                    String entryNum = entry.getText();

                    List lib = Library.getLib();
                    for (int k = 0; k < lib.size(); k++) {
                        if (((Element) lib.get(k)).getAttributeValue("id").equals(entryNum)) {
                            Element song = (Element) lib.get(k);
                            Vector<String> row = new Vector<String>();
                            row.add(song.getChildText("name"));
                            row.add(song.getChildText("artist"));
                            row.add(song.getChildText("album"));
                            model.addRow(row);
                        }
                    }
                }
            }
        }

        playlist.revalidate();
        revalidate();
        eventEnabled = true;
    }
}

From source file:Content.java

public void playSelected() {
    if (playlist.getSelectedRow() == -1) {
        try {/* www.ja v a2  s. com*/
            playlist.setRowSelectionInterval(0, 0);
        } catch (Exception e) {
            return;
        }
    }
    if (currentPlaylist.equals("Library")) {
        if (mediaPlayer != null) {
            mediaPlayer.stop();
        }

        try {
            List lib = Library.getLib();
            Element child = (Element) lib.get(playlist.getSelectedRow());

            if (child.getChildText("url").indexOf("http://") != -1) {
                Desktop.getDesktop().browse(new URI(child.getChildText("url")));
                return;
            }
            if (child.getChildText("url").toLowerCase().indexOf("youtube") != -1) {
                Desktop.getDesktop().browse(new URI(child.getChildText("url")));
                return;
            }
            if (child.getChildText("url").toLowerCase().indexOf(".com") != -1) {
                Desktop.getDesktop().browse(new URI(child.getChildText("url")));
                return;
            }

            String loc = "file:///" + child.getChildText("url");
            Media media = new Media(loc);
            mediaPlayer = new MediaPlayer(media);
            nowPlayingIndex = playlist.getSelectedRow();
            mediaPlayer.play();
            mediaPlayer.setOnEndOfMedia(new Runnable() {
                public void run() {
                    playNext();
                }
            });
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error playing media - please check the song location");
        }
    } else {
        if (mediaPlayer != null) {
            mediaPlayer.stop();
        }

        List list = Library.getList();

        for (int i = 0; i < list.size(); i++) {
            Element node = (Element) list.get(i);

            if (node.getAttributeValue("id").equals(currentPlaylist)) {
                Element elem = (Element) node.getChildren().get(playlist.getSelectedRow());
                String entryNum = elem.getText();

                try {
                    if (mediaPlayer != null) {
                        mediaPlayer.stop();
                    }

                    for (int j = 0; j < Library.getLib().size(); j++) {
                        Element current = (Element) Library.getLib().get(j);

                        if (current.getAttributeValue("id").equals(entryNum)) {
                            if (current.getChildText("url").indexOf("http://") != -1) {
                                Desktop.getDesktop().browse(new URI(current.getChildText("url")));
                                return;
                            }
                            if (current.getChildText("url").toLowerCase().indexOf("youtube") != -1) {
                                Desktop.getDesktop().browse(new URI(current.getChildText("url")));
                                return;
                            }
                            if (current.getChildText("url").toLowerCase().indexOf(".com") != -1) {
                                Desktop.getDesktop().browse(new URI(current.getChildText("url")));
                                return;
                            }

                            String loc = "file:///" + current.getChildText("url");
                            Media media = new Media(loc);
                            mediaPlayer = new MediaPlayer(media);
                            mediaPlayer.play();
                            nowPlayingIndex = playlist.getSelectedRow();

                            mediaPlayer.setOnEndOfMedia(new Runnable() {
                                public void run() {
                                    playNext();
                                }
                            });
                        }
                    }
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(this, "Error playing media - please check the song location");
                }
            }
        }
    }
}

From source file:VraagServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    //Bestandslocatie van de XML file. Later als parameter meegeven
    String xmlUrl = "file:///H:/NetBeansProjects/WebApplication1/GMFM.xml";

    PrintWriter out = new PrintWriter(response.getOutputStream());

    //Maakt HTML pagina aan
    out.println("<html>");
    out.println("<head><title>Formulier</title></head>");
    out.println("<body>");

    try {/*from w w  w.j  a  v  a 2 s . c  o  m*/
        //Maakt een URL aan die naar het XML document wijst. En een builder die vervolgens een document opbouwt.
        URL theDoc = new URL(xmlUrl);
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(theDoc);

        // Geeft het root element (Formulier)
        Element root = document.getRootElement();

        /* Maakt een lijst aan waarin alle XML staat die tussen <uitleg> </uitleg> staat. 
         De lijst wordt vervolgens geitereerd totdat alle elementen uit de uitleg zijn geweest en in de html staan.*/
        List uitleg = root.getChildren("UITLEG");
        Iterator uitlegItr = uitleg.iterator();
        while (uitlegItr.hasNext()) {
            Object u = uitlegItr.next();
            Element beschrijving = (Element) u;
            out.println(beschrijving.getChildText("BESCHRIJVING"));
        }

        /* Maakt een lijst aan waarin alle XML staat die tussen <regel> </regel> staat. 
         De lijst wordt vervolgens geitereerd totdat alle elementen uit de regel zijn geweest.*/
        List vragen = root.getChildren("REGEL");
        Iterator itr = vragen.iterator();

        //Er wordt net zolang doorgegaan totdat de laatste vraag is bereikt. Alle vragen worden in een tabel gestopt.
        out.println("<table border =1>");
        out.println("<form >");
        while (itr.hasNext()) {
            Object o = itr.next();
            Element vraag = (Element) o;

            /*Hieronder worden de verschillende invoermogelijkheden opgeslagen dus bijvoorbeeld 4 checkbox buttons naast elkaar.
             Een variabele met NT erachter betekent dat deze een extra knop heeft voor niet getest.
             VALUES NOG TOEVOEGEN AAN VARIABELEN
             Uitbreiden indien nodig!!*/
            StringBuffer row = new StringBuffer("<tr>");
            //                

            /*De vraag wordt opgehaald en in de eerste kolom van de tabel gezet.
            Vervolgens wordt het antwoord opgehaald en wordt gekeken waarmee dit antwoord overeen komt. 
            Dit bepaald vervolgens hoeveel checkbox buttons/tekstvakken er gemaakt worden of dat er gewoon tekst afgedrukt wordt. 
            Uitbreiden als nodig!!!
            */
            row.append("<td>" + vraag.getChildText("VRAAG") + "</td>");
            String antwoord = vraag.getChildText("INVOERMOGELIJKHEID");

            if (antwoord.equals("driecheckbox")) {
                row.append("<td>" + "<input type=\"checkbox\" name=\"driecheckbox\" value=\"0\">"
                        + "<input type=\"checkbox\" name=\"driecheckbox\" value=\"0\">"
                        + "<input type=\"checkbox\" name=\"driecheckbox\" value=\"0\">");
            } else if (antwoord.equals("viercheckboxNT")) {
                row.append("<td>" + "<input type=\"checkbox\" name=\"viercheckboxNT\" value=\"0\" id=\"0\">"
                        + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"1\"id=\"1\">"
                        + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"2\"id=\"2\">"
                        + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"3\"id=\"3\">"
                        + "<input type=\"checkbox\"name=\"viercheckboxNT\"value=\"\"id=\"4\">" + "</td>");

            } else if (antwoord.equals("vijfcheckbox")) {
                row.append("<td>" + "<input type=\"checkbox\" name=\"vijfcheckbox\" value=\"0\">"
                        + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"1\">"
                        + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"2\">"
                        + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"3\">"
                        + "<input type=\"checkbox\"name=\"vijfcheckbox\"value=\"4\">");
            } else if (antwoord.equals("tekstvak")) {
                row.append("<td>" + "<INPUT TYPE=\"text\" NAME=\"tekstvak\" SIZE=\"13\" MAXLENGTH=\"20\">");
            } else {
                row.append("<td>" + antwoord);
            }
            //Hier wordt de regel uitgeprint in de html 
            out.println(row.toString());

        }

        //Sluiten van tabel en html 
        out.println("</table>");
        out.println("<input type=\"submit\" value=\"Formulier verzenden\">");
        String[] results = request.getParameterValues("viercheckboxNT");
        for (int i = 0; i < results.length; i++) {
            out.println(results[i]);
        }
        out.println("</form>");

        out.println("</body></html>");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (JDOMException e) {
        e.printStackTrace();
    } finally {
        out.close();
    }
}

From source file:API.NTHAPI.NetworksResource.java

License:Apache License

public void init(String file) {

    Element params;
    try {/*from  w  ww . ja  va 2s  .co m*/
        parserXML = new ParserXML(new File(file));
        params = parserXML.getRootElement().getChild("pluginParams");
        fedSDNTarget = params.getChildText("fedSDNTarget");
    } //init();
    catch (Exception ex) {
        LOGGER.error("$$$$$$$$$$$$$" + ex.getMessage());
        ex.printStackTrace();
    }
}

From source file:API.NTHAPI.SitesResource.java

License:Apache License

/**
 * //from   www.j  a  va 2  s  . c om
 * @param file File that contains the FEDSDN URI.
 * @author gtricomi
 */
public void init(String file) {
    Element params;
    try {
        parser = new ParserXML(new File(file));
        params = parser.getRootElement().getChild("pluginParams");
        fedSDNTarget = params.getChildText("fedSDNTarget");
    } //init();
    catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:API.NTHAPI.UserssResource.java

License:Apache License

public void init(String file) {
    Element params;
    try {/*from  www  .j a va  2 s  . c o m*/
        parser = new ParserXML(new File(file));
        params = parser.getRootElement().getChild("pluginParams");
        fedSDNTarget = params.getChildText("fedSDNTarget");
    } //init();
    catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:app.simulation.Importer.java

License:MIT License

public void importXML() throws Exception {
    File file = new File(path);

    if (!file.exists())
        throw new FileNotFoundException(path);

    if (!getFileFormat().equalsIgnoreCase("xml"))
        throw new InvalidFileFormatException(getFileFormat());

    SAXBuilder saxBuilder = new SAXBuilder();
    Document document = saxBuilder.build(file);
    Element root = document.getRootElement();
    Element configuration = root.getChild("configuration");

    if (configuration != null) {

        String delayText = configuration.getChildText("delay");
        if (delayText == null)
            throw new AttributeNotFoundException("delay");

        String iterationsText = configuration.getChildText("iterations");
        if (iterationsText == null)
            throw new AttributeNotFoundException("iterations");

        String agentsText = configuration.getChildText("agents");
        if (agentsText == null)
            throw new AttributeNotFoundException("agents");

        String latticeSizeText = configuration.getChildText("latticeSize");
        if (latticeSizeText == null)
            throw new AttributeNotFoundException("latticeSize");

        String descriptionText = configuration.getChildText("description");
        if (descriptionText == null)
            throw new AttributeNotFoundException("description");

        int delay = Integer.parseInt(delayText);
        int iterations = Integer.parseInt(iterationsText);
        int agents = Integer.parseInt(agentsText);
        int latticeSize = Integer.parseInt(latticeSizeText);
        this.configuration = new Configuration(delay, iterations, agents, latticeSize, descriptionText);
    }// w ww  . j  a v  a 2s. c om

    Element initialCell = root.getChild("initialCell");

    if (initialCell != null) {

        String xText = initialCell.getChildText("x");
        if (xText == null)
            throw new AttributeNotFoundException("x");

        String yText = initialCell.getChildText("y");
        if (yText == null)
            throw new AttributeNotFoundException("y");

        String zText = initialCell.getChildText("z");
        if (zText == null)
            throw new AttributeNotFoundException("z");

        String stateText = initialCell.getChildText("state");
        if (stateText == null)
            throw new AttributeNotFoundException("state");

        Element colorElement = initialCell.getChild("color");
        if (colorElement == null)
            throw new AttributeNotFoundException("color");

        String rText = colorElement.getChildText("r");
        if (rText == null)
            throw new AttributeNotFoundException("r");

        String gText = colorElement.getChildText("g");
        if (gText == null)
            throw new AttributeNotFoundException("g");

        String bText = colorElement.getChildText("b");
        if (bText == null)
            throw new AttributeNotFoundException("b");

        int x = Integer.parseInt(xText);
        int y = Integer.parseInt(yText);
        int z = Integer.parseInt(zText);
        int state = Integer.parseInt(stateText);
        Color color = new Color(Integer.parseInt(rText), Integer.parseInt(gText), Integer.parseInt(bText));
        this.initialCell = new Cell(x, y, z, state, color);
    }

    Element tagRules = root.getChild("rules");
    rules = new ArrayList<Rule>();

    if (tagRules != null) {
        List<Element> elementRules = tagRules.getChildren("rule");

        if (elementRules.size() > 0) {

            for (Element rule : elementRules) {

                String neighbourhood = rule.getChildText("neighbourhood");
                if (neighbourhood == null)
                    throw new AttributeNotFoundException("neighbourhood");

                String stateText = rule.getChildText("state");
                if (stateText == null)
                    throw new AttributeNotFoundException("state");

                Element colorElement = rule.getChild("color");
                if (colorElement == null)
                    throw new AttributeNotFoundException("color");

                String rText = colorElement.getChildText("r");
                if (rText == null)
                    throw new AttributeNotFoundException("r");

                String gText = colorElement.getChildText("g");
                if (gText == null)
                    throw new AttributeNotFoundException("g");

                String bText = colorElement.getChildText("b");
                if (bText == null)
                    throw new AttributeNotFoundException("b");

                int state = Integer.parseInt(stateText);
                Color color = new Color(Integer.parseInt(rText), Integer.parseInt(gText),
                        Integer.parseInt(bText));

                rules.add(new Rule(neighbourhood, state, color));
            }
        }
    }

}

From source file:ataraxis.passwordmanager.XMLHandler.java

License:Open Source License

/**
 * Get a AccountEntry with the given id.
 * /* ww w.java  2s.c  o m*/
 * @param id
 * @return the requested AccountEntry
 * @throws EntryDoesNotExistException
 */
public AccountEntry getAccountEntry(String id) throws EntryDoesNotExistException {
    AccountEntry accountEntry = null;

    try {
        Element accountElement = getElement(id);
        if (accountElement != null) {
            if (!isGroupElement(id)) {
                String entryId = accountElement.getAttributeValue("id");
                accountEntry = new AccountEntry(entryId);
                accountEntry.setName(accountElement.getChildText("name"));
                accountEntry.setPassword(accountElement.getChildText("password"));
                accountEntry.setLink(accountElement.getChildText("link"));
                accountEntry.setComment(accountElement.getChildText("comment"));

                String parentId = accountElement.getParentElement().getAttributeValue("id");

                if (parentId != null && isGroupElement(parentId)) {
                    GroupEntry group = new GroupEntry(parentId);
                    accountEntry.setParentEntry(group);
                }
            }
        }
        /*else
        {
           throw new EntryDoesNotExistException("entry not found");
        }*/
    } catch (JDOMException e) {
        logger.fatal(e);
        throw new EntryDoesNotExistException("entry not found");
    }

    return accountEntry;
}

From source file:BB_ELA.Policies.SunLightPolicy.java

License:Apache License

public void init() {
    Element params;
    this.datacenterMap = new HashMap<String, ArrayList<String>>();
    try {/*from   w  ww  . ja  v a 2 s .  c  o  m*/

        parser = new ParserXML(new File(this.fileConf));
        params = parser.getRootElement().getChild("pluginParams");
        this.granularityCheck = Long.valueOf(params.getChildText("granularityCheck")).longValue();
        this.threshold = Integer.valueOf(params.getChildText("threshold"));
        this.bbUrl = params.getChildText("bburl");
        this.bbpass = params.getChildText("bbpass");
        this.bbuser = params.getChildText("bbuser");

        //this.connectReplication();
    } catch (Exception ex) {
        LOGGER.error("Error occurred in configuration ");
        ex.printStackTrace();
    }
}

From source file:bg.LanguageManager.java

/**
 * @brief Read text from node textField in language xml file
 * @param lanTextList store values of leaf node in language xml file
 * @param textfield_node internal node of language xml file
 * @marker If add any new element in xml, please check this function
 */// w  w w .  j a v  a2s . co m
private void addTextFieldChildrenText(HashMap<String, String> lanTextList, Element textfield_node) {
    lanTextList.put(LeafNodeLabel.INPUT_FILE_PATH.getText(),
            textfield_node.getChildText(LeafNodeLabel.INPUT_FILE_PATH.getText()));
    lanTextList.put(LeafNodeLabel.OUTPUT_FILE_PATH.getText(),
            textfield_node.getChildText(LeafNodeLabel.OUTPUT_FILE_PATH.getText()));
    lanTextList.put(LeafNodeLabel.OUTPUT_FILE_NAME.getText(),
            textfield_node.getChildText(LeafNodeLabel.OUTPUT_FILE_NAME.getText()));
    lanTextList.put(LeafNodeLabel.SPLIT_BY.getText(),
            textfield_node.getChildText(LeafNodeLabel.SPLIT_BY.getText()));
    lanTextList.put(LeafNodeLabel.INPUT_ENCODING.getText(),
            textfield_node.getChildText(LeafNodeLabel.INPUT_ENCODING.getText()));
    lanTextList.put(LeafNodeLabel.OUTPUT_ENCODING.getText(),
            textfield_node.getChildText(LeafNodeLabel.OUTPUT_ENCODING.getText()));
    lanTextList.put(LeafNodeLabel.LANGUAGE.getText(),
            textfield_node.getChildText(LeafNodeLabel.LANGUAGE.getText()));
    lanTextList.put(LeafNodeLabel.LINES_PER_FILE.getText(),
            textfield_node.getChildText(LeafNodeLabel.LINES_PER_FILE.getText()));
    lanTextList.put(LeafNodeLabel.SIZE_PER_FILE.getText(),
            textfield_node.getChildText(LeafNodeLabel.SIZE_PER_FILE.getText()));
    lanTextList.put(LeafNodeLabel.CUSTOM_DELIMITER.getText(),
            textfield_node.getChildText(LeafNodeLabel.CUSTOM_DELIMITER.getText()));
    lanTextList.put(LeafNodeLabel.DELETE_SOURCE.getText(),
            textfield_node.getChildText(LeafNodeLabel.DELETE_SOURCE.getText()));
    lanTextList.put(LeafNodeLabel.AUTO.getText(), textfield_node.getChildText(LeafNodeLabel.AUTO.getText()));
}