use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader 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();
}
use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader 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;
}
}
use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader 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;
}
}
use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader 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();
}
use of uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader in project openolat by klemens.
the class AssessmentItemPackageTest method loadAssessmentItem.
@Test
public void loadAssessmentItem() throws URISyntaxException {
QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
URL testUrl = AssessmentItemPackageTest.class.getResource("assessment-item-single-choice.xml");
ResourceLocator fileResourceLocator = new PathResourceLocator(Paths.get(testUrl.toURI()));
AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
ResolvedAssessmentItem item = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(testUrl.toURI());
Assert.assertNotNull(item);
AssessmentItem assessmentItem = item.getItemLookup().getRootNodeHolder().getRootNode();
Assert.assertNotNull(assessmentItem);
qtiSerializer.serializeJqtiObject(assessmentItem, System.out);
}
Aggregations