Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
XML-Schema beim Validieren nicht mehr relativ zu AbstractSEPAGenerator
Browse files Browse the repository at this point in the history
laden sondern ueber den Classloader.
Exception statt Log-Warnung, wenn bei aktivierter Schema-Validierung das
Schema-File nicht gefunden wurde
  • Loading branch information
willuhn committed Jan 9, 2014
1 parent d7a2df9 commit 82e03c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
28 changes: 10 additions & 18 deletions src/org/kapott/hbci/GV/generators/AbstractSEPAGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import org.kapott.hbci.exceptions.HBCI_Exception;
import org.kapott.hbci.exceptions.InvalidArgumentException;
import org.kapott.hbci.sepa.PainVersion;

Expand Down Expand Up @@ -65,7 +66,7 @@ protected void marshal(JAXBElement e, OutputStream os, boolean validate) throws
if (validate)
{
Source source = null;
InputStream is = this.getClass().getResourceAsStream(file);
InputStream is = this.getClass().getClassLoader().getResourceAsStream(file);

if (is != null)
{
Expand All @@ -74,31 +75,22 @@ protected void marshal(JAXBElement e, OutputStream os, boolean validate) throws
else
{
// Fallback auf File-Objekt

// Der Pfad-Prafix ist eigentlich nur fuer die Unit-Tests.
// Im normalen Betrieb ist der nicht gesetzt. Siehe "TestPainGen".
boolean debug = Boolean.parseBoolean(System.getProperty("hbci4java.pain.debugmode","false"));
File f = debug ? new File("src",file) : new File(file);
File f = new File(file);
if (f.isFile() && f.canRead())
source = new StreamSource(f);
}

if (source != null)
{
LOG.fine("activating schema validation against " + file);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(source);
marshaller.setSchema(schema);
}
else
{
LOG.warning("schema validation activated against " + file + " - but schema file could not be found");
}
if (source == null)
throw new HBCI_Exception("schema validation activated against " + file + " - but schema file could not be found");

LOG.fine("activating schema validation against " + file);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(source);
marshaller.setSchema(schema);
}
}
}


marshaller.marshal(e, os);
}

Expand Down
12 changes: 0 additions & 12 deletions test/hbci4java/sepa/TestPainGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.io.ByteArrayOutputStream;
import java.util.Properties;

import org.junit.BeforeClass;
import org.junit.Test;
import org.kapott.hbci.GV.generators.ISEPAGenerator;
import org.kapott.hbci.GV.generators.SEPAGeneratorFactory;
Expand All @@ -26,17 +25,6 @@
*/
public class TestPainGen
{
/**
* Initialisiert den Test.
* @throws Exception
*/
@BeforeClass
public static void beforeClass() throws Exception
{
// Siehe AbstractSEPAGenerator#marshal - damit werden die Schema-Files auch im Unit-Test gefunden.
System.setProperty("hbci4java.pain.debugmode","true");
}

/**
* Testet das Erstellen von SEPA-Ueberweisungen.
* @throws Exception
Expand Down

0 comments on commit 82e03c7

Please sign in to comment.