diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java b/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java index 9011532..aa1b6eb 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/model/ModelManager.java @@ -112,6 +112,15 @@ public class ModelManager { try{ Configuration model = (Configuration) u.unmarshal(bsource, Configuration.class).getValue(); + + // Ensure that the filename inside the xml file is always the file name + Data d = model.getData(); + if(d==null){ + d = new Data(); + model.setData(d); + } + d.setFileName(file.getName().replaceAll("\\.xml$", "")); + return (model); } catch(UnmarshalException e){ @@ -143,6 +152,15 @@ public class ModelManager { try{ Configuration model = (Configuration) u.unmarshal(new StreamSource(file), Configuration.class).getValue(); + + // Ensure that the filename inside the xml file is always the file name + Data d = model.getData(); + if(d==null){ + d = new Data(); + model.setData(d); + } + d.setFileName(file.getName().replaceAll("\\.xml$", "")); + return (model); } catch(UnmarshalException e){ @@ -180,7 +198,7 @@ public class ModelManager { d = new Data(); model.setData(d); } - d.setFileName(file.getName()); + d.setFileName(file.getName().replaceAll("\\.xml$", "")); m.marshal( new JAXBElement(qname, Configuration.class, model ), file); } diff --git a/ch.psi.fda/src/test/java/ch/psi/fda/model/ModelManagerTest.java b/ch.psi.fda/src/test/java/ch/psi/fda/model/ModelManagerTest.java index 54b1c6b..f6ff05b 100644 --- a/ch.psi.fda/src/test/java/ch/psi/fda/model/ModelManagerTest.java +++ b/ch.psi.fda/src/test/java/ch/psi/fda/model/ModelManagerTest.java @@ -75,6 +75,8 @@ public class ModelManagerTest { URL url = this.getClass().getClassLoader().getResource("home/scans/templates/scan1d.xml"); Configuration c = ModelManager.unmarshall(new File(new URI(url.toString()))); logger.info(""+c.getData().getFormat()); + + logger.info("FILENAME: "+c.getData().getFileName()); } /**