/**
* @see org.olat.ims.qti.container.qtielements.QTIElement#render(StringBuilder,
* RenderInstructions)
*/
public void render(StringBuilder buffer, RenderInstructions ri) {
ItemInput iinput = (ItemInput) ri.get(RenderInstructions.KEY_ITEM_INPUT);
String responseIdent = (String) ri.get(RenderInstructions.KEY_RESPONSE_IDENT);
// find parent render_xxx element
String renderClass = (String) ri.get(RenderInstructions.KEY_RENDER_CLASS);
if (ri == null) throw new AssertException("Render class must be set previousely to call respnse_label.render.");
if (renderClass.equals("choice")) {
// render multiple/single choice
Integer rCardinality = (Integer) ri.get(RenderInstructions.KEY_RESPONSE_RCARDINALITY);
if (rCardinality == null) throw new AssertException(
"Cardinality must be set previousely to call respnse_label.render for a render_choice class.");
if (rCardinality.intValue() == Response_lid.RCARDINALITY_SINGLE) {
// single choice
buffer.append("<input id=\"QTI_").append(getQTIIdent()).append("\" type=\"radio\" class=\"b_radio\" name=\"");
buffer.append("qti").append(PARA).append(ri.get(RenderInstructions.KEY_ITEM_IDENT)).append(PARA).append(
ri.get(RenderInstructions.KEY_RESPONSE_IDENT)).append(PARA).append("choice");
buffer.append("\" value=\"").append(getQTIIdent());
if (iinput != null && !iinput.isEmpty()) {
String response = iinput.getSingle(responseIdent);
if (response.equals(getQTIIdent())) buffer.append("\" checked=\"checked");
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\" /> ");
} else if (rCardinality.intValue() == Response_lid.RCARDINALITY_MULTIPLE) {
// multiple choice
buffer.append("<input id=\"QTI_").append(getQTIIdent()).append("\" type=\"checkbox\" class=\"b_checkbox\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" value=\"").append(getQTIIdent());
if (iinput != null) {
List responses = iinput.getAsList(responseIdent);
if (responses != null && responses.contains(getQTIIdent())) buffer.append("\" checked=\"checked");
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\" /> ");
}
super.render(buffer, ri);
} else if (renderClass.equals("kprim")) {
buffer.append("<tr><td align=\"center\"><input id=\"QTI_").append(getQTIIdent()).append("\" type=\"radio\" class=\"b_radio\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" value=\"" + getQTIIdent() + ":correct\"");
if (iinput != null && !iinput.isEmpty()) {
List responses = iinput.getAsList(responseIdent);
if (responses != null && responses.contains(getQTIIdent() + ":correct")) buffer.append("\" checked=\"checked");
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\"/>");
buffer.append("</td><td align=\"center\"><input id=\"QTI_").append(getQTIIdent()).append("\" type=\"radio\" class=\"b_radio\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" value=\"" + getQTIIdent() + ":wrong\"");
if (iinput != null && !iinput.isEmpty()) {
List responses = iinput.getAsList(responseIdent);
if (responses != null && responses.contains(getQTIIdent() + ":wrong")) buffer.append("\" checked=\"checked");
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\"/>");
buffer.append("</td><td>");
super.render(buffer, ri);
buffer.append("</td></tr>");
ri.put(RenderInstructions.KEY_FLOW_LABEL, new Integer(RenderInstructions.RENDER_FLOW_BLOCK));
} else if (renderClass.equals("fib")) {
Integer rows = (Integer) ri.get(RenderInstructions.KEY_FIB_ROWS);
Integer columns = (Integer) ri.get(RenderInstructions.KEY_FIB_COLUMNS);
Integer maxlength = (Integer) ri.get(RenderInstructions.KEY_FIB_MAXLENGTH);
if (rows == null || columns == null || maxlength == null) throw new AssertException(
"Rows and/or columns attribute not specified for render_fib.");
if (rows.intValue() > 1) {
// render as textarea
buffer.append("<textarea id=\"QTI_").append(getQTIIdent()).append("\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" rows=\"").append(rows).append("\" cols=\"").append(columns)
.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\">");
if (iinput != null && !iinput.isEmpty() && iinput.getSingle(responseIdent) != null) {
buffer.append(iinput.getSingle(getQTIIdent()));
}
buffer.append("</textarea>");
} else {
// render as input string
buffer.append("<input id=\"QTI_").append(getQTIIdent()).append("\" name=\"");
appendParameterIdent(buffer, ri);
buffer.append("\" type=\"text\" size=\"").append(columns).append("\" maxlength=\"").append(maxlength);
if (iinput != null && !iinput.isEmpty() && iinput.getSingle(responseIdent) != null) {
buffer.append("\" value=\"").append(iinput.getSingle(getQTIIdent())); //TODO: LD: must this value be escapeHtml?
}
buffer.append("\" onchange=\"return setFormDirty('ofo_iq_item')\" onclick=\"return setFormDirty('ofo_iq_item')\" /> ");
}
}
Integer flowLabelClass = (Integer) ri.get(RenderInstructions.KEY_FLOW_LABEL);