Changeset 7068
- Timestamp:
- 10/11/10 16:42:24 (9 years ago)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.2/components/bio-formats/src/loci/formats/services/OMEXMLServiceImpl.java
r7067 r7068 372 372 373 373 for (String key : metadata.keySet()) { 374 XMLAnnotation annotation = new XMLAnnotation();374 OriginalMetadataAnnotation annotation = new OriginalMetadataAnnotation(); 375 375 annotation.setID(MetadataTools.createLSID("Annotation", annotationIndex)); 376 annotation.setValue(makeOriginalMetadata(key, metadata.get(key))); 376 annotation.setKey(key); 377 annotation.setValue(metadata.get(key).toString()); 377 378 annotations.addXMLAnnotation(annotation); 378 379 annotationIndex++; … … 389 390 String key, String value) 390 391 { 391 int annotationIndex = 0; 392 try { 393 annotationIndex = omexmlMeta.getXMLAnnotationCount(); 394 } 395 catch (NullPointerException e) { } 396 397 String id = MetadataTools.createLSID("Annotation", annotationIndex); 398 omexmlMeta.setXMLAnnotationID(id, annotationIndex); 399 String xml = makeOriginalMetadata(key, value); 400 omexmlMeta.setXMLAnnotationValue(xml, annotationIndex); 392 OME root = (OME) omexmlMeta.getRoot(); 393 StructuredAnnotations annotations = root.getStructuredAnnotations(); 394 if (annotations == null) annotations = new StructuredAnnotations(); 395 int annotationIndex = annotations.sizeOfXMLAnnotationList(); 396 397 OriginalMetadataAnnotation annotation = new OriginalMetadataAnnotation(); 398 annotation.setID(MetadataTools.createLSID("Annotation", annotationIndex)); 399 annotation.setKey(key); 400 annotation.setValue(value); 401 annotations.addXMLAnnotation(annotation); 402 403 root.setStructuredAnnotations(annotations); 404 omexmlMeta.setRoot(root); 401 405 } 402 406 … … 494 498 } 495 499 496 /** Create an XML annotation for the given OriginalMetadata key/value pair. */ 497 private String makeOriginalMetadata(String key, Object value) { 498 return "<OriginalMetadata><Key>" + key + "</Key><Value>" + value + 499 "</Value></OriginalMetadata>"; 500 // -- Helper class -- 501 502 class OriginalMetadataAnnotation extends XMLAnnotation { 503 private static final String ORIGINAL_METADATA_NS = 504 "openmicroscopy.org/OriginalMetadata"; 505 506 private String key, value; 507 508 // -- OriginalMetadataAnnotation methods -- 509 510 public void setKey(String key) { 511 this.key = key; 512 } 513 514 public void setValue(String value) { 515 this.value = value; 516 } 517 518 // -- XMLAnnotation methods -- 519 520 /* @see ome.xml.model.XMLAnnotation#asXMLElement(Document, Element) */ 521 protected Element asXMLElement(Document document, Element element) { 522 if (element == null) { 523 element = 524 document.createElementNS(XMLAnnotation.NAMESPACE, "XMLAnnotation"); 525 } 526 527 Element keyElement = 528 document.createElementNS(ORIGINAL_METADATA_NS, "Key"); 529 Element valueElement = 530 document.createElementNS(ORIGINAL_METADATA_NS, "Value"); 531 keyElement.setTextContent(key); 532 valueElement.setTextContent(value); 533 534 Element originalMetadata = 535 document.createElementNS(ORIGINAL_METADATA_NS, "OriginalMetadata"); 536 originalMetadata.appendChild(keyElement); 537 originalMetadata.appendChild(valueElement); 538 539 Element annotationValue = 540 document.createElementNS(XMLAnnotation.NAMESPACE, "Value"); 541 annotationValue.appendChild(originalMetadata); 542 543 element.appendChild(annotationValue); 544 return super.asXMLElement(document, element); 545 } 546 500 547 } 501 548 -
trunk/components/bio-formats/src/loci/formats/services/OMEXMLServiceImpl.java
r7038 r7068 372 372 373 373 for (String key : metadata.keySet()) { 374 XMLAnnotation annotation = new XMLAnnotation();374 OriginalMetadataAnnotation annotation = new OriginalMetadataAnnotation(); 375 375 annotation.setID(MetadataTools.createLSID("Annotation", annotationIndex)); 376 annotation.setValue(makeOriginalMetadata(key, metadata.get(key))); 376 annotation.setKey(key); 377 annotation.setValue(metadata.get(key).toString()); 377 378 annotations.addXMLAnnotation(annotation); 378 379 annotationIndex++; … … 389 390 String key, String value) 390 391 { 391 int annotationIndex = 0; 392 try { 393 annotationIndex = omexmlMeta.getXMLAnnotationCount(); 394 } 395 catch (NullPointerException e) { } 396 397 String id = MetadataTools.createLSID("Annotation", annotationIndex); 398 omexmlMeta.setXMLAnnotationID(id, annotationIndex); 399 String xml = makeOriginalMetadata(key, value); 400 omexmlMeta.setXMLAnnotationValue(xml, annotationIndex); 392 OME root = (OME) omexmlMeta.getRoot(); 393 StructuredAnnotations annotations = root.getStructuredAnnotations(); 394 if (annotations == null) annotations = new StructuredAnnotations(); 395 int annotationIndex = annotations.sizeOfXMLAnnotationList(); 396 397 OriginalMetadataAnnotation annotation = new OriginalMetadataAnnotation(); 398 annotation.setID(MetadataTools.createLSID("Annotation", annotationIndex)); 399 annotation.setKey(key); 400 annotation.setValue(value); 401 annotations.addXMLAnnotation(annotation); 402 403 root.setStructuredAnnotations(annotations); 404 omexmlMeta.setRoot(root); 401 405 } 402 406 … … 494 498 } 495 499 496 /** Create an XML annotation for the given OriginalMetadata key/value pair. */ 497 private String makeOriginalMetadata(String key, Object value) { 498 return "<OriginalMetadata><Key>" + key + "</Key><Value>" + value + 499 "</Value></OriginalMetadata>"; 500 // -- Helper class -- 501 502 class OriginalMetadataAnnotation extends XMLAnnotation { 503 private static final String ORIGINAL_METADATA_NS = 504 "openmicroscopy.org/OriginalMetadata"; 505 506 private String key, value; 507 508 // -- OriginalMetadataAnnotation methods -- 509 510 public void setKey(String key) { 511 this.key = key; 512 } 513 514 public void setValue(String value) { 515 this.value = value; 516 } 517 518 // -- XMLAnnotation methods -- 519 520 /* @see ome.xml.model.XMLAnnotation#asXMLElement(Document, Element) */ 521 protected Element asXMLElement(Document document, Element element) { 522 if (element == null) { 523 element = 524 document.createElementNS(XMLAnnotation.NAMESPACE, "XMLAnnotation"); 525 } 526 527 Element keyElement = 528 document.createElementNS(ORIGINAL_METADATA_NS, "Key"); 529 Element valueElement = 530 document.createElementNS(ORIGINAL_METADATA_NS, "Value"); 531 keyElement.setTextContent(key); 532 valueElement.setTextContent(value); 533 534 Element originalMetadata = 535 document.createElementNS(ORIGINAL_METADATA_NS, "OriginalMetadata"); 536 originalMetadata.appendChild(keyElement); 537 originalMetadata.appendChild(valueElement); 538 539 Element annotationValue = 540 document.createElementNS(XMLAnnotation.NAMESPACE, "Value"); 541 annotationValue.appendChild(originalMetadata); 542 543 element.appendChild(annotationValue); 544 return super.asXMLElement(document, element); 545 } 546 500 547 } 501 548
Note: See TracChangeset
for help on using the changeset viewer.