Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

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

Prototype

public List<Element> getChildren() 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element, as Element objects.

Usage

From source file:TrainNet.java

License:Apache License

public void adjustWeights(Element node) throws JDOMException {
    //each backward connection's weight to equal current weight + LEARNING_RATE * output of neuron at other end of connection * this neuron's errorGradient
    int lock = java.lang.Integer
            .parseInt(node.getParentElement().getParentElement().getAttributeValue("ADJUST_LOCK"));
    Iterator synapses = node.getChildren().iterator(); //iterate through incoming synapses and adjust weights
    do {/*from w w w .j a v a2s  .c o  m*/
        Element currentSynapse = (Element) synapses.next();
        String OrgNodeID = currentSynapse.getAttributeValue("ORG_NEURODE");
        //if OrgNode !=input then continue else abort/return
        if (!"INPUT".equals(OrgNodeID) && lock != 1) {
            Element OrgNode = (Element) XPath.selectSingleNode(Erudite_gui.NNetMap,
                    "/NNETWORK/SUBNET/LAYER/NEURODE[@N_ID='" + OrgNodeID + "']");
            double weight = java.lang.Double.parseDouble(currentSynapse.getAttributeValue("WEIGHT"))
                    + (learningRate * (java.lang.Double.parseDouble(OrgNode.getAttributeValue("ACTIVITY"))
                            * java.lang.Double.parseDouble(node.getAttributeValue("NNET_V4"))));
            currentSynapse.setAttribute("WEIGHT", String.valueOf(weight));
        }
    } while (synapses.hasNext());
}

From source file:Api.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//w ww.  jav  a  2 s .c  o m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("Content-Type: text/javascript");
    PrintWriter out = response.getWriter();

    // Se crea un SAXBuilder para poder parsear el archivo
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File("Config.xml");

    try {
        //Se parcea el archivo xml para crear el documento 
        //que se va a tratar.
        Document documento = (Document) builder.build(xmlFile);
        // Se obtiene la raiz del documento. En este caso 'cruisecontrol'
        Element rootNode = documento.getRootElement();

        //            // Obtengo el tag "info" como nodo raiz para poder trabajar 
        //            // los tags de ste.
        //            Element rootNode_Level2 = rootNode.getChild("info");
        //            // Obtengo los nodos "property" del tag info y los almaceno en
        //            // una lista.
        //            List<Element> lista = rootNode_Level2.getChildren("property");
        //
        //            //Imprimo por consola la lista.
        //            for (int i = 0; i < lista.size(); i++) {
        //                System.out.println(((Element) lista.get(i)).getAttributeValue("value"));
        //            }
        // out.println("<!DOCTYPE html>");
        Map<String, Object> actions = new LinkedHashMap<String, Object>();

        for (Element action : rootNode.getChildren()) {

            ArrayList<Map> methods = new ArrayList<Map>();

            for (Element method : action.getChildren()) {

                Map<String, Object> md = new LinkedHashMap<String, Object>();

                if (method.getAttribute("len") != null) {

                    md.put("name", method.getName());
                    md.put("len", method.getAttributeValue("len"));

                } else {

                    md.put("name", method.getName());
                    md.put("params", method.getAttributeValue("params"));

                }

                if (method.getAttribute("formHandler") != null && method.getAttribute("formHandler") != null) {

                    md.put("formHandler", true);

                }

                methods.add(md);
            }

            actions.put(action.getName(), methods);
        }

    } catch (IOException io) {
        System.out.println(io.getMessage());
    } catch (JDOMException jdomex) {
        System.out.println(jdomex.getMessage());
    } finally {
        out.close();
    }

}

From source file:Content.java

