Search in sources :

Example 6 with ExpressionBuilder

use of org.olat.ims.qti.process.elements.ExpressionBuilder in project openolat by klemens.

the class QTI_and_selection method buildXPathExpression.

/**
 * <!ELEMENT and_selection (selection_metadata | and_selection | or_selection | not_selection)+>
 * @see org.olat.qti.process.elements.ExpressionBuilder#buildXPathExpression(org.dom4j.Element, java.lang.StringBuilder)
 */
public void buildXPathExpression(Element selectionElement, StringBuilder expr, boolean not_switch, boolean use_switch) {
    if (use_switch && not_switch) {
        // treat this "and" node as an "or" node (we need to propagate not's down the tree, since xpath only knows !=,< etc. , but not a not
        ExpressionBuilder eb = QTIHelper.getExpressionBuilder("or_selection");
        eb.buildXPathExpression(selectionElement, expr, not_switch, false);
    } else {
        List elems = selectionElement.elements();
        // dtd: > 0
        int size = elems.size();
        for (int i = 0; i < size; i++) {
            Element child = (Element) elems.get(i);
            String name = child.getName();
            ExpressionBuilder eb = QTIHelper.getExpressionBuilder(name);
            eb.buildXPathExpression(child, expr, not_switch, true);
            if (i < size - 1)
                expr.append(" and ");
        }
    }
}
Also used : Element(org.dom4j.Element) List(java.util.List) ExpressionBuilder(org.olat.ims.qti.process.elements.ExpressionBuilder)

Example 7 with ExpressionBuilder

use of org.olat.ims.qti.process.elements.ExpressionBuilder in project openolat by klemens.

the class QTI_not_selection method buildXPathExpression.

/**
 * <!ELEMENT and_selection (selection_metadata | and_selection | or_selection | not_selection)+>
 * @see org.olat.qti.process.elements.ExpressionBuilder#buildXPathExpression(org.dom4j.Element, java.lang.StringBuilder)
 */
public void buildXPathExpression(Element selectionElement, StringBuilder expr, boolean not_switch, boolean use_switch) {
    // assert: use_switch always true
    if (!use_switch)
        throw new RuntimeException("error in not_selection; use_switch was switched off");
    List elems = selectionElement.elements();
    Element child = (Element) elems.get(0);
    String name = child.getName();
    ExpressionBuilder eb = QTIHelper.getExpressionBuilder(name);
    eb.buildXPathExpression(child, expr, !not_switch, true);
}
Also used : Element(org.dom4j.Element) List(java.util.List) ExpressionBuilder(org.olat.ims.qti.process.elements.ExpressionBuilder)

Example 8 with ExpressionBuilder

use of org.olat.ims.qti.process.elements.ExpressionBuilder in project openolat by klemens.

the class QTI_or_selection method buildXPathExpression.

/**
 * @see org.olat.qti.process.elements.ExpressionBuilder#buildXPathExpression(org.dom4j.Element, java.lang.StringBuilder)
 */
public void buildXPathExpression(Element selectionElement, StringBuilder expr, boolean not_switch, boolean use_switch) {
    if (use_switch && not_switch) {
        // treat this and node as an "or
        ExpressionBuilder eb = QTIHelper.getExpressionBuilder("and_selection");
        eb.buildXPathExpression(selectionElement, expr, not_switch, false);
    } else {
        List elems = selectionElement.elements();
        // dtd: >0
        int size = elems.size();
        expr.append("(");
        for (int i = 0; i < size; i++) {
            Element child = (Element) elems.get(i);
            String name = child.getName();
            ExpressionBuilder eb = QTIHelper.getExpressionBuilder(name);
            eb.buildXPathExpression(child, expr, not_switch, true);
            if (i < size - 1)
                expr.append(" or ");
        }
        expr.append(")");
    }
}
Also used : Element(org.dom4j.Element) List(java.util.List) ExpressionBuilder(org.olat.ims.qti.process.elements.ExpressionBuilder)

Example 9 with ExpressionBuilder

use of org.olat.ims.qti.process.elements.ExpressionBuilder in project OpenOLAT by OpenOLAT.

the class QTI_not_selection method buildXPathExpression.

/**
 * <!ELEMENT and_selection (selection_metadata | and_selection | or_selection | not_selection)+>
 * @see org.olat.qti.process.elements.ExpressionBuilder#buildXPathExpression(org.dom4j.Element, java.lang.StringBuilder)
 */
public void buildXPathExpression(Element selectionElement, StringBuilder expr, boolean not_switch, boolean use_switch) {
    // assert: use_switch always true
    if (!use_switch)
        throw new RuntimeException("error in not_selection; use_switch was switched off");
    List elems = selectionElement.elements();
    Element child = (Element) elems.get(0);
    String name = child.getName();
    ExpressionBuilder eb = QTIHelper.getExpressionBuilder(name);
    eb.buildXPathExpression(child, expr, !not_switch, true);
}
Also used : Element(org.dom4j.Element) List(java.util.List) ExpressionBuilder(org.olat.ims.qti.process.elements.ExpressionBuilder)

Example 10 with ExpressionBuilder

use of org.olat.ims.qti.process.elements.ExpressionBuilder in project OpenOLAT by OpenOLAT.

the class QTI_or_selection method buildXPathExpression.

/**
 * @see org.olat.qti.process.elements.ExpressionBuilder#buildXPathExpression(org.dom4j.Element, java.lang.StringBuilder)
 */
public void buildXPathExpression(Element selectionElement, StringBuilder expr, boolean not_switch, boolean use_switch) {
    if (use_switch && not_switch) {
        // treat this and node as an "or
        ExpressionBuilder eb = QTIHelper.getExpressionBuilder("and_selection");
        eb.buildXPathExpression(selectionElement, expr, not_switch, false);
    } else {
        List elems = selectionElement.elements();
        // dtd: >0
        int size = elems.size();
        expr.append("(");
        for (int i = 0; i < size; i++) {
            Element child = (Element) elems.get(i);
            String name = child.getName();
            ExpressionBuilder eb = QTIHelper.getExpressionBuilder(name);
            eb.buildXPathExpression(child, expr, not_switch, true);
            if (i < size - 1)
                expr.append(" or ");
        }
        expr.append(")");
    }
}
Also used : Element(org.dom4j.Element) List(java.util.List) ExpressionBuilder(org.olat.ims.qti.process.elements.ExpressionBuilder)

Aggregations

List (java.util.List)10 Element (org.dom4j.Element)10 ExpressionBuilder (org.olat.ims.qti.process.elements.ExpressionBuilder)10 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 Random (java.util.Random)4 Objectives (org.olat.ims.qti.container.qtielements.Objectives)2