Exemple #1
0
  /**
   * This is used to create the user interface for a question
   *
   * @param doc
   * @param UINode
   * @return
   */
  private Element writeToXmlUi(Document doc, Element UINode) {
    // create an item element
    Element itemNode = doc.createElement(XformConstants.NODE_NAME_ITEM);
    // now attach the item to the UI node
    UINode.appendChild(itemNode);

    // now add the label
    Element labelNode = doc.createElement(XformConstants.NODE_NAME_LABEL_MINUS_PREFIX);
    labelNode.setAttribute(XformConstants.ATTRIBUTE_NAME_REF, "jr:itext('" + getBinding() + "')");
    itemNode.appendChild(labelNode);

    // now add the value
    Element valueNode = doc.createElement(XformConstants.NODE_NAME_VALUE);
    valueNode.appendChild(doc.createTextNode(getDefaultValue()));
    itemNode.appendChild(valueNode);
    return UINode;
  }
Exemple #2
0
  /**
   * Converts a form definition object to an XHTML document object.
   *
   * @param formDef the form definition object.
   * @return the xhtml document object.
   */
  public static Document fromFormDef2XhtmlDoc(FormDef formDef) {
    Document prevdoc = formDef.getDoc();

    Document doc = XMLParser.createDocument();
    doc.appendChild(doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));

    Element htmlNode = doc.createElement("h:html");
    // formDef.setXformsNode(htmlNode);

    htmlNode.setAttribute("xmlns:h", "http://www.w3.org/1999/xhtml");
    htmlNode.setAttribute("xmlns:jr", "http://openrosa.org/javarosa");
    htmlNode.setAttribute(
        XformConstants
            .XML_NAMESPACE /*XformConstants.XML_NAMESPACE_PREFIX+XformConstants.PREFIX_XFORMS*/,
        XformConstants.NAMESPACE_XFORMS);
    htmlNode.setAttribute(
        XformConstants.XML_NAMESPACE_PREFIX + XformConstants.PREFIX_XML_SCHEMA,
        XformConstants.NAMESPACE_XML_SCHEMA);

    doc.appendChild(htmlNode);

    // add head
    Element headNode = doc.createElement("h:head");
    htmlNode.appendChild(headNode);

    // add title
    Element titleNode = doc.createElement("h:title");
    titleNode.appendChild(doc.createTextNode(formDef.getName()));
    headNode.appendChild(titleNode);

    // add body
    Element bodyNode = doc.createElement("h:body");
    htmlNode.appendChild(bodyNode);

    // add model
    Element modelNode = doc.createElement(XformConstants.NODE_NAME_MODEL);
    headNode.appendChild(modelNode);

    // we do not want to lose anything that the model could have had which we do not build when
    // creating an xform from scratch
    XformBuilder.buildXform(formDef, doc, bodyNode, modelNode);

    XformUtil.copyModel(prevdoc, doc);

    return doc;
  }
Exemple #3
0
 /**
  * This will flesh out the iText
  *
  * @param doc
  * @param iTextNode
  */
 private void writeToXmliText(Document doc, List<Element> iTextNodes) {
   // we're assuming that all languages have already been fleshed out in the
   // itext node
   // the mapping of binds to language strings
   HashMap<String, ItextModel> itextMap = getFormDef().getITextMap();
   // loop the itext children, which should be translation elements
   for (Element translationNode : iTextNodes) {
     // get the language name
     String languageName = translationNode.getAttribute(XformConstants.ATTRIBUTE_NAME_LANG);
     // make sure it's not null
     if (languageName == null) {
       continue;
     }
     // get the ItextModel for this question
     ItextModel itext = itextMap.get(getBinding());
     // if there's nothing there, then this is probably a hidden question
     if (itext == null) {
       continue;
     }
     // get the string
     String text = itext.get(languageName);
     // make sure it's not null
     if (text == null) {
       continue;
     }
     // add it to the translation node
     // create the text for the form title
     Element titleTextNode = doc.createElement(XformConstants.NODE_NAME_TEXT);
     // set the id
     titleTextNode.setAttribute(XformConstants.ATTRIBUTE_NAME_ID, getBinding());
     // create the value node for the form title
     Element titleValueNode = doc.createElement(XformConstants.NODE_NAME_VALUE);
     // set the text itself
     titleValueNode.appendChild(doc.createTextNode(text));
     // now add the value node to the text node
     titleTextNode.appendChild(titleValueNode);
     // add the text node to the translation node
     translationNode.appendChild(titleTextNode);
   }
 }
  public String getGrade() {
    Document d = XMLParser.createDocument();
    Element root = d.createElement("Grade");

    // first, some specifications of the pedigree
    int numMales = 0;
    int numFemales = 0;
    int numAffectedMales = 0;
    int numAffectedFemales = 0;
    PelicanPerson[] people = getAllPeople();
    for (int i = 0; i < people.length; i++) {
      PelicanPerson p = people[i];
      if (p.sex == PelicanPerson.male) {
        numMales++;
        if (p.affection == PelicanPerson.affected) {
          numAffectedMales++;
        }
      } else {
        numFemales++;
        if (p.affection == PelicanPerson.affected) {
          numAffectedFemales++;
        }
      }
    }
    Element e = d.createElement("Counts");

    Element M = d.createElement("M");
    M.appendChild(d.createTextNode(String.valueOf(numMales)));
    e.appendChild(M);

    Element F = d.createElement("F");
    F.appendChild(d.createTextNode(String.valueOf(numFemales)));
    e.appendChild(F);

    Element aM = d.createElement("aM");
    aM.appendChild(d.createTextNode(String.valueOf(numAffectedMales)));
    e.appendChild(aM);

    Element aF = d.createElement("aF");
    aF.appendChild(d.createTextNode(String.valueOf(numAffectedFemales)));
    e.appendChild(aF);

    root.appendChild(e);

    // now, the analysis results
    renumberAll();
    updateDisplay();

    String integrity = checkIntegrity(history.lastElement());
    if (integrity.equals("")) {
      PedigreeSolver ps = new PedigreeSolver(getAllPeople(), getMatingList());
      PedigreeSolution sol = ps.solve();
      e = d.createElement("Analysis");

      GenotypeSet[] results = sol.getResults();

      Element AR = d.createElement("AR");
      if (results[0].getAll().size() > 0) {
        AR.appendChild(d.createTextNode("Y"));
      } else {
        AR.appendChild(d.createTextNode("N"));
      }
      e.appendChild(AR);

      Element AD = d.createElement("AD");
      if (results[1].getAll().size() > 0) {
        AD.appendChild(d.createTextNode("Y"));
      } else {
        AD.appendChild(d.createTextNode("N"));
      }
      e.appendChild(AD);

      Element SR = d.createElement("SR");
      if (results[2].getAll().size() > 0) {
        SR.appendChild(d.createTextNode("Y"));
      } else {
        SR.appendChild(d.createTextNode("N"));
      }
      e.appendChild(SR);

      Element SD = d.createElement("SD");
      if (results[3].getAll().size() > 0) {
        SD.appendChild(d.createTextNode("Y"));
      } else {
        SD.appendChild(d.createTextNode("N"));
      }
      e.appendChild(SD);
    }
    root.appendChild(e);

    return root.toString();
  }