Salome HOME
Loading of mappings of document types to lists of file formats is implemented. Projec...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / service / technical / ProjectSettingsServiceImpl.java
index 66790ae4540deb94191f2fa2fbb928ac663607eb..49f84de4a7dcbc795925dfddb64ec6ab5655eb71 100644 (file)
@@ -78,6 +78,10 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
         * Configuration document validation cycles.
         */
        private transient List<ProjectSettingsValidationCycle> _concycles;
+       /**
+        * Document type mappings to file formats which should be imported into SALOME during check-out.
+        */
+       private transient Map<String, List<String>> _mapimport;
 
        // Temporary attributes initialized from the configuration file for populating the database with object types
        /**
@@ -300,6 +304,20 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                return result;
        }
 
+       /**
+        * Check if a file of the given format should be imported during check-in of a document of the given type.
+        * 
+        * @param type
+        *            document type
+        * @param format
+        *            file format
+        * @return true if file should be imported
+        */
+       public boolean doImport(final String type, final String format) {
+               return (_mapimport.containsKey(type) && _mapimport.get(type).contains(
+                               format));
+       }
+
        /**
         * Initialize the database: create all necessary default staff defined in the configuration file.
         */
@@ -379,6 +397,8 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                        // Validations tag
                        _concycles = loadValidationCycles(children, resultype);
 
+                       _mapimport = loadFormatMappings(children);
+
                        if (!getDatabase().getCheckedDB().isInitialized()) {
                                // Load object type definitions
                                // Documents tag
@@ -411,6 +431,47 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                }
        }
 
+       /**
+        * Load mappings of document types to lists of importable file formats.
+        * 
+        * @param children
+        *            XML nodes
+        * @return map of document type names to lists of file formats
+        */
+       private Map<String, List<String>> loadFormatMappings(
+                       final Map<String, Node> children) {
+               Map<String, List<String>> res = new HashMap<String, List<String>>();
+               Element maps = (Element) children.get("mappings");
+               Element doc, imp;
+               String type, format;
+               List<String> formats;
+               NodeList docs, imports;
+               if (maps != null) {
+                       // Read document types
+                       docs = maps.getElementsByTagName("document");
+                       for (int i = 0; i < docs.getLength(); i++) {
+                               doc = (Element) docs.item(i);
+                               type = doc.getAttribute("type");
+                               if (!type.isEmpty()) {
+                                       // Read file formats for the document type
+                                       imports = doc.getElementsByTagName("import");
+                                       formats = new ArrayList<String>();
+                                       for (int j = 0; j < imports.getLength(); j++) {
+                                               imp = (Element) imports.item(j);
+                                               format = imp.getAttribute("format");
+                                               if (!format.isEmpty()) {
+                                                       formats.add(format);
+                                               }
+                                       }
+                                       if (!formats.isEmpty()) {
+                                               res.put(type, formats);
+                                       }
+                               }
+                       }
+               }
+               return res;
+       }
+
        /**
         * Load a step from the given XML node. Return the next step's number.
         * 
@@ -434,8 +495,8 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                        final List<String> resultype) {
                int res = snum;
                if ("step".equals(node.getNodeName())) {
-                       
-                       String name = ((Element)node).getAttribute("name");
+
+                       String name = ((Element) node).getAttribute("name");
                        HashMap<String, Node> tags = XDOM.getNamedChildNodes(node);
 
                        NamedNodeMap natr = tags.get("storage").getAttributes();
@@ -594,7 +655,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                if (slist != null) {
                                        uses = _mapuse.get(type);
                                        step = mapresult.get(type);
-       
+
                                        tprop.clear();
                                        tprop.setName(type).setStep(
                                                        slist.toArray(new ProjectSettingsService.Step[slist
@@ -602,7 +663,8 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                        if (uses != null) {
                                                tdoc = maptype.get(uses);
                                                if (tdoc == null) {
-                                                       LOG.warn("Undefined \"" + uses + "\" document type.");
+                                                       LOG.warn("Undefined \"" + uses
+                                                                       + "\" document type.");
                                                } else {
                                                        tprop.setUses(tdoc);
                                                }
@@ -610,7 +672,7 @@ public class ProjectSettingsServiceImpl implements ProjectSettingsService {
                                        if (step != null) {
                                                tprop.setResult(step);
                                        }
-       
+
                                        tprop.disableCheck();
                                        tdoc = getDocumentTypeService().createType(tprop); // Creation of Document Types
                                        getDocumentTypeService().approve(tdoc);