示例#1
0
  private void writeContours(XMLEventWriter writer, XMLEvent indent, TDRStructure structure) {

    XMLEventFactory efac = XMLEventFactory.newInstance();

    Collection<XMLEvent> attrContour = new ArrayList<XMLEvent>();
    XMLEvent startContour;
    XMLEvent endContour = efac.createEndElement("", "", "contour");

    Vector<TDRContour> contours = structure.getContours();
    Iterator<TDRContour> it = contours.iterator();

    try {

      while (it.hasNext()) {
        TDRContour contour = it.next();
        String section = String.valueOf(contour.getSection().getNumber());
        String startpoint = contour.get_startpoint_x() + "," + contour.get_startpoint_y();
        String offset = String.valueOf(contour.get_offset());
        String numpoints = String.valueOf(contour.get_numpoints());

        /* prepare contour's attributes */
        attrContour.clear(); /*clear existing attributes*/
        attrContour.add(efac.createAttribute("section", section));
        attrContour.add(efac.createAttribute("startpoint", startpoint));
        attrContour.add(efac.createAttribute("offset", offset));
        attrContour.add(efac.createAttribute("numpoints", numpoints));
        startContour = efac.createStartElement("", "", "contour", attrContour.iterator(), null);

        /*<contour>*/
        writer.add(indent);
        writer.add(startContour);
        writer.add(endContour);
        writer.add(newLine);
      }

    } catch (XMLStreamException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
示例#2
0
  private void writeStructures(XMLEventWriter writer, GAMObject go) {

    XMLEventFactory efac = XMLEventFactory.newInstance();

    /* create indent from 2 tabs */
    String sIndent = "  " + "  ";
    XMLEvent indent = efac.createDTD(sIndent);

    XMLEvent startStructures = efac.createStartElement("", "", "structures");
    XMLEvent endStructures = efac.createEndElement("", "", "structures");

    Collection<XMLEvent> attrStructure = new ArrayList<XMLEvent>();
    XMLEvent startStructure;
    XMLEvent endStructure = efac.createEndElement("", "", "structure");

    XMLEvent startBoundingbox = efac.createStartElement("", "", "boundingbox");
    XMLEvent attrMin, attrMax;
    XMLEvent endBoundingbox = efac.createEndElement("", "", "boundingbox");

    XMLEvent startSurfacemodel = efac.createStartElement("", "", "surfacemodel");
    XMLEvent attrSurfaceSrc;
    XMLEvent endSurfacemodel = efac.createEndElement("", "", "surfacemodel");

    XMLEvent startContourmodel = efac.createStartElement("", "", "contourmodel");
    XMLEvent attrContourSrc;
    XMLEvent endControumodel = efac.createEndElement("", "", "contourmodel");

    Collection<XMLEvent> attrContour = new ArrayList<XMLEvent>();
    XMLEvent startContour;
    XMLEvent endContour = efac.createEndElement("", "", "contour");

    Set<Entry<String, TDRStructure>> structures = go.getStructures().entrySet();
    if (structures == null) {
      /* no 3D structure */
      return;
    }
    Iterator<Entry<String, TDRStructure>> it = structures.iterator();

    try {
      /*<structures>*/
      writer.add(indent);
      writer.add(startStructures);
      writer.add(newLine);

      while (it.hasNext()) {
        Entry<String, TDRStructure> s = (Entry<String, TDRStructure>) it.next();
        TDRStructure structure = s.getValue();

        String label = structure.getLabel();
        String name = structure.getName();
        String type = structure.getType();
        Color c = structure.getColor();
        String color = c.getRed() + "," + c.getGreen() + "," + c.getBlue();

        /* prepare structure's attributes */
        attrStructure.clear(); /*clear existing attributes*/
        attrStructure.add(efac.createAttribute("label", label));
        attrStructure.add(efac.createAttribute("name", name));
        attrStructure.add(efac.createAttribute("type", type));
        attrStructure.add(efac.createAttribute("color", color));
        startStructure =
            efac.createStartElement("", "", "structure", attrStructure.iterator(), null);

        /* prepare boundingbox's attributes */
        String min = structure.getMinBB();
        String max = structure.getMaxBB();
        attrMin = efac.createAttribute("min", min);
        attrMax = efac.createAttribute("max", max);

        /*
         * prepare SRC attribute for surface and contour model
         *
         * local version: ObjectLoadingStr = ""
         * server version: ObjectLoadingStr = "ObjectLoadingServlet"
         * 											+ "biolobj_name=" + tdro.getName()
         * 											+ "?image=";
         * */

        /* prepare <surfacemodel>'s attribute */
        String surfaceSrc = structure.getSurfaceModel();
        if (surfaceSrc == null || surfaceSrc.trim().equalsIgnoreCase("")) {
          surfaceSrc = "";
        } else {
          surfaceSrc = ObjectLoadingStr + surfaceSrc;
        }
        attrSurfaceSrc = efac.createAttribute("src", surfaceSrc);

        /* prepare <contourmodel>'s attribute */
        String contourSrc = structure.getContourModel();
        if (contourSrc == null || contourSrc.trim().equalsIgnoreCase("")) {
          contourSrc = "";
        } else {
          contourSrc = ObjectLoadingStr + contourSrc;
        }
        attrContourSrc = efac.createAttribute("src", contourSrc);

        /*<structure>*/
        writer.add(indent);
        writer.add(tab);
        writer.add(startStructure);
        writer.add(newLine);

        /*<tags>*/
        Vector<String> tags = structure.getTags();
        if (tags.size() > 0) {
          String sIndent2 = sIndent + "  " + "  ";
          XMLEvent indent2 = efac.createDTD(sIndent2);

          writeTags(writer, indent2, tags);
        }

        /*<annotations>*/
        Properties annotations = structure.getAnnotations();
        if (annotations.size() > 0) {
          String sIndent2 = sIndent + "  " + "  ";
          XMLEvent indent2 = efac.createDTD(sIndent2);

          writeAnnotations(writer, indent2, annotations);
        }

        /*<boundingbox>*/
        writer.add(indent);
        writer.add(tab);
        writer.add(tab);
        writer.add(startBoundingbox);
        writer.add(attrMin);
        writer.add(attrMax);
        writer.add(endBoundingbox);
        writer.add(newLine);

        /*<surfacemodel>*/
        if (surfaceSrc != "") {
          writer.add(indent);
          writer.add(tab);
          writer.add(tab);
          writer.add(startSurfacemodel);
          writer.add(attrSurfaceSrc);
          writer.add(endSurfacemodel);
          writer.add(newLine);
        }

        if (contourSrc != "") {

          /*<contourmodel>*/
          writer.add(indent);
          writer.add(tab);
          writer.add(tab);
          writer.add(startContourmodel);
          writer.add(attrContourSrc);
          writer.add(newLine);

          /*<contour>*/
          String sIndent2 = sIndent + "  " + "  " + "  ";
          XMLEvent indent2 = efac.createDTD(sIndent2);
          writeContours(writer, indent2, structure);

          /*</contourmodel>*/
          writer.add(indent);
          writer.add(tab);
          writer.add(tab);
          writer.add(endControumodel);
          writer.add(newLine);
        }

        /*</structure>*/
        writer.add(indent);
        writer.add(tab);
        writer.add(endStructure);
        writer.add(newLine);
      }

      /*</structures>*/
      writer.add(indent);
      writer.add(endStructures);
      writer.add(newLine);

    } catch (XMLStreamException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }