Salome HOME
It was impossible to edit the body of the knowledge when the ordered or unordered...
[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.ArrayList;
6 import java.util.HashMap;
7 import java.util.HashSet;
8 import java.util.Iterator;
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
15 import javax.servlet.http.HttpServletRequest;
16 import javax.xml.parsers.DocumentBuilder;
17 import javax.xml.parsers.DocumentBuilderFactory;
18
19 import org.splat.dal.bo.kernel.User;
20 import org.splat.dal.bo.som.Document;
21 import org.splat.dal.bo.som.DocumentType;
22 import org.splat.dal.bo.som.KnowledgeElement;
23 import org.splat.dal.bo.som.SimulationContext;
24 import org.splat.dal.bo.som.Visibility;
25 import org.splat.log.AppLogger;
26 import org.splat.manox.XDOM;
27 import org.splat.service.DocumentTypeService;
28 import org.splat.service.technical.ProjectSettingsService;
29 import org.splat.som.DocumentRights;
30 import org.splat.som.Step;
31 import org.splat.som.StudyRights;
32 import org.splat.wapp.MenuItem;
33 import org.splat.wapp.PopupItem;
34 import org.splat.wapp.PopupMenu;
35 import org.splat.wapp.SimpleMenu;
36 import org.splat.wapp.ToolBar;
37 import org.springframework.web.context.request.RequestContextHolder;
38 import org.springframework.web.context.request.ServletRequestAttributes;
39 import org.w3c.dom.NamedNodeMap;
40 import org.w3c.dom.Node;
41 import org.w3c.dom.NodeList;
42
43 /**
44  * SIMAN project settings service. Provides settings according to XML customization.
45  */
46 public class ApplicationSettings {
47
48         /**
49          * Application settings logger.
50          */
51         protected final static AppLogger LOG = AppLogger
52                         .getLogger(ApplicationSettings.class);
53         /**
54          * JNDI context for launching converters.
55          */
56         private transient static final Properties _JNDPROPS;
57         /**
58          * Siman web application name.
59          */
60         private transient static String wappname;
61         /**
62          * General properties from the application properties files.
63          */
64         private transient static final Properties _WAPPROPS = new Properties();
65         /**
66          * Siman web application root path on the server.
67          */
68         private transient static String wapproot;
69         /**
70          * Available template files.
71          */
72         private transient static Map<String, String> tempfile;
73         /**
74          * List of file extensions mapped to a viewer.
75          */
76         private transient static String[] viewermap;
77         /**
78          * Available document format converters.
79          */
80         private transient static Map<String, Converter> convertmap;
81
82         static {
83                 synchronized (_WAPPROPS) {
84                         // Do common configuration for all users
85
86                         _JNDPROPS = new Properties();
87                         tempfile = new HashMap<String, String>();
88                         viewermap = new String[0];
89                         convertmap = new HashMap<String, Converter>();
90
91                         ClassLoader cloader = Thread.currentThread()
92                                         .getContextClassLoader();
93                         HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
94                                         .currentRequestAttributes()).getRequest();
95                         String appname = curRequest.getContextPath();
96                         if (appname.startsWith("/")) {
97                                 wappname = appname.substring(1);
98                         }
99                         // Set local path on the server to the application root.
100                         wapproot = curRequest.getSession().getServletContext().getRealPath(
101                                         "/");
102
103                         try {
104                                 _JNDPROPS.load(cloader.getResourceAsStream("jndi.properties"));
105                                 _WAPPROPS.load(cloader.getResourceAsStream(wappname
106                                                 + ".properties"));
107                         } catch (IOException e) {
108                                 LOG.info(
109                                                 "Can't load application properties: " + e.getMessage(),
110                                                 e);
111                         }
112
113                         // Configure login security
114                         System.setProperty("java.security.auth.login.config", wapproot
115                                         + ApplicationSettings.getApplicationProperty("wapp.login"));
116
117                         // Customization (must be done after above default settings)
118                         File config = new File(wapproot
119                                         + getApplicationProperty("wapp.customization"));
120                         if (config.exists()) {
121                                 loadCustomization(config); // Sets default document types, installed modules and available templates
122                         } else {
123                                 LOG.info("Could not find the application configuration file \""
124                                                 + config.getAbsolutePath()
125                                                 + "\", using default settings");
126                         }
127                 }
128         }
129
130         /**
131          * All value.
132          */
133         private static final String ALL = "all";
134
135         /**
136          * Hold icon file name.
137          */
138         private static final String IMG_HOLD = "image.hold.gif";
139         /**
140          * Attach icon file name.
141          */
142         private static final String IMG_ATTACH = "image.attach.png";
143         /**
144          * Version icon file name.
145          */
146         private static final String IMG_VERSION = "image.version.png";
147         /**
148          * Delete icon file name.
149          */
150         private static final String IMG_DELETE = "icon.delete.png";
151         /**
152          * Promote icon file name.
153          */
154         private static final String IMG_PROMOTE = "image.publish.png";
155         /**
156          * Demote icon file name.
157          */
158         private static final String IMG_DEMOTE = "image.demote.png";
159         
160         /**
161          * Attach menu item name.
162          */
163         private static final String MNU_ATTACH = "attach";
164         /**
165          * Demote menu item name.
166          */
167         private static final String MNU_DEMOTE = "demote";
168         /**
169          * Promote menu item name.
170          */
171         private static final String MNU_PROMOTE = "promote";
172         /**
173          * Publish menu item name.
174          */
175         private static final String MNU_PUBLISH = "publish";
176         /**
177          * Edit menu item name.
178          */
179         private static final String MNU_EDIT = "edit";
180         /**
181          * Script menu item name.
182          */
183         private static final String MNU_SCRIPT = "script";
184         /**
185          * Version menu item name.
186          */
187         private static final String MNU_VERSION = "version";
188         // /**
189         // * Purge menu item name.
190         // */
191         // private static final String MNU_PURGE = "purge";
192         /**
193          * Remove menu item name.
194          */
195         private static final String MNU_REMOVE = "remove";
196         /**
197          * Rename menu item name.
198          */
199         private static final String MNU_RENAME = "rename";
200
201         /**
202          * Attach menu item name.
203          */
204         private static final String MNU_NAME_ATTACH = "menu.attach";
205         /**
206          * Demote menu item name.
207          */
208         private static final String MNU_NAME_DEMOTE = "menu.demote";
209         /**
210          * Promote menu item name.
211          */
212         private static final String MNU_NAME_PROMOTE = "menu.promote";
213         /**
214          * Publish menu item name.
215          */
216         private static final String MNU_NAME_PUBLISH = "menu.publish";
217         /**
218          * Protect menu item name.
219          */
220         private static final String MNU_NAME_PROTECT = "menu.protect";
221         /**
222          * Edit menu item name.
223          */
224         private static final String MNU_NAME_EDIT = "menu.edit";
225         /**
226          * Edit menu item name.
227          */
228         private static final String MNU_NAME_REMOVE = "menu.remove";
229         /**
230          * Script menu item name.
231          */
232         private static final String MNU_NAME_SCRIPT = "menu.newscenario";
233         /**
234          * Version menu item name.
235          */
236         private static final String MNU_NAME_VERSION = "menu.version";
237         /**
238          * Purge menu item name.
239          */
240         // private static final String MNU_NAME_PURGE = "menu.purge";
241         /**
242          * Remove menu item name.
243          */
244         private static final String MNU_NAME_REMOVE_VERSION = "menu.remove.version";
245         /**
246          * Rename menu item name.
247          */
248         private static final String MNU_NAME_RENAME = "menu.rename";
249         /**
250          * Mark as reference menu item name.
251          */
252         private static final String MNU_MARK_AS_REFERENCE = "markasreference";
253         /**
254          * Mark as reference menu item label key.
255          */
256         private static final String MNU_NAME_MARK_AS_REFERENCE = "menu.markasreference";
257         /**
258          * Remove as reference menu item label key.
259          */
260         private static final String MNU_NAME_REMOVE_AS_REFERENCE = "menu.removeasreference";
261         // /**
262         // * Not yet implemented action name.
263         // */
264         // private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented";
265         /**
266          * Attach action name.
267          */
268         private static final String ACT_ATTACH = "select-file?nextAction=attach";
269         /**
270          * Version action name.
271          */
272         private static final String ACT_VERSION = "select-file?nextAction=version";
273         /**
274          * Mark as reference action name.
275          */
276         private static final String ACT_MARK_AS_REFERENCE = "markasref-study";
277         /**
278          * Remove as reference action name.
279          */
280         private static final String ACT_REMOVE_AS_REFERENCE = "removeasref-study";
281         /**
282          * Promote the study action name.
283          */
284         private static final String ACT_PROMOTE_STUDY = "edit-study?action=promote";
285         
286         /**
287          * Siman application server name.
288          */
289         private transient final String _wappserver;
290         /**
291          * Current user locale.
292          */
293         private transient Locale _locale;
294         /**
295          * Application menus.
296          */
297         private transient final Map<String, SimpleMenu> _menus = new HashMap<String, SimpleMenu>();
298         /**
299          * Study module-bars structured by steps.
300          */
301         private transient Map<Integer, ToolBar> _bars = null;
302         /**
303          * Popup menus.
304          */
305         private transient Map<String, PopupMenu> _popups = null;
306         /**
307          * Named search filters.
308          */
309         private transient Map<String, Map<String, Object>> _filter = null;
310         /**
311          * Injected project settings service.
312          */
313         private ProjectSettingsService _projectSettings;
314         /**
315          * Injected document type service.
316          */
317         private DocumentTypeService _documentTypeService;
318
319         /**
320          * Application settings constructor.
321          */
322         public ApplicationSettings() {
323                 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
324                                 .currentRequestAttributes()).getRequest();
325                 _wappserver = curRequest.getServerName() + ":"
326                                 + curRequest.getServerPort();
327
328                 LOG.info("Application server is set to " + _wappserver);
329                 LOG.info("Application name is set to " + wappname);
330         }
331
332         /**
333          * Get the projectSettingsService.
334          * 
335          * @return the projectSettingsService
336          */
337         public ProjectSettingsService getProjectSettings() {
338                 return _projectSettings;
339         }
340
341         /**
342          * Set the projectSettingsService.
343          * 
344          * @param projectSettingsService
345          *            the projectSettingsService to set
346          */
347         public void setProjectSettings(
348                         final ProjectSettingsService projectSettingsService) {
349                 _projectSettings = projectSettingsService;
350         }
351
352         /**
353          * New study menu.
354          */
355         private static class NewMenu extends SimpleMenu {
356                 /**
357                  * New study menu constructor.
358                  */
359                 private NewMenu() {
360                         super("create");
361                         addItem("new-empty", "menu.new.empty", "image.empty.png",
362                                         "select?menu=create&item=new-empty");
363                         addItem("new-copy", "menu.new.copy", "image.copy.png",
364                                         "select?menu=create&item=new-copy");
365                         /*
366                          * addItem("new-instance", new MenuItem("menu.new.instance") .icon(IMG_HOLD)); addItem("new-import", new
367                          * MenuItem("menu.new.import") .icon("icon.upload.png"));
368                          */
369                         this.selects("new-empty");
370                 }
371         }
372
373         /**
374          * Search menu.
375          */
376         private static class SearchMenu extends SimpleMenu {
377                 /**
378                  * Search menu constructor.
379                  */
380                 private SearchMenu() {
381                         super("search");
382                         addItem("search-study", "menu.search.study", "image.study.png",
383                                         "select?menu=search&item=search-study");
384                         addItem("search-knowledge", "menu.search.idea", "image.idea.png",
385                                         "select?menu=search&item=search-knowledge");
386                         addItem("search-document", new MenuItem("menu.search.document")
387                                         .icon("icon.any.png"));
388                         this.selects("search-study");
389                 }
390         }
391
392         /**
393          * Configuration menu.
394          */
395         private static class PropertiesMenu extends SimpleMenu {
396                 /**
397                  * Configuration menu constructor.
398                  */
399                 private PropertiesMenu() {
400                         super("configuration");
401                         addItem("prop-general", "menu.prop.general", IMG_HOLD,
402                                         "select?menu=configuration&item=prop-general");
403                         addItem("prop-scenario", "menu.prop.scenario", IMG_HOLD,
404                                         "select?menu=configuration&item=prop-scenario");
405                         // These menu items will not be implemented in the current version.
406                         /*
407                          * addItem("prop-timestamp", new MenuItem("menu.prop.timestamp") .icon("image.stamp.png")); addItem("prop-comlog", new
408                          * MenuItem("menu.prop.comlog") .icon(IMG_HOLD)); addItem("prop-version", new MenuItem("menu.prop.version")
409                          * .icon("image.dirclosed.png"));
410                          */
411                 }
412         }
413
414         /**
415          * Data administrator menu.
416          */
417         private static class DatadminMenu extends SimpleMenu {
418                 /**
419                  * Data administrator menu constructor.
420                  */
421                 private DatadminMenu() {
422                         super("datadmin");
423                         addItem("admin-scontext", "menu.admin.context", IMG_HOLD,
424                                         "select?menu=datadmin&item=admin-scontext");
425                         addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
426                                         "select?menu=datadmin&item=admin-knowelm");
427                         addItem("admin-study", new MenuItem("menu.admin.study")
428                                         .icon("image.study.png"));
429                 }
430         }
431
432         /**
433          * System administrator menu.
434          */
435         private static class SysadminMenu extends SimpleMenu {
436                 /**
437                  * System administrator menu constructor.
438                  */
439                 private SysadminMenu() {
440                         super("sysadmin");
441                         addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
442                                         "select?menu=sysadmin&item=admin-indexing");
443                         addItem("admin-importuser", "menu.admin.importuser",
444                                         "image.group.png",
445                                         "select?menu=sysadmin&item=admin-importuser");
446                 }
447         }
448
449         /**
450          * Menu items enumeration.
451          */
452         private enum Item {
453                 /**
454                  * Publish the study.
455                  */
456                 publish,
457                 /**
458                  * Accept the document.
459                  */
460                 accept,
461                 /**
462                  * Approve the document.
463                  */
464                 approve,
465                 /**
466                  * Promote the document.
467                  */
468                 promote,
469                 /**
470                  * Demote the docuemnt.
471                  */
472                 demote,
473                 /**
474                  * Undo the last operation.
475                  */
476                 undo,
477                 /**
478                  * Rename the document.
479                  */
480                 rename,
481                 /**
482                  * Attach a file to the document.
483                  */
484                 attach,
485                 /**
486                  * Edit the document.
487                  */
488                 edit,
489                 /**
490                  * script.
491                  */
492                 script,
493                 /**
494                  * Version the document.
495                  */
496                 version,
497                 /**
498                  * replace.
499                  */
500                 replace,
501                 /**
502                  * export.
503                  */
504                 export,
505                 /**
506                  * Remove the document.
507                  */
508                 remove,
509                 /**
510                  * purge.
511                  */
512                 purge,
513                 /**
514                  * Mark the study as reference.
515                  */
516                 markasreference
517         };
518
519         // Resources relative to studies
520         /**
521          * Base study popup menu.
522          */
523         private static class StudyPopup extends PopupMenu {
524                 /**
525                  * User rights for the selected study.
526                  */
527                 protected transient StudyRights _user = null;
528
529                 /**
530                  * Add items which are common for all study popup menus.
531                  */
532                 protected void addCommonItems() {
533                         addSeparator();
534                         addItem(MNU_EDIT, new PopupItem("menu.properties").icon(
535                                         "icon.ed.png").action(
536                                         "../select.action?menu=configuration"));
537                         addSeparator();
538                         addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT)
539                                         .action("add-scenario"));
540                         /*
541                          * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
542                          */
543                         addSeparator();
544                         /*
545                          * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
546                          * PopupItem("menu.export") .icon("image.export.png")); // For future needs
547                          */addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
548                                         IMG_DELETE).action("remove-study").confirmation(
549                                         "message.delete.study"));
550                 }
551
552                 /**
553                  * {@inheritDoc}
554                  * 
555                  * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
556                  */
557                 @Override
558                 public boolean isEnabled(final String name) {
559                         boolean res = (_user != null);
560                         if (res) {
561                                 Item item = Item.valueOf(name);
562                                 switch (item) {
563                                         case publish:
564                                                 if (_user.getOperand().getVisibility() == Visibility.PRIVATE) {
565                                                         res = _user.canPublish();
566                                                 } else {
567                                                         res = _user.canProtect();
568                                                 }
569                                                 break;
570                                         case edit:
571                                                 res = _user.canEditProperties();
572                                                 break;
573                                         case script:
574                                                 res = _user.canAddScenario();
575                                                 break;
576                                         case version:
577                                                 res = _user.canVersion();
578                                                 break;
579                                         case remove:
580                                                 res = _user.canRemove();
581                                                 break;
582                                         case promote:
583                                                 res = _user.canPromote();
584                                                 break;
585                                         case demote:
586                                                 res = _user.canDemote();
587                                                 break;
588                                         case approve:
589                                                 res = _user.canApprove();
590                                                 break;
591                                         case markasreference:
592                                                 if (_user.getOperand().getMarkreference() == 0) {
593                                                         res = _user.canMarkStudyAsReference();
594                                                 } else {
595                                                         res = _user.canRemoveStudyAsReference();
596                                                 }
597                                                 break;
598                                         default:
599                                                 res = false;
600                                 }
601                         }
602                         return res;
603                 }
604
605                 /**
606                  * {@inheritDoc}
607                  * 
608                  * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
609                  */
610                 @Override
611                 public void setContext(final String name, final Object context) {
612                         if (context instanceof StudyRights) {
613                                 _user = (StudyRights) context; // Just for optimizing
614                                 boolean history = _user.getOperand().isVersioned();
615                                 PopupItem item = this.item(MNU_REMOVE);
616                                 if (history) {
617                                         item.rename(MNU_NAME_REMOVE_VERSION);
618                                 } else {
619                                         item.rename("menu.remove.study");
620                                 }
621                         }
622                 }
623         }
624
625         /**
626          * Approved study popup menu.
627          */
628         private static class EditableMarkedStudyPopup extends StudyPopup {
629
630                 /**
631                  * Study popup menu constructor.
632                  * 
633                  * @param isPublic
634                  *            public study flag
635                  * @param isMarked
636                  *            "marked as reference" study flag
637                  */
638                 private EditableMarkedStudyPopup(final boolean isPublic,
639                                 final boolean isMarked) {
640                         super();
641
642                         if (isMarked) {
643                                 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
644                                                 MNU_NAME_REMOVE_AS_REFERENCE).action(
645                                                 ACT_REMOVE_AS_REFERENCE).confirmation(
646                                                 "message.removeasreference.study"));
647                         } else {
648                                 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
649                                                 MNU_NAME_MARK_AS_REFERENCE).action(
650                                                 ACT_MARK_AS_REFERENCE).confirmation(
651                                                 "message.markasreference.study"));
652                         }
653
654                         if (isPublic) {
655                                 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PROTECT).icon(
656                                                 IMG_PROMOTE)
657                                                 .action("edit-study?action=protect").confirmation(
658                                                                 "message.protect.study"));
659                         } else {
660                                 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon(
661                                                 IMG_PROMOTE)
662                                                 .action("edit-study?action=publish").confirmation(
663                                                                 "message.publish.study"));
664                         }
665
666                         addCommonItems();
667                 }
668
669         }
670
671         /**
672          * In-Work study popup menu.
673          */
674         private static class EditableStudyPopup extends StudyPopup {
675                 /**
676                  * Study popup menu constructor.
677                  */
678                 private EditableStudyPopup() {
679                         super();
680
681                         addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
682                                         IMG_PROMOTE).action(ACT_PROMOTE_STUDY)
683                                         .confirmation("message.promote.study"));
684
685                         addCommonItems();
686                 }
687         }
688
689         /**
690          * In-Work study popup menu.
691          */
692         private static class ReviewableStudyPopup extends StudyPopup {
693                 /**
694                  * Study popup menu constructor.
695                  */
696                 private ReviewableStudyPopup() {
697                         super();
698
699                         addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
700                                         IMG_DEMOTE).action("edit-study?action=demote")
701                                         .confirmation("message.demote.study"));
702                         addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
703                                         "image.review.png").action(ACT_PROMOTE_STUDY)
704                                         .confirmation("message.review.study"));
705
706                         addCommonItems();
707                 }
708         }
709
710         /**
711          * In-Work study popup menu.
712          */
713         private static class ApprovableStudyPopup extends StudyPopup {
714                 /**
715                  * Study popup menu constructor.
716                  */
717                 private ApprovableStudyPopup() {
718                         super();
719
720                         addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
721                                         IMG_PROMOTE).action(ACT_PROMOTE_STUDY)
722                                         .confirmation("message.promote.study"));
723                         // Refuse
724                         addItem(MNU_DEMOTE, new PopupItem("menu.demote").icon(
725                                         IMG_DEMOTE).action("edit-study?action=demote")
726                                         .confirmation("message.demote.study"));
727                         addItem("approve", new PopupItem("menu.approve").icon(
728                                         "icon.APPROVED.png").action(ACT_PROMOTE_STUDY)
729                                         .confirmation("message.approve.study"));
730
731                         addCommonItems();
732                 }
733         }
734
735         // Resources relative to documents
736         /**
737          * Popup of a document.
738          */
739         private static class DocumentPopup extends PopupMenu {
740                 /**
741                  * Current user rights.
742                  */
743                 private transient DocumentRights _user = null;
744
745                 /**
746                  * {@inheritDoc}
747                  * 
748                  * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
749                  */
750                 @Override
751                 public boolean isEnabled(final String name) {
752                         boolean res = (_user != null);
753                         if (res) {
754                                 Item item = Item.valueOf(name);
755                                 switch (item) {
756                                         case accept:
757                                                 res = _user.canAccept();
758                                                 break;
759                                         case promote:
760                                                 res = _user.canPromote();
761                                                 break;
762                                         case rename:
763                                                 res = _user.canRename();
764                                                 break;
765                                         case attach:
766                                                 res = _user.canAttach();
767                                                 break;
768                                         case edit:
769                                                 res = _user.canEdit();
770                                                 break;
771                                         case version:
772                                                 res = _user.canVersion();
773                                                 break;
774                                         case replace:
775                                                 res = _user.canReplace();
776                                                 break;
777                                         case remove:
778                                                 res = _user.canRemove();
779                                                 break;
780                                         case purge:
781                                                 res = _user.canPurge();
782                                                 break;
783                                         case undo:
784                                                 res = _user.canInvalidate();
785                                                 break;
786                                         case demote:
787                                                 res = _user.canDemote();
788                                                 break;
789                                         case approve:
790                                                 res = _user.canApprove();
791                                                 break;
792                                         default:
793                                                 res = false;
794                                 }
795                         }
796                         return res;
797                 }
798
799                 /**
800                  * {@inheritDoc}
801                  * 
802                  * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
803                  */
804                 @Override
805                 public void setContext(final String name, final Object context) {
806                         if (context instanceof DocumentRights) {
807                                 _user = (DocumentRights) context; // Just for optimizing
808                                 Document downer = _user.getOperand();
809                                 if (this.hasItem(MNU_REMOVE)) {
810                                         if (downer.getPreviousVersion() == null) {
811                                                 this.item(MNU_REMOVE).rename("menu.remove.document");
812                                         } else {
813                                                 this.item(MNU_REMOVE).rename(MNU_NAME_REMOVE_VERSION);
814                                         }
815                                 }
816                         }
817                 }
818         }
819
820         /**
821          * Popup of In-Work documents.
822          */
823         private static class EditableDocumentPopup extends DocumentPopup {
824                 /**
825                  * Document popup menu constructor.
826                  */
827                 private EditableDocumentPopup() {
828                         super();
829                         /*
830                          * addItem("accept", new PopupItem("menu.accept").icon( "image.accept.png").action("setDocument?action=accept")
831                          * .confirmation("message.accept.document"));
832                          */
833                         addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
834                                         IMG_PROMOTE).action("setDocument?action=promote")
835                                         .confirmation("message.promote.document"));
836                         addSeparator();
837                         addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
838                                         .action("edit-document?action=renameDocument"));
839                         addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
840                                         .action(ACT_ATTACH));
841                         addSeparator();
842                         addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
843                                         IMG_VERSION).action(ACT_VERSION));
844                         addItem("replace", new PopupItem("menu.replace").icon(
845                                         "image.replace.png").action(
846                                         "select-file?nextAction=replace"));
847                         addSeparator();
848                         /*
849                          * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
850                          */
851                         addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
852                                         IMG_DELETE).action("remove-document").confirmation(
853                                         "message.delete.document"));
854                 }
855         }
856
857         /**
858          * Popup of In-Draft documents.
859          */
860         private static class ReviewableDocumentPopup extends DocumentPopup {
861                 /**
862                  * Document popup menu constructor.
863                  */
864                 private ReviewableDocumentPopup() {
865                         super();
866                         addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
867                                         IMG_DEMOTE).action("setDocument?action=demote")
868                                         .confirmation("message.demote.document"));
869                         addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
870                                         "image.review.png").action("setDocument?action=review")
871                                         .confirmation("message.review.document"));
872                         addSeparator();
873                         addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
874                                         .action(ACT_ATTACH));
875                         addSeparator();
876                         addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
877                                         IMG_VERSION).action(ACT_VERSION));
878                         addSeparator();
879                         /*
880                          * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
881                          */
882                 }
883         }
884
885         /**
886          * Popup menu for documents which are not results of a step.
887          */
888         private static class NotResultDocumentPopup extends DocumentPopup {
889                 /**
890                  * Default constructor.
891                  */
892                 private NotResultDocumentPopup() {
893                         super();
894                         addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
895                                         IMG_DEMOTE).action("setDocument?action=demote")
896                                         .confirmation("message.demote.document"));
897                         addSeparator();
898                         addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
899                                         .action(ACT_ATTACH));
900                         addSeparator();
901                         addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
902                                         IMG_VERSION).action(ACT_VERSION));
903                         addSeparator();
904                         /*
905                          * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
906                          */
907                         addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
908                                         IMG_DELETE).action("remove-document").confirmation(
909                                         "message.delete.document"));
910                 }
911         }
912
913         /**
914          * Popup of In-Check documents.
915          */
916         private static class ApprovableDocumentPopup extends DocumentPopup {
917                 /**
918                  * Default constructor.
919                  */
920                 private ApprovableDocumentPopup() {
921                         super();
922                         /*addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon(
923                                         "image.invalidate.png").action(
924                                         "setDocument?action=invalidate").confirmation(
925                                         "message.demote.document"));*/
926                         addItem(MNU_DEMOTE, new PopupItem("menu.demote").icon(
927                                         IMG_DEMOTE).action("setDocument?action=demote")
928                                         .confirmation("message.demote.document"));
929                         addItem("approve", new PopupItem("menu.approve").icon(
930                                         "icon.APPROVED.png").action("setDocument?action=approve")
931                                         .confirmation("message.approve.document"));
932                 }
933         }
934
935         /**
936          * Popup of Approved documents.
937          */
938         private static class ApprovedPopup extends DocumentPopup {
939                 /**
940                  * Default constructor.
941                  */
942                 private ApprovedPopup() {
943                         super();
944                         addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
945                                         .action(ACT_ATTACH));
946                         addSeparator();
947                         addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
948                                         IMG_VERSION).action(ACT_VERSION));
949                 }
950         }
951
952         /**
953          * Popup of external documents.
954          */
955         private static class ExternPopup extends DocumentPopup {
956                 /**
957                  * Default constructor.
958                  */
959                 private ExternPopup() {
960                         super();
961                         addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
962                                         .action("edit-document?action=renameDocument"));
963                         addSeparator();
964                         addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
965                                         IMG_VERSION).action(ACT_VERSION));
966                         addSeparator();
967                         addItem("replace", new PopupItem("menu.replace").icon(
968                                         "image.replace.png").action(
969                                         "select-file?nextAction=replace"));
970                         addSeparator();
971                         addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon(
972                                         IMG_DELETE).action("remove-document").confirmation(
973                                         "message.delete.document"));
974                 }
975         }
976
977         /**
978          * Simulation context popup menu.
979          */
980         private static class ScontextPopup extends PopupMenu {
981                 /**
982                  * Owner object.
983                  */
984                 private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it.
985
986                 /**
987                  * Default constructor.
988                  */
989                 private ScontextPopup() {
990                         super();
991                         addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
992                                         .action("edit-context?action=renameContext"));
993                         addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
994                                         .action("edit-context?action=editContext"));
995                         addSeparator();
996                         addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
997                                         .action("remove-context").confirmation(
998                                                         "message.delete.context"));
999                 }
1000
1001                 /**
1002                  * {@inheritDoc}
1003                  * 
1004                  * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
1005                  */
1006                 @Override
1007                 public boolean isEnabled(final String name) {
1008                         Item item = Item.valueOf(name);
1009                         boolean res = true;
1010
1011                         if (item == Item.rename) {
1012                                 res = false;
1013                         } else if (item == Item.edit) {
1014                                 // if (!owner.isEditable())
1015                                 res = false;
1016                         }
1017                         return res;
1018                 }
1019
1020                 /**
1021                  * {@inheritDoc}
1022                  * 
1023                  * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
1024                  */
1025                 @Override
1026                 public void setContext(final String name, final Object context) {
1027                         if (context instanceof SimulationContextFacade) {
1028                                 _owner = (SimulationContextFacade) context; // Just for optimizing
1029                         } else {
1030                                 super.setContext(name, context);
1031                         }
1032                 }
1033         }
1034
1035         // Resources relative to knowledge
1036         /**
1037          * Knowledge element popup menu.
1038          */
1039         private static class FeedbexPopup extends PopupMenu {
1040
1041                 /**
1042                  * Popup menu owner object.
1043                  */
1044                 protected transient KnowledgeElement _owner = null;
1045
1046                 /**
1047                  * Default constructor.
1048                  */
1049                 private FeedbexPopup() {
1050                         super();
1051                         addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
1052                                         .action("edit-knowledge?action=renameKnowledge"));
1053                         addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
1054                                         .action("edit-knowledge?action=editKnowledge"));
1055                         addSeparator();
1056                         addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1057                                         .action("remove-knowledge").confirmation(
1058                                                         "message.delete.knowledge"));
1059                 }
1060
1061                 /**
1062                  * {@inheritDoc}
1063                  * 
1064                  * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
1065                  */
1066                 @Override
1067                 public boolean isEnabled(final String name) {
1068                         boolean res = true;
1069                         return res;
1070                 }
1071
1072                 /**
1073                  * {@inheritDoc}
1074                  * 
1075                  * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
1076                  */
1077                 @Override
1078                 public void setContext(final String name, final Object context) {
1079                         if (context instanceof KnowledgeElement) {
1080                                 _owner = (KnowledgeElement) context; // Just for optimizing
1081                         } else {
1082                                 super.setContext(name, context);
1083                         }
1084                 }
1085         }
1086
1087         /**
1088          * Pop-up menu for comments.
1089          */
1090         private static class CommentPopup extends PopupMenu {
1091                 /**
1092                  * Default constructor.
1093                  */
1094                 private CommentPopup() {
1095                         super();
1096                         addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1097                                         .action("editComment(entity_index)"));
1098                         addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1099                                         .action("removeComment(entity_index)").confirmation(
1100                                                         "message.delete.comment"));
1101                 }
1102
1103                 /**
1104                  * Is enabled.
1105                  * 
1106                  * @param name
1107                  *            the entry name
1108                  * @return true
1109                  */
1110                 @Override
1111                 public boolean isEnabled(final String name) {
1112                         return true;
1113                 }
1114         }
1115
1116         /**
1117          * Pop-up menu for comments.
1118          */
1119         private static class DescritptionPopup extends PopupMenu {
1120                 /**
1121                  * Default constructor.
1122                  */
1123                 private DescritptionPopup() {
1124                         super();
1125                         addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1126                                         .action("showDescriptionEditor()"));
1127                         addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1128                                         .action("removeDescription()").confirmation(
1129                                                         "message.delete.description"));
1130                 }
1131
1132                 /**
1133                  * Is enable.
1134                  * 
1135                  * @param name
1136                  *            the entry name
1137                  * @return true
1138                  */
1139                 @Override
1140                 public boolean isEnabled(final String name) {
1141                         return true;
1142                 }
1143         }
1144
1145         // ==============================================================================================================================
1146         // Construction
1147         // ==============================================================================================================================
1148
1149         // ==============================================================================================================================
1150         // Public member functions
1151         // ==============================================================================================================================
1152
1153         /**
1154          * Initialize application menus.
1155          */
1156         public void configure() {
1157                 // Non customizable settings
1158                 _menus.clear();
1159                 SimpleMenu menu = new NewMenu();
1160                 _menus.put(menu.getName(), menu);
1161                 menu = new SearchMenu();
1162                 _menus.put(menu.getName(), menu);
1163                 menu = new DatadminMenu();
1164                 _menus.put(menu.getName(), menu);
1165                 menu = new SysadminMenu();
1166                 _menus.put(menu.getName(), menu);
1167                 menu = new PropertiesMenu();
1168                 _menus.put(menu.getName(), menu);
1169
1170                 _popups = new HashMap<String, PopupMenu>();
1171                 _popups.put("steditablemarkpublic", new EditableMarkedStudyPopup(false,
1172                                 false));
1173                 _popups.put("steditableunmarkpublic", new EditableMarkedStudyPopup(
1174                                 false, true));
1175                 _popups.put("steditablemarkprivate", new EditableMarkedStudyPopup(true,
1176                                 false));
1177                 _popups.put("steditableunmarkprivate", new EditableMarkedStudyPopup(
1178                                 true, true));
1179                 _popups.put("steditable", new EditableStudyPopup());
1180                 _popups.put("streviewable", new ReviewableStudyPopup());
1181                 _popups.put("stapprovable", new ApprovableStudyPopup());
1182
1183                 _popups.put("editable", new EditableDocumentPopup());
1184                 _popups.put("notresult", new NotResultDocumentPopup());
1185                 _popups.put("reviewable", new ReviewableDocumentPopup());
1186                 _popups.put("approvable", new ApprovableDocumentPopup());
1187                 _popups.put("approved", new ApprovedPopup());
1188                 _popups.put("extern", new ExternPopup());
1189                 _popups.put("scontext", new ScontextPopup());
1190                 _popups.put("feedbex", new FeedbexPopup());
1191                 _popups.put("comment", new CommentPopup());
1192                 _popups.put("description", new DescritptionPopup());
1193
1194                 // Default customizable mandatory settings
1195                 Map<String, Object> fprop = new HashMap<String, Object>();
1196                 fprop.put("visibility", "PRIVATE");
1197                 fprop.put("matchamong", ALL);
1198                 fprop.put("matcontext", ALL);
1199                 fprop.put("state", "APPROVED");
1200                 fprop.put("author", "0");
1201                 fprop.put("reference", "");
1202                 fprop.put("title", "");
1203                 fprop.put("context", new ArrayList<SimulationContext>());
1204
1205                 Map<String, Object> gprop = new HashMap<String, Object>();
1206                 gprop.put("visibility", "PUBLIC");
1207                 gprop.put("matchamong", ALL);
1208                 gprop.put("matcontext", ALL);
1209                 gprop.put("type", "2"); // TODO: Get the index from the type name
1210                 gprop.put("author", "0");
1211                 gprop.put("reference", "");
1212                 gprop.put("title", "");
1213                 gprop.put("context", new ArrayList<SimulationContext>());
1214
1215                 _filter = new HashMap<String, Map<String, Object>>();
1216                 _filter.put("study", fprop);
1217                 _filter.put("knowledge", gprop);
1218
1219                 // Settings based on the customization
1220                 configureToolbars();
1221         }
1222
1223         /**
1224          * Configure toolbars for steps.
1225          */
1226         private void configureToolbars() {
1227                 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
1228
1229                 List<ProjectSettingsService.Step> steps = getProjectSettings()
1230                                 .getAllSteps();
1231                 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
1232                                 .hasNext();) {
1233                         ProjectSettingsService.Step step = i.next();
1234                         List<String> formats = getProjectSettings().getDefaultFormats(step);
1235                         if (formats.isEmpty()) {
1236                                 continue;
1237                         }
1238
1239                         ToolBar bar = new ToolBar(24); // Height of the module-bar
1240                         Set<String> module = new HashSet<String>(); // For not duplicating modules
1241                         for (String format : formats) {
1242                                 String command = getApplicationProperty("executable." + format);
1243                                 if (command == null) {
1244                                         continue; // Module not installed
1245                                 }
1246                                 if (module.contains(command)) {
1247                                         continue;
1248                                 }
1249                                 module.add(command);
1250                                 String[] parsed = command.split("/");
1251                                 String[] name = parsed[parsed.length - 1].split("\\x2E");
1252                                 DocumentType dtype = getProjectSettings()
1253                                                 .getDefaultDocumentType(step, format);
1254                                 String docname = "";
1255                                 if (dtype != null) {
1256                                         docname = dtype.getName();
1257                                 }
1258                                 if (tempfile.get(docname) == null) { // No available template
1259                                         String tool = parsed[parsed.length - 1];
1260                                         String icon = name[0];
1261                                         if ("index".equals(icon)) {
1262                                                 tool = parsed[parsed.length - 2];
1263                                                 icon = "tool." + tool.toLowerCase() + ".png";
1264                                         } else {
1265                                                 icon = "tool." + icon.toLowerCase() + ".png";
1266                                         }
1267                                         File image = new File(ApplicationSettings
1268                                                         .getApplicationSkinPath()
1269                                                         + icon);
1270                                         if (!image.exists()) {
1271                                                 icon = "tool.any.png";
1272                                         }
1273                                         bar.addTool(tool, icon, command);
1274                                 } else {
1275                                         docname = "/jsp/newDocument.jsp?type=" + docname;
1276                                         String icon = "tool." + name[0].toLowerCase() + ".png";
1277                                         File image = new File(ApplicationSettings
1278                                                         .getApplicationSkinPath()
1279                                                         + icon);
1280                                         if (!image.exists()) {
1281                                                 icon = "tool.any.png";
1282                                         }
1283                                         bar.addTool(name[0], icon, command, docname);
1284                                 }
1285                         }
1286                         if (!bar.isEmpty()) {
1287                                 _bars.put(step.getNumber(), bar);
1288                         }
1289                 }
1290         }
1291
1292         public static String getApplicationProperty(final String name) {
1293                 return _WAPPROPS.getProperty(name); // May be null
1294         }
1295
1296         public static String getApplicationRootPath() {
1297                 // The property is supposed including the Web application name
1298                 return wapproot;
1299         }
1300
1301         public String getApplicationURL() {
1302                 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1303                                 .append("/").append(wappname);
1304                 return url.toString();
1305         }
1306
1307         public Map<String, Object> getFilter(final String name) {
1308                 return _filter.get(name);
1309         }
1310
1311         public ToolBar getModuleBar(final Step step) {
1312                 return _bars.get(step.getNumber());
1313         }
1314
1315         static public Properties getNamingProperties() {
1316                 return _JNDPROPS;
1317         }
1318
1319         // ==============================================================================================================================
1320         // Public services
1321         // ==============================================================================================================================
1322
1323         public static String getApplicationPluginPath() {
1324                 return getApplicationRootPath() + "plugin/";
1325         }
1326
1327         public static String getApplicationResourcePath() {
1328                 return getApplicationRootPath() + "WEB-INF/classes/";
1329         }
1330
1331         public static String getApplicationSkinPath() {
1332                 return getApplicationRootPath() + "skin/";
1333         }
1334
1335         public static Converter getConverter(final DocumentType type,
1336                         final String format) {
1337                 return convertmap.get(format + type.getName()); // May be null;
1338         }
1339
1340         /**
1341          * Get default document type for the given format on the given study step.
1342          * 
1343          * @param step
1344          *            the study step
1345          * @param format
1346          *            the file format
1347          * @return default document type or null if not defined in the configuration
1348          */
1349         public DocumentType getDefaultDocumentType(final Step step,
1350                         final String format) {
1351                 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1352                                 format); // May be null
1353         }
1354
1355         public String getDownloadURL(final User user) {
1356                 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1357                                 .append("/download/").append(user.getUsername()).append("/");
1358                 return url.toString(); // The download Tomcat context is supposed being defined
1359         }
1360
1361         public Locale getCurrentLocale() {
1362                 return _locale;
1363         }
1364
1365         public SimpleMenu getMenu(final String name) {
1366                 return _menus.get(name);
1367         }
1368
1369         public PopupMenu getPopupMenu(final String name) {
1370                 return _popups.get(name);
1371         }
1372
1373         public String getRepositoryURL() {
1374                 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1375                                 .append("/repository/");
1376                 return url.toString(); // The repository Tomcat context is supposed being defined
1377         }
1378
1379         public static Locale[] getSupportedLocales() {
1380                 String[] code = _WAPPROPS.getProperty("locale.supported").split(",");
1381                 Locale[] result = new Locale[code.length];
1382                 for (int i = 0; i < code.length; i++) {
1383                         result[i] = new Locale(code[i]);
1384                 }
1385                 return result;
1386         }
1387
1388         public static String[] getViewersMapping() {
1389                 return viewermap;
1390         }
1391
1392         public static String getWebSiteURL() {
1393                 return getApplicationProperty("wapp.website");
1394         }
1395
1396         public static String getHelpURL() {
1397                 return getApplicationProperty("wapp.onlinehelp");
1398         }
1399
1400         // ==============================================================================================================================
1401         // Private services
1402         // ==============================================================================================================================
1403
1404         /**
1405          * Load application custom configuration from the given XML file (see conf/my.xml).
1406          * 
1407          * @param config
1408          *            the XML configuration file
1409          */
1410         private static void loadCustomization(final File config) {
1411                 try {
1412                         DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1413                                         .newInstance();
1414                         DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1415
1416                         org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1417                         HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1418                                         .getDocumentElement());
1419
1420                         // Modules tag
1421                         loadModules(children);
1422
1423                         // Converters tag
1424                         loadConverters(children);
1425
1426                         // Templates tag
1427                         loadTemplates(children);
1428                 } catch (Exception error) {
1429                         LOG.info("Error in customization", error);
1430                 }
1431         }
1432
1433         /**
1434          * Load modules from XML configuration.
1435          * 
1436          * @param children
1437          *            XML nodes
1438          */
1439         private static void loadModules(final Map<String, Node> children) {
1440                 Node child = children.get("modules");
1441                 NodeList nlist = child.getChildNodes();
1442                 for (int i = 0; i < nlist.getLength(); i++) {
1443                         child = nlist.item(i);
1444                         if (!child.getNodeName().equals("mapping")) {
1445                                 continue;
1446                         }
1447
1448                         NamedNodeMap natr = child.getAttributes();
1449                         String dext = natr.getNamedItem("extension").getNodeValue();
1450                         String exec = natr.getNamedItem("executable").getNodeValue();
1451                         _WAPPROPS.put("executable." + dext, exec);
1452                 }
1453                 // Viewer mappings tag
1454                 child = children.get("viewers");
1455                 viewermap = child.getAttributes().getNamedItem("extension")
1456                                 .getNodeValue().split(",");
1457         }
1458
1459         /**
1460          * Load converters from XML configuration.
1461          * 
1462          * @param children
1463          *            XML nodes
1464          */
1465         private static void loadConverters(final Map<String, Node> children) {
1466                 Node child = children.get("converters");
1467                 NodeList nlist = child.getChildNodes();
1468                 for (int i = 0; i < nlist.getLength(); i++) {
1469                         child = nlist.item(i);
1470
1471                         if (child.getNodeName().equals("geometry")) {
1472                                 NamedNodeMap natr = child.getAttributes();
1473                                 String from = natr.getNamedItem("from").getNodeValue();
1474                                 String to = natr.getNamedItem("to").getNodeValue();
1475                                 String exec = natr.getNamedItem("executable").getNodeValue();
1476                                 convertmap.put(from + "geometry", new Converter("geometry",
1477                                                 from, to, exec));
1478                         }
1479                 }
1480         }
1481
1482         /**
1483          * Load templates from XML configuration.
1484          * 
1485          * @param children
1486          *            XML nodes
1487          */
1488         private static void loadTemplates(final Map<String, Node> children) {
1489                 Node child = children.get("templates");
1490                 NodeList nlist = child.getChildNodes();
1491                 for (int i = 0; i < nlist.getLength(); i++) {
1492                         child = nlist.item(i);
1493                         if (!child.getNodeName().equals("document")) {
1494                                 continue;
1495                         }
1496
1497                         NamedNodeMap natr = child.getAttributes();
1498                         String type = natr.getNamedItem("type").getNodeValue();
1499                         String file = natr.getNamedItem("file").getNodeValue();
1500                         tempfile.put(type, file);
1501                 }
1502         }
1503
1504         /**
1505          * Get the documentTypeService.
1506          * 
1507          * @return the documentTypeService
1508          */
1509         public DocumentTypeService getDocumentTypeService() {
1510                 return _documentTypeService;
1511         }
1512
1513         /**
1514          * Set the documentTypeService.
1515          * 
1516          * @param documentTypeService
1517          *            the documentTypeService to set
1518          */
1519         public void setDocumentTypeService(
1520                         final DocumentTypeService documentTypeService) {
1521                 _documentTypeService = documentTypeService;
1522         }
1523
1524         /**
1525          * Get the locale.
1526          * 
1527          * @return the locale
1528          */
1529         public Locale getLocale() {
1530                 return _locale;
1531         }
1532
1533         /**
1534          * Set the locale.
1535          * 
1536          * @param locale
1537          *            the locale to set
1538          */
1539         public void setLocale(final Locale locale) {
1540                 _locale = locale;
1541         }
1542
1543 }