public void showPlaylist(String playlistName) {
    if (playlistName.equals("Library")) {
        setRightClick(true);/*from   www  . ja  va2  s . co  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 {/*from   w ww  . ja  va 2 s  .  c  om*/
            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:AIR.Common.xml.XmlReader.java

License:Open Source License

private boolean readToDescendant(String item) throws XmlReaderException, IOException {
    MutablePair<Content, Integer> alwaysTop = null;
    if (_stack.size() > 0) {
        alwaysTop = _stack.peek();//w  ww  . java 2  s .  co m
    }
    while (_stack.size() != 0) {
        MutablePair<Content, Integer> topElement = _stack.peek();

        if (topElement.getLeft().getCType() == CType.Element) {
            Element topElementNode = (Element) topElement.getLeft();
            if (StringUtils.equals(item, topElementNode.getName()))
                return true;

            int nextChild = topElement.getRight() + 1;
            if (topElementNode.getChildren().size() > nextChild) {
                topElement.setRight(nextChild);
                Element nextTraversalNode = topElementNode.getChildren().get(nextChild);
                _stack.push(new MutablePair<Content, Integer>(nextTraversalNode, -1));
            } else {
                // we do not want to pop the original top node (alwaysTop) as we are
                // only doing descendant.
                if (!alwaysTop.equals(topElement))
                    _stack.pop();
                else
                    break;
            }
        }
    }

    return false;
}

From source file:AIR.Common.xml.XmlReader.java

License:Open Source License

public boolean isEmptyElement() {
    Content thisNode = _stack.peek().getLeft();
    switch (thisNode.getCType()) {
    case CDATA:/*from  w  w w. j  a v a 2  s. c  o  m*/
    case Text:
    case Comment:
        return true;
    case Element:
        Element thisElement = getNodeAsElement();
        return thisElement.getChildren().size() > 0;
    }
    return true;
}

From source file:AIR.Common.xml.XmlReader.java

License:Open Source License

private boolean traverseNextSibling() throws IOException {
    /*/* w w w  .j  a  va2s . c  o  m*/
     * if (_file.available () == 0) { return false; }
     */
    if (_stack.size() == 0)
        return false;

    MutablePair<Content, Integer> currentTop = _stack.pop();
    if (_stack.size() != 0) {

        MutablePair<Content, Integer> topElement = _stack.peek();
        // We already went into topElement's children and so there is no
        // need to check if it of type element.
        Element topElementNode = (Element) topElement.getLeft();

        int nextChild = topElement.getRight() + 1;
        if (topElementNode.getChildren().size() > nextChild) {
            topElement.setRight(nextChild);
            Element nextTraversalNode = topElementNode.getChildren().get(nextChild);
            _stack.push(new MutablePair<Content, Integer>(nextTraversalNode, -1));
            return true;
        }
    }
    // else put the previous top back on the top.
    _stack.push(currentTop);
    return false;
}

From source file:AIR.Common.xml.XmlReader.java

License:Open Source License

private boolean traverseImmediateChild(boolean firstOnly) throws IOException {
    /*/*  www.j av  a2s .  c o  m*/
     * if (_file.available () == 0) { return false; }
     */
    if (_stack.size() == 0)
        return false;

    MutablePair<Content, Integer> topElement = _stack.peek();
    Content node = topElement.getLeft();
    if (node.getCType() == CType.Element) {
        Element topElementNode = (Element) node;
        int nextChild = 0;
        if (!firstOnly)
            nextChild = topElement.getRight() + 1;
        // if we have a next child then we will go to that.
        if (topElementNode.getChildren().size() > nextChild) {
            topElement.setRight(nextChild);
            Element nextTraversalNode = topElementNode.getChildren().get(nextChild);
            _stack.push(new MutablePair<Content, Integer>(nextTraversalNode, -1));
            return true;
        }
    }
    return false;
}

From source file:AIR.ResourceBundler.Xml.FileSet.java

License:Open Source License

public void parse(Element resourcesEl) throws ResourcesException {
    Attribute fileSetAttrib = null;

    // parse main attributes
    fileSetAttrib = resourcesEl.getAttribute("name");
    _name = (fileSetAttrib != null) ? fileSetAttrib.getValue() : null;

    fileSetAttrib = resourcesEl.getAttribute("output");
    setOutput((fileSetAttrib != null) ? fileSetAttrib.getValue() : null);

    // parse setting attributes
    fileSetAttrib = resourcesEl.getAttribute("compress");
    if (fileSetAttrib != null)
        _compress = (fileSetAttrib.getValue() == "true");

    fileSetAttrib = resourcesEl.getAttribute("removeLines");
    if (fileSetAttrib != null)
        _removeEmptyLines = (fileSetAttrib.getValue() == "true");

    fileSetAttrib = resourcesEl.getAttribute("removeComments");
    if (fileSetAttrib != null)
        _removeComments = (fileSetAttrib.getValue() == "true");

    fileSetAttrib = resourcesEl.getAttribute("removeSpaces");
    if (fileSetAttrib != null)
        removeSpaces = (fileSetAttrib.getValue() == "true");

    for (Element childEl : resourcesEl.getChildren()) {
        String childName = childEl.getName();

        if ("input".equalsIgnoreCase(childName)) {
            parseFileInput(childEl);//  w w  w.jav  a 2 s  .  c o m
        } else if ("reference".equalsIgnoreCase(childName)) {
            parseReference(childEl);
        } else if ("exclude".equalsIgnoreCase(childName)) {
            parseExclude(childEl);
        } else if ("replace".equalsIgnoreCase(childName)) {
            parseReplace(childEl);
        }
    }
}

From source file:AIR.ResourceBundler.Xml.Resources.java

License:Open Source License

public void parse() throws JDOMException, IOException, ResourcesException {
    SAXBuilder builder = new SAXBuilder();
    File xmlFile = new File(_configFile);
    Document document = (Document) builder.build(xmlFile);
    Element rootElement = document.getRootElement();

    String attr = rootElement.getAttributeValue("name");
    name = (attr != null) ? attr : null;
    for (Element childEl : rootElement.getChildren()) {
        String childName = childEl.getName();
        if ("import".equalsIgnoreCase(childName)) {
            parseImport(childEl);//from  w  w w .ja  v  a2s  .c om
        } else if ("fileSet".equalsIgnoreCase(childName)) {
            parseFileSet(childEl);
        } else if ("remove".equalsIgnoreCase(childName)) {
            parseRemove(childEl);
        }

    }
}