From 4888e2e08ebe3d14d9cbf42b4ee305f6a87be2f2 Mon Sep 17 00:00:00 2001 From: felmer <felmer> Date: Tue, 13 Oct 2009 07:59:38 +0000 Subject: [PATCH] SE-146 Schema validation for quantML files added SVN: 12910 --- rtd_yeastx/build/build.xml | 1 + rtd_yeastx/resource/examples/allFields.quantML | 2 +- .../ch/systemsx/cisd/yeastx/quant/QuantMLParser.java | 12 +++++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/rtd_yeastx/build/build.xml b/rtd_yeastx/build/build.xml index 304d58a568c..cc46a042d37 100644 --- a/rtd_yeastx/build/build.xml +++ b/rtd_yeastx/build/build.xml @@ -27,6 +27,7 @@ </fileset> <fileset dir="source"> <include name="**/*.sql" /> + <include name="**/*.xsd" /> </fileset> </recursive-jar> </target> diff --git a/rtd_yeastx/resource/examples/allFields.quantML b/rtd_yeastx/resource/examples/allFields.quantML index 58b62984f0f..8b6a654ad55 100644 --- a/rtd_yeastx/resource/examples/allFields.quantML +++ b/rtd_yeastx/resource/examples/allFields.quantML @@ -2,8 +2,8 @@ <quantML> <msQuantification> <source>msSoft</source> - <valid>true</valid> <comment>no comment</comment> + <valid>true</valid> <registrationDate>04-Apr-1980 12:00:21</registrationDate> <registrator>John Doe</registrator> <concentration> diff --git a/rtd_yeastx/source/java/ch/systemsx/cisd/yeastx/quant/QuantMLParser.java b/rtd_yeastx/source/java/ch/systemsx/cisd/yeastx/quant/QuantMLParser.java index 3fed98618f8..02c8cfd25b0 100644 --- a/rtd_yeastx/source/java/ch/systemsx/cisd/yeastx/quant/QuantMLParser.java +++ b/rtd_yeastx/source/java/ch/systemsx/cisd/yeastx/quant/QuantMLParser.java @@ -17,16 +17,23 @@ package ch.systemsx.cisd.yeastx.quant; import java.io.File; +import java.io.FileReader; import java.io.IOException; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.SchemaOutputResolver; import javax.xml.bind.Unmarshaller; +import javax.xml.bind.UnmarshallerHandler; import javax.xml.transform.Result; import javax.xml.transform.stream.StreamResult; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel; +import ch.systemsx.cisd.common.utilities.XMLInfraStructure; import ch.systemsx.cisd.yeastx.quant.dto.MSQuantificationsDTO; /** @@ -46,6 +53,9 @@ class QuantMLParser private QuantMLParser() { this.unmarshaller = createUnmarshaller(); + unmarshaller.setSchema(XMLInfraStructure.createSchema("/" + + QuantMLParser.class.getPackage().getName().replace('.', '/') + + "/quantml-schema.xsd")); } private static Unmarshaller createUnmarshaller() @@ -90,7 +100,7 @@ class QuantMLParser throw new IllegalArgumentException("Wrong type: " + object); } return (MSQuantificationsDTO) object; - } catch (JAXBException ex) + } catch (Exception ex) { throw CheckedExceptionTunnel.wrapIfNecessary(ex); } -- GitLab