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