List of usage examples for org.jdom2 Element getText
public String getText()
From source file:ca.nrc.cadc.vosi.avail.CheckWebService.java
License:Open Source License
void checkReturnedXml(String strXml) throws CheckException { Document doc;//w w w . j a va2s . co m String xpathStr; try { StringReader reader = new StringReader(strXml); doc = XmlUtil.buildDocument(reader, schemaMap); //get namespace and/or prefix from Document, then create xpath based on the prefix String nsp = doc.getRootElement().getNamespacePrefix(); //Namespace Prefix if (nsp != null && nsp.length() > 0) nsp = nsp + ":"; else nsp = ""; xpathStr = "/" + nsp + "availability/" + nsp + "available"; XPathBuilder<Element> builder = new XPathBuilder<Element>(xpathStr, Filters.element()); Namespace ns = Namespace.getNamespace(VOSI.NS_PREFIX, VOSI.AVAILABILITY_NS_URI); builder.setNamespace(ns); XPathExpression<Element> xpath = builder.compileWith(XPathFactory.instance()); Element eleAvail = xpath.evaluateFirst(doc); log.debug(eleAvail); String textAvail = eleAvail.getText(); // TODO: is this is actually valid? is the content not constrained by the schema? if (textAvail == null) throw new CheckException(wsURL + " output is invalid: no content in <available> element", null); if (!textAvail.equalsIgnoreCase("true")) { xpathStr = "/" + nsp + "availability/" + nsp + "note"; builder = new XPathBuilder<Element>(xpathStr, Filters.element()); builder.setNamespace(ns); xpath = builder.compileWith(XPathFactory.instance()); Element eleNotes = xpath.evaluateFirst(doc); String textNotes = eleNotes.getText(); throw new CheckException("service " + wsURL + " is not available, reported reason: " + textNotes, null); } } catch (IOException e) { // probably an incorrect setup or bug in the checks throw new RuntimeException("failed to test " + wsURL, e); } catch (JDOMException e) { throw new CheckException(wsURL + " output is invalid", e); } }
From source file:ca.nrc.cadc.vosi.Availability.java
License:Open Source License
public AvailabilityStatus fromXmlDocument(Document doc) throws ParseException { Namespace vosi = Namespace.getNamespace("vosi", VOSI.AVAILABILITY_NS_URI); Element availability = doc.getRootElement(); if (!availability.getName().equals("availability")) throw new IllegalArgumentException("missing root element 'availability'"); Element elemAvailable = availability.getChild("available", vosi); if (elemAvailable == null) throw new IllegalArgumentException("missing element 'available'"); boolean available = elemAvailable.getText().equalsIgnoreCase("true"); DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC); Element elemUpSince = availability.getChild("upSince", vosi); Element elemDownAt = availability.getChild("downAt", vosi); Element elemBackAt = availability.getChild("backAt", vosi); Element elemNote = availability.getChild("note", vosi); Date upSince = null;//w w w . j a v a 2s . co m Date downAt = null; Date backAt = null; String note = null; if (elemUpSince != null) upSince = df.parse(elemUpSince.getText()); if (elemDownAt != null) downAt = df.parse(elemDownAt.getText()); if (elemBackAt != null) backAt = df.parse(elemBackAt.getText()); if (elemNote != null) note = elemNote.getText(); return new AvailabilityStatus(available, upSince, downAt, backAt, note); }
From source file:centroinfantil.PasoLista.java
License:Open Source License
/** * * @return//from w w w.ja v a 2 s .c o m */ static public ArrayList<ArrayList<String>> cargarXml() { //Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); File xmlFile = new File("historial.xml"); ArrayList<ArrayList<String>> salida = new ArrayList<>(); try { ArrayList<String> nino = new ArrayList<>(); String cadena; //Se crea el documento a traves del archivo Document document = (Document) builder.build(xmlFile); //Se obtiene la raiz 'tables' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'tables' List list = rootNode.getChildren("child"); System.out.println(list.size()); //Se recorre la lista de hijos de 'tables' for (int i = 0; i < list.size(); i++) { //Se obtiene el elemento 'tabla' Element tabla = (Element) list.get(i); //Se obtiene la lista de hijos del tag 'tabla' List lista_campos = tabla.getChildren(); //Se recorre la lista de campos for (int j = 0; j < lista_campos.size() - 1; j++) { //Se obtiene el elemento 'campo' Element campo = (Element) lista_campos.get(j); cadena = campo.getText(); nino.add(cadena); } Element campo = (Element) lista_campos.get(lista_campos.size() - 1); nino.add(campo.getChildTextTrim("fecha")); nino.add(campo.getChildTextTrim("sala")); nino.add(campo.getChildTextTrim("camara")); nino.add(campo.getChildTextTrim("posicionX")); nino.add(campo.getChildTextTrim("posicionY")); salida.add(nino); } } catch (IOException | JDOMException io) { System.out.println(io.getMessage()); } return salida; }
From source file:ch.kostceco.tools.kostval.validation.modulesiard.impl.ValidationDstructureModuleImpl.java
License:Open Source License
private boolean validateSchema(Element schema, Namespace ns, String pathToWorkDir) { int onWork = 41; boolean valid = true; Element schemaFolder = schema.getChild("folder", ns); File schemaPath = new File(new StringBuilder(pathToWorkDir).append(File.separator).append("content") .append(File.separator).append(schemaFolder.getText()).toString()); if (schemaPath.isDirectory()) { List<Element> tables = schema.getChild("tables", ns).getChildren("table", ns); for (Element table : tables) { valid = valid && validateTable(table, ns, pathToWorkDir, schemaPath); if (onWork == 41) { onWork = 2;//from w w w. j a v a2s.com System.out.print("D- "); System.out.print("\r"); } else if (onWork == 11) { onWork = 12; System.out.print("D\\ "); System.out.print("\r"); } else if (onWork == 21) { onWork = 22; System.out.print("D| "); System.out.print("\r"); } else if (onWork == 31) { onWork = 32; System.out.print("D/ "); System.out.print("\r"); } else { onWork = onWork + 1; } } } else { valid = false; if (schemaPath.exists()) { getMessageService().logError( getTextResourceService().getText(MESSAGE_XML_MODUL_D_SIARD) + getTextResourceService() .getText(MESSAGE_XML_D_INVALID_FOLDER, "content", schemaPath.getName())); } else { getMessageService().logError( getTextResourceService().getText(MESSAGE_XML_MODUL_D_SIARD) + getTextResourceService() .getText(MESSAGE_XML_D_MISSING_FOLDER, "content", schemaPath.getName())); } } return valid; }
From source file:ch.kostceco.tools.kostval.validation.modulesiard.impl.ValidationDstructureModuleImpl.java
License:Open Source License
private boolean validateTable(Element table, Namespace ns, String pathToWorkDir, File schemaPath) { boolean valid = true; Element tableFolder = table.getChild("folder", ns); File tablePath = new File(new StringBuilder(schemaPath.getAbsolutePath()).append(File.separator) .append(tableFolder.getText()).toString()); if (tablePath.isDirectory()) { File tableXml = new File(new StringBuilder(tablePath.getAbsolutePath()).append(File.separator) .append(tableFolder.getText() + ".xml").toString()); valid = valid && validateFile(tableXml, tablePath); File tableXsd = new File(new StringBuilder(tablePath.getAbsolutePath()).append(File.separator) .append(tableFolder.getText() + ".xsd").toString()); valid = valid && validateFile(tableXsd, tablePath); } else {//from ww w. jav a 2 s.c o m valid = false; if (tablePath.exists()) { getMessageService().logError( getTextResourceService().getText(MESSAGE_XML_MODUL_D_SIARD) + getTextResourceService() .getText(MESSAGE_XML_D_INVALID_FOLDER, schemaPath.getName(), tablePath.getName())); } else { getMessageService().logError( getTextResourceService().getText(MESSAGE_XML_MODUL_D_SIARD) + getTextResourceService() .getText(MESSAGE_XML_D_MISSING_FOLDER, schemaPath.getName(), tablePath.getName())); } } return valid; }
From source file:ch.kostceco.tools.kostval.validation.modulesiard.impl.ValidationFrowModuleImpl.java
License:Open Source License
private boolean validateSchema(Element schema, Namespace ns, String pathToWorkDir) { int onWork = 41; boolean valid = true; boolean validT = true; Element schemaFolder = schema.getChild("folder", ns); File schemaPath = new File(new StringBuilder(pathToWorkDir).append(File.separator).append("content") .append(File.separator).append(schemaFolder.getText()).toString()); if (schemaPath.isDirectory()) { List<Element> tables = schema.getChild("tables", ns).getChildren("table", ns); for (Element table : tables) { // Valid = True ansonsten validiert er nicht validT = true;/* w w w .j a v a 2 s . co m*/ validT = validT && validateTable(table, ns, pathToWorkDir, schemaPath); if (onWork == 41) { onWork = 2; System.out.print("F- "); System.out.print("\r"); } else if (onWork == 11) { onWork = 12; System.out.print("F\\ "); System.out.print("\r"); } else if (onWork == 21) { onWork = 22; System.out.print("F| "); System.out.print("\r"); } else if (onWork == 31) { onWork = 32; System.out.print("F/ "); System.out.print("\r"); } else { onWork = onWork + 1; } // Validierungsergebnis in valid speichern valid = valid && validT; } } else { valid = false; } valid = valid && validT; return valid; }
From source file:ch.kostceco.tools.kostval.validation.modulesiard.impl.ValidationFrowModuleImpl.java
License:Open Source License
private boolean validateTable(Element table, Namespace ns, String pathToWorkDir, File schemaPath) { boolean valid = true; boolean validR = true; Element tableFolder = table.getChild("folder", ns); Element tablerows = table.getChild("rows", ns); int rowmax = Integer.parseInt(tablerows.getText()); File tablePath = new File(new StringBuilder(schemaPath.getAbsolutePath()).append(File.separator) .append(tableFolder.getText()).toString()); File tableXsd = new File(new StringBuilder(tablePath.getAbsolutePath()).append(File.separator) .append(tableFolder.getText() + ".xsd").toString()); validR = validateRow(tableXsd, rowmax); valid = valid && validR;/*from w w w. ja va2 s . c o m*/ return valid; }
From source file:ch.kostceco.tools.kostval.validation.modulesiard.impl.ValidationHcontentModuleImpl.java
License:Open Source License
@Override public boolean validate(File valDatei, File directoryOfLogfile) throws ValidationHcontentException { // Ausgabe SIARD-Modul Ersichtlich das KOST-Val arbeitet System.out.print("H "); System.out.print("\r"); int onWork = 41; boolean valid = true; try {/*from w ww.j av a 2s . com*/ /* Extract the metadata.xml from the temporary work folder and build a jdom document */ String pathToWorkDir = getConfigurationService().getPathToWorkDir(); pathToWorkDir = pathToWorkDir + File.separator + "SIARD"; File metadataXml = new File(new StringBuilder(pathToWorkDir).append(File.separator).append("header") .append(File.separator).append("metadata.xml").toString()); InputStream fin = new FileInputStream(metadataXml); SAXBuilder builder = new SAXBuilder(); Document document = builder.build(fin); fin.close(); /* read the document and for each schema and table entry verify existence in temporary * extracted structure */ Namespace ns = Namespace.getNamespace("http://www.bar.admin.ch/xmlns/siard/1.0/metadata.xsd"); // select schema elements and loop List<Element> schemas = document.getRootElement().getChild("schemas", ns).getChildren("schema", ns); for (Element schema : schemas) { Element schemaFolder = schema.getChild("folder", ns); File schemaPath = new File(new StringBuilder(pathToWorkDir).append(File.separator).append("content") .append(File.separator).append(schemaFolder.getText()).toString()); if (schemaPath.isDirectory()) { Element[] tables = schema.getChild("tables", ns).getChildren("table", ns) .toArray(new Element[0]); for (Element table : tables) { Element tableFolder = table.getChild("folder", ns); File tablePath = new File(new StringBuilder(schemaPath.getAbsolutePath()) .append(File.separator).append(tableFolder.getText()).toString()); if (tablePath.isDirectory()) { File tableXml = new File(new StringBuilder(tablePath.getAbsolutePath()) .append(File.separator).append(tableFolder.getText() + ".xml").toString()); File tableXsd = new File(new StringBuilder(tablePath.getAbsolutePath()) .append(File.separator).append(tableFolder.getText() + ".xsd").toString()); // TODO: hier erfolgt die Validerung if (verifyRowCount(tableXml, tableXsd)) { // valid = validate1( tableXml, tableXsd ) && valid; // xmllint via cmd // resources\xmllint\xmllint --noout --stream --schema tableXsd tableXml try { // Pfad zum Programm xmllint existiert die Dateien? String pathToxmllintExe = "resources" + File.separator + "xmllint" + File.separator + "xmllint.exe"; String pathToxmllintDll1 = "resources" + File.separator + "xmllint" + File.separator + "iconv.dll"; String pathToxmllintDll2 = "resources" + File.separator + "xmllint" + File.separator + "libxml2.dll"; String pathToxmllintDll3 = "resources" + File.separator + "xmllint" + File.separator + "zlib1.dll"; File fpathToxmllintExe = new File(pathToxmllintExe); File fpathToxmllintDll1 = new File(pathToxmllintDll1); File fpathToxmllintDll2 = new File(pathToxmllintDll2); File fpathToxmllintDll3 = new File(pathToxmllintDll3); if (!fpathToxmllintExe.exists()) { getMessageService().logError(getTextResourceService() .getText(MESSAGE_XML_MODUL_H_SIARD) + getTextResourceService().getText(ERROR_XML_XMLLINT1_MISSING)); valid = false; } else if (!fpathToxmllintDll1.exists()) { getMessageService().logError(getTextResourceService() .getText(MESSAGE_XML_MODUL_H_SIARD) + getTextResourceService().getText(ERROR_XML_XMLLINT2_MISSING)); valid = false; } else if (!fpathToxmllintDll2.exists()) { getMessageService().logError(getTextResourceService() .getText(MESSAGE_XML_MODUL_H_SIARD) + getTextResourceService().getText(ERROR_XML_XMLLINT3_MISSING)); valid = false; } else if (!fpathToxmllintDll3.exists()) { getMessageService().logError(getTextResourceService() .getText(MESSAGE_XML_MODUL_H_SIARD) + getTextResourceService().getText(ERROR_XML_XMLLINT4_MISSING)); valid = false; } else { StringBuffer command = new StringBuffer("resources" + File.separator + "xmllint" + File.separator + "xmllint "); command.append("--noout --stream "); command.append(" --schema "); command.append(" "); command.append("\""); command.append(tableXsd.getAbsolutePath()); command.append("\""); command.append(" "); command.append("\""); command.append(tableXml.getAbsolutePath()); command.append("\""); Process proc = null; Runtime rt = null; try { File outTableXml = new File(pathToWorkDir + File.separator + "SIARD_H_" + tableXml.getName() + ".txt"); Util.switchOffConsoleToTxt(outTableXml); rt = Runtime.getRuntime(); proc = rt.exec(command.toString().split(" ")); // .split(" ") ist notwendig wenn in einem Pfad ein Doppelleerschlag vorhanden // ist! // Fehleroutput holen StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR-" + tableXml.getName()); // Output holen StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT-" + tableXml.getName()); // Threads starten errorGobbler.start(); outputGobbler.start(); // Warte, bis wget fertig ist 0 = Alles io int exitStatus = proc.waitFor(); // 200ms warten bis die Konsole umgeschaltet wird, damit wirklich alles im // file landet Thread.sleep(200); Util.switchOnConsole(); if (0 != exitStatus) { // message.xml.h.invalid.xml = <Message>{0} ist invalid zu // {1}</Message></Error> getMessageService().logError( getTextResourceService().getText(MESSAGE_XML_MODUL_H_SIARD) + getTextResourceService().getText( MESSAGE_XML_H_INVALID_XML, tableXml.getName(), tableXsd.getName())); valid = false; // Fehlermeldung aus outTableXml auslesen BufferedReader br = new BufferedReader(new FileReader(outTableXml)); try { String line = br.readLine(); String linePrev = null; /* Fehlermeldungen holen, ausser die letzte, die besagt, dass es invalide * ist (wurde bereits oben in D, F,E ausgegeben */ while (line != null) { if (linePrev != null) { getMessageService().logError(getTextResourceService() .getText(MESSAGE_XML_MODUL_H_SIARD) + getTextResourceService().getText( MESSAGE_XML_H_INVALID_ERROR, linePrev)); } linePrev = line; line = br.readLine(); } } finally { br.close(); /* Konsole zuerst einmal noch umleiten und die Streams beenden, damit die * dateien gelscht werden knnen */ Util.switchOffConsoleToTxtClose(outTableXml); System.out.println(" . "); Util.switchOnConsole(); Util.deleteFile(outTableXml); } } else { /* Konsole zuerst einmal noch umleiten und die Streams beenden, damit die * dateien gelscht werden knnen */ Util.switchOffConsoleToTxtClose(outTableXml); System.out.println(" . "); Util.switchOnConsole(); Util.deleteFile(outTableXml); } /* Konsole zuerst einmal noch umleiten und die Streams beenden, damit die * dateien gelscht werden knnen */ Util.switchOffConsoleToTxtClose(outTableXml); System.out.println(" . "); Util.switchOnConsole(); Util.deleteFile(outTableXml); } catch (Exception e) { getMessageService().logError( getTextResourceService().getText(MESSAGE_XML_MODUL_H_SIARD) + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage())); return false; } finally { if (proc != null) { closeQuietly(proc.getOutputStream()); closeQuietly(proc.getInputStream()); closeQuietly(proc.getErrorStream()); } } } } finally { } } } if (onWork == 41) { onWork = 2; System.out.print("H- "); System.out.print("\r"); } else if (onWork == 11) { onWork = 12; System.out.print("H\\ "); System.out.print("\r"); } else if (onWork == 21) { onWork = 22; System.out.print("H| "); System.out.print("\r"); } else if (onWork == 31) { onWork = 32; System.out.print("H/ "); System.out.print("\r"); } else { onWork = onWork + 1; } } } if (onWork == 41) { onWork = 2; System.out.print("H- "); System.out.print("\r"); } else if (onWork == 11) { onWork = 12; System.out.print("H\\ "); System.out.print("\r"); } else if (onWork == 21) { onWork = 22; System.out.print("H| "); System.out.print("\r"); } else if (onWork == 31) { onWork = 32; System.out.print("H/ "); System.out.print("\r"); } else { onWork = onWork + 1; } } } catch (java.io.IOException ioe) { valid = false; getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_H_SIARD) + getTextResourceService().getText(ERROR_XML_UNKNOWN, ioe.getMessage() + " (IOException)")); } catch (JDOMException e) { valid = false; getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_H_SIARD) + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage() + " (JDOMException)")); } catch (SAXException e) { valid = false; getMessageService().logError(getTextResourceService().getText(MESSAGE_XML_MODUL_H_SIARD) + getTextResourceService().getText(ERROR_XML_UNKNOWN, e.getMessage() + " (SAXException)")); } return valid; }
From source file:ch.kostceco.tools.siardval.validation.module.impl.ValidationDstructureModuleImpl.java
License:Open Source License
private boolean validateSchema(Element schema, Namespace ns, String pathToWorkDir) { boolean valid = true; Element schemaFolder = schema.getChild("folder", ns); File schemaPath = new File(new StringBuilder(pathToWorkDir).append(File.separator).append("content") .append(File.separator).append(schemaFolder.getText()).toString()); if (schemaPath.isDirectory()) { List<Element> tables = schema.getChild("tables", ns).getChildren("table", ns); for (Element table : tables) { valid = valid && validateTable(table, ns, pathToWorkDir, schemaPath); }// w w w. ja va 2 s .c om } else { valid = false; if (schemaPath.exists()) { getMessageService().logError(getTextResourceService().getText(MESSAGE_MODULE_D) + getTextResourceService().getText(MESSAGE_DASHES) + getTextResourceService().getText("content" + " " + MESSAGE_MODULE_D_INVALID_FOLDER) + " " + schemaPath.getName() + " in "); } else { getMessageService().logError(getTextResourceService().getText(MESSAGE_MODULE_D) + getTextResourceService().getText(MESSAGE_DASHES) + getTextResourceService().getText(MESSAGE_MODULE_D_MISSING_FOLDER) + " " + "content" + ": " + schemaPath.getName()); } } return valid; }
From source file:ch.kostceco.tools.siardval.validation.module.impl.ValidationDstructureModuleImpl.java
License:Open Source License
private boolean validateTable(Element table, Namespace ns, String pathToWorkDir, File schemaPath) { boolean valid = true; Element tableFolder = table.getChild("folder", ns); File tablePath = new File(new StringBuilder(schemaPath.getAbsolutePath()).append(File.separator) .append(tableFolder.getText()).toString()); if (tablePath.isDirectory()) { File tableXml = new File(new StringBuilder(tablePath.getAbsolutePath()).append(File.separator) .append(tableFolder.getText() + ".xml").toString()); valid = valid && validateFile(tableXml, tablePath); File tableXsd = new File(new StringBuilder(tablePath.getAbsolutePath()).append(File.separator) .append(tableFolder.getText() + ".xsd").toString()); valid = valid && validateFile(tableXsd, tablePath); } else {//from w w w .j a v a2 s .c o m valid = false; if (tablePath.exists()) { getMessageService().logError(getTextResourceService().getText(MESSAGE_MODULE_D) + getTextResourceService().getText(MESSAGE_DASHES) + getTextResourceService() .getText(schemaPath.getName() + " " + MESSAGE_MODULE_D_INVALID_FOLDER) + " " + tablePath.getName() + " in "); } else { getMessageService().logError(getTextResourceService().getText(MESSAGE_MODULE_D) + getTextResourceService().getText(MESSAGE_DASHES) + getTextResourceService().getText(MESSAGE_MODULE_D_MISSING_FOLDER) + " " + schemaPath.getName() + ": " + tablePath.getName()); } } return valid; }