add template files

This commit is contained in:
2024-06-03 15:03:25 +02:00
commit cf9470e6d0
9 changed files with 584 additions and 0 deletions

28
.gitignore vendored Normal file
View File

@@ -0,0 +1,28 @@
### Java ###
# Compiled class file
*.class
# Log file
*.log
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
### Maven ###
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.idea

22
README.md Normal file
View File

@@ -0,0 +1,22 @@
# XPATH-repository-tasks:
## Complete the XPathTasks.xml file that is located in src/main/resources/xpath with the answers to the following exercises:
1. Take XML with books and calculate number of all books available.
2. Take XML with books and return first, third and last book from collection
3. Take XML with books and return book with id = 7 from collection
4. Take XML with books and return all books from year 2018
5. Take XML with books and return all books which was released between 1990 and 1995
6. Take XML with books and return book with title starting with word Harry
7. Take XML with books and return book witch contains word "Law" in the title
8. Take XML with books and return all attributes that are named id use // operator
9. Take XML with books and return all attributes that are named id don't use // operator
10. Take XML with books and return all node names in document
11. Take XML with books and return book written by authors which are still alive
12. Take XML with readers and sum age of all readers
13. Take XML with readers and return age node name without namespace for book with id = 7
14. Take XML with readers and return lastname node name with namespace for book with id = 4
15. Take XML with readers and return namespace for reader with id = 2
16. Take XML with readers and return first name and last name for each reader in following format: first name , last name
17. Take XML with readers and return all child nodes of each reader
18. Take XML with book or reader try write XPath expressions for each Xpath Axes operator

96
pom.xml Normal file
View File

