Пример #1
0
  private void writeMetaSections(XMLEventWriter writer, GAMObject go) {

    XMLEventFactory efac = XMLEventFactory.newInstance();

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

    XMLEvent startMetadata = efac.createStartElement("", "", "meta");
    XMLEvent endMetadata = efac.createEndElement("", "", "meta");

    String data = String.valueOf(go.getFirstNum());
    if (data == null) {
      data = "";
    }
    XMLEvent startFirst = efac.createStartElement("", "", "firstnum");
    XMLEvent charsFirst = efac.createCharacters(data);
    XMLEvent endFirst = efac.createEndElement("", "", "firstnum");

    data = String.valueOf(go.getLastNum());
    if (data == null) {
      data = "";
    }
    XMLEvent startLast = efac.createStartElement("", "", "lastnum");
    XMLEvent charsLast = efac.createCharacters(data);
    XMLEvent endLast = efac.createEndElement("", "", "lastnum");

    data = go.getSectionType();
    if (data == null) {
      data = "";
    }
    XMLEvent startType = efac.createStartElement("", "", "type");
    XMLEvent charsType = efac.createCharacters(data);
    XMLEvent endType = efac.createEndElement("", "", "type");

    data = go.getSectionFormat();
    if (data == null) {
      data = "";
    }
    XMLEvent startFormat = efac.createStartElement("", "", "format");
    XMLEvent charsFormat = efac.createCharacters(data);
    XMLEvent endFormat = efac.createEndElement("", "", "format");

    data = go.getStackFileName();
    if (data == null) {
      data = "";
    }
    XMLEvent startStackFile = efac.createStartElement("", "", "stack_file");
    XMLEvent charsStackFile = efac.createCharacters(data);
    XMLEvent endStackFile = efac.createEndElement("", "", "stack_file");

    try {

      /*<metadata>*/
      writer.add(indent);
      writer.add(startMetadata);
      writer.add(newLine);

      /*<firstnum>*/
      writer.add(indent);
      writer.add(tab);
      writer.add(startFirst);
      writer.add(charsFirst);
      writer.add(endFirst);
      writer.add(newLine);

      /*<lastnum>*/
      writer.add(indent);
      writer.add(tab);
      writer.add(startLast);
      writer.add(charsLast);
      writer.add(endLast);
      writer.add(newLine);

      /*<type>*/
      writer.add(indent);
      writer.add(tab);
      writer.add(startType);
      writer.add(charsType);
      writer.add(endType);
      writer.add(newLine);

      /*<format>*/
      writer.add(indent);
      writer.add(tab);
      writer.add(startFormat);
      writer.add(charsFormat);
      writer.add(endFormat);
      writer.add(newLine);

      /*<stack_file>*/
      writer.add(indent);
      writer.add(tab);
      writer.add(startStackFile);
      writer.add(charsStackFile);
      writer.add(endStackFile);
      writer.add(newLine);

      /*</metadata>*/
      writer.add(indent);
      writer.add(endMetadata);
      writer.add(newLine);

    } catch (XMLStreamException e) {
      System.out.println("GAMLWriterV10::writerMetaSections - error writing Metadata");
      e.printStackTrace();
    }
  }
Пример #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();
    }
  }