private void writeMetaStructure(XMLEventWriter writer, GAMObject go) { XMLEventFactory efac = XMLEventFactory.newInstance(); /* create indent from 2 tabs */ String sIndent = " " + " "; XMLEvent indent = efac.createDTD(sIndent); XMLEvent startMetadata = efac.createStartElement("", "", "metadata"); XMLEvent endMetadata = efac.createEndElement("", "", "metadata"); String data = go.getType(); if (data == null) { data = ""; } XMLEvent startType = efac.createStartElement("", "", "type"); XMLEvent charsType = efac.createCharacters(data); XMLEvent endType = efac.createEndElement("", "", "type"); data = go.getAuthor(); if (data == null) { data = ""; } XMLEvent startAuthor = efac.createStartElement("", "", "author"); XMLEvent charsAuthor = efac.createCharacters(data); XMLEvent endAuthor = efac.createEndElement("", "", "author"); data = go.getOrganization(); if (data == null) { data = ""; } XMLEvent startOrganization = efac.createStartElement("", "", "organization"); XMLEvent charsOrganization = efac.createCharacters(data); XMLEvent endOrganization = efac.createEndElement("", "", "organization"); data = go.getOrganism(); if (data == null) { data = ""; } XMLEvent startOrganism = efac.createStartElement("", "", "organism"); XMLEvent charsOrganism = efac.createCharacters(data); XMLEvent endOrganism = efac.createEndElement("", "", "organism"); data = go.getStage(); if (data == null) { data = ""; } XMLEvent startDevelStage = efac.createStartElement("", "", "developmental_stage"); XMLEvent charsDevelStage = efac.createCharacters(data); XMLEvent endDevelStage = efac.createEndElement("", "", "developmental_stage"); data = go.getDescription(); if (data == null) { data = ""; } XMLEvent startDescription = efac.createStartElement("", "", "description"); XMLEvent charsDescription = efac.createCharacters(data); XMLEvent endDescription = efac.createEndElement("", "", "description"); Collection<XMLEvent> attrSampling = new ArrayList<XMLEvent>(); attrSampling.add(efac.createAttribute("pointdistX", String.valueOf(go.getPointDistX()))); attrSampling.add(efac.createAttribute("pointdistY", String.valueOf(go.getPointDistY()))); attrSampling.add(efac.createAttribute("stepsize", String.valueOf(go.getStepsize()))); attrSampling.add(efac.createAttribute("numberofpointsX", String.valueOf(go.getNumPointsX()))); attrSampling.add(efac.createAttribute("numberofpointsY", String.valueOf(go.getNumPointsY()))); String voxelSize = go.getVoxelSize(); if (voxelSize == null) { voxelSize = ""; } attrSampling.add(efac.createAttribute("voxelsize", voxelSize)); XMLEvent startSampling = efac.createStartElement("", "", "sampling", attrSampling.iterator(), null); XMLEvent endSampling = efac.createEndElement("", "", "sampling"); try { /*<metadata>*/ writer.add(indent); writer.add(startMetadata); writer.add(newLine); /*<type>*/ writer.add(indent); writer.add(tab); writer.add(startType); writer.add(charsType); writer.add(endType); writer.add(newLine); /*<author>*/ writer.add(indent); writer.add(tab); writer.add(startAuthor); writer.add(charsAuthor); writer.add(endAuthor); writer.add(newLine); /*<organization>*/ writer.add(indent); writer.add(tab); writer.add(startOrganization); writer.add(charsOrganization); writer.add(endOrganization); writer.add(newLine); /*<organism>*/ writer.add(indent); writer.add(tab); writer.add(startOrganism); writer.add(charsOrganism); writer.add(endOrganism); writer.add(newLine); /*<developmental_stage>*/ writer.add(indent); writer.add(tab); writer.add(startDevelStage); writer.add(charsDevelStage); writer.add(endDevelStage); writer.add(newLine); /*<description>*/ writer.add(indent); writer.add(tab); writer.add(startDescription); writer.add(charsDescription); writer.add(endDescription); writer.add(newLine); /*<sampling>*/ writer.add(indent); writer.add(tab); writer.add(startSampling); writer.add(endSampling); writer.add(newLine); /*</metadata>*/ writer.add(indent); writer.add(endMetadata); writer.add(newLine); } catch (XMLStreamException e) { System.out.println("GAMLWriterV10::writerMetadata - error writing Metadata"); e.printStackTrace(); } }
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(); } }
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(); } }
@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(); } }
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(); } }