@@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.r11.xsd</groupId>
<artifactId>xsd</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>6.3.0.202209071007-r</version>
</dependency>
<!-- Jsch from jgit dependency is not supported [RSA 2048] so we need use mwiede fork. -->
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.ssh.jsch</artifactId>
<version>6.3.0.202209071007-r</version>
<exclusions>
<exclusion>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.mwiede</groupId>
<artifactId>jsch</artifactId>
<version>0.2.4</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.ssh.apache</artifactId>
<version>6.3.0.202209071007-r</version>
</dependency>
<dependency>
<groupId>jaxb</groupId>
<artifactId>activation</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>Saxon-HE</artifactId>
<version>11.4</version>
</dependency>
<dependency>
<groupId>xml-resolver</groupId>
<artifactId>xml-resolver</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,50 @@
package com.r11.xpath;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "task")
@XmlAccessorType(XmlAccessType.FIELD)
public class Task {
@XmlAttribute
private int id;
private String name;
private String xpath;
public Task() {
}
public Task(int id, String name, String xpath) {
this.id = id;
this.name = name;
this.xpath = xpath;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getXPath() {
return xpath;
}
public void setXpath(String xpath) {
this.xpath = xpath;
}
}

View File

@@ -0,0 +1,29 @@
package com.r11.xpath;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
@XmlRootElement(name = "tasks")
@XmlAccessorType(XmlAccessType.FIELD)
public class TasksContainer {
@XmlElement(name = "task")
private final List<Task> tasks = new ArrayList<>();
public List<Task> getTasks() {
tasks.sort(Comparator.comparingInt(Task::getId));
return tasks;
}
public Task getOne(int id) {
return tasks.stream()
.filter(b -> b.getId() == id)
.findFirst()
.orElse(null);
}
}

View File

@@ -0,0 +1,189 @@
<?xml version="1.0" encoding="utf-8"?>
<b:books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:b="http://www.demo.com"
xmlns:a="http://www.demo.com/author"
xmlns:p="http://www.demo.com/person"
xsi:schemaLocation="http://www.demo.com file:///C:/Users/Kacper%20Makuch/Desktop/makuchk/library/book.xsd">
<b:book id="1">
<b:name>Hamlet</b:name>
<b:date>2001-05-04</b:date>
<a:author id="1">
<p:firstname>William</p:firstname>
<p:lastname>Shakespeare</p:lastname>
<a:date-of-birth>1564-04-23</a:date-of-birth>
<a:date-of-death>1616-04-23</a:date-of-death>
</a:author>
<b:availability>false</b:availability>
</b:book>
<b:book id="2">
<b:name>Macbeth</b:name>
<b:date>2000-12-13</b:date>
<a:author id="1">
<p:firstname>William</p:firstname>
<p:lastname>Shakespeare</p:lastname>
<a:date-of-birth>1564-04-23</a:date-of-birth>
<a:date-of-death>1616-04-23</a:date-of-death>
</a:author>
<b:availability>false</b:availability>
</b:book>
<b:book id="3">
<b:name>Harry Potter and the Sorcerer's Stone</b:name>
<b:date>2005-04-29</b:date>
<a:author id="2">
<p:firstname>J.K.</p:firstname>
<p:lastname>Rowling</p:lastname>
<a:date-of-birth>1965-07-31</a:date-of-birth>
</a:author>
<b:availability>true</b:availability>
</b:book>
<b:book id="4">
<b:name>The Long Walk</b:name>
<b:date>2018-07-01</b:date>
<a:author id="4">
<p:firstname>Stephen</p:firstname>
<p:lastname>King</p:lastname>
<a:date-of-birth>1947-09-21</a:date-of-birth>
</a:author>
<b:availability>true</b:availability>
</b:book>
<b:book id="5">
<b:name>Misery</b:name>
<b:date>2018-01-31</b:date>
<a:author id="4">
<p:firstname>Stephen</p:firstname>
<p:lastname>King</p:lastname>
<a:date-of-birth>1947-09-21</a:date-of-birth>
</a:author>
<b:availability>true</b:availability>
</b:book>
<b:book id="6">
<b:name>Think and Grow Rich</b:name>
<b:date>2004-09-10</b:date>
<a:author id="6">
<p:firstname>Napoleon</p:firstname>
<p:lastname>Hill</p:lastname>
<a:date-of-birth>1883-09-26</a:date-of-birth>
<a:date-of-death>1970-11-08</a:date-of-death>
</a:author>
<b:availability>true</b:availability>
</b:book>
<b:book id="7">
<b:name>The Law of Success</b:name>
<b:date>1982-05-09</b:date>
<a:author id="6">
<p:firstname>Napoleon</p:firstname>
<p:lastname>Hill</p:lastname>
<a:date-of-birth>1883-09-26</a:date-of-birth>
<a:date-of-death>1970-11-08</a:date-of-death>
</a:author>
<b:availability>false</b:availability>
</b:book>
<b:book id="8">
<b:name>Patriot Games</b:name>
<b:date>1995-10-21</b:date>
<a:author id="5">
<p:firstname>Tom</p:firstname>
<p:lastname>Clancy</p:lastname>
<a:date-of-birth>1947-04-12</a:date-of-birth>
<a:date-of-death>2013-10-01</a:date-of-death>
</a:author>
<b:availability>false</b:availability>
</b:book>
<b:book id="9">
<b:name>The Sum of All Fears</b:name>
<b:date>1992-09-19</b:date>
<a:author id="5">
<p:firstname>Tom</p:firstname>
<p:lastname>Clancy</p:lastname>
<a:date-of-birth>1947-04-12</a:date-of-birth>
<a:date-of-death>2013-10-01</a:date-of-death>
</a:author>
<b:availability>false</b:availability>
</b:book>
<b:book id="10">
<b:name>The Alchemist</b:name>
<b:date>2017-02-20</b:date>
<a:author id="3">
<p:firstname>Paulo</p:firstname>
<p:lastname>Coelho</p:lastname>
<a:date-of-birth>1947-08-24</a:date-of-birth>
</a:author>
<b:availability>false</b:availability>
</b:book>
<b:book id="11">
<b:name>Hamlet</b:name>
<b:date>1994-06-01</b:date>
<a:author id="1">
<p:firstname>William</p:firstname>
<p:lastname>Shakespeare</p:lastname>
<a:date-of-birth>1564-04-23</a:date-of-birth>
<a:date-of-death>1616-04-23</a:date-of-death>
</a:author>
<b:availability>false</b:availability>
</b:book>
<b:book id="12">
<b:name>Measure for Measure</b:name>
<b:date>1990-03-23</b:date>
<a:author id="1">
<p:firstname>William</p:firstname>
<p:lastname>Shakespeare</p:lastname>
<a:date-of-birth>1564-04-23</a:date-of-birth>
<a:date-of-death>1616-04-23</a:date-of-death>
</a:author>
<b:availability>false</b:availability>
</b:book>
<b:book id="13">
<b:name>Hamlet</b:name>
<b:date>1989-05-05</b:date>
<a:author id="1">
<p:firstname>William</p:firstname>
<p:lastname>Shakespeare</p:lastname>
<a:date-of-birth>1564-04-23</a:date-of-birth>
<a:date-of-death>1616-04-23</a:date-of-death>
</a:author>
<b:availability>true</b:availability>
</b:book>
<b:book id="14">
<b:name>Hamlet</b:name>
<b:date>1999-05-30</b:date>
<a:author id="1">
<p:firstname>William</p:firstname>
<p:lastname>Shakespeare</p:lastname>
<a:date-of-birth>1564-04-23</a:date-of-birth>
<a:date-of-death>1616-04-23</a:date-of-death>
</a:author>
<b:availability>true</b:availability>
</b:book>
<b:book id="15">
<b:name>The Law of Success</b:name>
<b:date>2004-11-26</b:date>
<a:author id="6">
<p:firstname>Napoleon</p:firstname>
<p:lastname>Hill</p:lastname>
<a:date-of-birth>1883-09-26</a:date-of-birth>
<a:date-of-death>1970-11-08</a:date-of-death>
</a:author>
<b:availability>true</b:availability>
</b:book>
<b:book id="16">
<b:name>Romeo and Juliet</b:name>
<b:date>1997-02-08</b:date>
<a:author id="1">
<p:firstname>William</p:firstname>
<p:lastname>Shakespeare</p:lastname>
<a:date-of-birth>1564-04-23</a:date-of-birth>
<a:date-of-death>1616-04-23</a:date-of-death>
</a:author>
<b:availability>true</b:availability>
</b:book>
<b:book id="17">
<b:name>The Alchemist</b:name>
<b:date>2009-08-21</b:date>
<a:author id="3">
<p:firstname>Paulo</p:firstname>
<p:lastname>Coelho</p:lastname>
<a:date-of-birth>1947-08-24</a:date-of-birth>
</a:author>
<b:availability>true</b:availability>
</b:book>
</b:books>

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<r:readers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:r="http://www.demo.com/reader"
xmlns:p="http://www.demo.com/person"
xsi:schemaLocation="http://www.demo.com/reader file:///C:/Users/Kacper%20Makuch/Desktop/makuchk/library/reader.xsd">
<r:reader id="1">
<p:firstname>John</p:firstname>
<p:lastname>Burg</p:lastname>
<p:age>45</p:age>
<r:bookId>32</r:bookId>
<r:bookId>57</r:bookId>
</r:reader>
<r:reader id="2">
<p:firstname>Steven</p:firstname>
<p:lastname>Pick</p:lastname>
<p:age>29</p:age>
<r:bookId>27</r:bookId>
<r:bookId>12</r:bookId>
<r:bookId>91</r:bookId>
</r:reader>
<r:reader id="3">
<!--warning-->
<p:firstname>Peter</p:firstname>
<p:lastname>Stock</p:lastname>
<p:age>21</p:age>
<r:bookId>42</r:bookId>
<r:bookId>1</r:bookId>
<r:bookId>9</r:bookId>
<r:bookId>98</r:bookId>
<r:bookId>60</r:bookId>
</r:reader>
<r:reader id="4">
<p:firstname>Robert</p:firstname>
<p:lastname>Neat</p:lastname>
<p:age>32</p:age>
<r:bookId>87</r:bookId>
<r:bookId>23</r:bookId>
<r:bookId>11</r:bookId>
<r:bookId>7</r:bookId>
<r:bookId>55</r:bookId>
</r:reader>
<r:reader id="5">
<p:firstname>John</p:firstname>
<p:lastname>Pale</p:lastname>
<p:age>36</p:age>
<r:bookId>81</r:bookId>
</r:reader>
<r:reader id="6">
<p:firstname>Josh</p:firstname>
<p:lastname>Ericson</p:lastname>
<p:age>46</p:age>
<r:bookId>8</r:bookId>
</r:reader>
<r:reader id="7">
<p:firstname>Patrick</p:firstname>
<p:lastname>Evans</p:lastname>
<p:age>50</p:age>
</r:reader>
<r:reader id="8">
<p:firstname>Paul</p:firstname>
<p:lastname>Navy</p:lastname>
<p:age>23</p:age>
<r:bookId>69</r:bookId>
<r:bookId>78</r:bookId>
</r:reader>
<r:reader id="9">
<p:firstname>Rob</p:firstname>
<p:lastname>Rockwell</p:lastname>
<p:age>30</p:age>
<r:bookId>47</r:bookId>
</r:reader>
<r:reader id="10">
<p:firstname>Luis</p:firstname>
<p:lastname>Pocket</p:lastname>
<p:age>52</p:age>
<r:bookId>10</r:bookId>
<r:bookId>83</r:bookId>
<r:bookId>2</r:bookId>
</r:reader>
</r:readers>

View File

View File

@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
Special characters for xml:
https://docs.oracle.com/cd/A97335_02/apps.102/bc4j/developing_bc_projects/obcCustomXml.htm
-->
<tasks>
<task id="1">
<name>Take XML with books and calculate number of all books available.</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="2">
<name>Take XML with books and return first, third and last book from collection.</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="3">
<name>Take XML with books and return book with id = 7 from collection.</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="4">
<name>Take XML with books and return all books from year 2018.</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="5">
<name>Take XML with books and return all books which was released between 1990 and 1995</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="6">
<name>Take XML with books and return book with title starting with word Harry</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="7">
<name>Take XML with books and return book witch contains word "Law" in the title</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="8">
<name>Take XML with books and return all attributes that are named id use // operator</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="9">
<name>Take XML with books and return all attributes that are named id don't use // operator</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="10">
<name>Take XML with books and return all node names in document</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="11">
<name>Take XML with books and return book written by authors which are still alive</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="12">
<name>Take XML with readers and sum age of all readers</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="13">
<name>Take XML with readers and return age node name without namespace for book with id = 7</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="14">
<name>Take XML with readers and return lastname node name with namespace for book with id = 4</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="15">
<name>Take XML with readers and return namespace for reader with id = 2</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="16">
<name>Take XML with readers and return first name and last name for each reader in following format: first name , last name</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="17">
<name>Take XML with readers and return all child nodes of each reader</name>
<xpath>Type the xpath here</xpath>
</task>
<task id="18">
<name>Take XML with book or reader try write XPath expressions for each Xpath Axes operator</name>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
<xpath>Type the xpath here</xpath>
</task>
</tasks>