List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:dk.netarkivet.harvester.datamodel.H1HeritrixTemplate.java
License:Open Source License
/** * Constructor for HeritrixTemplate class. * * @param doc the order.xml/*from w w w .j a v a 2s . c o m*/ * @param verify If true, verifies if the given dom4j Document contains the elements required by our software. * @throws ArgumentNotValid if doc is null, or verify is true and doc does not obey the constraints required by our * software. */ public H1HeritrixTemplate(Document doc, boolean verify) { ArgumentNotValid.checkNotNull(doc, "Document doc"); String xpath; Node node; Pattern pattern; Matcher matcher; if (verify) { for (Map.Entry<String, Pattern> required : requiredXpaths.entrySet()) { xpath = required.getKey(); node = doc.selectSingleNode(xpath); ArgumentNotValid.checkTrue(node != null, "Template error: Missing node: " + xpath + ". The template looks like this: " + doc.asXML()); pattern = required.getValue(); matcher = pattern.matcher(node.getText().trim()); ArgumentNotValid.checkTrue(matcher.matches(), "Template error: Value '" + node.getText() + "' of node '" + xpath + "' does not match required regexp '" + pattern + "'. The template looks like this: " + doc.asXML()); } verified = true; // Required that Heritrix write its ARC/WARC files to the correct dir // relative to the crawldir. This dir is defined by the constant: // dk.netarkivet.common.Constants.ARCDIRECTORY_NAME. // dk.netarkivet.common.Constants.WARCDIRECTORY_NAME. int validArchivePaths = 0; node = doc.selectSingleNode(ARC_ARCHIVER_PATH_XPATH); if (node != null) { pattern = Pattern.compile(dk.netarkivet.common.Constants.ARCDIRECTORY_NAME); matcher = pattern.matcher(node.getText().trim()); ArgumentNotValid.checkTrue(matcher.matches(), "Template error: Value '" + node.getText() + "' of node '" + ARC_ARCHIVER_PATH_XPATH + "' does not match required regexp '" + pattern + "'"); ++validArchivePaths; } node = doc.selectSingleNode(WARC_ARCHIVER_PATH_XPATH); if (node != null) { pattern = Pattern.compile(dk.netarkivet.common.Constants.WARCDIRECTORY_NAME); matcher = pattern.matcher(node.getText().trim()); ArgumentNotValid.checkTrue(matcher.matches(), "Template error: Value '" + node.getText() + "' of node '" + WARC_ARCHIVER_PATH_XPATH + "' does not match required regexp '" + pattern + "'"); ++validArchivePaths; } ArgumentNotValid.checkTrue(validArchivePaths > 0, "Template error: " + "An ARC or WARC writer processor seems to be missing"); } this.template = (Document) doc.clone(); }
From source file:dk.netarkivet.harvester.datamodel.H1HeritrixTemplate.java
License:Open Source License
/** * Return true if the templatefile has deduplication enabled. * @return True if Deduplicator is enabled. */// w ww .j a va2s . com @Override public boolean IsDeduplicationEnabled() { Node xpathNode = template.selectSingleNode(DEDUPLICATOR_ENABLED); return xpathNode != null && xpathNode.getText().trim().equals("true"); }
From source file:dk.netarkivet.harvester.datamodel.H1HeritrixTemplate.java
License:Open Source License
@Override public void setMaxJobRunningTime(Long maxJobRunningTimeSecondsL) { // get and set the "max-time-sec" node of the orderXMLdoc String xpath = MAXTIMESEC_PATH_XPATH; Node groupMaxTimeSecNode = template.selectSingleNode(xpath); if (groupMaxTimeSecNode != null) { String currentMaxTimeSec = groupMaxTimeSecNode.getText(); groupMaxTimeSecNode.setText(Long.toString(maxJobRunningTimeSecondsL)); log.trace("Value of groupMaxTimeSecNode changed from " + currentMaxTimeSec + " to " + maxJobRunningTimeSecondsL); } else {// w w w.j a va 2s.c o m throw new IOFailure("Unable to locate xpath '" + xpath + "' in the order.xml: " + template.asXML()); } }
From source file:dk.netarkivet.testutils.XmlAsserts.java
License:Open Source License
public static void assertNodeTextInXpath(String message, Document doc, String xpath, String expected) { Node dedup_index_node = doc.selectSingleNode(xpath); assertEquals(message, expected, dedup_index_node.getText().trim()); }
From source file:edu.ku.brc.af.ui.forms.persist.ViewLoader.java
License:Open Source License
/** * @param element the DOM element for building the form * @param type the type of form to be built * @param id the id of the form/*from www .ja v a 2 s . c o m*/ * @param name the name of the form * @param className the class name of the data object * @param gettableClassName the class name of the getter * @param settableClassName the class name of the setter * @param desc the description * @param useResourceLabels whether to use resource labels * @param tableinfo table info * @return a form view of type "form" */ protected static FormViewDef createFormViewDef(final Element element, final ViewDef.ViewType type, final String name, final String className, final String gettableClassName, final String settableClassName, final String desc, final boolean useResourceLabels, final DBTableInfo tableinfo) { FormViewDef formViewDef = new FormViewDef(type, name, className, gettableClassName, settableClassName, desc, useResourceLabels); fldVerTableInfo = null; if (type != ViewDefIFace.ViewType.formtable) { if (doFieldVerification) { if (instance.fldVerTableModel == null) { instance.createFieldVerTableModel(); } try { //log.debug(className); Class<?> classObj = Class.forName(className); if (FormDataObjIFace.class.isAssignableFrom(classObj)) { fldVerTableInfo = DBTableIdMgr.getInstance().getByClassName(className); isTreeClass = fldVerTableInfo != null && fldVerTableInfo.getFieldByName("highestChildNodeNumber") != null; fldVerFormViewDef = formViewDef; } } catch (ClassNotFoundException ex) { String msg = "ClassNotFoundException[" + className + "] Name[" + name + "]"; log.error(msg); FormDevHelper.appendFormDevError(msg); //edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); //edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ViewLoader.class, comments, ex); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ViewLoader.class, ex); } } List<FormRowIFace> rows = formViewDef.getRows(); instance.doingResourceLabels = useResourceLabels; //gViewDef = formViewDef; processRows(element, rows, tableinfo); instance.doingResourceLabels = false; createDef(element, "columnDef", rows.size(), formViewDef.getColumnDefItem()); createDef(element, "rowDef", rows.size(), formViewDef.getRowDefItem()); formViewDef.setEnableRules(getEnableRules(element)); fixLabels(formViewDef.getName(), rows, tableinfo); } else { Node defNode = element.selectSingleNode("definition"); if (defNode != null) { String defName = defNode.getText(); if (StringUtils.isNotEmpty(defName)) { formViewDef.setDefinitionName(defName); return formViewDef; } } String msg = "formtable is missing or has empty <defintion> node"; log.error(msg); FormDevHelper.appendFormDevError(msg); return null; } return formViewDef; }
From source file:edu.ku.brc.specify.toycode.L18NStringResApp.java
License:Open Source License
/** * @param file/*from w w w.j av a 2s. co m*/ */ public void process(final File fileArg, final boolean doDiffs) { try { String dirName = RES_PATH + "values-" + destLocale.getLanguage(); String path = dirName + File.separator + fileArg.getName(); File file = fileArg; if (doDiffs) { file = new File(path); } Document doc = readFileToDOM4J(new FileInputStream(file)); Node root = doc.getRootElement(); for (Object nodeObj : root.selectNodes("/resources/string")) { Node node = (Node) nodeObj; String name = XMLHelper.getAttr((Element) node, "name", null); if (doDiffs) { if (baseHash.get(name) != null) { continue; } } String text = node.getText(); String transText = translate(text); if (transText != null) { node.setText(transText); } System.out.println(name + "[" + text + "][" + transText + "]"); } File dir = new File(dirName); if (!dir.exists()) { dir.mkdir(); } FileOutputStream fos = new FileOutputStream(path); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(fos, format); writer.write(doc); writer.flush(); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.ku.brc.specify.toycode.L18NStringResApp.java
License:Open Source License
/** * @param file// ww w.j a v a 2 s.co m * @param hash * @param index */ public void process(final File file, final HashMap<String, Pair<String, String>> hash, final int index) { try { Document doc = readFileToDOM4J(new FileInputStream(file)); Node root = doc.getRootElement(); for (Object nodeObj : root.selectNodes("/resources/string")) { Node node = (Node) nodeObj; String name = XMLHelper.getAttr((Element) node, "name", null); String text = node.getText(); Pair<String, String> p = hash.get(name); if (p == null) { p = new Pair<String, String>(); hash.put(name, p); } if (index == 0) { p.first = text; } else { p.second = text; } } if (index == 1) { FileOutputStream fos = new FileOutputStream( FilenameUtils.getBaseName(file.getName()) + "_compare" + destLocale.getLanguage() + ".txt"); PrintWriter pw = new PrintWriter(fos); Vector<String> keys = new Vector<String>(hash.keySet()); Collections.sort(keys); for (String key : keys) { Pair<String, String> p = hash.get(key); pw.println(String.format("\n---- %s -----\n%s\n%s", key, chk(p.first), chk(p.second))); } pw.flush(); pw.close(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.scripps.fl.pubchem.EUtilsFactory.java
License:Apache License
public Document getDocument(InputStream in) throws Exception { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DOMReader reader = new DOMReader(); Document document = reader.read(builder.parse(new BufferedInputStream(in))); // SAXReader reader = new SAXReader(); // Document document = reader.read(in); in.close();/*from ww w .j a v a2 s .com*/ Node node = document.selectSingleNode("/eSearchResult/ERROR"); if (node != null) throw new Exception(node.getText()); return document; }
From source file:edu.scripps.fl.pubchem.EUtilsFactory.java
License:Apache License
public List<Relation> getRelations(Document document) { String fromDb = document.selectSingleNode("/eLinkResult/LinkSet/DbFrom").getText(); String idStr = document.selectSingleNode("/eLinkResult/LinkSet/IdList/Id").getText(); Long id = Long.parseLong(idStr); List<Node> linkSetDbs = document.selectNodes("/eLinkResult/LinkSet/LinkSetDb"); ArrayList<Relation> list = new ArrayList<Relation>(); for (Node linkSetDb : linkSetDbs) { String toDb = linkSetDb.selectSingleNode("DbTo").getText(); String linkName = linkSetDb.selectSingleNode("LinkName").getText(); List<Node> ids = linkSetDb.selectNodes("Link/Id"); list.ensureCapacity(list.size() + ids.size()); for (Node idNode : ids) { long relatedId = Long.parseLong(idNode.getText()); if (id == relatedId) continue; Relation relation = new Relation(); relation.setRelationName(linkName); relation.setFromDb(fromDb);//from w ww . ja va2 s . com relation.setFromId(id); relation.setToDb(toDb); relation.setToId(relatedId); list.add(relation); } } return list; }
From source file:edu.scripps.fl.pubchem.EUtilsFactory.java
License:Apache License
public Collection<Long> getIds(Long id, String fromDb, String toDb) throws Exception { Document document = EUtilsFactory.getInstance().getDocument( "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/elink.fcgi", "dbfrom", fromDb, "db", toDb, "id", "" + id); List<Node> linkSetDbs = document.selectNodes("/eLinkResult/LinkSet/LinkSetDb"); Set<Long> relatedIds = new HashSet<Long>(); for (Node linkSetDb : linkSetDbs) { String linkName = linkSetDb.selectSingleNode("LinkName").getText(); List<Node> ids = linkSetDb.selectNodes("Link/Id"); for (Node idNode : ids) { long relatedId = Long.parseLong(idNode.getText()); if (id.equals(relatedId)) continue; relatedIds.add(relatedId);/*w ww . ja va2s . c o m*/ } } return relatedIds; }