List of usage examples for org.dom4j.tree DefaultDocument getRootElement
public Element getRootElement()
From source file:de.tud.kom.p2psim.impl.network.gnp.topology.HostMap.java
License:Open Source License
/** * //w ww . j a v a 2s. c o m * @return xml Document Object of relevant Class Attributes */ private Document getDocument() { Set<Host> hosts = new HashSet<Host>(); // "GroupLookup" Element log.debug("Generate XML-Element \"GroupLookup\""); DefaultElement groups = new DefaultElement("GroupLookup"); for (String group : this.groups.keySet()) { log.debug(" - Export Group: " + group); hosts.addAll(this.groups.get(group)); DefaultElement peerXml = new DefaultElement("Group"); peerXml.addAttribute("id", group); peerXml.addAttribute("maxsize", String.valueOf(this.groups.get(group).size())); String ip = ""; int x = 0; int blockSize = 1000; // IP Block of 1000, too long blocks leads to hangUp ?? for (Host host : this.groups.get(group)) { x++; ip += "," + host.getIpAddress(); if (x % blockSize == 0) { ip = ip.substring(1); DefaultElement ips = new DefaultElement("IPs"); ips.addAttribute("value", ip); peerXml.add(ips); ip = ""; } } if (ip.length() > 0) { ip = ip.substring(1); DefaultElement ips = new DefaultElement("IPs"); ips.addAttribute("value", ip); peerXml.add(ips); } groups.add(peerXml); } // "Hosts" Element log.debug("Generate XML-Element \"Hosts\""); DefaultElement peers = new DefaultElement("Hosts"); for (Host host : hosts) { DefaultElement peer = new DefaultElement("Host"); peer.addAttribute("ip", String.valueOf(host.getIpAddress())); String area = (host.getArea() != null) ? host.getArea() : "--"; peer.addAttribute("continentalArea", area); String countryCode = (host.getCountryCode() != null) ? host.getCountryCode() : "--"; peer.addAttribute("countryCode", countryCode); String region = (host.getRegion() != null) ? host.getRegion() : "--"; peer.addAttribute("region", region); String city = (host.getCity() != null) ? host.getCity() : "--"; peer.addAttribute("city", city); String isp = (host.getISP() != null) ? host.getISP() : "--"; peer.addAttribute("isp", isp); peer.addAttribute("longitude", String.valueOf(host.getLongitude())); peer.addAttribute("latitude", String.valueOf(host.getLatitude())); String coordinates = (host.getGnpPositionReference() != null) ? host.getGnpPositionReference().getCoordinateString() : "0"; peer.addAttribute("coordinates", coordinates); peers.add(peer); } // "PingErLookup" Elements log.debug("Generate XML-Element \"PingErLookup\""); Element pingEr = pingErLookup.exportToXML(); // "CountryLookup" Element log.debug("Generate XML-Element \"CountryLookup\""); Element country = countryLookup.exportToXML(); DefaultDocument document = new DefaultDocument(new DefaultElement("gnp")); document.getRootElement().add(groups); document.getRootElement().add(peers); document.getRootElement().add(pingEr); document.getRootElement().add(country); return document; }
From source file:org.peerfact.impl.network.gnp.topology.HostMap.java
License:Open Source License
/** * //from w w w .j a v a2 s.c o m * @return xml Document Object of relevant Class Attributes */ private Document getDocument() { Set<Host> hosts = new LinkedHashSet<Host>(); // "GroupLookup" Element log.debug("Generate XML-Element \"GroupLookup\""); DefaultElement groupsDefault = new DefaultElement("GroupLookup"); for (String group : this.groups.keySet()) { log.debug(" - Export Group: " + group); hosts.addAll(this.groups.get(group)); DefaultElement peerXml = new DefaultElement("Group"); peerXml.addAttribute("id", group); peerXml.addAttribute("maxsize", String.valueOf(this.groups.get(group).size())); String ip = ""; int x = 0; int blockSize = 1000; // IP Block of 1000, too long blocks leads to hangUp ?? for (Host host : this.groups.get(group)) { x++; ip += "," + host.getIpAddress(); if (x % blockSize == 0) { ip = ip.substring(1); DefaultElement ips = new DefaultElement("IPs"); ips.addAttribute("value", ip); peerXml.add(ips); ip = ""; } } if (ip.length() > 0) { ip = ip.substring(1); DefaultElement ips = new DefaultElement("IPs"); ips.addAttribute("value", ip); peerXml.add(ips); } groupsDefault.add(peerXml); } // "Hosts" Element log.debug("Generate XML-Element \"Hosts\""); DefaultElement peers = new DefaultElement("Hosts"); for (Host host : hosts) { DefaultElement peer = new DefaultElement("Host"); peer.addAttribute("ip", String.valueOf(host.getIpAddress())); String area = (host.getArea() != null) ? host.getArea() : "--"; peer.addAttribute("continentalArea", area); String countryCode = (host.getCountryCode() != null) ? host.getCountryCode() : "--"; peer.addAttribute("countryCode", countryCode); String region = (host.getRegion() != null) ? host.getRegion() : "--"; peer.addAttribute("region", region); String city = (host.getCity() != null) ? host.getCity() : "--"; peer.addAttribute("city", city); String isp = (host.getISP() != null) ? host.getISP() : "--"; peer.addAttribute("isp", isp); peer.addAttribute("longitude", String.valueOf(host.getLongitude())); peer.addAttribute("latitude", String.valueOf(host.getLatitude())); String coordinates = (host.getGnpPositionReference() != null) ? host.getGnpPositionReference().getCoordinateString() : "0"; peer.addAttribute("coordinates", coordinates); peers.add(peer); } // "PingErLookup" Elements log.debug("Generate XML-Element \"PingErLookup\""); Element pingEr = pingErLookup.exportToXML(); // "CountryLookup" Element log.debug("Generate XML-Element \"CountryLookup\""); Element country = countryLookup.exportToXML(); DefaultDocument document = new DefaultDocument(new DefaultElement("gnp")); document.getRootElement().add(groupsDefault); document.getRootElement().add(peers); document.getRootElement().add(pingEr); document.getRootElement().add(country); return document; }
From source file:org.pentaho.ui.xul.dom.dom4j.DocumentDom4J.java
License:Open Source License
public DocumentDom4J(org.dom4j.tree.DefaultDocument document) { super();/* ww w .java 2s.c om*/ this.document = document; this.element = document.getRootElement(); }