Salome HOME
Siman codebase is refactored. Spring beans are introduced in the context.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / ApplicationSettings.java
1 package org.splat.simer;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.HashMap;
6 import java.util.HashSet;
7 import java.util.Iterator;
8 import java.util.LinkedHashMap;
9 import java.util.List;
10 import java.util.Locale;
11 import java.util.Map;
12 import java.util.Properties;
13 import java.util.Set;
14 import java.util.Vector;
15
16 import javax.xml.parsers.DocumentBuilder;
17 import javax.xml.parsers.DocumentBuilderFactory;
18 import org.w3c.dom.Node;
19 import org.w3c.dom.NodeList;
20 import org.w3c.dom.NamedNodeMap;
21
22 import org.apache.log4j.Logger;
23 import org.splat.dal.bo.kernel.User;
24 import org.splat.manox.XDOM;
25 import org.splat.dal.bo.som.Document;
26 import org.splat.som.DocumentRights;
27 import org.splat.dal.bo.som.DocumentType;
28 import org.splat.dal.bo.som.KnowledgeElement;
29 import org.splat.dal.bo.som.ProgressState;
30 import org.splat.service.technical.ProjectSettingsService;
31 import org.splat.dal.bo.som.SimulationContext;
32 import org.splat.som.Step;
33 import org.splat.som.StudyRights;
34 import org.splat.wapp.MenuItem;
35 import org.splat.wapp.PopupMenu;
36 import org.splat.wapp.PopupItem;
37 import org.splat.wapp.SimpleMenu;
38 import org.splat.wapp.ToolBar;
39
40
41 public class ApplicationSettings {
42
43     private  String                            wappserver;
44     private  String                            wappname;
45         private  Properties                        wapprops;                 // General properties from the application properties files
46         private  Locale                            locale;                   // Current user locale
47     private  Map<String,SimpleMenu>            menus      = null;        // Application menus
48     private  Map<Integer,ToolBar>              bars       = null;        // Study module-bars structured by steps
49     private  Map<String,PopupMenu>             popups     = null;
50     private  Map<String,Map<String,Object>>    filter     = null;        // Named search filters
51         private  Map<String,DocumentType>          defdoctype = null;        // Default document types structured by step.formats
52     private  Map<String,String>                tempfile   = null;        // Available template files
53     private  String[]                          viewermap  = null;        // List of file extensions mapped to a viewer
54     private  Map<String,Converter>             convertmap = null;        // Available document format converters
55     private  Properties                        jndprops   = null;        // JNDI context for launching converters
56
57         private         static ApplicationSettings my         = null;        // Singleton instance
58     protected final static Logger              logger     = Logger.getLogger(ApplicationSettings.class);
59
60     private ProjectSettingsService _projectSettingsService;
61
62         /**
63          * Get the projectSettingsService.
64          * @return the projectSettingsService
65          */
66         public ProjectSettingsService getProjectSettings() {
67                 return _projectSettingsService;
68         }
69         /**
70          * Set the projectSettingsService.
71          * @param projectSettingsService the projectSettingsService to set
72          */
73         public void setProjectSettings(
74                         ProjectSettingsService projectSettingsService) {
75                 _projectSettingsService = projectSettingsService;
76         }
77
78         private   static class NewMenu                 extends SimpleMenu {
79 //  -----------------------------------------------------------------
80       private NewMenu ()
81       {
82         super("create"); 
83         addItem("new-empty", "menu.new.empty", "image.empty.png", "select?menu=create&item=new-empty");
84         addItem("new-copy",     new MenuItem("menu.new.copy").icon("image.copy.png") );
85         addItem("new-instance", new MenuItem("menu.new.instance").icon("image.hold.gif") );
86         addItem("new-import",   new MenuItem("menu.new.import").icon("icon.upload.png") );
87         this.selects("new-empty");
88       }
89         }
90         private   static class SearchMenu              extends SimpleMenu {
91 //  -----------------------------------------------------------------
92       private SearchMenu ()
93       {
94         super("search");
95         addItem("search-study",     "menu.search.study", "image.study.png", "select?menu=search&item=search-study");
96         addItem("search-knowledge", "menu.search.idea",  "image.idea.png",  "select?menu=search&item=search-knowledge");
97         addItem("search-document", new MenuItem("menu.search.document").icon("icon.any.png") );
98         this.selects("search-study");
99       }
100         }
101     private   static class PropertiesMenu          extends SimpleMenu {
102 //  -----------------------------------------------------------------
103       private PropertiesMenu ()
104       {
105         super("configuration");
106         addItem("prop-general",  "menu.prop.general",  "image.hold.gif", "select?menu=properties&item=prop-general");
107         addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif", "select?menu=properties&item=prop-scenario");
108         addItem("prop-timestamp", new MenuItem("menu.prop.timestamp").icon("image.stamp.png") );
109         addItem("prop-comlog",    new MenuItem("menu.prop.comlog").icon("image.hold.gif") );
110         addItem("prop-version",   new MenuItem("menu.prop.version").icon("image.dirclosed.png") );
111       }
112     }
113         private   static class DatadminMenu            extends SimpleMenu {
114 //  -----------------------------------------------------------------
115           private DatadminMenu ()
116           {
117                 super("datadmin");
118         addItem("admin-scontext", "menu.admin.context",   "image.hold.gif", "select?menu=datadmin&item=admin-scontext");
119         addItem("admin-knowelm",  "menu.admin.knowledge", "image.idea.png", "select?menu=datadmin&item=admin-knowelm");
120         addItem("admin-study", new MenuItem("menu.admin.study").icon("image.study.png") );
121           }
122         }
123         private   static class SysadminMenu            extends SimpleMenu {
124 //  -----------------------------------------------------------------
125       private SysadminMenu ()
126       {
127         super("sysadmin");
128         addItem("admin-indexing",   "menu.admin.indexing",   "image.index.png", "select?menu=sysadmin&item=admin-indexing");
129         addItem("admin-importuser", "menu.admin.importuser", "image.group.png", "select?menu=sysadmin&item=admin-importuser");
130       }
131         }
132         private          enum  Item { publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge };
133 //  Resources relative to studies
134     private   static class EditableStudyPopup      extends PopupMenu {
135 //  ----------------------------------------------------------------
136       private StudyRights  user = null;
137
138       private EditableStudyPopup ()
139       {
140         addItem("publish", new PopupItem("menu.publish").icon("image.publish.png").action("edit-study?action=publish").confirmation("message.publish.study"));
141         addItem("promote", new PopupItem("menu.archive"));
142         addSeparator();
143         addItem("edit",    new PopupItem("menu.properties").icon("icon.ed.png").action("../select?menu=properties"));
144         addSeparator();
145         addItem("script",  new PopupItem("menu.newscenario").action("add-scenario"));
146         addItem("version", new PopupItem("menu.version").icon("image.version.png").action("notyetimplemented"));
147         addSeparator();
148         addItem("purge",   new PopupItem("menu.purge").confirmation("message.purge.study"));
149         addItem("export",  new PopupItem("menu.export").icon("image.export.png"));   // For future needs
150         addItem("remove",  new PopupItem("menu.remove.version").icon("icon.delete.png").action("notyetimplemented").confirmation("message.delete.study"));
151       }
152       public boolean isEnabled (String name)
153       {
154         if (user == null) return false;      // Should not happen
155         Item item =  Item.valueOf(name);
156         if  (item == Item.publish) return user.canPublish();
157         if  (item == Item.edit)    return user.canEditProperties();
158         if  (item == Item.script)  return user.canAddScenario();
159         if  (item == Item.version) return user.canVersion();
160         if  (item == Item.remove)  return user.canRemove();
161         if  (item == Item.purge)   return user.canPurge();
162         return false;
163       }
164       public void setContext (String name, Object context)
165       {
166         if (context instanceof StudyRights) {
167           user = (StudyRights)context;          // Just for optimizing
168           boolean       history = user.getOperand().isVersioned();
169           PopupItem     item    = this.item("remove");
170           if (history) item.rename("menu.remove.version");
171           else         item.rename("menu.remove.study");
172         }
173       }
174     }
175 //  Resources relative to documents
176         private   static class EditableDocumentPopup   extends PopupMenu {   // Popup of In-Work documents
177 //  ----------------------------------------------------------------
178       private DocumentRights  user = null;
179
180       private EditableDocumentPopup ()
181       {
182         addItem("accept",  new PopupItem("menu.accept").icon("image.accept.png").action("setDocument?action=accept").confirmation("message.accept.document"));
183         addItem("promote", new PopupItem("menu.promote").icon("image.publish.png").action("setDocument?action=promote").confirmation("message.promote.document"));
184         addSeparator();
185         addItem("rename",  new PopupItem("menu.rename").action("edit-document?action=renameDocument"));
186         addItem("attach",  new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
187         addSeparator();
188         addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
189         addItem("replace", new PopupItem("menu.replace").icon("image.replace.png").action("select-file?nextAction=replace"));
190         addSeparator();
191         addItem("purge",   new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
192         addItem("remove",  new PopupItem("menu.remove.version").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
193       }
194       public boolean isEnabled (String name)
195       {
196         if (user == null) return false;      // Should not happen
197         Item item =  Item.valueOf(name);
198         if  (item == Item.accept)  return user.canAccept();
199         if  (item == Item.promote) return user.canPromote();
200         if  (item == Item.rename)  return user.canRename();
201         if  (item == Item.attach)  return user.canAttach();
202         if  (item == Item.version) return user.canVersion();
203         if  (item == Item.replace) return user.canReplace();
204         if  (item == Item.purge)   return user.canPurge();
205         if  (item == Item.remove)  return user.canRemove();
206         return false;
207       }
208       public void setContext (String name, Object context)
209       {
210         if (context instanceof DocumentRights) {
211           user = (DocumentRights)context;       // Just for optimizing
212           Document downer = user.getOperand();
213           PopupItem  item = this.item("remove");
214           if (downer.isVersioned()) item.rename("menu.remove.version");
215           else                      item.rename("menu.remove.document");
216         }
217       }
218         }
219         private   static class ReviewableDocumentPopup extends PopupMenu {   // Popup of In-Draft documents
220 //  ----------------------------------------------------------------
221       private DocumentRights  user = null;
222
223       private ReviewableDocumentPopup ()
224       {
225         addItem("demote",  new PopupItem("menu.demote").icon("image.demote.png").action("setDocument?action=demote").confirmation("message.demote.document"));
226         addItem("promote", new PopupItem("menu.review").icon("image.review.png").action("setDocument?action=review").confirmation("message.review.document"));
227         addSeparator();
228         addItem("attach",  new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
229         addSeparator();
230         addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
231         addSeparator();
232         addItem("purge",   new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
233       }
234       public boolean isEnabled (String name)
235       {
236         if (user == null) return false;      // Should not happen
237         Item item =  Item.valueOf(name);
238         if  (item == Item.demote)  return user.canDemote();
239         if  (item == Item.promote) return user.canReview();
240         if  (item == Item.attach)  return user.canAttach();
241         if  (item == Item.version) return user.canVersion();
242         if  (item == Item.purge)   return user.canPurge();
243         return false;
244       }
245       public void setContext (String name, Object context)
246       {
247         if (context instanceof DocumentRights) {
248           user = (DocumentRights)context;       // Just for optimizing
249         }
250       }
251         }
252         private   static class NotResultDocumentPopup  extends PopupMenu {
253 //  ----------------------------------------------------------------
254       private DocumentRights  user = null;
255
256       private NotResultDocumentPopup ()
257       {
258         addItem("demote",  new PopupItem("menu.demote").icon("image.demote.png").action("setDocument?action=demote").confirmation("message.demote.document"));
259         addSeparator();
260         addItem("attach",  new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
261         addSeparator();
262         addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
263         addSeparator();
264         addItem("purge",   new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
265         addItem("remove",  new PopupItem("menu.remove.version").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
266       }
267         }
268     private   static class ApprovableDocumentPopup extends PopupMenu {   // Popup of In-Check documents
269 //  ----------------------------------------------------------------
270       private DocumentRights  user = null;
271
272       private ApprovableDocumentPopup ()
273       {
274         addItem("undo",    new PopupItem("menu.demote").icon("image.invalidate.png").action("setDocument?action=invalidate").confirmation("message.demote.document"));
275         addItem("demote",  new PopupItem("menu.disapprove").icon("image.demote.png").action("setDocument?action=disapprove").confirmation("message.disapprove.document"));
276         addItem("approve", new PopupItem("menu.approve").icon("icon.APPROVED.png").action("setDocument?action=approve").confirmation("message.approve.document"));
277       }
278       public boolean isEnabled (String name)
279       {
280         if (user == null) return false;      // Should not happen
281         Item item =  Item.valueOf(name);
282         if  (item == Item.undo)    return user.canInvalidate();
283         if  (item == Item.demote)  return user.canDemote(); 
284         if  (item == Item.approve) return user.canApprove();
285         return false;
286       }
287       public void setContext (String name, Object context)
288       {
289         if (context instanceof DocumentRights) {
290           user = (DocumentRights)context;       // Just for optimizing
291         }
292       }
293     }
294     private   static class ApprovedPopup           extends PopupMenu {   // Popup of Approved documents
295 //  ----------------------------------------------------------------
296       private ApprovedPopup ()
297       {
298         addItem("attach",  new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
299         addSeparator();
300         addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
301       }
302     }
303     private   static class ExternPopup             extends PopupMenu {   // Popup of Extern documents
304 //  ----------------------------------------------------------------
305       private DocumentRights  user = null;
306
307       private ExternPopup ()
308       {
309         addItem("rename",  new PopupItem("menu.rename").action("edit-document?action=renameDocument"));
310         addItem("replace", new PopupItem("menu.replace").icon("image.replace.png").action("select-file?nextAction=replace"));
311         addSeparator();
312         addItem("remove",  new PopupItem("menu.remove.document").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
313       }
314       public boolean isEnabled (String name)
315       {
316         if (user == null) return false;      // Should not happen
317         Item item =  Item.valueOf(name);
318         if  (item == Item.rename)  return user.canRename();
319         if  (item == Item.replace) return user.canReplace();
320         if  (item == Item.remove)  return user.canRemove();
321         return false;
322       }
323       public void setContext (String name, Object context)
324       {
325         if (context instanceof DocumentRights) {
326           user = (DocumentRights)context;          // Just for optimizing
327         }
328       }
329     }
330 //  Resources relative to simulation contexts
331     private   static class ScontextPopup   extends PopupMenu {
332 //  --------------------------------------------------------
333       private SimulationContextFacade owner = null;
334
335       private ScontextPopup ()
336       {
337         addItem("rename",  new PopupItem("menu.rename").action("edit-context?action=renameContext"));
338         addItem("edit",    new PopupItem("menu.edit").action("edit-context?action=editContext"));
339         addSeparator();
340         addItem("remove",  new PopupItem("menu.remove").icon("icon.delete.png").action("remove-context").confirmation("message.delete.context"));
341       }
342       public boolean isEnabled (String name)
343       {
344         Item  item = Item.valueOf(name);
345
346         if (item == Item.rename) {
347           return false;
348         } else
349         if (item == Item.edit) {
350 //        if (!owner.isEditable())
351             return false;
352         }
353         return true;
354       }
355       public void setContext (String name, Object context)
356       {
357         if (context instanceof SimulationContextFacade) {
358           owner = (SimulationContextFacade)context;   // Just for optimizing
359         }
360         else {
361           super.setContext(name, context);
362         }
363       }
364     }
365 //  Resources relative to knowledge
366         private   static class FeedbexPopup    extends PopupMenu {
367 //  --------------------------------------------------------
368       private KnowledgeElement  owner = null;
369
370       private FeedbexPopup ()
371       {
372         addItem("promote", new PopupItem("menu.promote").icon("image.review.png").action("promote-knowledge").confirmation("message.promote.knowledge"));
373         addItem("demote",  new PopupItem("menu.demote").icon("image.invalidate.png").action("demote-knowledge").confirmation("message.demote.knowledge"));
374         addSeparator();
375         addItem("rename",  new PopupItem("menu.rename").action("edit-knowledge?action=renameKnowledge"));
376         addItem("edit",    new PopupItem("menu.edit").action("edit-knowledge?action=editKnowledge"));
377         addSeparator();
378         addItem("remove",  new PopupItem("menu.remove").icon("icon.delete.png").action("remove-knowledge").confirmation("message.delete.knowledge"));
379       }
380       public boolean isEnabled (String name)
381       {
382         Item  item = Item.valueOf(name);
383
384         if (item == Item.promote) {
385           if (owner.getProgressState() != ProgressState.inDRAFT) return false;
386         } else
387         if (item == Item.demote) {
388           if (owner.getProgressState() != ProgressState.inCHECK) return false;
389         }
390         return true;
391       }
392       public void setContext (String name, Object context)
393       {
394         if (context instanceof KnowledgeElement) owner = (KnowledgeElement)context;   // Just for optimizing
395         else {
396           super.setContext(name, context);
397         }
398       }
399         }
400
401 //  ==============================================================================================================================
402 //  Construction
403 //  ==============================================================================================================================
404
405     public static ApplicationSettings getMe () {
406 //  ------------------------------------------
407       return my;                                  // The application is supposed being previously created below
408     }
409         /**
410          * @param wappurl
411          * @param lang
412          * @return
413          */
414         public ApplicationSettings init(String wappurl, Locale lang) throws IOException {
415       ClassLoader cloader = getClass().getClassLoader();
416       String[]    wurl    = wappurl.split("/");   // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
417
418       locale     = lang;
419           wappserver = wurl[2];
420           wappname   = wurl[3];
421       wapprops   = new Properties();
422       jndprops   = new Properties();
423       wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
424       jndprops.load(cloader.getResourceAsStream("jndi.properties"));
425
426       logger.info("Application root set to " + wapprops.getProperty("wapp.root"));
427       my = this;
428       return this;
429     }
430     
431 //  ==============================================================================================================================
432 //  Public member functions
433 //  ==============================================================================================================================
434
435         public void configure (String filename) {
436 //  ---------------------------------------
437 //    Non customizable settings
438       menus = new HashMap<String, SimpleMenu>();
439       SimpleMenu menu = new NewMenu();
440       menus.put( menu.getName(), menu );
441                  menu = new SearchMenu();
442       menus.put( menu.getName(), menu );
443                  menu = new DatadminMenu();
444       menus.put( menu.getName(), menu );
445                  menu = new SysadminMenu();
446       menus.put( menu.getName(), menu );
447                  menu = new PropertiesMenu();
448       menus.put( menu.getName(), menu );
449
450       popups = new HashMap<String, PopupMenu>();
451       popups.put("steditable", new EditableStudyPopup());
452       popups.put("editable",   new EditableDocumentPopup());
453       popups.put("notresult",  new NotResultDocumentPopup());
454       popups.put("reviewable", new ReviewableDocumentPopup());
455       popups.put("approvable", new ApprovableDocumentPopup());
456       popups.put("approved",   new ApprovedPopup());
457       popups.put("extern",     new ExternPopup());
458       popups.put("scontext",   new ScontextPopup());
459       popups.put("feedbex",    new FeedbexPopup());
460
461 //    Default customizable mandatory settings
462       Map<String, Object> fprop = new HashMap<String, Object>();
463       fprop.put("visibility", "PRIVATE");
464       fprop.put("matchamong", "all");
465       fprop.put("matcontext", "all");
466       fprop.put("state",     "END");
467       fprop.put("author",    "0");
468       fprop.put("reference", "");
469       fprop.put("title",     "");
470       fprop.put("context", new Vector<SimulationContext>());
471               
472       Map<String, Object> gprop = new HashMap<String, Object>();
473       gprop.put("visibility", "PUBLIC");
474       gprop.put("matchamong", "all");
475       gprop.put("matcontext", "all");
476       gprop.put("type",      "2");                        //TODO: Get the index from the type name
477       gprop.put("author",    "0");
478       gprop.put("reference", "");
479       gprop.put("title",     "");
480       gprop.put("context", new Vector<SimulationContext>());
481
482       defdoctype = new LinkedHashMap<String, DocumentType>();
483       tempfile   = new HashMap<String, String>();
484       viewermap  = new String[0];
485       convertmap = new HashMap<String, Converter>();
486       filter     = new HashMap<String, Map<String, Object>>();
487       filter.put("study", fprop);
488       filter.put("knowledge", gprop);
489
490 //        Customization (must be done after above default settings)
491       File config = new File(filename);
492       if  (config.exists()) {
493         loadCustomization(config);   // Sets default document types, installed modules and available templates
494       } else {
495         logger.info("Could not find the application configuration file \"" + config.getAbsolutePath() + "\", using default settings");
496       }
497 //    Settings based on the customization
498           bars = new HashMap<Integer, ToolBar>();             // May be empty if no module installed
499           
500           List<ProjectSettingsService.Step> steps = getProjectSettings().getAllSteps();
501           for (Iterator<ProjectSettingsService.Step> i=steps.iterator(); i.hasNext();) {
502                   ProjectSettingsService.Step step    = i.next();
503                 List<String>         formats = getDefaultFormats(step);
504                 if (formats.size() == 0) continue;
505
506         ToolBar         bar    = new ToolBar(24);         // Height of the module-bar
507         HashSet<String> module = new HashSet<String>();   // For not duplicating modules
508                 for (Iterator<String> j=formats.iterator(); j.hasNext();) {
509           String   format  = j.next();
510           String   command = getApplicationProperty("executable." + format);
511           if (command == null)          continue;         // Module not installed
512           if (module.contains(command)) continue;
513           module.add(command);
514           String[] parsed  = command.split("/");
515           String[] name    = parsed[parsed.length-1].split("\\x2E");
516           String   docname = my.defdoctype.get(step.getNumber() + "." + format).getName();
517           if (tempfile.get(docname) == null) {            // No available template
518             String tool = parsed[parsed.length-1];
519             String icon = name[0];
520             if    (icon.equals("index")) {
521                    tool = parsed[parsed.length-2];
522                    icon = "tool." + tool.toLowerCase() + ".png";
523             }
524             else {
525                    icon = "tool." + icon.toLowerCase() + ".png";
526             }
527             File   image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
528             if   (!image.exists()) icon = "tool.any.png";
529             bar.addTool(tool, icon, command);
530           } else {
531                      docname = "/jsp/newDocument.jsp?type=" + docname;
532             String   icon    = "tool." + name[0].toLowerCase() + ".png";
533             File    image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
534             if    (!image.exists()) icon = "tool.any.png";
535             bar.addTool(name[0], icon, command, docname);
536           }
537                 }
538                 if (!bar.isEmpty()) bars.put(step.getNumber(), bar);
539           }
540         }
541
542     public String getApplicationProperty (String name) {
543 //  --------------------------------------------------
544       return wapprops.getProperty(name);                // May be null
545     }
546
547     public String getApplicationRootPath () {
548 //  ---------------------------------------
549       return getApplicationProperty("wapp.root");       // The property is supposed including the Web application name
550     }
551
552     public String getApplicationURL () {
553 //  ----------------------------------
554       StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/").append(wappname);
555       return       url.toString();
556     }
557
558     public Map<String, Object> getFilter (String name) {
559 //  --------------------------------------------------
560       return filter.get(name);
561     }
562
563     public ToolBar getModuleBar (Step step) {
564 //  -----------------------------------------
565       return bars.get(step.getNumber());
566     }
567
568     public Properties getNamingProperties () {
569 //  ----------------------------------------
570       return jndprops;
571     }
572
573 //  ==============================================================================================================================
574 //  Public services
575 //  ==============================================================================================================================    
576
577     public static String getApplicationPluginPath () {
578 //  ------------------------------------------------
579       return my.getApplicationRootPath() + "plugin/";
580     }
581     public static String getApplicationResourcePath () {
582 //  --------------------------------------------------
583       return my.getApplicationRootPath() + "WEB-INF/classes/";
584     }
585     public static String getApplicationSkinPath () {
586 //  ----------------------------------------------
587       return my.getApplicationRootPath() + "skin/";
588     }
589     public static Converter getConverter (DocumentType type, String format) {
590 //  -----------------------------------------------------------------------
591       return my.convertmap.get(format + type.getName());                           // May be null;
592     }
593     public static DocumentType getDefaultDocumentType (Step step, String format) {
594 //  ----------------------------------------------------------------------------
595       String[] table = format.split("\\x2E");
596       return my.defdoctype.get(step.getNumber() + "." + table[table.length-1]);    // May be null
597     }
598     public static String getDownloadURL (User user) {
599 //  --------------------------------------------------
600       StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/download/").append(user.getUsername()).append("/");
601       return       url.toString();     // The download Tomcat context is supposed being defined
602     }
603     public static Locale getCurrentLocale () {
604 //  ----------------------------------------
605       return my.locale;
606     }
607     public static SimpleMenu getMenu (String name) {
608 //  ----------------------------------------------
609       return my.menus.get(name);
610         }
611     public static PopupMenu getPopupMenu (String name) {
612 //  --------------------------------------------------
613       return my.popups.get(name);
614     }
615     public static String getRepositoryURL () {
616 //  ----------------------------------------
617       StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/repository/");
618       return       url.toString();     // The repository Tomcat context is supposed being defined
619     }
620     public static Locale[] getSupportedLocales () {
621 //  ---------------------------------------------
622       String[] code   = my.wapprops.getProperty("locale.supported").split(",");
623       Locale[] result = new Locale[code.length];
624       for (int i=0; i<code.length; i++) result[i] = new Locale(code[i]);
625       return result;
626     }
627     public static String[] getViewersMapping () {
628 //  -------------------------------------------
629       return my.viewermap;
630     }
631     public static String getWebSiteURL () {
632 //  -------------------------------------
633       return my.getApplicationProperty("wapp.website");
634     }
635     public static String getHelpURL () {
636 //  ----------------------------------
637       return my.getApplicationProperty("wapp.onlinehelp");
638     }
639 //  ==============================================================================================================================
640 //  Private services
641 //  ==============================================================================================================================
642
643     private List<String> getDefaultFormats (ProjectSettingsService.Step step) {
644 //  ------------------------------------------------------------------
645       Set<String>    keys   = defdoctype.keySet();
646       int            number = step.getNumber();
647       Vector<String> result = new Vector<String>();
648
649       for (Iterator<String> i=keys.iterator(); i.hasNext();) {
650         String[] key = i.next().split("\\x2E");
651         if (Integer.valueOf(key[0]) != number) continue;
652         if (key[1].equals("pdf"))              continue;           // PDF is not an authoring format
653         result.add(key[1]);                                        // Formats are unique
654       }
655       return result;
656     }
657
658     private void loadCustomization (File config) {
659 //  --------------------------------------------
660       try {
661         DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
662         DocumentBuilder        dBuilder = dfactory.newDocumentBuilder();
663      
664         org.w3c.dom.Document   conf     = dBuilder.parse(config.getPath());
665         HashMap<String, Node>  children = XDOM.getNamedChildNodes(conf.getDocumentElement());
666
667 //      Default document types tag
668         Node     child = children.get("default-doctypes");
669             NodeList nlist = child.getChildNodes();
670             
671         List<DocumentType>           listype = Document.selectAllTypes();
672         HashMap<String,DocumentType> maptype = new HashMap<String,DocumentType>();
673         for (Iterator<DocumentType> i=listype.iterator(); i.hasNext();) {
674           DocumentType  type = i.next();
675           maptype.put(type.getName(), type);
676         }           
677         for (int i=0; i<nlist.getLength(); i++) {
678           child = nlist.item(i);
679           if (!child.getNodeName().equals("step")) continue;
680
681           String   nstep = child.getAttributes().getNamedItem("number").getNodeValue();
682           NodeList map   = child.getChildNodes();
683           for (int j=0; j<map.getLength(); j++) {
684             child = map.item(j);
685             if (!child.getNodeName().equals("mapping")) continue;
686             NamedNodeMap natr = child.getAttributes();
687             String       dext = natr.getNamedItem("extension").getNodeValue();
688             String       type = natr.getNamedItem("type").getNodeValue();
689             defdoctype.put(nstep + "." + dext, maptype.get(type));
690           }
691         }
692 //      Modules tag
693         child = children.get("modules");
694         nlist = child.getChildNodes();
695         for (int i=0; i<nlist.getLength(); i++) {
696           child = nlist.item(i);
697           if (!child.getNodeName().equals("mapping")) continue;
698           
699           NamedNodeMap natr = child.getAttributes();
700           String       dext = natr.getNamedItem("extension").getNodeValue();
701           String       exec = natr.getNamedItem("executable").getNodeValue();
702           wapprops.put("executable." + dext,  exec);
703         }
704 //      Viewer mappings tag
705         child     = children.get("viewers");
706         viewermap = child.getAttributes().getNamedItem("extension").getNodeValue().split(",");
707
708 //      Converters tag
709         child = children.get("converters");
710         nlist = child.getChildNodes();
711         for (int i=0; i<nlist.getLength(); i++) {
712           child = nlist.item(i);
713
714           if (child.getNodeName().equals("geometry")) {
715             NamedNodeMap natr = child.getAttributes();
716             String       from = natr.getNamedItem("from").getNodeValue();
717             String       to   = natr.getNamedItem("to").getNodeValue();
718             String       exec = natr.getNamedItem("executable").getNodeValue();
719             convertmap.put(from + "geometry", new Converter("geometry", from, to, exec));
720           }
721         }
722
723 //      Templates tag
724         child = children.get("templates");
725         nlist = child.getChildNodes();
726         for (int i=0; i<nlist.getLength(); i++) {
727           child = nlist.item(i);
728           if (!child.getNodeName().equals("document")) continue;
729
730           NamedNodeMap natr = child.getAttributes();
731           String       type = natr.getNamedItem("type").getNodeValue();
732           String       file = natr.getNamedItem("file").getNodeValue();
733           tempfile.put(type, file);
734         }
735       }
736       catch (Exception error) {
737                 logger.info("Error in customization", error);
738       }
739     }
740 }