Java Code Examples for org.jdom2.xpath.XPath#newInstance()
The following examples show how to use
org.jdom2.xpath.XPath#newInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VersionsValidatorTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
public String getTargetValue(String wfcKey) throws JDOMException { Element rootNode; if (wfcKey.startsWith("version.camel.")) { rootNode = camelRoot; } else if (wfcKey.startsWith("version.wildfly.")) { rootNode = wfRoot; } else { return null; } String targetKey = mapping.get(wfcKey); if (targetKey == null) { problems.add("Cannot find mapping for: " + wfcKey); return null; } XPath xpath = XPath.newInstance("/ns:project/ns:properties/ns:" + targetKey); xpath.addNamespace(Namespace.getNamespace("ns", "http://maven.apache.org/POM/4.0.0")); Element propNode = (Element) xpath.selectSingleNode(rootNode); if (propNode == null) { problems.add("Cannot obtain target property: " + targetKey); return null; } return propNode.getText(); }
Example 2
Source File: VersionsValidatorTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testVersions() throws Exception { XPath xpath = XPath.newInstance("/ns:project/ns:properties"); xpath.addNamespace(Namespace.getNamespace("ns", "http://maven.apache.org/POM/4.0.0")); Element node = (Element) xpath.selectSingleNode(wfcRoot); for (Object child : node.getChildren()) { String wfcKey = ((Element) child).getName(); String wfcVal = ((Element) child).getText(); String targetVal = getTargetValue(wfcKey); if (targetVal != null) { if (!targetVal.equals(wfcVal) && !targetVal.startsWith(wfcVal + ".redhat")) { problems.add(wfcKey + ": " + wfcVal + " => " + targetVal); } } } for (String line : problems) { System.err.println(line); } Assert.assertEquals("Mapping problems", Collections.emptyList(), problems); }
Example 3
Source File: XMLUtils.java From yawl with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public static List getXMLObjects(Document doc, String xpath) { List objects = new ArrayList(); try { XPath xp = XPath.newInstance(xpath); objects = xp.selectNodes(doc); } catch (Exception e) { logger.error("cannot process xpath: " + xpath + " on document: " + Utils.element2String(doc == null ? null : doc.getRootElement(), true)); } return objects; }
Example 4
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileCourseSets(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling CourseSets"); try { XPath docsPath = XPath.newInstance("/cm-data/course-sets/course-set"); List items = docsPath.selectNodes(doc); if(log.isDebugEnabled()) log.debug("Found " + items.size() + " course sets to reconcile"); // Add or update each of the course offerings specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Reconciling course set " + eid); CourseSet courseSet = null; if(cmService.isCourseSetDefined(eid)) { courseSet = updateCourseSet(cmService.getCourseSet(eid), element); } else { courseSet = addCourseSet(element); } // Update the members Element members = element.getChild("members"); if(members != null) { updateCourseSetMembers(members, courseSet); } } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling CourseSets in " + (System.currentTimeMillis()-start) + " ms"); }
Example 5
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileCourseSets(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling CourseSets"); try { XPath docsPath = XPath.newInstance("/cm-data/course-sets/course-set"); List items = docsPath.selectNodes(doc); if(log.isDebugEnabled()) log.debug("Found " + items.size() + " course sets to reconcile"); // Add or update each of the course offerings specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Reconciling course set " + eid); CourseSet courseSet = null; if(cmService.isCourseSetDefined(eid)) { courseSet = updateCourseSet(cmService.getCourseSet(eid), element); } else { courseSet = addCourseSet(element); } // Update the members Element members = element.getChild("members"); if(members != null) { updateCourseSetMembers(members, courseSet); } } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling CourseSets in " + (System.currentTimeMillis()-start) + " ms"); }
Example 6
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileEnrollmentSets(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling EnrollmentSets"); try { XPath docsPath = XPath.newInstance("/cm-data/enrollment-sets/enrollment-set"); List items = docsPath.selectNodes(doc); if(log.isDebugEnabled()) log.debug("Found " + items.size() + " enrollment sets to reconcile"); // Add or update each of the enrollment sets specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Reconciling enrollment set " + eid); EnrollmentSet enr = null; if(cmService.isEnrollmentSetDefined(eid)) { enr = updateEnrollmentSet(cmService.getEnrollmentSet(eid), element); } else { enr = addEnrollmentSet(element); } reconcileEnrollments(element.getChild("enrollments"), enr); reconcileOfficialInstructors(element, enr); } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling EnrollmentSets in " + (System.currentTimeMillis()-start) + " ms"); }
Example 7
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileCourseOfferings(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling CourseOfferings"); try { XPath docsPath = XPath.newInstance("/cm-data/course-offerings/course-offering"); List items = docsPath.selectNodes(doc); if(log.isDebugEnabled()) log.debug("Found " + items.size() + " course offerings to reconcile"); // Add or update each of the course offerings specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Reconciling course offering " + eid); CourseOffering courseOffering = null; if(cmService.isCourseOfferingDefined(eid)) { courseOffering = updateCourseOffering(cmService.getCourseOffering(eid), element); } else { courseOffering = addCourseOffering(element); } // Update the members Element members = element.getChild("members"); if(members != null) { updateCourseOfferingMembers(members, courseOffering); } } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling CourseOfferings in " + (System.currentTimeMillis()-start) + " ms"); }
Example 8
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileCanonicalCourses(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling CanonicalCourses"); try { XPath docsPath = XPath.newInstance("/cm-data/canonical-courses/canonical-course"); List items = docsPath.selectNodes(doc); if(log.isDebugEnabled()) log.debug("Found " + items.size() + " canonical courses to reconcile"); // Add or update each of the canonical courses specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Reconciling canonical course " + eid); if(cmService.isCanonicalCourseDefined(eid)) { updateCanonicalCourse(cmService.getCanonicalCourse(eid), element); } else { addCanonicalCourse(element); } } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling CanonicalCourses in " + (System.currentTimeMillis()-start) + " ms"); }
Example 9
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileCurrentAcademicSessions(Document doc) { try { List<String> academicSessionEids = new ArrayList<String>(); XPath docsPath = XPath.newInstance("/cm-data/current-academic-sessions/academic-session-eid"); List<Element> items = (List<Element>) docsPath.selectNodes(doc); for (Element element : items) { academicSessionEids.add(element.getText()); } if(log.isDebugEnabled()) log.debug("Found current academic sessions to reconcile: " + academicSessionEids); cmAdmin.setCurrentAcademicSessions(academicSessionEids); } catch (JDOMException jde) { log.error(jde.getMessage()); } }
Example 10
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileAcademicSessions(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling AcademicSessions"); // Get a list of all existing academic sessions List existing = cmService.getAcademicSessions(); // Create a map of existing AcademicSession EIDs to AcademicSessions Map academicSessionMap = new HashMap(); for(Iterator iter = existing.iterator(); iter.hasNext();) { AcademicSession as = (AcademicSession)iter.next(); academicSessionMap.put(as.getEid(), as); } // Find the academic sessions specified in the xml doc and reconcile them try { XPath docsPath = XPath.newInstance("/cm-data/academic-sessions/academic-session"); List items = docsPath.selectNodes(doc); // Add or update each of the academic sessions specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Found academic section to reconcile: " + eid); if(academicSessionMap.containsKey(eid)) { updateAcademicSession((AcademicSession)academicSessionMap.get(eid), element); } else { addAcademicSession(element); } } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling AcademicSessions in " + (System.currentTimeMillis()-start) + " ms"); }
Example 11
Source File: NcmlParserUtil.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static List getNcMLElements(String path, Document doc) { // XPath doesn't support default namespaces, so we add nc as a prefix for the tags within the namespace!!! if (!path.startsWith(NS_PREFIX_ON_TAG) && !path.startsWith("/")) path = NS_PREFIX_ON_TAG + path; Pattern pattern = Pattern.compile("/\\w"); Matcher matcher = pattern.matcher(path); StringBuilder sb = new StringBuilder(); int currentChar = 0; while (matcher.find()) { sb.append(path.substring(currentChar, matcher.start() - currentChar + 1)); if (!sb.toString().endsWith("/")) sb.append("/"); sb.append(NS_PREFIX_ON_TAG); currentChar = matcher.start() + 1; } sb.append(path.substring(currentChar, path.length())); XPath xpath; try { xpath = XPath.newInstance(sb.toString()); xpath.addNamespace(NS_PREFIX, doc.getRootElement().getNamespaceURI()); return xpath.selectNodes(doc); } catch (JDOMException e) { e.printStackTrace(); } return null; }
Example 12
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileEnrollmentSets(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling EnrollmentSets"); try { XPath docsPath = XPath.newInstance("/cm-data/enrollment-sets/enrollment-set"); List items = docsPath.selectNodes(doc); if(log.isDebugEnabled()) log.debug("Found " + items.size() + " enrollment sets to reconcile"); // Add or update each of the enrollment sets specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Reconciling enrollment set " + eid); EnrollmentSet enr = null; if(cmService.isEnrollmentSetDefined(eid)) { enr = updateEnrollmentSet(cmService.getEnrollmentSet(eid), element); } else { enr = addEnrollmentSet(element); } reconcileEnrollments(element.getChild("enrollments"), enr); reconcileOfficialInstructors(element, enr); } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling EnrollmentSets in " + (System.currentTimeMillis()-start) + " ms"); }
Example 13
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileCourseOfferings(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling CourseOfferings"); try { XPath docsPath = XPath.newInstance("/cm-data/course-offerings/course-offering"); List items = docsPath.selectNodes(doc); if(log.isDebugEnabled()) log.debug("Found " + items.size() + " course offerings to reconcile"); // Add or update each of the course offerings specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Reconciling course offering " + eid); CourseOffering courseOffering = null; if(cmService.isCourseOfferingDefined(eid)) { courseOffering = updateCourseOffering(cmService.getCourseOffering(eid), element); } else { courseOffering = addCourseOffering(element); } // Update the members Element members = element.getChild("members"); if(members != null) { updateCourseOfferingMembers(members, courseOffering); } } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling CourseOfferings in " + (System.currentTimeMillis()-start) + " ms"); }
Example 14
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileCanonicalCourses(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling CanonicalCourses"); try { XPath docsPath = XPath.newInstance("/cm-data/canonical-courses/canonical-course"); List items = docsPath.selectNodes(doc); if(log.isDebugEnabled()) log.debug("Found " + items.size() + " canonical courses to reconcile"); // Add or update each of the canonical courses specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Reconciling canonical course " + eid); if(cmService.isCanonicalCourseDefined(eid)) { updateCanonicalCourse(cmService.getCanonicalCourse(eid), element); } else { addCanonicalCourse(element); } } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling CanonicalCourses in " + (System.currentTimeMillis()-start) + " ms"); }
Example 15
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileCurrentAcademicSessions(Document doc) { try { List<String> academicSessionEids = new ArrayList<String>(); XPath docsPath = XPath.newInstance("/cm-data/current-academic-sessions/academic-session-eid"); List<Element> items = (List<Element>) docsPath.selectNodes(doc); for (Element element : items) { academicSessionEids.add(element.getText()); } if(log.isDebugEnabled()) log.debug("Found current academic sessions to reconcile: " + academicSessionEids); cmAdmin.setCurrentAcademicSessions(academicSessionEids); } catch (JDOMException jde) { log.error(jde.getMessage()); } }
Example 16
Source File: CmSynchronizer.java From sakai with Educational Community License v2.0 | 5 votes |
protected void reconcileAcademicSessions(Document doc) { long start = System.currentTimeMillis(); if(log.isInfoEnabled()) log.info("Reconciling AcademicSessions"); // Get a list of all existing academic sessions List existing = cmService.getAcademicSessions(); // Create a map of existing AcademicSession EIDs to AcademicSessions Map academicSessionMap = new HashMap(); for(Iterator iter = existing.iterator(); iter.hasNext();) { AcademicSession as = (AcademicSession)iter.next(); academicSessionMap.put(as.getEid(), as); } // Find the academic sessions specified in the xml doc and reconcile them try { XPath docsPath = XPath.newInstance("/cm-data/academic-sessions/academic-session"); List items = docsPath.selectNodes(doc); // Add or update each of the academic sessions specified in the xml for(Iterator iter = items.iterator(); iter.hasNext();) { Element element = (Element)iter.next(); String eid = element.getChildText("eid"); if(log.isDebugEnabled()) log.debug("Found academic section to reconcile: " + eid); if(academicSessionMap.containsKey(eid)) { updateAcademicSession((AcademicSession)academicSessionMap.get(eid), element); } else { addAcademicSession(element); } } } catch (JDOMException jde) { log.error(jde.getMessage()); } if(log.isInfoEnabled()) log.info("Finished reconciling AcademicSessions in " + (System.currentTimeMillis()-start) + " ms"); }
Example 17
Source File: TestRDFXMLSerializer.java From incubator-taverna-language with Apache License 2.0 | 5 votes |
protected Object xpathSelectElement(Element element, String xpath) throws JDOMException { XPath x = XPath.newInstance(xpath); x.addNamespace(SCUFL2_NS); x.addNamespace(RDF_NS); x.addNamespace(RDSF_NS); x.addNamespace(BEANSHELL_NS); //x.addNamespace(XML_NS); return x.selectSingleNode(element); }
Example 18
Source File: TestUCFPackage.java From incubator-taverna-language with Apache License 2.0 | 5 votes |
protected Object xpathSelectElement(Element element, String xpath) throws JDOMException { XPath x = XPath.newInstance(xpath); x.addNamespace(MANIFEST_NS); x.addNamespace(CONTAINER_NS); x.addNamespace(EXAMPLE_NS); return x.selectSingleNode(element); }
Example 19
Source File: ConsistentDatesTest.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test @Ignore("WMS not working") public void checkWMSDates() throws JDOMException, IOException { String endpoint = TestOnLocalServer.withHttpPath( "/wms/cdmUnitTest/ncss/climatology/PF5_SST_Climatology_Monthly_1985_2001.nc?service=WMS&version=1.3.0&request=GetCapabilities"); byte[] result = TestOnLocalServer.getContent(endpoint, 200, ContentType.xml); Reader in = new StringReader(new String(result, StandardCharsets.UTF_8)); SAXBuilder sb = new SAXBuilder(); Document doc = sb.build(in); if (show) { XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat()); fmt.output(doc, System.out); } XPath xPath = XPath.newInstance("//wms:Dimension"); xPath.addNamespace("wms", doc.getRootElement().getNamespaceURI()); Element dimNode = (Element) xPath.selectSingleNode(doc); // List<String> content = Arrays.asList(dimNode.getText().trim().split(",")); List<String> content = new ArrayList<>(); for (String d : Arrays.asList(dimNode.getText().trim().split(","))) { // System.out.printf("Date= %s%n", d); CalendarDate cd = CalendarDate.parseISOformat(null, d); content.add(cd.toString()); } assertEquals(expectedDatesAsDateTime, content); }