List of usage examples for org.dom4j Node valueOf
String valueOf(String xpathExpression);
valueOf
evaluates an XPath expression and returns the textual representation of the results the XPath string-value of this node.
From source file:edu.scripps.fl.dom4j.util.FormControlVisitorSupport.java
License:Apache License
public void visit(Element node) { // Visits the given Element if ("input".equalsIgnoreCase(node.getName())) { String value = node.valueOf("@value"); if ("checkbox".equalsIgnoreCase(node.valueOf("@type"))) if ("".equals(node.valueOf("@checked"))) value = ""; addParameter(node.valueOf("@name"), value); } else if ("textarea".equalsIgnoreCase(node.getName())) addParameter(node.valueOf("@name"), node.getText()); else if ("select".equalsIgnoreCase(node.getName())) { for (Node n : (List<Node>) node.selectNodes("option")) { for (Node attr : (List<Node>) ((Element) n).attributes()) { if ("selected".equalsIgnoreCase(attr.getName())) { addParameter(node.valueOf("@name"), n.valueOf("@value")); return; }//from w w w. j a v a2 s . c om } } } }
From source file:edu.scripps.fl.pubchem.PubChemFactory.java
License:Apache License
public PCAssay populateAssayFromSummaryDocument(Session session, Node docSumNode) throws Exception { // Node idNode = docSumNode.selectSingleNode("AID"); // Integer aid = Integer.parseInt(idNode.getText()); String uid = docSumNode.valueOf("@uid"); PCAssay assay = getAssay(session, Integer.parseInt(uid)); populateAssayFromSummaryDocument(assay, docSumNode); for (PCAssayXRef assayXRef : assay.getAssayXRefs()) { session.saveOrUpdate(assayXRef); }//from w w w . j a v a 2 s . c o m session.save(assay); return assay; }
From source file:edu.scripps.fl.pubchem.PubChemFactory.java
License:Apache License
public void populateAssayFromSummaryDocument(PCAssay assay, Node docSumNode) throws Exception { Node errorNode = docSumNode.selectSingleNode("error"); if (errorNode != null) throw new Exception("Entrez error: " + errorNode.getText()); List<Node> list = docSumNode.selectNodes("*"); String uid = docSumNode.valueOf("@uid"); assay.setAID(Integer.parseInt(uid)); for (Node node : list) { String name = node.getName(); Object value = node.getText(); if (node.selectNodes("*").size() > 0) { } else {// www . ja v a2 s .c o m String property = propMap.getProperty(name); if (null != property) { Class clazz = PropertyUtils.getPropertyType(assay, property); if (clazz.isAssignableFrom(Date.class)) value = parseDate(value); BeanUtils.setProperty(assay, property, value); } else { if (!unprocessedProperties.containsKey(name)) { unprocessedProperties.put(name, ""); log.warn(String.format("Cannot determine PCAssay bean property '%s'", name)); } } } } String desc = assay.getDescription(); // eutils summary description doesn't contain new lines // so don't update it if it already has a value (when we populate via xml first). if (desc == null || "".equals(desc) || !desc.contains("\n")) { Node node = docSumNode.selectSingleNode("AssayDescription"); assay.setDescription(node.getText()); } return; }
From source file:edu.scripps.fl.pubchem.PubChemXMLParserFactory.java
License:Apache License
protected void populateAssayResultsFromXML(PCAssay assay, Node assayDescriptionNode) throws Exception { List<PCAssayResult> results = null; List<Node> assayResultNodes = assayDescriptionNode .selectNodes("../../../PC-AssaySubmit_data/PC-AssayResults"); if (assayResultNodes.size() == 0) return;/* w ww .j a va 2 s . co m*/ else results = new ArrayList<PCAssayResult>(assayResultNodes.size()); List<PCAssayColumn> testedCols = assay.getTestedColumns(); PCAssayColumn activeColumn = assay.getActiveColumn(); for (Node resultNode : assayResultNodes) { PCAssayResult result = new PCAssayResult(); String val = resultNode.selectSingleNode("PC-AssayResults_sid").valueOf("text()"); result.setSID(Long.parseLong(val)); val = resultNode.selectSingleNode("PC-AssayResults_outcome").valueOf("@value"); val = val.substring(0, 1).toUpperCase() + val.substring(1); result.setOutcome(val); val = resultNode.selectSingleNode("PC-AssayResults_rank").valueOf("text()"); result.setRankScore(Integer.parseInt(val)); List<Node> assayDataNodes = resultNode.selectNodes("PC-AssayResults_data/PC-AssayData"); List<String> all = GrowthList.decorate(new ArrayList(assay.getColumns().size() - 2)); result.setAllValues(all); for (Node node : assayDataNodes) { val = node.valueOf("PC-AssayData_tid/text()"); int index = Integer.parseInt(val) - 1; val = node.selectSingleNode(".//*[starts-with(name(),'PC-AssayData_value_')]").getText(); all.set(index, val); } // if a dose response assay with a marked activeConcentration if ("confirmatory".equals(assay.getActivityOutcomeMethod()) && activeColumn != null) { String actConc = all.get(activeColumn.getTID() - 1); if (null != actConc && !"".equals(actConc)) { result.setPrimaryValue(Double.valueOf(actConc)); result.setPrimaryColumn(activeColumn); PCAssayColumn qualCol = assay.getQualifierColumn(); if (qualCol != null) { String qual = all.get(qualCol.getTID() - 1); if (!"".equals(qual)) result.setQualifier(qual); } } } else if ("screening".equals(assay.getActivityOutcomeMethod()) && testedCols.size() > 0) { PCAssayColumn testedCol = testedCols.get(0); String value = all.get(testedCol.getTID() - 1); result.setPrimaryColumn(testedCol); if (null != value && !"".equals(value)) if ("float".equals(testedCol.getType()) || "int".equals(testedCol.getType())) result.setPrimaryValue(Double.parseDouble(value)); else result.setPrimaryValueAsString(value); } // put all testedConcentration columns into an ordered array. Interested in numbers here only. result.getTestedValues().clear(); for (int ii = 0; ii < testedCols.size(); ii++) { PCAssayColumn testedCol = testedCols.get(ii); String value = all.get(testedCol.getTID() - 1); if (null != value && !"".equals(value)) { try { Double dbl = Double.parseDouble(value); result.getTestedValues().set(ii, dbl); } catch (NumberFormatException ex) { // if not a number then don't worry about it. } } } assay.getResults().add(result); } }
From source file:edu.scripps.fl.pubchem.PubChemXMLParserFactory.java
License:Apache License
protected PCAssay populateAssayFromXMLNode(Node topNode) throws Exception { // String assayDescPath = "PC-AssaySubmit_assay/PC-AssaySubmit_assay_descr/PC-AssayDescription"; Node assayDescNode = null;/*from ww w . j ava2s.co m*/ if (topNode.getName().equals("PC-AssayDescription")) assayDescNode = topNode; else { assayDescNode = topNode.selectSingleNode(".//PC-AssayDescription"); } if (assayDescNode == null) throw new Exception( String.format("Cannot find PC-AssayDescription node in provided node %s", topNode.getPath())); Node node = assayDescNode.selectSingleNode("PC-AssayDescription_aid/PC-ID/PC-ID_id"); Integer aid = new Integer(node.getText()); try { PCAssay assay = new PCAssay(); if (aid > 0) assay.setAID(aid); node = assayDescNode.selectSingleNode("PC-AssayDescription_aid/PC-ID/PC-ID_version"); Integer version = new Integer(node.getText()); assay.setVersion(version); node = assayDescNode.selectSingleNode("PC-AssayDescription_revision"); Integer revision = new Integer(node.getText()); assay.setRevision(revision); Node trackingNode = assayDescNode .selectSingleNode("PC-AssayDescription_aid-source/PC-Source/PC-Source_db/PC-DBTracking"); node = trackingNode.selectSingleNode("PC-DBTracking_name"); assay.setSourceName(node.getText()); node = trackingNode.selectSingleNode("PC-DBTracking_source-id/Object-id/Object-id_str"); assay.setExtRegId(node.getText()); // hold until date node = trackingNode.selectSingleNode("PC-DBTracking_date"); if (node != null) { String year = node.selectSingleNode("Date/Date_std/Date-std/Date-std_year").getText(); String month = node.selectSingleNode("Date/Date_std/Date-std/Date-std_month").getText(); String day = node.selectSingleNode("Date/Date_std/Date-std/Date-std_day").getText(); if (DEBUGGING) log.info("year: " + year + " month: " + month + " day: " + day); Calendar calendar = Calendar.getInstance(); calendar.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day)); assay.setHoldUntilDate(calendar.getTime()); if (DEBUGGING) log.info(calendar.getTime().toString()); } node = assayDescNode.selectSingleNode("PC-AssayDescription_name"); assay.setName(node.getText()); List<Node> nodes = assayDescNode .selectNodes("PC-AssayDescription_description/PC-AssayDescription_description_E"); assay.setDescription(join(nodes, separator)); nodes = assayDescNode.selectNodes("PC-AssayDescription_protocol/PC-AssayDescription_protocol_E"); assay.setProtocol(join(nodes, separator)); nodes = assayDescNode.selectNodes("PC-AssayDescription_comment/PC-AssayDescription_comment_E"); assay.setComment(join(nodes, separator)); node = assayDescNode.selectSingleNode("PC-AssayDescription_activity-outcome-method"); if (node != null) assay.setActivityOutcomeMethod(node.valueOf("@value")); node = assayDescNode .selectSingleNode("PC-AssayDescription_grant-number/PC-AssayDescription_grant-number_E"); if (node != null) assay.setGrantNumber(node.getText()); node = assayDescNode.selectSingleNode("PC-AssayDescription_project-category"); if (node != null) assay.setProjectCategory(node.valueOf("@value")); assay.getAssayXRefs().removeAll(assay.getAssayXRefs()); nodes = assayDescNode.selectNodes("PC-AssayDescription_xref/PC-AnnotatedXRef"); handleXRefs(assay, null, nodes); nodes = assayDescNode.selectNodes("PC-AssayDescription_target/PC-AssayTargetInfo"); handleTargetXRefs(assay, null, nodes); handlePanels(assay, assayDescNode); handleColumns(assay, assayDescNode); handleComments(assay, assayDescNode); return assay; } catch (Exception ex) { throw new RuntimeException("Problem with AID " + aid, ex); } }
From source file:edu.scripps.fl.pubchem.PubChemXMLParserFactory.java
License:Apache License
protected void handleColumns(PCAssay assay, Node assayDescNode) { Map<Integer, PCAssayColumn> map = new HashMap(); for (PCAssayColumn col : assay.getColumns()) map.put(col.getTID(), col);//ww w.j a va 2 s . com ensureColumn(assay, -1, "Outcome", "string"); ensureColumn(assay, 0, "Score", "float"); Map<Integer, PCAssayPanel> mapPanels = new HashMap(); for (PCAssayPanel panel : assay.getPanels()) mapPanels.put(panel.getPanelNumber(), panel); List<Node> nodes = assayDescNode.selectNodes("PC-AssayDescription_results/PC-ResultType"); for (Node n : nodes) { String tid = n.selectSingleNode("PC-ResultType_tid").getText(); String name = n.selectSingleNode("PC-ResultType_name").getText(); String type = n.selectSingleNode("PC-ResultType_type").valueOf("@value"); PCAssayColumn column = ensureColumn(assay, Integer.parseInt(tid), name, type); Node node = n.selectSingleNode("PC-ResultType_unit"); if (node != null) column.setUnit(node.valueOf("@value")); List<Node> descNodes = n.selectNodes("PC-ResultType_description/PC-ResultType_description_E"); column.setDescription(join(descNodes, separator)); if (DEBUGGING) log.info("Column description: " + join(descNodes, separator)); node = n.selectSingleNode("PC-ResultType_ac"); if (node != null) column.setActiveConcentration("true".equals(node.valueOf("@value"))); node = n.selectSingleNode("PC-ResultType_tc"); if (node != null) { Node node2 = node.selectSingleNode("PC-ConcentrationAttr/PC-ConcentrationAttr_dr-id"); if (node2 != null) { column.setCurvePlotLabel(Integer.parseInt(node2.getText())); } String testedConc = node.selectSingleNode("PC-ConcentrationAttr/PC-ConcentrationAttr_concentration") .getText(); column.setTestedConcentration(Double.parseDouble(testedConc)); String testedUnit = node.selectSingleNode("PC-ConcentrationAttr/PC-ConcentrationAttr_unit") .valueOf("@value"); column.setTestedConcentrationUnit(testedUnit); } node = n.selectSingleNode("PC-ResultType_panel-info/PC-AssayPanelTestResult"); if (node != null) { String panelId = node.selectSingleNode("PC-AssayPanelTestResult_mid").getText(); PCAssayPanel panel = mapPanels.get(Integer.parseInt(panelId)); column.setPanel(panel); String panelColumnType = node.selectSingleNode("PC-AssayPanelTestResult_readout-annot") .valueOf("@value"); column.setPanelReadoutType(panelColumnType); } } }
From source file:edu.scripps.fl.pubchem.web.session.PCWebSession.java
License:Apache License
protected InputStream getFtpLinkAsStream(Document document) throws Exception { Node linkNode = document.selectSingleNode("//a[@href=starts-with(.,'ftp://')]"); if (null != linkNode) { String url = linkNode.valueOf("@href"); log.info("Found ftp link: " + url); return new GZIPInputStream(new URL(url).openStream()); }// ww w. j ava 2s . co m File file = File.createTempFile(getClass().getName(), ".html"); document.write(new FileWriter(file)); throw new Exception("Received a PubChem web page without an ftp link. Please check " + file); }
From source file:edu.scripps.fl.pubchem.xml.extract.ResultTidExtractor.java
License:Apache License
public List<ResultTid> getTidValuesFromXML(Document doc) throws IllegalAccessException, InvocationTargetException { List<ResultTid> tidValues = new ArrayList<ResultTid>(); List<Node> nodes = doc.selectNodes("//PC-AssayDescription_results/PC-ResultType"); for (Node nn : nodes) { ResultTid tidValue = new ResultTid(); tidValue.setTidName(nn.selectSingleNode("PC-ResultType_name").getText()); tidValue.setTidType(nn.selectSingleNode("PC-ResultType_type").valueOf("@value")); Node node = nn.selectSingleNode("PC-ResultType_unit"); if (node != null) tidValue.setTidUnit(node.valueOf("@value")); node = nn.selectSingleNode("PC-ResultType_description/PC-ResultType_description_E"); if (node != null) tidValue.setTidDescription(node.getText()); node = nn.selectSingleNode("PC-ResultType_ac"); if (node != null) tidValue.setIsActiveConcentration(true); node = nn.selectSingleNode("PC-ResultType_tc"); if (node != null) { Node node2 = node.selectSingleNode("PC-ConcentrationAttr/PC-ConcentrationAttr_dr-id"); if (node2 != null) { BeanUtils.setProperty(tidValue, "tidPlot", node2.getText()); }// w w w . j a v a 2s . c om BeanUtils.setProperty(tidValue, "tidConcentration", node.selectSingleNode("PC-ConcentrationAttr/PC-ConcentrationAttr_concentration").getText()); } node = nn.selectSingleNode("PC-ResultType_panel-info/PC-AssayPanelTestResult"); if (node != null) { BeanUtils.setProperty(tidValue, "tidPanelNum", node.selectSingleNode("PC-AssayPanelTestResult_mid").getText()); tidValue.setTidPanelReadout( node.selectSingleNode("PC-AssayPanelTestResult_readout-annot").valueOf("@value")); } tidValues.add(tidValue); } return tidValues; }
From source file:edu.umd.cs.buildServer.builder.JavaSubmissionExtractor.java
License:Apache License
@Override protected void pruneSourceFileList(List<String> sourceFileList) { // Apply exclusion patterns, if any if (excludedSourceFileList.size() > 0) { outer: for (Iterator<String> i = sourceFileList.iterator(); i.hasNext();) { String sourceFile = i.next(); for (Iterator<Pattern> j = excludedSourceFileList.iterator(); j.hasNext();) { Pattern regex = j.next(); Matcher m = regex.matcher(sourceFile); if (m.matches()) { i.remove();/*from ww w . j av a2 s .co m*/ continue outer; } } } } if (classpathFile == null) return; // The submission contained a .classpath file. // Try to read it so we can find out the sourcepath // and remove all entries that aren't on the sourcepath // from the source files list. try { List<String> sourcePath = new LinkedList<String>(); InputStream in = null; try { in = new BufferedInputStream(new FileInputStream(new File(getDirectory(), classpathFile))); SAXReader reader = new SAXReader(); Document document = reader.read(in); for (Iterator<?> i = document.selectNodes(SRC_ENTRY_XPATH).iterator(); i.hasNext();) { Node node = (Node) i.next(); String srcPathEntry = node.valueOf("@path"); if (!srcPathEntry.equals("") && !srcPathEntry.endsWith("/")) srcPathEntry += "/"; sourcePath.add(srcPathEntry); } if (!allSourcePathsExist(sourcePath)) return; // Remove all files that don't begin with a valid source path // element from the source file list for (Iterator<String> i = sourceFileList.iterator(); i.hasNext();) { String sourceFile = i.next(); if (!isOnSourcePath(sourceFile, sourcePath)) { // Source file wasn't on the source path i.remove(); } } } finally { try { if (in != null) in.close(); } catch (IOException ignore) { // Ignore } } } catch (IOException e) { getLog().warn("Could not read .classpath file in submission zipfile", e); } catch (DocumentException e) { getLog().warn("Could not read .classpath file in submission zipfile", e); } }
From source file:edu.umd.cs.buildServer.inspection.PMDRunner.java
License:Apache License
private void readPMDTestOutcomes(XMLDocumentBuilder stdoutMonitor) { Document document = stdoutMonitor.getDocument(); if (document == null) return;/* w w w.jav a2s. c om*/ int count = TestOutcome.FIRST_TEST_NUMBER; Iterator<?> fileNodeIter = document.selectNodes("//pmd/file").iterator(); while (fileNodeIter.hasNext()) { Node fileElement = (Node) fileNodeIter.next(); String fileName = fileElement.valueOf("@name"); Iterator<?> violationIter = fileElement.selectNodes("./violation").iterator(); while (violationIter.hasNext()) { Node violationElement = (Node) violationIter.next(); String line = violationElement.valueOf("@line"); String rule = violationElement.valueOf("@rule"); String description = violationElement.getText(); String priority = violationElement.valueOf("@priority"); // Turn the warning into a TestOutcome TestOutcome testOutcome = new TestOutcome(); testOutcome.setTestType(TestOutcome.TestType.PMD); testOutcome.setTestName(rule); testOutcome.setOutcome(TestOutcome.STATIC_ANALYSIS); testOutcome.setShortTestResult(fileName + ":" + line); testOutcome.setLongTestResultCompressIfNeeded(description); testOutcome.setTestNumber(Integer.toString(count++)); testOutcome.setExceptionClassName(priority); // XXX: HACK! testOutcomeCollection.add(testOutcome); } } projectSubmission.getLog().info("Recorded " + count + " PMD warnings as test outcomes"); }