List of usage examples for org.jdom2 Element getChild
public Element getChild(final String cname)
From source file:com.khodev.oradiff.io.XmlSchemaReader.java
License:Open Source License
private Function getFunction(Element element) { Function function = new Function(element.getAttributeValue("name")); function.getBody().clear();/*from w w w.j a v a 2 s . co m*/ String bodyStr = element.getChild("body").getText(); String[] lines = bodyStr.split("\n"); for (String line : lines) function.getBody().add(line + "\n"); return function; }
From source file:com.khodev.oradiff.io.XmlSchemaReader.java
License:Open Source License
private DBPackage getPackage(Element element) { DBPackage pkg = new DBPackage(element.getAttributeValue("name")); pkg.getDeclaration().clear();//from ww w.j a va 2s . co m String declarationStr = element.getChild("declaration").getText(); String[] lines = declarationStr.split("\n"); for (String line : lines) pkg.getDeclaration().add(line + "\n"); pkg.getBody().clear(); String bodyStr = element.getChild("body").getText(); lines = bodyStr.split("\n"); for (String line : lines) pkg.getBody().add(line + "\n"); return pkg; }
From source file:com.kixeye.scout.eureka.EurekaServiceAmazonDataCenterInfo.java
License:Apache License
/** * Creates a descriptor from a parent and a raw element. * /*from w ww . j a v a2s . com*/ * @param parent * @param instanceElement */ protected EurekaServiceAmazonDataCenterInfo(EurekaServiceInstanceDescriptor parent, Element instanceElement) { this.parent = parent; this.name = instanceElement.getChildText("name"); Element metadata = instanceElement.getChild("metadata"); if (metadata != null) { for (Element element : metadata.getChildren()) { this.metadata.put(element.getName(), element.getText()); } } }
From source file:com.kixeye.scout.eureka.EurekaServiceInstanceDescriptor.java
License:Apache License
/** * Creates a descriptor from a parent and a raw element. * /*from www . j a v a 2 s .com*/ * @param parent * @param instanceElement */ protected EurekaServiceInstanceDescriptor(EurekaApplication parent, Element instanceElement) { this.parent = parent; this.app = instanceElement.getChildText("app"); this.ipAddress = instanceElement.getChildText("ipAddr"); this.hostname = instanceElement.getChildText("hostName"); this.vipAddress = instanceElement.getChildText("vipAddress"); int lastUpdatedTimestampRaw; try { lastUpdatedTimestampRaw = Integer.parseInt(instanceElement.getChildText("lastUpdatedTimestamp")); } catch (Exception e) { lastUpdatedTimestampRaw = -11; } this.lastUpdatedTimestamp = lastUpdatedTimestampRaw; int lastDirtyTimestampRaw; try { lastDirtyTimestampRaw = Integer.parseInt(instanceElement.getChildText("lastDirtyTimestamp")); } catch (Exception e) { lastDirtyTimestampRaw = -11; } this.lastDirtyTimestamp = lastDirtyTimestampRaw; Element port = instanceElement.getChild("port"); if (port != null) { this.isPortEnabled = Boolean.valueOf(port.getAttributeValue("enabled", "true")); this.port = Integer.valueOf(port.getTextTrim()); } else { this.isPortEnabled = false; this.port = -1; } Element securePort = instanceElement.getChild("securePort"); if (securePort != null) { this.isSecurePortEnabled = Boolean.valueOf(securePort.getAttributeValue("enabled", "true")); this.securePort = Integer.valueOf(securePort.getTextTrim()); } else { this.isSecurePortEnabled = false; this.securePort = -1; } Element statusElement = instanceElement.getChild("status"); ServiceStatus status = null; if (statusElement != null) { switch (statusElement.getTextTrim()) { case "UP": status = ServiceStatus.UP; break; case "DOWN": status = ServiceStatus.DOWN; break; default: status = ServiceStatus.UNKNOWN; } } this.status = status; Element overridenStatusElement = instanceElement.getChild("overriddenstatus"); ServiceStatus overridenStatus = null; if (overridenStatusElement != null) { switch (overridenStatusElement.getTextTrim()) { case "UP": overridenStatus = ServiceStatus.UP; break; case "DOWN": overridenStatus = ServiceStatus.DOWN; break; default: overridenStatus = ServiceStatus.UNKNOWN; } } this.overridenStatus = overridenStatus; Element metadata = instanceElement.getChild("metadata"); if (metadata != null) { for (Element element : metadata.getChildren()) { this.metadata.put(element.getName(), element.getText()); } } Element dataCenterInfo = instanceElement.getChild("dataCenterInfo"); if (dataCenterInfo != null) { Attribute dataCenterInfoClass = instanceElement.getAttribute("class"); if (dataCenterInfoClass != null && dataCenterInfoClass.getValue() != null) { switch (dataCenterInfoClass.getValue()) { case EurekaServiceAmazonDataCenterInfo.DATA_CENTER_INFO_CLASS: this.dataCenterInfo = new EurekaServiceAmazonDataCenterInfo(this, dataCenterInfo); break; default: this.dataCenterInfo = null; } } else { this.dataCenterInfo = null; } } else { this.dataCenterInfo = null; } }
From source file:com.lapis.jsfexporter.xml.XMLExportType.java
License:Apache License
@Override public Element exportRow(IExportRow row) { Element currentElement = (Element) row.getParentRowId(); if (currentElement == null) { currentElement = rootElement;// w w w . ja v a 2s . co m } for (String namePart : row.getName()) { Element subElement = new Element(cleanElementName(namePart)); currentElement.addContent(subElement); currentElement = subElement; } for (IExportCell cell : row.getCells()) { Element cellElement = currentElement; for (String namePart : cell.getName()) { Element subElement = cellElement.getChild(namePart); if (subElement == null) { subElement = new Element(cleanElementName(namePart)); cellElement.addContent(subElement); } cellElement = subElement; } if (!cellElement.getText().equals("")) { String cellName = cellElement.getName(); cellElement = cellElement.getParentElement(); Element newCellElement = new Element(cellName); cellElement.addContent(newCellElement); cellElement = newCellElement; } cellElement.setText(cell.getValue()); } return currentElement; }
From source file:com.medvision360.medrecord.basex.AbstractXmlConverter.java
License:Creative Commons License
protected void set(Element element, String xpath, String value) { Element currentElement = element; String[] paths = xpath.split("/"); for (int i = 0; i < paths.length; i++) { String pathPart = paths[i].trim(); if (pathPart.isEmpty()) { continue; }// ww w . j a va 2 s . co m Element newElement = element.getChild(pathPart); if (newElement == null) { newElement = new Element(pathPart); currentElement.addContent(newElement); } currentElement = newElement; } currentElement.setText(value); }
From source file:com.medvision360.medrecord.basex.MockLocatableSerializer.java
License:Creative Commons License
private void set(Element element, String xpath, String value) { Element currentElement = element; String[] paths = xpath.split("/"); for (int i = 0; i < paths.length; i++) { String pathPart = paths[i].trim(); if (pathPart.isEmpty()) { continue; }/*from w w w . j a v a 2 s .co m*/ Element newElement = element.getChild(pathPart); if (newElement == null) { newElement = new Element(pathPart); } currentElement.addContent(newElement); currentElement = newElement; } currentElement.setText(value); }
From source file:com.move.in.nantes.cars.ParkingParser.java
private static List<Parking> parseXml() { List<Parking> listPakings = new ArrayList<Parking>(); try {/*w w w. j ava2 s.co m*/ SAXBuilder saxb = new SAXBuilder(); File file = new File("WEB-INF/json/Parking.xml"); Document doc = saxb.build(file); Element root = doc.getRootElement(); List<Element> locations = root.getChildren("data").get(0).getChildren("element"); for (int i = 0; i < locations.size(); i++) { Element elem = locations.get(i); if (elem.getChildText("CATEGORIE").equalsIgnoreCase("1001")) { String name = elem.getChild("geo").getChildText("name"); Coordinates coordinates = getCoordinates(elem.getChildText("_l")); String postalCode = elem.getChildText("CODE_POSTAL"); String city = elem.getChildText("COMMUNE"); String address = elem.getChildText("ADRESSE"); listPakings.add(new Parking(name, coordinates, postalCode, city, address)); } } } catch (JDOMException ex) { Logger.getLogger(ParkingParser.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(ParkingParser.class.getName()).log(Level.SEVERE, null, ex); } return listPakings; }
From source file:com.oagsoft.grafo.util.XMLLoader.java
public static Grafo leerArchivoXml(String nomArch) { SAXBuilder builder = new SAXBuilder(); Grafo g = null;/* w w w. j a v a2 s . c om*/ try { Document document = (Document) builder.build(new File(nomArch)); Element rootNode = document.getRootElement(); Element nV = rootNode.getChild("numero-vertices"); int numVertices = Integer.parseInt(nV.getValue().trim()); g = new Grafo(numVertices); Element ad = rootNode.getChild("adyacencias"); List<Element> hijos = ad.getChildren("adyacencia"); for (Element hijo : hijos) { int nIni = Integer.parseInt(hijo.getChildTextTrim("nodo-inicial")); int nFin = Integer.parseInt(hijo.getChildTextTrim("nodo-final")); g.adyacencia(nIni, nFin); } // System.out.println("Hay " + hijos.size()+ " adyacencias"); } catch (JDOMException | IOException ex) { System.out.println(ex.getMessage()); } return g; }
From source file:com.oagsoft.wazgle.tools.XMLLoader.java
public static Grafo<GraphicNode> leerArchivoXml(String nomArch) { SAXBuilder builder = new SAXBuilder(); Grafo<GraphicNode> g = null;//from w w w. j a v a 2 s . c om try { Document document = (Document) builder.build(new File(nomArch)); Element rootNode = document.getRootElement(); Element nV = rootNode.getChild("numero-vertices"); int numVertices = Integer.parseInt(nV.getValue().trim()); g = new Grafo(numVertices); Element nodos = rootNode.getChild("nodos"); List<Element> hijos = nodos.getChildren("nodo"); for (Element hijo : hijos) { int id = Integer.parseInt(hijo.getChildTextTrim("id")); int coorX = Integer.parseInt(hijo.getChildTextTrim("coor-x")); int coorY = Integer.parseInt(hijo.getChildTextTrim("coor-y")); GraphicNode nodo = new GraphicNode(id, new Point(coorX, coorY), 10, false); g.adVertice(nodo); } Element adyacencias = rootNode.getChild("adyacencias"); List<Element> ad = adyacencias.getChildren("adyacencia"); for (Element hijo : ad) { int vIni = Integer.parseInt(hijo.getChildTextTrim("nodo-inicial")); int vFinal = Integer.parseInt(hijo.getChildTextTrim("nodo-final")); GraphicNode nIni = g.getVertice(vIni); GraphicNode nFin = g.getVertice(vFinal); g.adyacencia(nIni, nFin); } // System.out.println("Hay " + hijos.size()+ " adyacencias"); } catch (JDOMException | IOException ex) { System.out.println(ex.getMessage()); } return g; }