Salome HOME
Default document types mappings are moved from application settings (my.xml) to proje...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / ApplicationSettings.java
index a95b58b4b36ecd93244e3ecfa5d3d6afceba529d..9309647d848b3ac104acdb74b7b0b426056c1a48 100644 (file)
@@ -6,7 +6,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -208,10 +207,6 @@ public class ApplicationSettings implements ServletContextAware {
         * Named search filters.
         */
        private transient Map<String, Map<String, Object>> _filter = null;
-       /**
-        * Default document types structured by step.formats.
-        */
-       private transient Map<String, DocumentType> _defdoctype = null;
        /**
         * Available template files.
         */
@@ -862,14 +857,14 @@ public class ApplicationSettings implements ServletContextAware {
                gprop.put("title", "");
                gprop.put("context", new ArrayList<SimulationContext>());
 
-               _defdoctype = new LinkedHashMap<String, DocumentType>();
-               _tempfile = new HashMap<String, String>();
-               _viewermap = new String[0];
-               _convertmap = new HashMap<String, Converter>();
                _filter = new HashMap<String, Map<String, Object>>();
                _filter.put("study", fprop);
                _filter.put("knowledge", gprop);
 
+               _tempfile = new HashMap<String, String>();
+               _viewermap = new String[0];
+               _convertmap = new HashMap<String, Converter>();
+
                // Customization (must be done after above default settings)
                File config = new File(filename);
                if (config.exists()) {
@@ -879,8 +874,6 @@ public class ApplicationSettings implements ServletContextAware {
                                        + config.getAbsolutePath() + "\", using default settings");
                }
                // Settings based on the customization
-               _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
-
                configureToolbars();
        }
 
@@ -888,12 +881,14 @@ public class ApplicationSettings implements ServletContextAware {
         * Configure toolbars for steps.
         */
        private void configureToolbars() {
+               _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
+
                List<ProjectSettingsService.Step> steps = getProjectSettings()
                                .getAllSteps();
                for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
                                .hasNext();) {
                        ProjectSettingsService.Step step = i.next();
-                       List<String> formats = getDefaultFormats(step);
+                       List<String> formats = getProjectSettings().getDefaultFormats(step);
                        if (formats.isEmpty()) {
                                continue;
                        }
@@ -912,8 +907,8 @@ public class ApplicationSettings implements ServletContextAware {
                                module.add(command);
                                String[] parsed = command.split("/");
                                String[] name = parsed[parsed.length - 1].split("\\x2E");
-                               DocumentType dtype = MY_APP._defdoctype.get(step.getNumber()
-                                               + "." + format);
+                               DocumentType dtype = getProjectSettings()
+                                               .getDefaultDocumentType(step, format);
                                String docname = "";
                                if (dtype != null) {
                                        docname = dtype.getName();
@@ -1000,11 +995,10 @@ public class ApplicationSettings implements ServletContextAware {
                return MY_APP._convertmap.get(format + type.getName()); // May be null;
        }
 
-       public static DocumentType getDefaultDocumentType(final Step step,
+       public DocumentType getDefaultDocumentType(final Step step,
                        final String format) {
-               String[] table = format.split("\\x2E");
-               return MY_APP._defdoctype.get(step.getNumber() + "."
-                               + table[table.length - 1]); // May be null
+               return getProjectSettings().getDefaultDocumentType(step.getStep(),
+                               format); // May be null
        }
 
        public static String getDownloadURL(final User user) {
@@ -1058,28 +1052,11 @@ public class ApplicationSettings implements ServletContextAware {
        // Private services
        // ==============================================================================================================================
 
-       private List<String> getDefaultFormats(
-                       final ProjectSettingsService.Step step) {
-               Set<String> keys = _defdoctype.keySet();
-               int number = step.getNumber();
-               List<String> result = new ArrayList<String>();
-
-               for (Iterator<String> i = keys.iterator(); i.hasNext();) {
-                       String[] key = i.next().split("\\x2E");
-                       if (Integer.valueOf(key[0]) != number) {
-                               continue;
-                       }
-                       if (key[1].equals("pdf")) {
-                               continue; // PDF is not an authoring format
-                       }
-                       result.add(key[1]); // Formats are unique
-               }
-               return result;
-       }
-
        /**
         * Load customization of workflow from the given XML file.
-        * @param config the XML configuration file
+        * 
+        * @param config
+        *            the XML configuration file
         */
        private void loadCustomization(final File config) {
                try {
@@ -1091,9 +1068,6 @@ public class ApplicationSettings implements ServletContextAware {
                        HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
                                        .getDocumentElement());
 
-                       // Load default document types.
-                       loadDocTypes(children);
-
                        // Modules tag
                        loadModules(children);
 
@@ -1178,44 +1152,6 @@ public class ApplicationSettings implements ServletContextAware {
                }
        }
 
-       /**
-        * Load default document types from XML configuration.
-        * 
-        * @param children
-        *            XML nodes
-        */
-       private void loadDocTypes(final Map<String, Node> children) {
-               Node child = children.get("default-doctypes");
-               NodeList nlist = child.getChildNodes();
-
-               List<DocumentType> listype = getDocumentTypeService().selectAllTypes();
-               Map<String, DocumentType> maptype = new HashMap<String, DocumentType>();
-               for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
-                       DocumentType type = i.next();
-                       maptype.put(type.getName(), type);
-               }
-               for (int i = 0; i < nlist.getLength(); i++) {
-                       child = nlist.item(i);
-                       if (!child.getNodeName().equals("step")) {
-                               continue;
-                       }
-
-                       String nstep = child.getAttributes().getNamedItem("number")
-                                       .getNodeValue();
-                       NodeList map = child.getChildNodes();
-                       for (int j = 0; j < map.getLength(); j++) {
-                               child = map.item(j);
-                               if (!child.getNodeName().equals("mapping")) {
-                                       continue;
-                               }
-                               NamedNodeMap natr = child.getAttributes();
-                               String dext = natr.getNamedItem("extension").getNodeValue();
-                               String type = natr.getNamedItem("type").getNodeValue();
-                               _defdoctype.put(nstep + "." + dext, maptype.get(type));
-                       }
-               }
-       }
-
        /**
         * Get the documentTypeService.
         *