Search in sources :

Example 31 with ResourceLocator

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

the class QTI12To21ConverterTest method validateAssessmentItem.

private boolean validateAssessmentItem(File assessmentItemFile) {
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(assessmentItemFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(assessmentItemFile.toURI());
    BadResourceException e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    return itemResult.getModelValidationErrors().isEmpty();
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)

Example 32 with ResourceLocator

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

the class QTI12To21ConverterTest method validateAssessmentTest.

private boolean validateAssessmentTest(File assessmentTestFile) {
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(assessmentTestFile.toPath());
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    TestValidationResult test = assessmentObjectXmlLoader.loadResolveAndValidateTest(assessmentTestFile.toURI());
    for (Notification notification : test.getModelValidationErrors()) {
        log.error(notification.getQtiNode() + " : " + notification.getMessage());
    }
    BadResourceException e = test.getResolvedAssessmentTest().getTestLookup().getBadResourceException();
    if (e != null) {
        StringBuilder err = new StringBuilder();
        BadRessourceHelper.extractMessage(e, err);
        log.error(err.toString());
    }
    return test.getModelValidationErrors().isEmpty();
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) TestValidationResult(uk.ac.ed.ph.jqtiplus.validation.TestValidationResult) Notification(uk.ac.ed.ph.jqtiplus.notification.Notification) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)

Example 33 with ResourceLocator

use of uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator 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 34 with ResourceLocator

use of uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator 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)

Example 35 with ResourceLocator

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

the class AssessmentItemCheckerTest method loadAssessmentItem.

private AssessmentItem loadAssessmentItem(URL itemUrl) throws URISyntaxException {
    QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
    ResourceLocator fileResourceLocator = new PathResourceLocator(Paths.get(itemUrl.toURI()));
    AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
    ResolvedAssessmentItem item = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(itemUrl.toURI());
    return item.getItemLookup().getRootNodeHolder().getRootNode();
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)

Aggregations

ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)50 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)48 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)44 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)42 JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)34 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)26 BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)22 File (java.io.File)16 IOException (java.io.IOException)16 ItemValidationResult (uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)14 URISyntaxException (java.net.URISyntaxException)12 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)12 URI (java.net.URI)10 URL (java.net.URL)10 Test (org.junit.Test)10 TestValidationResult (uk.ac.ed.ph.jqtiplus.validation.TestValidationResult)8 FileResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator)8 InputStream (java.io.InputStream)6 Writer (java.io.Writer)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)6