commit bd76da3d301dbb104d6912581f147f35170264b9
parent fd23fea563a0bf63c40c8ab4563eb319030e2ffc
Author: Marcello Stanisci <stanisci.m@gmail.com>
Date: Sun, 15 Sep 2019 19:26:08 +0200
fix resource loading
Diffstat:
3 files changed, 145 insertions(+), 16 deletions(-)
diff --git a/src/main/java/tech/libeufin/XMLManagement.java b/src/main/java/tech/libeufin/XMLManagement.java
@@ -25,25 +25,19 @@ public class XMLManagement {
* Load all the XSDs from disk.
*/
public XMLManagement(){
- ClassLoader classLoader = ClassLoader.getSystemClassLoader();
+ ClassLoader classLoader = this.getClass().getClassLoader();
File ebics_hev_file = new File(classLoader.getResource("ebics_hev.xsd").getFile());
- // other schemas in other similar lines ..
-
- /* Ideally, there will be a method that return some "iterable"
- * object for all the files in the resources directory. */
-
- Source schemas[] = {
- new StreamSource(ebics_hev_file)
+ Source schemas[] = {new StreamSource(ebics_hev_file)
// other StreamSources for other schemas here ..
};
- SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
- try{
- this.bundle = sf.newSchema(schemas;
+ try {
+ SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ this.bundle = sf.newSchema(schemas);
this.validator = this.bundle.newValidator();
- } catch (IOException e){
- System.out.println("Could not import all XSDs from disk" + "(" + e + ")");
+ } catch (SAXException e) {
+ System.out.println("SAX exception shall never happen here " + "(" + e + ")");
}
}
diff --git a/src/main/resources/ebics_hev.xsd b/src/main/resources/ebics_hev.xsd
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ebics="http://www.ebics.org/H000" targetNamespace="http://www.ebics.org/H000" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">ebics_hev.xsd ist das EBICS-Protokollschema entweder für Anfragen oder Rückmeldungen der Bank zu unterstützten EBICS-Versionen.</xs:documentation>
+ <xs:documentation xml:lang="en">ebics_hev.xsd is the appropriate EBICS protocol schema either for requests or responses according the EBICS versions supported by a bank.</xs:documentation>
+ </xs:annotation>
+ <xs:simpleType name="HostIDType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Datentyp für die Host-ID.</xs:documentation>
+ <xs:documentation xml:lang="en">Dataype for Host-ID.</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:token">
+ <xs:maxLength value="35"/>
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:simpleType name="OrderTBaseType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Datentyp für allgemeine Auftragsarten (Grundtyp).</xs:documentation>
+ <xs:documentation xml:lang="en">Datatype for general order types (basic type).</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:token">
+ <xs:length value="3"/>
+ <xs:pattern value="HEV"/>
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:simpleType name="ReturnCodeType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Datentyp für Antwortcodes.</xs:documentation>
+ <xs:documentation xml:lang="en">Datatype for the return code</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:token">
+ <xs:length value="6"/>
+ <xs:pattern value="\d{6}"/>
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:simpleType name="ReportTextType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Datentyp für den Erklärungstext zum Antwortcode.</xs:documentation>
+ <xs:documentation xml:lang="en">Datatype for report text with respect to the return code</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:normalizedString">
+ <xs:maxLength value="256"/>
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:simpleType name="VersionNumberType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Datentyp für eine Versionsnummer</xs:documentation>
+ <xs:documentation xml:lang="en">Datatype for a release number </xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:token">
+ <xs:length value="5"/>
+ <xs:pattern value="[0-9]{2}[.][0-9]{2}"/>
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:simpleType name="ProtocolVersionType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Datentyp für Versionsnummer des EBICS-schemas</xs:documentation>
+ <xs:documentation xml:lang="en">Datatype for release-number of the EBICS scheme</xs:documentation>
+ </xs:annotation>
+ <xs:restriction base="xs:token">
+ <xs:length value="4"/>
+ <xs:pattern value="H\d{3}"/>
+ </xs:restriction>
+ </xs:simpleType>
+ <xs:complexType name="SystemReturnCodeType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Datentyp für technische Fehler.</xs:documentation>
+ <xs:documentation xml:lang="en">Datatype for technical error</xs:documentation>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:element name="ReturnCode" type="ebics:ReturnCodeType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Rückmeldung des Ausführungsstatus mit einer eindeutigen Fehlernummer.</xs:documentation>
+ <xs:documentation xml:lang="en">Confirmation of the carried out status with a unique error code.</xs:documentation>
+ </xs:annotation>
+ </xs:element>
+ <xs:element name="ReportText" type="ebics:ReportTextType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Klartext der Rückmeldung des Ausführungsstatus.</xs:documentation>
+ <xs:documentation xml:lang="en">Clear text of the response (carried out status).</xs:documentation>
+ </xs:annotation>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="HEVRequestDataType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Datentyp für die Request-Daten</xs:documentation>
+ <xs:documentation xml:lang="en">Data type for Request data</xs:documentation>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:element name="HostID" type="ebics:HostIDType"/>
+ <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="HEVResponseDataType">
+ <xs:annotation>
+ <xs:documentation xml:lang="en">Datentyp für die Response-Daten</xs:documentation>
+ <xs:documentation xml:lang="en">Data type for Request data</xs:documentation>
+ </xs:annotation>
+ <xs:sequence>
+ <xs:element name="SystemReturnCode" type="ebics:SystemReturnCodeType"/>
+ <xs:element name="VersionNumber" minOccurs="0" maxOccurs="unbounded">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Von der Bank unterstützte EBICS-Versionen, z.B. 2.4</xs:documentation>
+ <xs:documentation xml:lang="en">EBICS-releases supported by the bank, e.g. 2.4</xs:documentation>
+ </xs:annotation>
+ <xs:complexType>
+ <xs:simpleContent>
+ <xs:extension base="ebics:VersionNumberType">
+ <xs:attribute name="ProtocolVersion" type="ebics:ProtocolVersionType" use="required">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">der EBICS-Version eindeutig zugeordnete Schema-Version, z.B. H003</xs:documentation>
+ <xs:documentation xml:lang="en">EBICS-scheme-version, e.g. H003, well-defined for EBICS-release-Version</xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ </xs:extension>
+ </xs:simpleContent>
+ </xs:complexType>
+ </xs:element>
+ <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:element name="ebicsHEVRequest" type="ebics:HEVRequestDataType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Requestdaten</xs:documentation>
+ <xs:documentation xml:lang="en">request data</xs:documentation>
+ </xs:annotation>
+ </xs:element>
+ <xs:element name="ebicsHEVResponse" type="ebics:HEVResponseDataType">
+ <xs:annotation>
+ <xs:documentation xml:lang="de">Responsedaten</xs:documentation>
+ <xs:documentation xml:lang="en">response data</xs:documentation>
+ </xs:annotation>
+ </xs:element>
+</xs:schema>
diff --git a/src/test/java/XMLManagementTest.java b/src/test/java/XMLManagementTest.java
@@ -1,12 +1,12 @@
import org.junit.Test;
+import tech.libeufin.XMLManagement;
+
import static org.junit.Assert.*;
public class XMLManagementTest {
@Test
public void XMLManagementTest(){
- XMLManagement xmlm = new XMLManagement();
- xmlm.printtheline();
- assertEquals(4, 4);
+ XMLManagement xm = new XMLManagement();
}
}