Example usage for org.dom4j Node valueOf

List of usage examples for org.dom4j Node valueOf

Introduction

In this page you can find the example usage for org.dom4j Node valueOf.

Prototype

String valueOf(String xpathExpression);

Source Link

Document

valueOf evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.

Usage

From source file:ru.itx.ccm.beans.EventListener.java

License:Apache License

private void processFifo(Document document) throws Exception {
    String fifo = document.selectSingleNode("/fifo_report/fifo").valueOf("@name");
    List<Node> members = document.selectNodes("/fifo_report/fifo/outbound/member");
    List<Node> callers = document.selectNodes("/fifo_report/fifo/callers/caller");
    List<Node> bridges = document.selectNodes("/fifo_report/fifo/bridges/bridge");
    List<String> activeMembers = new ArrayList<String>();
    List<String> connectedMembers = new ArrayList<String>();
    if (fifoDirectory != null && !fifoDirectory.isEmpty()) {
        FileWriter writer = new FileWriter(fifoDirectory + "/" + fifo + ".status");
        for (Node node : callers) {
            writer.append(node.valueOf("@timestamp") + " ");
            writer.append(String.format("%10s", node.valueOf("@caller_id_number")) + "\n");
        }/*from  w  ww.j  a  va 2 s  .co  m*/
        for (Node node : bridges) {
            String agent[] = node.valueOf(
                    "consumer/cdr/callflow/caller_profile/originator/originator_caller_profile/chan_name")
                    .replace("sofia/" + profile + "/sip:", "").replace(":5060", "").split("@");
            writer.append(node.valueOf("@bridge_start") + " ");
            writer.append(String.format("%10s", node.valueOf("caller/@caller_id_number")) + " -> ");
            writer.append(
                    agent[0] + " " + ((users.get(agent[0]) == null) ? ("") : (users.get(agent[0]))) + "\n");
            connectedMembers.add(agent[0]);
        }
        for (Node node : members) {
            String member = node.getText().replace("user/", "").replace("@" + domain, "");
            if (!connectedMembers.contains(member)) {
                writer.append("                                  ");
                writer.append(member + " " + ((users.get(member) == null) ? ("") : (users.get(member))) + "\n");
            }
            if (users.containsKey(member))
                activeMembers.add(member);
        }
        writer.append("\n");
        writer.close();
    }
    eventManager.count(fifo, members.size(), activeMembers.size(), callers.size(), bridges.size());
}

From source file:threeLayerNetwork.ThreeLayerNetwork.java

License:Open Source License

@Override
public AbstractRepresentation loadFromXML(Node nd) {
    try {//from   w w w .  java  2 s. c  o m
        String fitnessString = nd.valueOf("./@fitness");
        if (!fitnessString.isEmpty()) {
            this.setFitness(Double.parseDouble(fitnessString));
        }

        this.input_nodes = Integer.parseInt(nd.valueOf("./@input_nodes"));
        this.output_nodes = Integer.parseInt(nd.valueOf("./@output_nodes"));
        this.nodes = Integer.parseInt(nd.valueOf("./@nodes"));
        this.weight_range = Float.parseFloat(nd.valueOf("./@weight_range"));
        this.bias_range = Float.parseFloat(nd.valueOf("./@bias_range"));
        // this.iteration =
        // Integer.parseInt(nd.valueOf("./simulation/@iteration"));
        // this.score = Integer.parseInt(nd.valueOf("./simulation/@score"));
        this.activation = new float[this.nodes];
        this.output = new float[this.nodes];
        this.bias = new float[this.nodes];
        this.weight = new float[this.nodes][this.nodes];
        Node dnodes = nd.selectSingleNode("./nodes");
        for (int nr = this.input_nodes; nr < this.nodes; nr++) {
            Node curnode = dnodes.selectSingleNode("./node[@nr='" + nr + "']");
            if (curnode == null)
                throw new IllegalArgumentException("ThreeLayerNetwork: node tags inconsistent!"
                        + "\ncheck 'nr' attributes and nodes count in nnetwork!");
            this.bias[nr] = Float.parseFloat(curnode.valueOf("./bias"));
            Node dweights = curnode.selectSingleNode("./weights");
            for (int from = 0; from < this.nodes; from++) {
                String ws = dweights.valueOf("./weight[@from='" + from + "']");
                if (ws.length() == 0)
                    throw new IllegalArgumentException("ThreeLayerNetwork: weight tags inconsistent!"
                            + "\ncheck 'from' attributes and nodes count in nnetwork!");
                float val = Float.parseFloat(ws);
                this.weight[from][nr] = val;
            }
        }
        // this.gahist = new GAHistory(this.config, nd);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("ThreeLayerNetwork: NumberFormatException! Check XML File");
    }
    return this;
}