List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:fr.gouv.culture.vitam.reader.XmlReader.java
License:Open Source License
@Override public String[] readOneLine() throws IOException { if (this.nodes != null) { if (this.nodes.isEmpty()) { this.nodes = null; return null; }/*from ww w . ja v a 2 s. c o m*/ String[] result = new String[xpaths.length - 1]; Node root = this.nodes.remove(0); for (int i = 1; i < xpaths.length; i++) { Node sub = root.selectSingleNode(xpaths[i]); if (sub != null) { result[i - 1] = sub.getText(); } else { result[i - 1] = null; } } return result; } return null; }
From source file:fr.gouv.culture.vitam.utils.XmlDom.java
License:Open Source License
/** * Attached file accessibility test/* w w w .j a v a2 s . co m*/ * * @param current_file * @param task * optional * @param config * @param argument * @param checkDigest * @param checkFormat * @param showFormat * @return VitamResult */ static final public VitamResult all_tests_in_one(File current_file, RunnerLongTask task, ConfigLoader config, VitamArgument argument, boolean checkDigest, boolean checkFormat, boolean showFormat) { SAXReader saxReader = new SAXReader(); VitamResult finalResult = new VitamResult(); Element root = initializeCheck(argument, finalResult, current_file); try { Document document = saxReader.read(current_file); removeAllNamespaces(document); Node nodesrc = document.selectSingleNode("/digests"); String src = null; String localsrc = current_file.getParentFile().getAbsolutePath() + File.separator; if (nodesrc != null) { nodesrc = nodesrc.selectSingleNode("@source"); if (nodesrc != null) { src = nodesrc.getText() + "/"; } } if (src == null) { src = localsrc; } @SuppressWarnings("unchecked") List<Node> nodes = document.selectNodes("//" + config.DOCUMENT_FIELD); if (nodes == null) { Element result = fillInformation(argument, root, "result", "filefound", "0"); addDate(argument, config, result); } else { String number = "" + nodes.size(); Element result = fillInformation(argument, root, "result", "filefound", number); XMLWriter writer = null; writer = new XMLWriter(System.out, StaticValues.defaultOutputFormat); int currank = 0; for (Node node : nodes) { currank++; Node attachment = node.selectSingleNode(config.ATTACHMENT_FIELD); if (attachment == null) { continue; } Node file = attachment.selectSingleNode(config.FILENAME_ATTRIBUTE); if (file == null) { continue; } Node mime = null; Node format = null; if (checkFormat) { mime = attachment.selectSingleNode(config.MIMECODE_ATTRIBUTE); format = attachment.selectSingleNode(config.FORMAT_ATTRIBUTE); } String sfile = null; String smime = null; String sformat = null; String sintegrity = null; String salgo = null; if (file != null) { sfile = file.getText(); } if (mime != null) { smime = mime.getText(); } if (format != null) { sformat = format.getText(); } // Now check // first existence check String ficname = src + sfile; Element check = fillInformation(argument, root, "check", "filename", sfile); File fic1 = new File(ficname); File fic2 = new File(localsrc + sfile); File fic = null; if (fic1.canRead()) { fic = fic1; } else if (fic2.canRead()) { fic = fic2; } if (fic == null) { fillInformation(argument, check, "find", "status", StaticValues.LBL.error_filenotfile.get()); addDate(argument, config, result); finalResult.values[AllTestsItems.FileError.ordinal()]++; finalResult.values[AllTestsItems.GlobalError.ordinal()]++; } else { Element find = fillInformation(argument, check, "find", "status", "ok"); addDate(argument, config, find); finalResult.values[AllTestsItems.FileSuccess.ordinal()]++; if (checkDigest) { @SuppressWarnings("unchecked") List<Node> integrities = node.selectNodes(config.INTEGRITY_FIELD); for (Node integrity : integrities) { Node algo = integrity.selectSingleNode(config.ALGORITHME_ATTRIBUTE); salgo = null; sintegrity = null; if (integrity != null) { sintegrity = integrity.getText(); if (algo != null) { salgo = algo.getText(); } else { salgo = config.DEFAULT_DIGEST; } } // Digest check if (salgo == null) { // nothing } else if (salgo.equals(StaticValues.XML_SHA1)) { salgo = "SHA-1"; } else if (salgo.equals(StaticValues.XML_SHA256)) { salgo = "SHA-256"; } else if (salgo.equals(StaticValues.XML_SHA512)) { salgo = "SHA-512"; } else { salgo = null; } if (algo != null) { Element eltdigest = Commands.checkDigest(fic, salgo, sintegrity); if (eltdigest.selectSingleNode(".[@status='ok']") != null) { finalResult.values[AllTestsItems.DigestSuccess.ordinal()]++; } else { finalResult.values[AllTestsItems.DigestError.ordinal()]++; finalResult.values[AllTestsItems.GlobalError.ordinal()]++; } addDate(argument, config, eltdigest); addElement(writer, argument, check, eltdigest); } } } // Check format if (checkFormat && config.droidHandler != null) { try { // Droid List<DroidFileFormat> list = config.droidHandler.checkFileFormat(fic, argument); Element cformat = Commands.droidFormat(list, smime, sformat, sfile, fic); if (config.droidHandler != null) { cformat.addAttribute("pronom", config.droidHandler.getVersionSignature()); } if (config.droidHandler != null) { cformat.addAttribute("droid", "6.1"); } if (cformat.selectSingleNode(".[@status='ok']") != null) { finalResult.values[AllTestsItems.FormatSuccess.ordinal()]++; } else if (cformat.selectSingleNode(".[@status='warning']") != null) { finalResult.values[AllTestsItems.FormatWarning.ordinal()]++; finalResult.values[AllTestsItems.GlobalWarning.ordinal()]++; } else { finalResult.values[AllTestsItems.FormatError.ordinal()]++; finalResult.values[AllTestsItems.GlobalError.ordinal()]++; } addDate(argument, config, cformat); addElement(writer, argument, check, cformat); } catch (Exception e) { Element cformat = fillInformation(argument, check, "format", "status", "Error " + e.toString()); addDate(argument, config, cformat); finalResult.values[AllTestsItems.SystemError.ordinal()]++; } } // Show format if (showFormat && config.droidHandler != null) { Element showformat = Commands.showFormat(sfile, smime, sformat, fic, config, argument); if (showformat.selectSingleNode(".[@status='ok']") != null) { finalResult.values[AllTestsItems.ShowSuccess.ordinal()]++; } else if (showformat.selectSingleNode(".[@status='warning']") != null) { finalResult.values[AllTestsItems.ShowWarning.ordinal()]++; finalResult.values[AllTestsItems.GlobalWarning.ordinal()]++; } else { finalResult.values[AllTestsItems.ShowError.ordinal()]++; finalResult.values[AllTestsItems.GlobalError.ordinal()]++; } addDate(argument, config, showformat); addElement(writer, argument, check, showformat); } } addDate(argument, config, result); root = finalizeOneCheck(argument, finalResult, current_file, number); if (root != null) { result = root.element("result"); } if (task != null) { float value = ((float) currank) / (float) nodes.size(); value *= 100; task.setProgressExternal((int) value); } } } document = null; } catch (DocumentException e1) { Element result = fillInformation(argument, root, "result", "parsererror", StaticValues.LBL.error_error.get() + " " + e1 + " - " + StaticValues.LBL.error_parser.get() + " (" + SAXReader.class.getName() + ")"); addDate(argument, config, result); finalResult.values[AllTestsItems.SystemError.ordinal()]++; } catch (UnsupportedEncodingException e1) { Element result = fillInformation(argument, root, "result", "parsererror", StaticValues.LBL.error_error.get() + " " + e1 + " - " + StaticValues.LBL.error_parser.get() + " (" + XMLWriter.class.getName() + ")"); addDate(argument, config, result); finalResult.values[AllTestsItems.SystemError.ordinal()]++; } finalizeAllCheck(argument, finalResult); return finalResult; }
From source file:gg.imports.ImporterEngine.java
License:Open Source License
/** * Gets the version of the Grisbi file/* w w w .j av a2 s. c om*/ * @param grisbiFileDocument Document of the Grisbi file for which the version is wanted * @return Version of the Grisbi file (<CODE>FileVersion.UNSUPPORTED_VERSION</CODE> if the file is not supported) */ private FileVersion getFileVersion(Document grisbiFileDocument) { log.entering(this.getClass().getName(), "getFileVersion"); assert (grisbiFileDocument != null); FileVersion fileVersion = FileVersion.UNSUPPORTED_VERSION; // Get the version of the grisbi file Node fileVersionNode = grisbiFileDocument.selectSingleNode("/Grisbi/Generalites/Version_fichier"); if (fileVersionNode != null) { String fileVersionStr = fileVersionNode.getText(); if (fileVersionStr.compareToIgnoreCase("0.5.0") == 0) { fileVersion = FileVersion.VERSION_0_5_0; } } log.exiting(this.getClass().getName(), "getFileVersion", fileVersion); return fileVersion; }
From source file:io.mashin.oep.hpdl.XMLReadUtils.java
License:Open Source License
public static HashMap<String, Point> graphicalInfoFrom(Document document) { HashMap<String, Point> graphicalInfoMap = new HashMap<String, Point>(); try {/* w w w . j a v a 2 s.co m*/ SAXReader reader = new SAXReader(); Pattern p = Pattern.compile("\\s*<workflow>.*</workflow>\\s*", Pattern.DOTALL); @SuppressWarnings("unchecked") Iterator<Node> iter = document.nodeIterator(); while (iter.hasNext()) { Node xmlNode = iter.next(); if (xmlNode.getNodeType() == Node.COMMENT_NODE) { String graphicalInfo = xmlNode.getText(); if (p.matcher(graphicalInfo).find()) { Element graphicalElement = reader.read(new StringReader(graphicalInfo)).getRootElement(); @SuppressWarnings("unchecked") Iterator<Node> gIter = graphicalElement.nodeIterator(); while (gIter.hasNext()) { Node gNode = gIter.next(); if (gNode.getName() != null && gNode.getName().equals("node")) { graphicalInfoMap.put(gNode.valueOf("@name"), new Point(Integer.parseInt(gNode.valueOf("@x")), Integer.parseInt(gNode.valueOf("@y")))); } } break; } } } } catch (DocumentException ex) { ex.printStackTrace(); } return graphicalInfoMap; }
From source file:io.mashin.oep.hpdl.XMLReadUtils.java
License:Open Source License
private static void initPropertyPropertyElementFrom(PropertyPropertyElement ppe, Node node) { String propName = ""; String propValue = ""; String propDescription = ""; Node n = node.selectSingleNode("name"); if (n != null) { propName = n.getText(); }/*ww w. j a va2 s. c o m*/ n = node.selectSingleNode("value"); if (n != null) { propValue = n.getText(); } n = node.selectSingleNode("description"); if (n != null) { propDescription = n.getText(); } ppe.setValueOfName(propName); ppe.setValueOfValue(propValue); ppe.setValueOfDescription(propDescription); }
From source file:io.mashin.oep.hpdl.XMLReadUtils.java
License:Open Source License
public static PropertyElementCollection textCollectionFrom(Node element, String xpath, PropertyElementCollection pec) { @SuppressWarnings("unchecked") List<Node> nodes = element.selectNodes(xpath); if (nodes != null) { for (Node node : nodes) { TextPropertyElement tpe = (TextPropertyElement) pec.createAndAdd(); String value = node.getText(); if (value != null) { tpe.setStringValue(value); }/*ww w . j av a 2 s.c o m*/ } } return pec; }
From source file:it.alidays.mapengine.core.fetch.PathBinder.java
License:Apache License
@Override public Object bind(Element element) { String result = null;//from ww w . j a va 2s . c om Node node = element.selectSingleNode(this.path); if (node != null) { result = node.getText(); } return result; }
From source file:it.pdfsam.plugin.coverfooter.GUI.CoverFooterMainGUI.java
License:Open Source License
private void addTableRowsFromNode(Node file_node) { if (file_node != null) { boolean encrypt = false; String num_pages = ""; String page_selection = ""; File file_to_add = null;/*from w w w .j a v a 2s . co m*/ try { Node file_name = (Node) file_node.selectSingleNode("@name"); if (file_name != null) { file_to_add = new File(file_name.getText()); } } catch (Exception ex) { file_to_add = null; fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Error: ") + ex.getMessage(), LogPanel.LOG_ERROR); } try { if (file_to_add != null) { PdfReader pdf_reader = new PdfReader(new RandomAccessFileOrArray(file_to_add.getAbsolutePath()), null); encrypt = pdf_reader.isEncrypted(); // we retrieve the total number of pages num_pages = Integer.toString(pdf_reader.getNumberOfPages()); pdf_reader.close(); } } catch (Exception ex) { num_pages = ex.getMessage(); } try { Node file_pages = (Node) file_node.selectSingleNode("@pageselection"); if (file_pages != null) { page_selection = file_pages.getText(); } else { page_selection = CoverFooterMainGUI.ALL_STRING; } } catch (Exception ex) { page_selection = CoverFooterMainGUI.ALL_STRING; } try { modello_cover_table.addRow(new CoverFooterItemType(file_to_add.getName(), file_to_add.getAbsolutePath(), num_pages, page_selection, encrypt)); fireLogPropertyChanged( GettextResource.gettext(i18n_messages, "File selected: ") + file_to_add.getName(), LogPanel.LOG_INFO); } catch (Exception ex) { fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Error: ") + ex.getMessage(), LogPanel.LOG_ERROR); } } }
From source file:it.pdfsam.plugin.coverfooter.GUI.CoverFooterMainGUI.java
License:Open Source License
public void loadJobNode(Node arg) throws LoadJobException { final Node arg0 = arg; final Thread loadnode_thread = new Thread(add_or_run_threads, "load") { private String wip_text; public void run() { try { Node cover_node = (Node) arg0.selectSingleNode("cover/@value"); if (cover_node != null) { cover_text_field.setText(cover_node.getText()); }//from w w w. j a v a2 s.c o m Node footer_node = (Node) arg0.selectSingleNode("footer/@value"); if (footer_node != null) { footer_text_field.setText(footer_node.getText()); } Node file_destination = (Node) arg0.selectSingleNode("destination/@value"); if (file_destination != null) { destination_text_field.setText(file_destination.getText()); } Node file_overwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (file_overwrite != null) { overwrite_checkbox.setSelected(file_overwrite.getText().equals("true")); } Node file_compressed = (Node) arg0.selectSingleNode("compressed/@value"); if (file_compressed != null) { output_compressed_check.setSelected(file_compressed.getText().equals("true")); } modello_cover_table.clearData(); List file_list = arg0.selectNodes("filelist/file"); wip_text = GettextResource.gettext(i18n_messages, "Please wait while reading ") + " ..."; addWipText(wip_text); for (int i = 0; file_list != null && i < file_list.size(); i++) { Node file_node = (Node) file_list.get(i); addTableRowsFromNode(file_node); } removeWipText(wip_text); fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "CoverAndFooter section loaded."), LogPanel.LOG_INFO); } catch (Exception ex) { fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Error: ") + ex.getMessage(), LogPanel.LOG_ERROR); } } }; loadnode_thread.start(); }
From source file:it.pdfsam.plugin.encrypt.GUI.EncryptMainGUI.java
License:Open Source License
public void loadJobNode(Node arg0) throws LoadJobException { try {//from w ww . j ava 2 s . c o m Node file_source = (Node) arg0.selectSingleNode("source/@value"); if (file_source != null) { source_text_field.setText(file_source.getText()); } Node allow_all = (Node) arg0.selectSingleNode("allowall/@value"); if (allow_all != null && allow_all.getText().equals("true")) { allowall_check.doClick(); } else { Node permissions = (Node) arg0.selectSingleNode("permissions"); if (permissions != null) { List listEnab = permissions.selectNodes("enabled"); for (int j = 0; listEnab != null && j < listEnab.size(); j++) { Node enabledNode = (Node) listEnab.get(j); if (enabledNode != null) { permissions_check[Integer.parseInt(enabledNode.selectSingleNode("@value").getText())] .doClick(); } } } } Node enc_type = (Node) arg0.selectSingleNode("enctype/@value"); if (enc_type != null) { encrypt_type.setSelectedItem((String) enc_type.getText()); } Node user_pwd = (Node) arg0.selectSingleNode("usrpwd/@value"); if (user_pwd != null) { user_pwd_field.setText(user_pwd.getText()); } Node owner_pwd = (Node) arg0.selectSingleNode("ownerpwd/@value"); if (owner_pwd != null) { owner_pwd_field.setText(owner_pwd.getText()); } Node file_destination = (Node) arg0.selectSingleNode("destination/@value"); if (file_destination != null) { dest_folder_text.setText(file_destination.getText()); choose_a_folder_radio.doClick(); } else { same_as_source_radio.doClick(); } Node file_overwrite = (Node) arg0.selectSingleNode("overwrite/@value"); if (file_overwrite != null) { overwrite_checkbox.setSelected(file_overwrite.getText().equals("true")); } Node file_compressed = (Node) arg0.selectSingleNode("compressed/@value"); if (file_compressed != null) { output_compressed_check.setSelected(file_compressed.getText().equals("true")); } Node file_prefix = (Node) arg0.selectSingleNode("prefix/@value"); if (file_prefix != null) { out_prefix_text.setText(file_prefix.getText()); } fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Encrypt section loaded."), LogPanel.LOG_INFO); } catch (Exception ex) { fireLogPropertyChanged(GettextResource.gettext(i18n_messages, "Error: ") + ex.getMessage(), LogPanel.LOG_ERROR); } }