예제 #1
0
  /**
   * Converts a form definition object to XHTML.
   *
   * @param formDef the form definition object.
   * @return the xhtml.
   */
  public static String fromFormDef2Xhtml(FormDef formDef) {
    Document doc = fromFormDef2XhtmlDoc(formDef);
    formDef.setDoc(doc);
    formDef.setXformsNode(doc.getDocumentElement());

    if (FormUtil.isJavaRosaSaveFormat()) ItextBuilder.build(formDef);

    return XmlUtil.fromDoc2String(doc);
  }
예제 #2
0
 protected void readModel(Model aModel) throws Exception {
   Element el =
       DATAMODEL_TAG_NAME.equals(doc.getDocumentElement().getNodeName())
           ? doc.getDocumentElement()
           : Utils.getElementByTagName(doc.getDocumentElement(), DATAMODEL_TAG_NAME);
   if (el != null && aModel != null) {
     model = aModel;
     try {
       currentTag = el;
       NodeList nl = currentTag.getChildNodes();
       if (nl != null && nl.getLength() > 0) {
         Element lcurrentTag = currentTag;
         try {
           for (int i = 0; i < nl.getLength(); i++) {
             if (ENTITY_TAG_NAME.equals(nl.item(i).getNodeName())) {
               currentTag = (Element) nl.item(i);
               Entity entity = new Entity();
               entity.accept(this);
             } else if (RELATION_TAG_NAME.equals(nl.item(i).getNodeName())) {
               currentTag = (Element) nl.item(i);
               Relation relation = new Relation();
               relation.accept(this);
             } else if (REFERENCE_RELATION_TAG_NAME.equals(nl.item(i).getNodeName())) {
               currentTag = (Element) nl.item(i);
               Relation relation = new ReferenceRelation();
               relation.accept(this);
             }
           }
         } finally {
           currentTag = lcurrentTag;
         }
       }
       model.validateQueries();
       for (Runnable resolver : relationsResolvers) {
         resolver.run();
       }
       model.checkRelationsIntegrity();
     } finally {
       relationsResolvers = null;
       model = null;
     }
   }
 }
  public void loadQueryDef(String xml) {
    Document doc = XMLParser.parse(xml);
    Element rootNode = doc.getDocumentElement();
    if (!rootNode.getNodeName().equalsIgnoreCase(XmlBuilder.NODE_NAME_QUERYDEF)) return;

    HashMap<String, DisplayColumnWidget> displayCols = new HashMap<String, DisplayColumnWidget>();

    NodeList nodes = rootNode.getElementsByTagName(XmlBuilder.NODE_NAME_DISPLAY_FIELDS);
    if (nodes != null && nodes.getLength() > 0)
      loadDisplayFields((Element) nodes.item(0), displayCols);

    nodes = rootNode.getElementsByTagName(XmlBuilder.NODE_NAME_SORT_FIELDS);
    if (nodes != null && nodes.getLength() > 0)
      loadSortFields((Element) nodes.item(0), displayCols);
  }
