use of uk.ac.ed.ph.jqtiplus.value.SingleValue in project openolat by klemens.
the class AssessmentRenderFunctions method extractRecordFieldValue.
/*
<xsl:function name="qw:extract-record-field-value" as="xs:string?">
<xsl:param name="valueHolder" as="element()"/>
<xsl:param name="fieldName" as="xs:string"/>
<xsl:choose>
<xsl:when test="qw:is-record-cardinality-value($valueHolder)">
<xsl:value-of select="$valueHolder/qw:value[@fieldIdentifier=$fieldName]"/>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
Expected value <xsl:copy-of select="$valueHolder"/> to have record
cardinalty.
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
*/
public static SingleValue extractRecordFieldValue(Value value, Identifier identifier) {
SingleValue mappedValue = null;
if (value != null && identifier != null && value.hasCardinality(Cardinality.RECORD)) {
RecordValue recordValue = (RecordValue) value;
mappedValue = recordValue.get(identifier);
}
return mappedValue;
}
use of uk.ac.ed.ph.jqtiplus.value.SingleValue in project openolat by klemens.
the class AssessmentObjectComponentRenderer method renderPrintedVariable.
/**
* The QTI spec says that this variable must have single cardinality.
*
* For convenience, we also accept multiple, ordered and record cardinality variables here,
* printing them out in a hard-coded form that probably won't make sense to test
* candidates but might be useful for debugging.
*
* Our implementation additionally adds support for "printing" MathsContent variables
* used in MathAssess, outputting an inline Presentation MathML element, as documented
* in the MathAssses spec.
*/
protected void renderPrintedVariable(AssessmentRenderer renderer, StringOutput sb, PrintedVariable source, VariableDeclaration valueDeclaration, Value valueHolder) {
if (isNullValue(valueHolder)) {
// (Spec says to output nothing in this case)
} else if (isSingleCardinalityValue(valueHolder)) {
if (valueDeclaration.hasBaseType(BaseType.INTEGER) || valueDeclaration.hasBaseType(BaseType.FLOAT)) {
renderSingleCardinalityValue(sb, valueHolder);
} else {
renderSingleCardinalityValue(sb, valueHolder);
}
// math content is a record with special markers
} else if (isMathsContentValue(valueHolder)) {
// <xsl:copy-of select="qw:extract-maths-content-pmathml($valueHolder)"/>
String mathMlContent = extractMathsContentPmathml(valueHolder);
if (renderer.isMathXsltDisabled()) {
sb.append(mathMlContent);
} else {
transformMathmlAsString(sb, mathMlContent);
}
} else if (isMultipleCardinalityValue(valueHolder)) {
String delimiter = source.getDelimiter();
if (!StringHelper.containsNonWhitespace(delimiter)) {
delimiter = ";";
}
renderMultipleCardinalityValue(sb, valueHolder, delimiter);
} else if (isOrderedCardinalityValue(valueHolder)) {
if (source.getIndex() != null) {
int index = -1;
if (source.getIndex().isConstantInteger()) {
index = source.getIndex().getConstantIntegerValue().intValue();
} else if (source.getIndex().isVariableRef()) {
// TODO qti what to do???
}
SingleValue indexedValue = extractIterableElement(valueHolder, index);
renderSingleCardinalityValue(sb, indexedValue);
} else {
String delimiter = source.getDelimiter();
if (!StringHelper.containsNonWhitespace(delimiter)) {
delimiter = ";";
}
renderOrderedCardinalityValue(sb, valueHolder, delimiter);
}
} else if (isRecordCardinalityValue(valueHolder)) {
String field = source.getField();
if (StringHelper.containsNonWhitespace(field)) {
Identifier fieldIdentifier = Identifier.assumedLegal(field);
SingleValue mappedValue = extractRecordFieldValue(valueHolder, fieldIdentifier);
renderSingleCardinalityValue(sb, mappedValue);
} else {
String delimiter = source.getDelimiter();
String mappingIndicator = source.getMappingIndicator();
if (!StringHelper.containsNonWhitespace(delimiter)) {
delimiter = ";";
}
if (!StringHelper.containsNonWhitespace(mappingIndicator)) {
mappingIndicator = "=";
}
renderRecordCardinalityValue(sb, valueHolder, delimiter, mappingIndicator);
}
} else {
sb.append("printedVariable may not be applied to value ").append(valueHolder.toString());
}
}
Aggregations