-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Eddy Vermoen
committed
Dec 24, 2023
0 parents
commit 73d10a6
Showing
22 changed files
with
347 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?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>ben-eddy74</groupId> | ||
<artifactId>plesk-xml-api-jaxbindings</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<name>jaxbinding</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>jakarta.xml.bind</groupId> | ||
<artifactId>jakarta.xml.bind-api</artifactId> | ||
<version>4.0.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.xml.bind</groupId> | ||
<artifactId>jaxb-impl</artifactId> | ||
<version>4.0.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>3.7.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-project-info-reports-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package plesk.xml.api.bindings; | ||
|
||
import jakarta.xml.bind.JAXBContext; | ||
import jakarta.xml.bind.JAXBException; | ||
import jakarta.xml.bind.Marshaller; | ||
import jakarta.xml.bind.PropertyException; | ||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.xml.namespace.NamespaceContext; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
import javax.xml.xpath.XPath; | ||
import javax.xml.xpath.XPathConstants; | ||
import javax.xml.xpath.XPathExpressionException; | ||
import javax.xml.xpath.XPathFactory; | ||
import org.w3c.dom.Document; | ||
import org.w3c.dom.NodeList; | ||
import org.xml.sax.SAXException; | ||
import plesk.xml.api.bindings.entity.NodeBinding; | ||
import plesk.xml.api.bindings.entity.PropertyBinding; | ||
import plesk.xml.api.bindings.entity.RootBindings; | ||
import plesk.xml.api.bindings.entity.SchemaBinding; | ||
|
||
/** | ||
* Hello world! | ||
* | ||
*/ | ||
public class App { | ||
|
||
public static void main(String[] args) throws IOException, PropertyException, JAXBException { | ||
System.out.println("Hello World!"); | ||
|
||
DocumentBuilderFactory docfactory = DocumentBuilderFactory.newInstance(); | ||
docfactory.setNamespaceAware(true); | ||
|
||
XPathFactory xpathfactory = XPathFactory.newDefaultInstance(); | ||
XPath xpath = xpathfactory.newXPath(); | ||
xpath.setNamespaceContext(new NamespaceContext() { | ||
@Override | ||
public String getNamespaceURI(String prefix) { | ||
return switch (prefix) { | ||
case "jaxb" -> | ||
"https://jakarta.ee/xml/ns/jaxb"; | ||
case "xs" -> | ||
"http://www.w3.org/2001/XMLSchema"; | ||
default -> | ||
""; | ||
}; | ||
} | ||
|
||
@Override | ||
public String getPrefix(String namespaceURI) { | ||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody | ||
} | ||
|
||
@Override | ||
public Iterator<String> getPrefixes(String namespaceURI) { | ||
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody | ||
} | ||
}); | ||
String xsdfolder = "C:\\Temp\\Plesk\\1.6.9.1\\"; | ||
String expression = "//xs:complexType[xs:choice/xs:element[@name='add']]"; | ||
|
||
RootBindings root = new RootBindings(); | ||
root.version = "3.0"; | ||
|
||
Files.list(Paths.get(xsdfolder)).forEach(path -> { | ||
|
||
if (Files.isDirectory(path)) { | ||
return; | ||
} | ||
|
||
try { | ||
Document doc = docfactory.newDocumentBuilder().parse(path.toFile()); | ||
|
||
NodeList nodeList = (NodeList) xpath.compile(expression).evaluate(doc, XPathConstants.NODESET); | ||
|
||
SchemaBinding schemabinding = new SchemaBinding(); | ||
schemabinding.schemafile = path.getFileName().toString(); | ||
|
||
System.out.println(nodeList.getLength()); | ||
for (int i = 0; i < nodeList.getLength(); i++) { | ||
|
||
if (nodeList.item(i).getAttributes().getLength() > 0) { | ||
NodeBinding nodebinding = new NodeBinding(); | ||
nodebinding.node = "//%s[@name='%s']/xs:choice".formatted( | ||
nodeList.item(i).getNodeName(), | ||
nodeList.item(i).getAttributes().item(0).getTextContent() | ||
); | ||
schemabinding.nodebindings.add(nodebinding); | ||
|
||
PropertyBinding property = new PropertyBinding(); | ||
property.propertyname = "operations"; | ||
nodebinding.bindings = List.of(property); | ||
} | ||
} | ||
|
||
if(!schemabinding.nodebindings.isEmpty()){ | ||
root.schemabindings.add(schemabinding); | ||
} | ||
} catch (SAXException | IOException | XPathExpressionException | ParserConfigurationException ex) { | ||
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
}); | ||
|
||
JAXBContext context = JAXBContext.newInstance(RootBindings.class); | ||
Marshaller marshaller = context.createMarshaller(); | ||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); | ||
StringWriter result = new StringWriter(); | ||
marshaller.marshal(root, result); | ||
System.out.println(result.toString()); | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/plesk/xml/api/bindings/entity/NodeBinding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package plesk.xml.api.bindings.entity; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.xml.bind.annotation.XmlAttribute; | ||
import jakarta.xml.bind.annotation.XmlElement; | ||
|
||
public class NodeBinding { | ||
|
||
@XmlAttribute(name = "node") | ||
public String node; | ||
|
||
|
||
@XmlElement(name = "property", namespace = "https://jakarta.ee/xml/ns/jaxb") | ||
public List<PropertyBinding> bindings; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/plesk/xml/api/bindings/entity/PropertyBinding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package plesk.xml.api.bindings.entity; | ||
|
||
import jakarta.xml.bind.annotation.XmlAttribute; | ||
|
||
public class PropertyBinding { | ||
|
||
@XmlAttribute(name = "name") | ||
public String propertyname; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/plesk/xml/api/bindings/entity/RootBindings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package plesk.xml.api.bindings.entity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import jakarta.xml.bind.annotation.XmlAttribute; | ||
import jakarta.xml.bind.annotation.XmlElement; | ||
import jakarta.xml.bind.annotation.XmlRootElement; | ||
|
||
@XmlRootElement(name = "bindings", namespace = "https://jakarta.ee/xml/ns/jaxb") | ||
public class RootBindings { | ||
|
||
@XmlAttribute(name = "version") | ||
public String version; | ||
|
||
@XmlElement(name = "bindings", namespace = "https://jakarta.ee/xml/ns/jaxb") | ||
public List<SchemaBinding> schemabindings = new ArrayList<>(); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/plesk/xml/api/bindings/entity/SchemaBinding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package plesk.xml.api.bindings.entity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import jakarta.xml.bind.annotation.XmlAttribute; | ||
import jakarta.xml.bind.annotation.XmlElement; | ||
|
||
public class SchemaBinding { | ||
|
||
@XmlAttribute(name = "schemaLocation") | ||
public String schemafile; | ||
|
||
|
||
@XmlElement(name = "bindings", namespace = "https://jakarta.ee/xml/ns/jaxb") | ||
public List<NodeBinding> nodebindings = new ArrayList<>(); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/plesk/xml/api/bindings/entity/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@XmlSchema( | ||
xmlns = { | ||
@XmlNs(prefix = "jaxb", namespaceURI = "https://jakarta.ee/xml/ns/jaxb"), | ||
@XmlNs(prefix = "xs", namespaceURI = "http://www.w3.org/2001/XMLSchema") | ||
} | ||
) | ||
package plesk.xml.api.bindings.entity; | ||
|
||
import jakarta.xml.bind.annotation.XmlNs; | ||
import jakarta.xml.bind.annotation.XmlSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package plesk.xml.api.bindings; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.StringWriter; | ||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
|
||
import plesk.xml.api.bindings.entity.NodeBinding; | ||
import plesk.xml.api.bindings.entity.PropertyBinding; | ||
import plesk.xml.api.bindings.entity.RootBindings; | ||
import plesk.xml.api.bindings.entity.SchemaBinding; | ||
|
||
import jakarta.xml.bind.JAXBContext; | ||
import jakarta.xml.bind.JAXBException; | ||
import jakarta.xml.bind.Marshaller; | ||
|
||
/** | ||
* Unit test for simple App. | ||
*/ | ||
public class AppTest | ||
{ | ||
/** | ||
* Rigorous Test :-) | ||
* @throws JAXBException | ||
*/ | ||
@Test | ||
public void shouldAnswerWithTrue() throws JAXBException | ||
{ | ||
|
||
RootBindings root = new RootBindings(); | ||
root.version = "3.0"; | ||
|
||
SchemaBinding schemabinding = new SchemaBinding(); | ||
schemabinding.schemafile = "test.xsd"; | ||
root.schemabindings.add(schemabinding); | ||
|
||
NodeBinding nodebinding = new NodeBinding(); | ||
nodebinding.node = "//xs:ComplexType"; | ||
schemabinding.nodebindings.add(nodebinding); | ||
|
||
PropertyBinding property = new PropertyBinding(); | ||
property.propertyname = "operations"; | ||
nodebinding.bindings = List.of(property); | ||
|
||
JAXBContext context = JAXBContext.newInstance(RootBindings.class); | ||
Marshaller marshaller = context.createMarshaller(); | ||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); | ||
StringWriter result = new StringWriter(); | ||
marshaller.marshal(root, result); | ||
System.out.println(result.toString()); | ||
assertTrue( true ); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#Created by Apache Maven 3.9.5 | ||
artifactId=plesk-xml-api-jaxbindings | ||
groupId=ben-eddy74 | ||
version=1.0-SNAPSHOT |
7 changes: 7 additions & 0 deletions
7
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plesk\xml\api\bindings\entity\SchemaBinding.class | ||
plesk\xml\api\bindings\App.class | ||
plesk\xml\api\bindings\entity\NodeBinding.class | ||
plesk\xml\api\bindings\entity\package-info.class | ||
plesk\xml\api\bindings\App$1.class | ||
plesk\xml\api\bindings\entity\PropertyBinding.class | ||
plesk\xml\api\bindings\entity\RootBindings.class |
6 changes: 6 additions & 0 deletions
6
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
C:\Development\plesk-xml-api-jaxbinding\src\main\java\plesk\xml\api\bindings\entity\PropertyBinding.java | ||
C:\Development\plesk-xml-api-jaxbinding\src\main\java\plesk\xml\api\bindings\entity\NodeBinding.java | ||
C:\Development\plesk-xml-api-jaxbinding\src\main\java\plesk\xml\api\bindings\entity\package-info.java | ||
C:\Development\plesk-xml-api-jaxbinding\src\main\java\plesk\xml\api\bindings\entity\SchemaBinding.java | ||
C:\Development\plesk-xml-api-jaxbinding\src\main\java\plesk\xml\api\bindings\App.java | ||
C:\Development\plesk-xml-api-jaxbinding\src\main\java\plesk\xml\api\bindings\entity\RootBindings.java |
1 change: 1 addition & 0 deletions
1
target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
plesk\xml\api\bindings\AppTest.class |
1 change: 1 addition & 0 deletions
1
target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
C:\Development\plesk-xml-api-jaxbinding\src\test\java\plesk\xml\api\bindings\AppTest.java |
Binary file not shown.
Binary file not shown.