예제 #4
0
  public void setState(String state) {
    // read in this pedigree from the xml
    Vector<PelicanPerson> newPedigree = new Vector<PelicanPerson>();
    int pedSize = 0;
    Vector<Integer> pidList = new Vector<Integer>();
    Vector<Integer> midList = new Vector<Integer>();
    HashMap<Integer, Integer> idMap = new HashMap<Integer, Integer>();

    Document doc = XMLParser.parse(state);
    NodeList people = doc.getDocumentElement().getChildNodes();
    for (int i = 0; i < people.getLength(); i++) {
      Element e = (Element) people.item(i);
      if (e.getTagName().equals("Person")) {
        int id = Integer.parseInt(e.getAttribute("Id"));
        int sex = Integer.parseInt(e.getAttribute("Sex"));
        int affection = Integer.parseInt(e.getAttribute("Affection"));

        String[] genotype = new String[2];
        genotype[0] = "?";
        genotype[1] = "?";

        PelicanPerson person =
            new PelicanPerson(this, id, null, null, sex, affection, "", 0, genotype);
        newPedigree.add(person);

        int father = Integer.parseInt(e.getAttribute("Father"));
        pidList.add(new Integer(father));
        int mother = Integer.parseInt(e.getAttribute("Mother"));
        midList.add(new Integer(mother));

        idMap.put(new Integer(id), new Integer(pedSize++));
      }
    }

    for (int i = 0; i < newPedigree.size(); i++) {
      PelicanPerson person = (PelicanPerson) newPedigree.elementAt(i);
      // gww	    if (((Integer)pidList.elementAt(i)).intValue()!=PelicanPerson.unknown) {
      if ((Integer) pidList.elementAt(i) != PelicanPerson.unknownID) {
        if (!idMap.containsKey(pidList.elementAt(i)))
          // gww		    throw(new Error("Father of subject "+String.valueOf(person.id)+" is
          // missing"));
          throw (new Error("Father of subject " + person.id + " is missing"));
        person.father =
            (PelicanPerson)
                newPedigree.elementAt(((Integer) idMap.get(pidList.elementAt(i))).intValue());
      }
      // gww	    if (((Integer)midList.elementAt(i)).intValue()!=PelicanPerson.unknown) {
      if ((Integer) midList.elementAt(i) != PelicanPerson.unknownID) {
        if (!idMap.containsKey(midList.elementAt(i)))
          // gww		    throw(new Error("Mother of subject "+String.valueOf(person.id)+" is
          // missing"));
          throw (new Error("Mother of subject " + person.id + " is missing"));
        person.mother =
            (PelicanPerson)
                newPedigree.elementAt(((Integer) idMap.get(midList.elementAt(i))).intValue());
      }
    }

    // figure out the generations
    ((PelicanPerson) newPedigree.elementAt(0)).laidOut = true;
    boolean someChange = true;
    int nperson = newPedigree.size();
    // repeatedly pass through the pedigree all subjects laid out
    while (someChange) {
      someChange = false;
      for (int i = 0; i < nperson; i++) {
        PelicanPerson p = (PelicanPerson) newPedigree.elementAt(i);
        if (!p.laidOut) {
          // try to get it from the parents
          for (int j = 0; j < nperson; j++) {
            PelicanPerson parent = (PelicanPerson) newPedigree.elementAt(j);
            if (parent == p.father && parent.laidOut) {
              p.generation = parent.generation + 1;
              p.laidOut = true;
              someChange = true;
            }
            if (parent == p.mother && parent.laidOut) {
              p.generation = parent.generation + 1;
              p.laidOut = true;
              someChange = true;
            }
          }
        }
        if (p.laidOut) {
          // assign parents generation
          for (int j = 0; j < nperson; j++) {
            PelicanPerson parent = (PelicanPerson) newPedigree.elementAt(j);
            if (parent == p.father && !parent.laidOut) {
              parent.generation = p.generation - 1;
              parent.laidOut = true;
              someChange = true;
            }
            if (parent == p.mother && !parent.laidOut) {
              parent.generation = p.generation - 1;
              parent.laidOut = true;
              someChange = true;
            }
          }
        }
      }
    }

    if (!checkIntegrity(newPedigree).equals("")) {
      return;
    }

    // end
    clear();
    currentId = 0;
    for (int i = 0; i < nperson; i++) {
      PelicanPerson p = (PelicanPerson) newPedigree.elementAt(i);
      add(p);
      // gww need to add in check for valid integer ID else ignore updating of currentId
      if (p.id > 0) {
        // gww           if (i==0 || p.id>currentId) currentId=p.id;
        if (i == 0 || p.id > currentId) currentId = p.id;
      }
    }
    currentId++;
    newPedigree.removeAllElements();
    updateDisplay();
  }