List of usage examples for org.jdom2 Element getChildren
public List<Element> getChildren(final String cname)
List
of all the child elements nested directly (one level deep) within this element with the given local name and belonging to no namespace, returned as Element
objects. From source file:com.thoughtworks.go.util.SvnLogXmlParser.java
License:Apache License
public HashMap<String, String> parseInfoToGetUUID(String output, String queryURL, SAXBuilder builder) { HashMap<String, String> uidToUrlMap = new HashMap<>(); try {/* ww w .jav a 2 s.c om*/ Document document = builder.build(new StringReader(output)); Element root = document.getRootElement(); List<Element> entries = root.getChildren("entry"); for (Element entry : entries) { uidToUrlMap.put(queryURL, entry.getChild("repository").getChild("uuid").getValue()); } } catch (Exception e) { throw new RuntimeException(e); } return uidToUrlMap; }
From source file:com.versionmaintain.files.LastVersionInfosParser.java
License:Apache License
public List<VersionInfo> getVersionInfo() { SAXBuilder builder = new SAXBuilder(); List<VersionInfo> infos = new ArrayList<VersionInfo>(); try {/* w w w. j av a 2 s . c o m*/ Document doc = builder.build(new File(System.getProperty("user.dir") + File.separator + FILE_NAME)); Element root = doc.getRootElement(); List<Element> softEles = root.getChildren("software"); for (Element softEle : softEles) { String appName = softEle.getAttribute("name").getValue(); String versionCode = softEle.getChildText("latest-version-code"); String versionName = softEle.getChildText("latest-version"); Element detailEles = softEle.getChild("latest-version-detail"); List<Element> detailItemEles = detailEles.getChildren("item"); List<VersionInfoDetail> details = new ArrayList<VersionInfoDetail>(); for (Element detailItem : detailItemEles) { String title = detailItem.getAttributeValue("name"); List<Element> detailEleList = detailItem.getChildren("detail"); List<String> detailList = new ArrayList<String>(); for (Element detailEle : detailEleList) { String strDetail = detailEle.getText(); detailList.add(strDetail); } details.add(new VersionInfoDetail(title, detailList)); } VersionInfo versionInfo = new VersionInfo(); versionInfo.setAppName(appName); versionInfo.setVersion(versionName); versionInfo.setVersionCode(Integer.parseInt(versionCode)); versionInfo.setDetails(details); infos.add(versionInfo); } } catch (Exception e) { e.printStackTrace(); } return infos; }
From source file:core.xml.java
/** * @param args the command line arguments *//*from w ww.ja v a 2s. c o m*/ public static void main(String[] args) throws JDOMException { // TODO code application logic here SAXBuilder builder = new SAXBuilder(); File xmlFile = new File("/home/dark/Escritorio/Desde-Java/estructura.xml"); System.err.println(xmlFile); System.err.println(xmlFile.exists()); try { Document document = (Document) builder.build(xmlFile); Element rootNode = document.getRootElement(); List list = (List) rootNode.getChildren("configuracion"); extraerInformacion(list); System.err.println(descripcion); System.err.println(atributos); System.out.println(num_columnas); System.err.println(parametros); System.err.println(cabecera); } catch (IOException io) { System.err.println("Se exploto 1"); System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.err.println("Se exploto 2"); System.out.println(jdomex.getMessage()); } }
From source file:cz.lbenda.dbapp.rc.db.JDBCConfiguration.java
License:Apache License
public final void loadFromElement(Element element) { setPassword(subElementText(element, "password", "")); setUsername(subElementText(element, "user", "SA")); setUrl(subElementText(element, "url", "")); setDriverClass(subElementText(element, "driverClass", "")); Element libraries = element.getChild("libraries"); if (libraries != null) { for (Element librarie : (List<Element>) libraries.getChildren("librarie")) { getImportedLibreries().add(librarie.getValue()); }/*from w ww . j av a 2 s.c o m*/ } }
From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java
License:Apache License
public static void loadFromDocument(final Document document) { configurations.clear();/* www . j a va 2s . c o m*/ Element root = document.getRootElement(); Element sessions = root.getChild("sessions"); for (Element session : sessions.getChildren("session")) { LOG.trace("loadFromDocument - session"); SessionConfiguration sc = new SessionConfiguration(); configurations.add(sc); sc.fromElement(session); } }
From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java
License:Apache License
private void fromElement(final Element element) { setId(element.getAttributeValue("id")); if (element.getChild("connectionTimeout") != null) { this.connectionTimeout = Integer.valueOf(element.getChildText("connectionTimeout")); } else {/*from w w w .jav a 2 s. c o m*/ connectionTimeout = -1; } jdbcConfigurationFromElement(element.getChild("jdbc")); // tableOfKeysSQLFromElement(element.getChild("tableOfKeySQLs")); Element ed = element.getChild("extendedDescription"); if (ed != null) { setExtendedConfigurationType(ExtendedConfigurationType.valueOf(ed.getAttributeValue("type"))); setExtendedConfigurationPath(ed.getText()); } Element e = element.getChild("libraries"); this.librariesPaths.clear(); if (e != null) { for (Element lib : e.getChildren("library")) { this.librariesPaths.add(lib.getText()); } } loadExtendedConfiguration(); }
From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java
License:Apache License
private void tableOfKeysSQLFromElement(final Element element) { LOG.trace("load table of keys sql"); if (element == null) { return;/*from ww w.ja v a 2s. co m*/ } tableOfKeysSQL.clear(); for (Element tableOfKey : element.getChildren("tableOfKeySQL")) { this.tableOfKeysSQL.put(tableOfKey.getAttributeValue("id"), tableOfKey.getText()); } }
From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java
License:Apache License
/** Load schemas which will be showed */ private void loadSchemas(final Element element) { shownSchemas.clear();/* ww w. j ava 2 s . co m*/ for (Element sch : element.getChildren("schema")) { String catalog = sch.getAttributeValue("catalog"); String schema = sch.getAttributeValue("schema"); List<String> list = shownSchemas.get(catalog); if (list == null) { list = new ArrayList<>(); shownSchemas.put(catalog, list); } list.add(schema); } }
From source file:cz.pecina.retro.memory.Snapshot.java
License:Open Source License
/** * Processes a block tag.// w ww .j av a 2s . co m * * @param memory memory array * @param tag tag to process * @param destinationAddress destination address ({@code -1} = none) * @return info info record */ public static Info processBlockElement(final byte[] memory, final Element tag, final int destinationAddress) { log.finer( String.format("Method processMemoryElement called: destination address: %04x", destinationAddress)); assert (destinationAddress >= -1) && (destinationAddress <= 0xffff); final int size = memory.length; final Info info = new Info(); int startAddress = 0; if (destinationAddress == -1) { try { startAddress = Integer.parseInt(tag.getAttributeValue("start"), 16); } catch (final Exception exception) { log.fine("Error in starting address, exception: " + exception.getMessage()); throw Application.createError(Snapshot.class, "parsing"); } log.finer(String.format("Starting address: %04x", startAddress)); } else { startAddress = destinationAddress; log.finer(String.format("Destination address used instead: %04x", startAddress)); } for (Element bytes : tag.getChildren(subtagName)) { int count; String string; if ((string = bytes.getAttributeValue("count")) != null) { try { count = Integer.parseInt(string); } catch (final Exception exception) { log.fine("Error in count, exception: " + exception.getMessage()); throw Application.createError(Snapshot.class, "parsing"); } } else { count = 1; } string = bytes.getTextTrim(); try { for (; count > 0; count--) { for (int i = 0; i < (string.length() / 2); i++) { startAddress &= 0xffff; if (startAddress < info.minAddress) { info.minAddress = startAddress; } if (startAddress > info.maxAddress) { info.maxAddress = startAddress; } final int dataByte = Integer.parseInt(string.substring(i * 2, (i + 1) * 2), 16); memory[startAddress % size] = (byte) dataByte; log.finest(String.format("Read: %02x -> (%04x)", dataByte, startAddress)); startAddress++; info.number++; } } } catch (final Exception exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(Snapshot.class, "parsing"); } } log.finer("Method processMemoryElement finished"); return info; }
From source file:cz.pecina.retro.trec.XML.java
License:Open Source License
/** * Reads the tape from an XML file./*from w w w. j a v a2 s . c om*/ * * @param file input file */ public void read(final File file) { log.fine("Reading tape data from an XML file, file: " + file); try { SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(new StreamSource( getClass().getResourceAsStream("tape-" + TAPE_XML_FILE_VERSION + ".xsd"))) .newValidator().validate(new StreamSource(file)); } catch (final Exception exception) { log.fine("Error, validation failed, exception: " + exception.getMessage()); throw Application.createError(this, "validation"); } Document doc; try { doc = new SAXBuilder().build(file); } catch (final JDOMException exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(this, "parsing"); } catch (final Exception exception) { log.fine("Error, reading failed, exception: " + exception.getMessage()); throw Application.createError(this, "XMLRead"); } Element tag; try { tag = doc.getRootElement(); } catch (final Exception exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(this, "parsing"); } if (!tag.getName().equals("tape")) { log.fine("Error, parsing failed, no <tape> tag"); throw Application.createError(this, "noTape"); } if (!TAPE_XML_FILE_VERSION.equals(tag.getAttributeValue("version"))) { log.fine("Version mismatch"); throw Application.createError(this, "version"); } if (!"per sec".equals(tag.getAttributeValue("unit"))) { log.fine("Unsupported sample rate"); throw Application.createError(this, "XMLSampleRate"); } tape.clear(); try { long currPos = -1; for (Element pulse : tag.getChildren("pulse")) { final long start = Long.parseLong(pulse.getAttributeValue("start")); final long duration = Long.parseLong(pulse.getAttributeValue("duration")); if ((start <= currPos) || (duration <= 0)) { log.fine("Error in XML file"); throw Application.createError(this, "XML"); } tape.put(start, duration); log.finest(String.format("Read: (%d, %d)", start, duration)); currPos = start; } } catch (final Exception exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(this, "parsing"); } log.fine("Reading completed"); }