use of uk.ac.ed.ph.jqtiplus.JqtiExtensionManager in project openolat by klemens.
the class AssessmentHtmlBuilderTest method serializeVideo.
@Test
public void serializeVideo() throws IOException {
String content = "<p><span id=\"olatFlashMovieViewer213060\" class=\"olatFlashMovieViewer\" style=\"display:block;border:solid 1px #000; width:320px; height:240px;\">\n" + "<script src=\"/raw/fx-111111x11/movie/player.js\" type=\"text/javascript\"></script>\n" + "<script type=\"text/javascript\" defer=\"defer\">// <![CDATA[\n" + "BPlayer.insertPlayer(\"demo-video.mp4\",\"olatFlashMovieViewer213060\",320,240,0,0,\"video\",undefined,false,false,true,undefined);\n" + "// ]]></script>\n" + "</span></p>";
AssessmentItem item = new AssessmentItem();
ItemBody helper = new ItemBody(item);
new AssessmentHtmlBuilder().appendHtml(helper, content);
List<Block> paragraphs = helper.getBlocks();
Assert.assertNotNull(paragraphs);
Assert.assertEquals(1, paragraphs.size());
StringOutput sb = new StringOutput();
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
qtiSerializer.serializeJqtiObject(helper, new StreamResult(sb));
String serializedQti = sb.toString();
Assert.assertNotNull(serializedQti);
Assert.assertTrue(serializedQti.contains("object"));
Assert.assertFalse(serializedQti.contains("span"));
Assert.assertFalse(serializedQti.contains("script"));
sb.close();
}
use of uk.ac.ed.ph.jqtiplus.JqtiExtensionManager in project openolat by klemens.
the class QTI21ServiceImpl method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
final List<JqtiExtensionPackage<?>> extensionPackages = new ArrayList<JqtiExtensionPackage<?>>();
/* Enable MathAssess extensions if requested */
if (qtiModule.isMathAssessExtensionEnabled()) {
log.info("Enabling the MathAssess extensions");
extensionPackages.add(new MathAssessExtensionPackage(xsltStylesheetCache));
extensionPackages.add(new OpenOLATExtensionPackage(xsltStylesheetCache));
}
jqtiExtensionManager = new JqtiExtensionManager(extensionPackages);
xsltStylesheetManager = new XsltStylesheetManager(new ClassPathResourceLocator(), xsltStylesheetCache);
jqtiExtensionManager.init();
Cacher cacher = coordinatorManager.getInstance().getCoordinator().getCacher();
assessmentTestsCache = cacher.getCache("QTIWorks", "assessmentTests");
assessmentItemsCache = cacher.getCache("QTIWorks", "assessmentItems");
}
use of uk.ac.ed.ph.jqtiplus.JqtiExtensionManager in project openolat by klemens.
the class CopyAndConvertVisitor method validate.
private boolean validate(Path inputFile, InputType type, boolean verbose) {
try {
QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
ResourceLocator fileResourceLocator = new PathResourceLocator(inputFile.getParent());
AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
RootNode rootNode = null;
BadResourceException e = null;
URI uri = new URI("zip", inputFile.getFileName().toString(), null);
if (type == InputType.assessmentItem) {
ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(uri);
e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(uri);
rootNode = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
} else if (type == InputType.assessmentTest) {
TestValidationResult testResult = assessmentObjectXmlLoader.loadResolveAndValidateTest(uri);
e = testResult.getResolvedAssessmentTest().getTestLookup().getBadResourceException();
ResolvedAssessmentTest resolvedAssessmentTest = assessmentObjectXmlLoader.loadAndResolveAssessmentTest(uri);
rootNode = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
}
if (e != null && verbose) {
StringBuilder err = new StringBuilder();
BadRessourceHelper.extractMessage(e, err);
log.warn(err.toString());
}
return (rootNode != null) && (e == null || (e instanceof QtiXmlInterpretationException && ((QtiXmlInterpretationException) e).getXmlParseResult().getFatalErrors().isEmpty()));
} catch (URISyntaxException e) {
log.error("", e);
return false;
}
}
Aggregations