Example #1
0
 /**
  * Goes through a given map of constraints attribute vaues and replaces the question whose
  * variable name matches with a given question.
  *
  * @param constraints a map of contraints attribute values keyed by their question definition
  *     objects.
  * @param questionDef the question definition object to replace that in the constraint map.
  */
 public static void replaceConstraintQtn(
     HashMap<QuestionDef, String> constraints, QuestionDef questionDef) {
   Iterator<QuestionDef> keys = constraints.keySet().iterator();
   while (keys.hasNext()) {
     QuestionDef qtn = (QuestionDef) keys.next();
     if (qtn.getBinding().equals(questionDef.getBinding())) {
       String constraint = (String) constraints.get(qtn);
       if (constraint != null) {
         constraints.remove(qtn);
         constraints.put(questionDef, constraint);
       }
       return;
     }
   }
 }
Example #2
0
  /**
   * Gets the skip rule action for a question.
   *
   * @param qtn the question definition object.
   * @return the skip rule action which can be (ModelConstants.ACTION_DISABLE,
   *     ModelConstants.ACTION_HIDE,ModelConstants.ACTION_SHOW or ModelConstants.ACTION_ENABLE)
   */
  public static int getAction(QuestionDef qtn) {
    Element node = qtn.getBindNode();
    if (node == null) return ModelConstants.ACTION_DISABLE;

    String value = node.getAttribute(XformConstants.ATTRIBUTE_NAME_ACTION);
    if (value == null) return ModelConstants.ACTION_DISABLE;

    int action = 0;
    if (value.equalsIgnoreCase(XformConstants.ATTRIBUTE_VALUE_ENABLE))
      action |= ModelConstants.ACTION_ENABLE;
    else if (value.equalsIgnoreCase(XformConstants.ATTRIBUTE_VALUE_DISABLE))
      action |= ModelConstants.ACTION_DISABLE;
    else if (value.equalsIgnoreCase(XformConstants.ATTRIBUTE_VALUE_SHOW))
      action |= ModelConstants.ACTION_SHOW;
    else if (value.equalsIgnoreCase(XformConstants.ATTRIBUTE_VALUE_HIDE))
      action |= ModelConstants.ACTION_HIDE;

    value = node.getAttribute(XformConstants.ATTRIBUTE_NAME_REQUIRED);
    if (XformConstants.XPATH_VALUE_TRUE.equalsIgnoreCase(value))
      action |= ModelConstants.ACTION_MAKE_MANDATORY;
    else action |= ModelConstants.ACTION_MAKE_OPTIONAL;

    return action;
  }
Example #3
0
 /**
  * Sets the question definition object data type based on an xml xsd type.
  *
  * @param def the question definition object.
  * @param type the xml xsd type.
  * @param node the xforms node having the type attribute.
  */
 public static void setQuestionType(QuestionDef def, String type, Element node) {
   if (type != null) {
     if (type.equals(XformConstants.DATA_TYPE_TEXT) || type.indexOf("string") != -1) {
       String format = node.getAttribute(XformConstants.ATTRIBUTE_NAME_FORMAT);
       if (XformConstants.ATTRIBUTE_VALUE_GPS.equals(format))
         def.setDataType(QuestionDef.QTN_TYPE_GPS);
       else def.setDataType(QuestionDef.QTN_TYPE_TEXT);
     } else if ((type.equals("xsd:integer") || type.equals(XformConstants.DATA_TYPE_INT))
         || (type.indexOf("integer") != -1
             || (type.indexOf("int") != -1) && !type.equals("geopoint")))
       def.setDataType(QuestionDef.QTN_TYPE_NUMERIC);
     else if (type.equals("xsd:decimal") || type.indexOf("decimal") != -1)
       def.setDataType(QuestionDef.QTN_TYPE_DECIMAL);
     else if (type.equals("xsd:dateTime") || type.indexOf("dateTime") != -1)
       def.setDataType(QuestionDef.QTN_TYPE_DATE_TIME);
     else if (type.equals("xsd:time") || type.indexOf("time") != -1)
       def.setDataType(QuestionDef.QTN_TYPE_TIME);
     else if (type.equals(XformConstants.DATA_TYPE_DATE) || type.indexOf("date") != -1)
       def.setDataType(QuestionDef.QTN_TYPE_DATE);
     else if (type.equals(XformConstants.DATA_TYPE_BOOLEAN) || type.indexOf("boolean") != -1)
       def.setDataType(QuestionDef.QTN_TYPE_BOOLEAN);
     else if (type.equals(XformConstants.DATA_TYPE_BINARY) || type.indexOf("base64Binary") != -1) {
       String format = node.getAttribute(XformConstants.ATTRIBUTE_NAME_FORMAT);
       if (XformConstants.ATTRIBUTE_VALUE_VIDEO.equals(format))
         def.setDataType(QuestionDef.QTN_TYPE_VIDEO);
       else if (XformConstants.ATTRIBUTE_VALUE_AUDIO.equals(format))
         def.setDataType(QuestionDef.QTN_TYPE_AUDIO);
       else def.setDataType(QuestionDef.QTN_TYPE_IMAGE);
     }
     // TODO These two are used by ODK
     else if (type.equalsIgnoreCase("binary")) {
       def.setDataType(QuestionDef.QTN_TYPE_IMAGE);
     } else if (type.equalsIgnoreCase("geopoint")) def.setDataType(QuestionDef.QTN_TYPE_GPS);
     else if (type.equalsIgnoreCase("barcode")) def.setDataType(QuestionDef.QTN_TYPE_BARCODE);
   } else def.setDataType(QuestionDef.QTN_TYPE_TEXT); // QTN_TYPE_REPEAT
 }