Changeset 6622


Ignore:
Timestamp:
07/01/10 16:17:52 (9 years ago)
Author:
melissa
Message:

Ensure that xmlns:ome elements are preserved during transformation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/bio-formats/src/loci/formats/services/OMEXMLServiceImpl.java

    r6621 r6622  
    123123    try { 
    124124      if (version.equals("2003-FC")) { 
     125        xml = verifyOMENamespace(xml); 
    125126        transformed = XMLTools.transformXML(xml, UPDATE_2003FC); 
    126127      } 
    127128      else if (version.equals("2006-LO")) { 
     129        xml = verifyOMENamespace(xml); 
    128130        transformed = XMLTools.transformXML(xml, UPDATE_2006LO); 
    129131      } 
    130132      else if (version.equals("2007-06")) { 
     133        xml = verifyOMENamespace(xml); 
    131134        transformed = XMLTools.transformXML(xml, UPDATE_200706); 
    132135      } 
    133136      else if (version.equals("2008-02")) { 
     137        xml = verifyOMENamespace(xml); 
    134138        transformed = XMLTools.transformXML(xml, UPDATE_200802); 
    135139      } 
     
    139143 
    140144      if (!version.equals("2009-09") && !version.equals("2010-04")) { 
     145        transformed = verifyOMENamespace(transformed); 
    141146        transformed = XMLTools.transformXML(transformed, UPDATE_200809); 
    142147      } 
     
    144149      LOGGER.trace("At least 2009-09 dump: {}", transformed); 
    145150      if (!version.equals("2010-04")) { 
     151        transformed = verifyOMENamespace(transformed); 
    146152        transformed = XMLTools.transformXML(transformed, UPDATE_200909); 
    147153      } 
    148154      LOGGER.debug("XML updated to at least 2010-04"); 
    149155      LOGGER.trace("At least 2010-04 dump: {}", transformed); 
     156      transformed = verifyOMENamespace(transformed); 
    150157      transformed = XMLTools.transformXML(transformed, UPDATE_201004); 
    151158      LOGGER.debug("XML updated to at least 2010-06"); 
     
    430437  } 
    431438 
     439  // -- Helper methods -- 
     440 
     441  /** Ensures that an xmlns:ome element exists. */ 
     442  private String verifyOMENamespace(String xml) { 
     443    try { 
     444      Document doc = XMLTools.parseDOM(xml); 
     445      Element e = doc.getDocumentElement(); 
     446      String omeNamespace = e.getAttribute("xmlns:ome"); 
     447      if (omeNamespace == null || omeNamespace.equals("")) { 
     448        e.setAttribute("xmlns:ome", e.getAttribute("xmlns")); 
     449      } 
     450      return XMLTools.getXML(doc); 
     451    } 
     452    catch (ParserConfigurationException pce) { } 
     453    catch (TransformerConfigurationException tce) { } 
     454    catch (TransformerException te) { } 
     455    catch (SAXException se) { } 
     456    catch (IOException ioe) { } 
     457    return null; 
     458  } 
     459 
    432460} 
Note: See TracChangeset for help on using the changeset viewer.