Search in sources :

Example 76 with JqtiExtensionManager

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();
}
Also used : ItemBody(uk.ac.ed.ph.jqtiplus.node.content.ItemBody) JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) StreamResult(javax.xml.transform.stream.StreamResult) QtiSerializer(uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer) Block(uk.ac.ed.ph.jqtiplus.node.content.basic.Block) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) StringOutput(org.olat.core.gui.render.StringOutput) Test(org.junit.Test)

Example 77 with JqtiExtensionManager

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");
}
Also used : JqtiExtensionManager(uk.ac.ed.ph.jqtiplus.JqtiExtensionManager) JqtiExtensionPackage(uk.ac.ed.ph.jqtiplus.JqtiExtensionPackage) ArrayList(java.util.ArrayList) MathAssessExtensionPackage(uk.ac.ed.ph.qtiworks.mathassess.MathAssessExtensionPackage) ClassPathResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ClassPathResourceLocator) Cacher(org.olat.core.util.coordinate.Cacher) XsltStylesheetManager(uk.ac.ed.ph.jqtiplus.xmlutils.xslt.XsltStylesheetManager)

Example 78 with JqtiExtensionManager

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;
    }
}
Also used : AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) RootNode(uk.ac.ed.ph.jqtiplus.node.RootNode) BadResourceException(uk.ac.ed.ph.jqtiplus.provision.BadResourceException) TestValidationResult(uk.ac.ed.ph.jqtiplus.validation.TestValidationResult) QtiXmlInterpretationException(uk.ac.ed.ph.jqtiplus.reading.QtiXmlInterpretationException) URISyntaxException(java.net.URISyntaxException) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) URI(java.net.URI) 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) FileResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator) PathResourceLocator(org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator) ItemValidationResult(uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)

Aggregations

JqtiExtensionManager (uk.ac.ed.ph.jqtiplus.JqtiExtensionManager)78 Test (org.junit.Test)52 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)52 QtiSerializer (uk.ac.ed.ph.jqtiplus.serialization.QtiSerializer)46 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)42 PathResourceLocator (org.olat.fileresource.types.ImsQTI21Resource.PathResourceLocator)34 AssessmentObjectXmlLoader (uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader)34 QtiXmlReader (uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader)34 ResourceLocator (uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)34 URL (java.net.URL)30 Interaction (uk.ac.ed.ph.jqtiplus.node.item.interaction.Interaction)26 ItemValidationResult (uk.ac.ed.ph.jqtiplus.validation.ItemValidationResult)26 ChoiceInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.ChoiceInteraction)24 BadResourceException (uk.ac.ed.ph.jqtiplus.provision.BadResourceException)20 File (java.io.File)16 URISyntaxException (java.net.URISyntaxException)16 IOException (java.io.IOException)14 SimpleChoice (uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice)14 SingleChoiceAssessmentItemBuilder (org.olat.ims.qti21.model.xml.interactions.SingleChoiceAssessmentItemBuilder)12 EndAttemptInteraction (uk.ac.ed.ph.jqtiplus.node.item.interaction.EndAttemptInteraction)12