Esempio n. 1
0
  @Override
  public void write(GAMObject go) {

    try {
      XMLEventFactory efac = XMLEventFactory.newInstance();

      XMLEvent startDoc = efac.createStartDocument("UTF-8", "1.0");
      XMLEvent endDoc = efac.createEndDocument();

      XMLEvent startGAML = efac.createStartElement("", "", "gaml");
      XMLEvent attrVersion = efac.createAttribute("version", "1.0");
      XMLEvent endGAML = efac.createEndElement("", "", "gaml");

      XMLEvent startServer = efac.createStartElement("", "", "server");
      String server = go.getServer();
      if (server == null) {
        server = "";
      }
      XMLEvent charServer = efac.createCharacters(server);
      XMLEvent endServer = efac.createEndElement("", "", "server");

      XMLEvent startModel = efac.createStartElement("", "", "model");
      XMLEvent attrName = efac.createAttribute("name", go.getName());
      XMLEvent endModel = efac.createEndElement("", "", "model");

      /*<?xml version="1.0" encoding="UTF-8"?>*/
      writer.add(startDoc);
      writer.add(newLine);

      /*<gaml>*/
      writer.add(startGAML);
      writer.add(attrVersion);
      writer.add(newLine);

      /*<server>*/
      writer.add(tab);
      writer.add(startServer);
      writer.add(charServer);
      writer.add(endServer);
      writer.add(newLine);

      /*<model>*/
      writer.add(tab);
      writer.add(startModel);
      writer.add(attrName);
      writer.add(newLine);

      /*<meta>*/
      writeMetaModel(writer, go);

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

        writeTags(writer, indent2, tags);
      }

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

        writeAnnotations(writer, indent2, annotations);
      }

      /*<sections>*/
      if (go.getSections().size() > 0) {
        writeSections(writer, go);
      }

      /*<structures>*/
      if (go.getStructures().size() > 0) {
        writeStructures(writer, go);
      }

      /*</model>*/
      writer.add(tab);
      writer.add(endModel);
      writer.add(newLine);

      /*<user-annotations>*/
      Properties userAnnotations = go.getUserAnnotations();
      if (userAnnotations.size() > 0) {
        String sIndent1 = "  ";
        XMLEvent indent1 = efac.createDTD(sIndent1);

        writeUserAnnotations(writer, indent1, userAnnotations);
      }

      /*</gaml>*/
      writer.add(endGAML);
      writer.add(newLine);

      writer.add(endDoc);
      writer.flush();

    } catch (XMLStreamException e) {
      System.out.println("GAMLWriterV10::write - error writing GAM");
      e.printStackTrace();
    }
  }
Esempio n. 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();
    }
  }