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