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 writeSections(XMLEventWriter writer, GAMObject go) {
    XMLEventFactory efac = XMLEventFactory.newInstance();

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

    String section_format = go.getSectionFormat();
    if (section_format == null) {
      section_format = "JPEG";
    }

    String section_type = go.getSectionType();
    if (section_type == null) {
      section_type = "sequence_image";
    }

    XMLEvent startSections = efac.createStartElement("", "", "sections");
    XMLEvent endSections = efac.createEndElement("", "", "sections");
    XMLEvent attrFirstnum = efac.createAttribute("firstnum", String.valueOf(go.getFirstNum()));
    XMLEvent attrLastnum = efac.createAttribute("lastnum", String.valueOf(go.getLastNum()));
    XMLEvent attrSectionType = efac.createAttribute("type", section_type);
    XMLEvent attrSectionFormat = efac.createAttribute("format", section_format);

    XMLEvent startSection = efac.createStartElement("", "", "section");
    XMLEvent endSection = efac.createEndElement("", "", "section");

    XMLEvent startStack = efac.createStartElement("", "", "stack");
    XMLEvent endStack = efac.createEndElement("", "", "stack");

    XMLEvent attrNumber;
    XMLEvent attrSrc;
    Set<Entry<Integer, TDRSection>> sections = go.getSections().entrySet();
    Iterator<Entry<Integer, TDRSection>> it = sections.iterator();

    try {

      /* sequence images or stack image? */
      if (section_type == null || section_type.equalsIgnoreCase("sequence_image")) {

        /*<sections>: in case of SEQUENCE images */
        writer.add(indent);
        writer.add(startSections);
        writer.add(attrFirstnum);
        writer.add(attrLastnum);
        writer.add(attrSectionType);
        writer.add(attrSectionFormat);
        writer.add(newLine);

        while (it.hasNext()) {
          Entry<Integer, TDRSection> section = (Entry<Integer, TDRSection>) it.next();
          String number = String.valueOf(section.getKey());

          /* local version: ObjectLoadingStr = ""
           * server version: ObjectLoadingStr = "ObjectLoadingServlet"
           * 											+ "biolobj_name=" + tdro.getName()
           * 											+ "?image=";
           * */
          String src = ObjectLoadingStr + section.getValue().getImageFileName();

          attrNumber = efac.createAttribute("number", number);
          attrSrc = efac.createAttribute("src", src);

          /*<section>*/
          writer.add(indent);
          writer.add(tab);
          writer.add(startSection);
          writer.add(attrNumber);
          writer.add(attrSrc);
          writer.add(endSection);
          writer.add(newLine);
        }

        /*<sections>*/
        writer.add(indent);
        writer.add(endSections);
        writer.add(newLine);

      } else {

        /*<sections>: in case of STACK images */
        writer.add(indent);
        writer.add(startSections);
        writer.add(attrFirstnum);
        writer.add(attrLastnum);
        writer.add(attrSectionType);
        writer.add(attrSectionFormat);
        writer.add(newLine);

        /* local version: ObjectLoadingStr = ""
         * server version: ObjectLoadingStr = "ObjectLoadingServlet"
         * 											+ "biolobj_name=" + tdro.getName()
         * 											+ "?image=";
         * */
        String src = ObjectLoadingStr + go.getStackFileName();
        attrSrc = efac.createAttribute("src", src);

        /*<stack>*/
        writer.add(indent);
        writer.add(tab);
        writer.add(startStack);
        writer.add(attrSrc);
        writer.add(endStack);
        writer.add(newLine);

        /*<sections>*/
        writer.add(indent);
        writer.add(endSections);
        writer.add(newLine);
      }

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