Skip to content
Snippets Groups Projects
Commit 542ad875 authored by srosse's avatar srosse
Browse files

OO-3238: prevent duplicate attribute class during conversion of customOperator

parent f4618e7e
No related branches found
No related tags found
No related merge requests found
......@@ -132,14 +132,9 @@ public class OnyxToQtiWorksHandler extends DefaultHandler2 {
writeObjectElementAttributes(attributes);
} else if("img".equals(qName)) {
writeImgElementAttributes(attributes);
} else if("customOperator".equals(qName)) {
writeCustomOperatorAttributes(attributes);
} else {
if("customOperator".equals(qName)) {
String customOperatorDefinition = attributes.getValue("definition");
if("MAXIMA".equals(customOperatorDefinition)) {
xtw.writeAttribute("class", "org.olat.ims.qti21.manager.extensions.MaximaOperator");
}
}
int numOfAttributes = attributes.getLength();
for(int i=0;i<numOfAttributes; i++) {
String attrQName = attributes.getQName(i);
......@@ -218,6 +213,34 @@ public class OnyxToQtiWorksHandler extends DefaultHandler2 {
}
}
/**
* The customOperator accept the class attribute or the definition attribute but not
* both at the same time.
*
* @param attributes The attributes
* @param withDefinition true if you want to write the definition attribute, false if you want to skip it
* @throws XMLStreamException
*/
private void writeCustomOperatorAttributes(Attributes attributes)
throws XMLStreamException {
String customOperatorDefinition = attributes.getValue("definition");
boolean maxima = "MAXIMA".equals(customOperatorDefinition);
if(maxima) {
xtw.writeAttribute("class", "org.olat.ims.qti21.manager.extensions.MaximaOperator");
}
int numOfAttributes = attributes.getLength();
for(int i=0;i<numOfAttributes; i++) {
String attrQName = attributes.getQName(i);
if(maxima && "class".equals(attrQName)) {
continue;
}
String attrValue = attributes.getValue(i);
xtw.writeAttribute(attrQName, attrValue);
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
......
......@@ -19,6 +19,7 @@
*/
package org.olat.ims.qti21.model.xml;
import java.io.IOException;
import java.util.List;
import javax.xml.transform.stream.StreamResult;
......@@ -80,7 +81,7 @@ public class AssessmentHtmlBuilderTest {
}
@Test
public void filter() {
public void filter() throws IOException {
String content = "<html><p>Test \u00EA<strong><span><img src='img.jpg'></span></strong></p><p>Test 2</p></html>";
AssessmentItem item = new AssessmentItem();
......@@ -98,10 +99,11 @@ public class AssessmentHtmlBuilderTest {
qtiSerializer.serializeJqtiObject(helper, new StreamResult(sb));
String serializedQti = sb.toString();
Assert.assertTrue(serializedQti.contains("img.jpg"));
sb.close();
}
@Test
public void serializeVideo() {
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"
......@@ -125,5 +127,6 @@ public class AssessmentHtmlBuilderTest {
Assert.assertTrue(serializedQti.contains("object"));
Assert.assertFalse(serializedQti.contains("span"));
Assert.assertFalse(serializedQti.contains("script"));
sb.close();
}
}
......@@ -76,7 +76,8 @@ public class OnyxToQtiWorksAssessementItemsTest {
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{ "match-with-latex-5-11.xml", new QTI21Infos() }
{ "match-with-latex-5-11.xml", new QTI21Infos() },
{ "maxima-7-6-1.xml", new QTI21Infos() }
});
}
......
<?xml version='1.0' encoding='utf-8'?>
<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 http://www.imsglobal.org/xsd/qti/qtiv2p1/imsqti_v2p1p1.xsd http://www.w3.org/1998/Math/MathML http://www.w3.org/Math/XMLSchema/mathml2/mathml2.xsd"
identifier="id44f57778-313b-4d5f-bf64-5320339a7a09" title="Berechnungsaufgabe"
adaptive="false" timeDependent="false" toolName="ONYX Editor"
toolVersion="7.6.1">
<responseDeclaration identifier="RESPONSE"
cardinality="single" baseType="float">
<correctResponse>
<value>1</value>
</correctResponse>
</responseDeclaration>
<outcomeDeclaration identifier="MAXSCORE_RESPONSE"
cardinality="single" baseType="float" view="testConstructor">
<defaultValue>
<value>1</value>
</defaultValue>
</outcomeDeclaration>
<outcomeDeclaration identifier="SCORE_RESPONSE"
cardinality="single" baseType="float" view="testConstructor">
<defaultValue>
<value>0</value>
</defaultValue>
</outcomeDeclaration>
<outcomeDeclaration identifier="MINSCORE_RESPONSE"
cardinality="single" baseType="float" view="testConstructor">
<defaultValue>
<value>0</value>
</defaultValue>
</outcomeDeclaration>
<outcomeDeclaration identifier="SCORE" cardinality="single"
baseType="float">
<defaultValue>
<value>0</value>
</defaultValue>
</outcomeDeclaration>
<outcomeDeclaration identifier="MAXSCORE"
cardinality="single" baseType="float">
<defaultValue>
<value>1</value>
</defaultValue>
</outcomeDeclaration>
<outcomeDeclaration identifier="MINSCORE"
cardinality="single" baseType="float" view="testConstructor">
<defaultValue>
<value>0</value>
</defaultValue>
</outcomeDeclaration>
<templateDeclaration identifier="var1" cardinality="single"
baseType="integer" />
<templateDeclaration identifier="var2" cardinality="single"
baseType="integer" />
<templateDeclaration identifier="solution"
cardinality="single" baseType="integer" />
<templateProcessing>
<setTemplateValue identifier="var1">
<randomInteger min="1" max="10" />
</setTemplateValue>
<setTemplateValue identifier="var2">
<randomInteger min="1" max="10" />
</setTemplateValue>
<setTemplateValue identifier="solution">
<customOperator
class="org.olat.ims.qti21.manager.extensions.MaximaOperator"
definition="MAXIMA" value="float($(1)+$(2));">
<variable identifier="var1" />
<variable identifier="var2" />
</customOperator>
</setTemplateValue>
</templateProcessing>
<itemBody>
<p>
Berechnen Sie: 2-1 =
<textEntryInteraction responseIdentifier="RESPONSE" />
</p>
</itemBody>
<responseProcessing>
<responseCondition>
<responseIf>
<equal toleranceMode="exact">
<variable identifier="RESPONSE" />
<correct identifier="RESPONSE" />
</equal>
<setOutcomeValue identifier="SCORE_RESPONSE">
<variable identifier="MAXSCORE_RESPONSE" />
</setOutcomeValue>
</responseIf>
</responseCondition>
<setOutcomeValue identifier="SCORE">
<sum>
<variable identifier="SCORE_RESPONSE" />
</sum>
</setOutcomeValue>
<responseCondition>
<responseIf>
<gt>
<variable identifier="SCORE" />
<variable identifier="MAXSCORE" />
</gt>
<setOutcomeValue identifier="SCORE">
<variable identifier="MAXSCORE" />
</setOutcomeValue>
</responseIf>
</responseCondition>
<responseCondition>
<responseIf>
<lt>
<variable identifier="SCORE" />
<variable identifier="MINSCORE" />
</lt>
<setOutcomeValue identifier="SCORE">
<variable identifier="MINSCORE" />
</setOutcomeValue>
</responseIf>
</responseCondition>
</responseProcessing>
</assessmentItem>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment