Search in sources :

Example 1 with ChainedResourceLocator

use of uk.ac.ed.ph.jqtiplus.xmlutils.locators.ChainedResourceLocator in project openolat by klemens.

the class ImsQTI21Resource method validateImsManifest.

public static boolean validateImsManifest(QTI21ContentPackage cp, ResourceLocator resourceLocator) {
    try {
        if (cp.hasTest()) {
            URI test = cp.getTest().toUri();
            ResourceLocator chainedResourceLocator = createResolvingResourceLocator(resourceLocator);
            XmlReadResult result = new QtiXmlReader().read(chainedResourceLocator, test, true, true);
            if (result != null && !result.isSchemaValid()) {
                StringBuilder out = new StringBuilder();
                BadRessourceHelper.extractMessage(result.getXmlParseResult(), out);
                log.warn(out.toString());
            }
            return result != null && result.isSchemaValid() || true;
        }
        return false;
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
}
Also used : QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) XmlReadResult(uk.ac.ed.ph.jqtiplus.xmlutils.XmlReadResult) URI(java.net.URI) IOException(java.io.IOException) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) NetworkHttpResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.NetworkHttpResourceLocator) ChainedResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ChainedResourceLocator)

Example 2 with ChainedResourceLocator

use of uk.ac.ed.ph.jqtiplus.xmlutils.locators.ChainedResourceLocator in project openolat by klemens.

the class ImsQTI21Resource method validate.

public static boolean validate(File resource) {
    try {
        PathResourceLocator resourceLocator = new PathResourceLocator(resource.getParentFile().toPath());
        ResourceLocator chainedResourceLocator = createResolvingResourceLocator(resourceLocator);
        XmlReadResult result = new QtiXmlReader().read(chainedResourceLocator, resource.toURI(), true, true);
        return result != null && result.isSchemaValid();
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
}
Also used : QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) XmlReadResult(uk.ac.ed.ph.jqtiplus.xmlutils.XmlReadResult) IOException(java.io.IOException) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) NetworkHttpResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.NetworkHttpResourceLocator) ChainedResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ChainedResourceLocator)

Example 3 with ChainedResourceLocator

use of uk.ac.ed.ph.jqtiplus.xmlutils.locators.ChainedResourceLocator in project OpenOLAT by OpenOLAT.

the class ImsQTI21Resource method validate.

public static boolean validate(File resource) {
    try {
        PathResourceLocator resourceLocator = new PathResourceLocator(resource.getParentFile().toPath());
        ResourceLocator chainedResourceLocator = createResolvingResourceLocator(resourceLocator);
        XmlReadResult result = new QtiXmlReader().read(chainedResourceLocator, resource.toURI(), true, true);
        return result != null && result.isSchemaValid();
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
}
Also used : QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) XmlReadResult(uk.ac.ed.ph.jqtiplus.xmlutils.XmlReadResult) IOException(java.io.IOException) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) NetworkHttpResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.NetworkHttpResourceLocator) ChainedResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ChainedResourceLocator)

Example 4 with ChainedResourceLocator

use of uk.ac.ed.ph.jqtiplus.xmlutils.locators.ChainedResourceLocator in project OpenOLAT by OpenOLAT.

the class ImsQTI21Resource method validateImsManifest.

public static boolean validateImsManifest(QTI21ContentPackage cp, ResourceLocator resourceLocator) {
    try {
        if (cp.hasTest()) {
            URI test = cp.getTest().toUri();
            ResourceLocator chainedResourceLocator = createResolvingResourceLocator(resourceLocator);
            XmlReadResult result = new QtiXmlReader().read(chainedResourceLocator, test, true, true);
            if (result != null && !result.isSchemaValid()) {
                StringBuilder out = new StringBuilder();
                BadRessourceHelper.extractMessage(result.getXmlParseResult(), out);
                log.warn(out.toString());
            }
            return result != null && result.isSchemaValid() || true;
        }
        return false;
    } catch (Exception e) {
        log.error("", e);
        return false;
    }
}
Also used : QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) XmlReadResult(uk.ac.ed.ph.jqtiplus.xmlutils.XmlReadResult) URI(java.net.URI) IOException(java.io.IOException) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) NetworkHttpResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.NetworkHttpResourceLocator) ChainedResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ChainedResourceLocator)

Aggregations

IOException (java.io.IOException)4 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)4 XmlReadResult (uk.ac.ed.ph.jqtiplus.xmlutils.XmlReadResult)4 ChainedResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ChainedResourceLocator)4 NetworkHttpResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.NetworkHttpResourceLocator)4 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)4 URI (java.net.URI)2