1 package org.splat.simer;
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;
10 import java.util.Locale;
12 import java.util.Properties;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.xml.parsers.DocumentBuilder;
17 import javax.xml.parsers.DocumentBuilderFactory;
19 import org.apache.log4j.Logger;
20 import org.splat.dal.bo.kernel.User;
21 import org.splat.dal.bo.som.Document;
22 import org.splat.dal.bo.som.DocumentType;
23 import org.splat.dal.bo.som.KnowledgeElement;
24 import org.splat.dal.bo.som.ProgressState;
25 import org.splat.dal.bo.som.SimulationContext;
26 import org.splat.dal.bo.som.Visibility;
27 import org.splat.manox.XDOM;
28 import org.splat.service.DocumentTypeService;
29 import org.splat.service.technical.ProjectSettingsService;
30 import org.splat.som.DocumentRights;
31 import org.splat.som.Step;
32 import org.splat.som.StudyRights;
33 import org.splat.wapp.MenuItem;
34 import org.splat.wapp.PopupItem;
35 import org.splat.wapp.PopupMenu;
36 import org.splat.wapp.SimpleMenu;
37 import org.splat.wapp.ToolBar;
38 import org.springframework.web.context.request.RequestContextHolder;
39 import org.springframework.web.context.request.ServletRequestAttributes;
40 import org.w3c.dom.NamedNodeMap;
41 import org.w3c.dom.Node;
42 import org.w3c.dom.NodeList;
45 * SIMAN project settings service. Provides settings according to XML customization.
47 public class ApplicationSettings {
50 * Application settings logger.
52 protected final static Logger LOG = Logger
53 .getLogger(ApplicationSettings.class);
55 * JNDI context for launching converters.
57 private transient static final Properties _JNDPROPS;
59 * Siman web application name.
61 private transient static String wappname;
63 * General properties from the application properties files.
65 private transient static final Properties _WAPPROPS = new Properties();
67 * Siman web application root path on the server.
69 private transient static String wapproot;
71 * Available template files.
73 private transient static Map<String, String> tempfile;
75 * List of file extensions mapped to a viewer.
77 private transient static String[] viewermap;
79 * Available document format converters.
81 private transient static Map<String, Converter> convertmap;
84 synchronized (_WAPPROPS) {
85 // Do common configuration for all users
87 _JNDPROPS = new Properties();
88 tempfile = new HashMap<String, String>();
89 viewermap = new String[0];
90 convertmap = new HashMap<String, Converter>();
92 ClassLoader cloader = Thread.currentThread()
93 .getContextClassLoader();
94 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
95 .currentRequestAttributes()).getRequest();
96 String appname = curRequest.getContextPath();
97 if (appname.startsWith("/")) {
98 wappname = appname.substring(1);
100 // Set local path on the server to the application root.
101 wapproot = curRequest.getSession().getServletContext().getRealPath(
105 _JNDPROPS.load(cloader.getResourceAsStream("jndi.properties"));
106 _WAPPROPS.load(cloader.getResourceAsStream(wappname
108 } catch (IOException e) {
110 "Can't load application properties: " + e.getMessage(),
114 // Configure login security
115 System.setProperty("java.security.auth.login.config", wapproot
116 + ApplicationSettings.getApplicationProperty("wapp.login"));
118 // Customization (must be done after above default settings)
119 File config = new File(wapproot
120 + getApplicationProperty("wapp.customization"));
121 if (config.exists()) {
122 loadCustomization(config); // Sets default document types, installed modules and available templates
124 LOG.info("Could not find the application configuration file \""
125 + config.getAbsolutePath()
126 + "\", using default settings");
134 private static final String ALL = "all";
137 * Hold icon file name.
139 private static final String IMG_HOLD = "image.hold.gif";
141 * Attach icon file name.
143 private static final String IMG_ATTACH = "image.attach.png";
145 * Version icon file name.
147 private static final String IMG_VERSION = "image.version.png";
149 * Delete icon file name.
151 private static final String IMG_DELETE = "icon.delete.png";
153 * Attach menu item name.
155 private static final String MNU_ATTACH = "attach";
157 * Demote menu item name.
159 private static final String MNU_DEMOTE = "demote";
161 * Promote menu item name.
163 private static final String MNU_PROMOTE = "promote";
165 * Publish menu item name.
167 private static final String MNU_PUBLISH = "publish";
169 * Edit menu item name.
171 private static final String MNU_EDIT = "edit";
173 * Script menu item name.
175 private static final String MNU_SCRIPT = "script";
177 * Version menu item name.
179 private static final String MNU_VERSION = "version";
181 * Purge menu item name.
183 private static final String MNU_PURGE = "purge";
185 * Remove menu item name.
187 private static final String MNU_REMOVE = "remove";
189 * Rename menu item name.
191 private static final String MNU_RENAME = "rename";
194 * Attach menu item name.
196 private static final String MNU_NAME_ATTACH = "menu.attach";
198 * Demote menu item name.
200 private static final String MNU_NAME_DEMOTE = "menu.demote";
202 * Promote menu item name.
204 private static final String MNU_NAME_PROMOTE = "menu.promote";
206 * Publish menu item name.
208 private static final String MNU_NAME_PUBLISH = "menu.publish";
210 * Protect menu item name.
212 private static final String MNU_NAME_PROTECT = "menu.protect";
214 * Edit menu item name.
216 private static final String MNU_NAME_EDIT = "menu.edit";
218 * Script menu item name.
220 private static final String MNU_NAME_SCRIPT = "menu.newscenario";
222 * Version menu item name.
224 private static final String MNU_NAME_VERSION = "menu.version";
226 * Purge menu item name.
228 private static final String MNU_NAME_PURGE = "menu.purge";
230 * Remove menu item name.
232 private static final String MNU_NAME_REMOVE = "menu.remove.version";
234 * Rename menu item name.
236 private static final String MNU_NAME_RENAME = "menu.rename";
238 * Mark as reference menu item name.
240 private static final String MNU_MARK_AS_REFERENCE = "markasreference";
242 * Remove as reference menu item name.
244 private static final String MNU_REMOVE_AS_REFERENCE = "removeasreference";
246 * Mark as reference menu item label key.
248 private static final String MNU_NAME_MARK_AS_REFERENCE = "menu.markasreference";
250 * Remove as reference menu item label key.
252 private static final String MNU_NAME_REMOVE_AS_REFERENCE = "menu.removeasreference";
254 * Not yet implemented action name.
256 private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented";
258 * Attach action name.
260 private static final String ACT_ATTACH = "select-file?nextAction=attach";
262 * Version action name.
264 private static final String ACT_VERSION = "select-file?nextAction=version";
266 * Mark as reference action name.
268 private static final String ACT_MARK_AS_REFERENCE = "markasref-study";
270 * Remove as reference action name.
272 private static final String ACT_REMOVE_AS_REFERENCE = "removeasref-study";
275 * Siman application server name.
277 private transient final String _wappserver;
279 * Current user locale.
281 private transient Locale _locale;
285 private transient final Map<String, SimpleMenu> _menus = new HashMap<String, SimpleMenu>();
287 * Study module-bars structured by steps.
289 private transient Map<Integer, ToolBar> _bars = null;
293 private transient Map<String, PopupMenu> _popups = null;
295 * Named search filters.
297 private transient Map<String, Map<String, Object>> _filter = null;
299 * Injected project settings service.
301 private ProjectSettingsService _projectSettings;
303 * Injected document type service.
305 private DocumentTypeService _documentTypeService;
308 * Application settings constructor.
310 public ApplicationSettings() {
311 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
312 .currentRequestAttributes()).getRequest();
313 _wappserver = curRequest.getServerName() + ":"
314 + curRequest.getServerPort();
316 LOG.info("Application server is set to " + _wappserver);
317 LOG.info("Application name is set to " + wappname);
321 * Get the projectSettingsService.
323 * @return the projectSettingsService
325 public ProjectSettingsService getProjectSettings() {
326 return _projectSettings;
330 * Set the projectSettingsService.
332 * @param projectSettingsService
333 * the projectSettingsService to set
335 public void setProjectSettings(
336 final ProjectSettingsService projectSettingsService) {
337 _projectSettings = projectSettingsService;
340 private static class NewMenu extends SimpleMenu {
343 addItem("new-empty", "menu.new.empty", "image.empty.png",
344 "select?menu=create&item=new-empty");
345 addItem("new-copy", new MenuItem("menu.new.copy")
346 .icon("image.copy.png"));
348 * addItem("new-instance", new MenuItem("menu.new.instance") .icon(IMG_HOLD)); addItem("new-import", new
349 * MenuItem("menu.new.import") .icon("icon.upload.png"));
351 this.selects("new-empty");
355 private static class SearchMenu extends SimpleMenu {
356 private SearchMenu() {
358 addItem("search-study", "menu.search.study", "image.study.png",
359 "select?menu=search&item=search-study");
360 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
361 "select?menu=search&item=search-knowledge");
362 addItem("search-document", new MenuItem("menu.search.document")
363 .icon("icon.any.png"));
364 this.selects("search-study");
368 private static class PropertiesMenu extends SimpleMenu {
369 private PropertiesMenu() {
370 super("configuration");
371 addItem("prop-general", "menu.prop.general", IMG_HOLD,
372 "select?menu=configuration&item=prop-general");
373 addItem("prop-scenario", "menu.prop.scenario", IMG_HOLD,
374 "select?menu=configuration&item=prop-scenario");
375 // These menu items will not be implemented in the current version.
377 * addItem("prop-timestamp", new MenuItem("menu.prop.timestamp") .icon("image.stamp.png")); addItem("prop-comlog", new
378 * MenuItem("menu.prop.comlog") .icon(IMG_HOLD)); addItem("prop-version", new MenuItem("menu.prop.version")
379 * .icon("image.dirclosed.png"));
384 private static class DatadminMenu extends SimpleMenu {
385 private DatadminMenu() {
387 addItem("admin-scontext", "menu.admin.context", IMG_HOLD,
388 "select?menu=datadmin&item=admin-scontext");
389 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
390 "select?menu=datadmin&item=admin-knowelm");
391 addItem("admin-study", new MenuItem("menu.admin.study")
392 .icon("image.study.png"));
396 private static class SysadminMenu extends SimpleMenu {
397 private SysadminMenu() {
399 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
400 "select?menu=sysadmin&item=admin-indexing");
401 addItem("admin-importuser", "menu.admin.importuser",
403 "select?menu=sysadmin&item=admin-importuser");
408 * Menu items enumeration.
416 * Accept the document.
420 * Approve the document.
424 * Promote the document.
428 * Demote the docuemnt.
432 * Undo the last operation.
436 * Rename the document.
440 * Attach a file to the document.
452 * Version the document.
464 * Remove the document.
472 * Mark the study as reference.
477 // Resources relative to studies
478 private static class EditableMarkedStudyPopup extends PopupMenu {
479 private transient StudyRights _user = null;
481 private EditableMarkedStudyPopup(final boolean isPublic, final boolean isMarked) {
485 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
486 MNU_NAME_REMOVE_AS_REFERENCE).action(ACT_REMOVE_AS_REFERENCE)
487 .confirmation("message.removeasreference.study"));
489 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(MNU_NAME_MARK_AS_REFERENCE)
490 .action(ACT_MARK_AS_REFERENCE).confirmation(
491 "message.markasreference.study"));
495 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PROTECT).icon(
496 "image.publish.png").action("edit-study?action=protect")
497 .confirmation("message.protect.study"));
499 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon(
500 "image.publish.png").action("edit-study?action=publish")
501 .confirmation("message.publish.study"));
504 /* addItem(MNU_PROMOTE, new PopupItem("menu.archive")); */
506 addItem(MNU_EDIT, new PopupItem("menu.properties").icon(
507 "icon.ed.png").action("../select?menu=properties"));
509 addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT)
510 .action("add-scenario"));
512 * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
516 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
517 * PopupItem("menu.export") .icon("image.export.png")); // For future needs
518 */addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(
519 IMG_DELETE).action(ACT_NOT_YET_IMPLEMENTED).confirmation(
520 "message.delete.study"));
526 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
529 public boolean isEnabled(final String name) {
530 boolean res = (_user != null);
532 Item item = Item.valueOf(name);
535 if (_user.getOperand().getVisibility() == Visibility.PRIVATE) {
536 res = _user.canPublish();
538 res = _user.canProtect();
542 res = _user.canEditProperties();
545 res = _user.canAddScenario();
548 res = _user.canVersion();
551 res = _user.canRemove();
554 res = _user.canPurge();
556 case markasreference:
557 if (_user.getOperand().getMarkreference() == 0) {
558 res = _user.canMarkStudyAsReference();
560 res = _user.canRemoveStudyAsReference();
571 public void setContext(final String name, final Object context) {
572 if (context instanceof StudyRights) {
573 _user = (StudyRights) context; // Just for optimizing
574 boolean history = _user.getOperand().isVersioned();
575 PopupItem item = this.item(MNU_REMOVE);
577 item.rename(MNU_NAME_REMOVE);
579 item.rename("menu.remove.study");
585 // Resources relative to documents
587 * Popup of In-Work documents.
589 private static class EditableDocumentPopup extends PopupMenu {
590 private transient DocumentRights _user = null;
592 private EditableDocumentPopup() {
594 addItem("accept", new PopupItem("menu.accept").icon(
595 "image.accept.png").action("setDocument?action=accept")
596 .confirmation("message.accept.document"));
597 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
598 "image.publish.png").action("setDocument?action=promote")
599 .confirmation("message.promote.document"));
601 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
602 .action("edit-document?action=renameDocument"));
603 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
604 .action(ACT_ATTACH));
606 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
607 IMG_VERSION).action(ACT_VERSION));
608 addItem("replace", new PopupItem("menu.replace").icon(
609 "image.replace.png").action(
610 "select-file?nextAction=replace"));
612 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
613 ACT_NOT_YET_IMPLEMENTED).confirmation(
614 "message.purge.document"));
615 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
616 .action("remove-document").confirmation(
617 "message.delete.document"));
621 public boolean isEnabled(final String name) {
622 boolean res = (_user != null);
624 Item item = Item.valueOf(name);
627 res = _user.canAccept();
630 res = _user.canPromote();
633 res = _user.canRename();
636 res = _user.canAttach();
639 res = _user.canVersion();
642 res = _user.canReplace();
645 res = _user.canPurge();
648 res = _user.canRemove();
658 public void setContext(final String name, final Object context) {
659 if (context instanceof DocumentRights) {
660 _user = (DocumentRights) context; // Just for optimizing
661 Document downer = _user.getOperand();
662 PopupItem item = this.item(MNU_REMOVE);
663 if (downer.isVersioned()) {
664 item.rename(MNU_NAME_REMOVE);
666 item.rename("menu.remove.document");
673 * Popup of In-Draft documents.
675 private static class ReviewableDocumentPopup extends PopupMenu {
676 private transient DocumentRights _user = null;
678 private ReviewableDocumentPopup() {
680 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
681 "image.demote.png").action("setDocument?action=demote")
682 .confirmation("message.demote.document"));
683 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
684 "image.review.png").action("setDocument?action=review")
685 .confirmation("message.review.document"));
687 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
688 .action(ACT_ATTACH));
690 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
691 IMG_VERSION).action(ACT_VERSION));
693 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
694 ACT_NOT_YET_IMPLEMENTED).confirmation(
695 "message.purge.document"));
699 public boolean isEnabled(final String name) {
700 boolean res = (_user != null);
702 Item item = Item.valueOf(name);
705 res = _user.canDemote();
708 res = _user.canReview();
711 res = _user.canAttach();
714 res = _user.canVersion();
717 res = _user.canPurge();
727 public void setContext(final String name, final Object context) {
728 if (context instanceof DocumentRights) {
729 _user = (DocumentRights) context; // Just for optimizing
734 private static class NotResultDocumentPopup extends PopupMenu {
735 // private final DocumentRights _user = null;
737 private NotResultDocumentPopup() {
739 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
740 "image.demote.png").action("setDocument?action=demote")
741 .confirmation("message.demote.document"));
743 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
744 .action(ACT_ATTACH));
746 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
747 IMG_VERSION).action(ACT_VERSION));
749 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
750 ACT_NOT_YET_IMPLEMENTED).confirmation(
751 "message.purge.document"));
752 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
753 .action("remove-document").confirmation(
754 "message.delete.document"));
759 * Popup of In-Check documents.
761 private static class ApprovableDocumentPopup extends PopupMenu {
762 private transient DocumentRights _user = null;
764 private ApprovableDocumentPopup() {
766 addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon(
767 "image.invalidate.png").action(
768 "setDocument?action=invalidate").confirmation(
769 "message.demote.document"));
770 addItem(MNU_DEMOTE, new PopupItem("menu.disapprove").icon(
771 "image.demote.png").action("setDocument?action=disapprove")
772 .confirmation("message.disapprove.document"));
773 addItem("approve", new PopupItem("menu.approve").icon(
774 "icon.APPROVED.png").action("setDocument?action=approve")
775 .confirmation("message.approve.document"));
779 public boolean isEnabled(final String name) {
780 boolean res = (_user != null);
782 Item item = Item.valueOf(name);
785 res = _user.canInvalidate();
788 res = _user.canDemote();
791 res = _user.canApprove();
801 public void setContext(final String name, final Object context) {
802 if (context instanceof DocumentRights) {
803 _user = (DocumentRights) context; // Just for optimizing
809 * Popup of Approved documents.
811 private static class ApprovedPopup extends PopupMenu {
812 private ApprovedPopup() {
814 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
815 .action(ACT_ATTACH));
817 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
818 IMG_VERSION).action(ACT_VERSION));
823 * Popup of Extern documents.
825 private static class ExternPopup extends PopupMenu {
826 private transient DocumentRights _user = null;
828 private ExternPopup() {
830 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
831 .action("edit-document?action=renameDocument"));
833 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
834 IMG_VERSION).action(ACT_VERSION));
836 addItem("replace", new PopupItem("menu.replace").icon(
837 "image.replace.png").action(
838 "select-file?nextAction=replace"));
840 addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon(
841 IMG_DELETE).action("remove-document").confirmation(
842 "message.delete.document"));
846 public boolean isEnabled(final String name) {
847 boolean res = (_user != null);
849 Item item = Item.valueOf(name);
852 res = _user.canRename();
855 res = _user.canVersion();
858 res = _user.canReplace();
861 res = _user.canRemove();
871 public void setContext(final String name, final Object context) {
872 if (context instanceof DocumentRights) {
873 _user = (DocumentRights) context; // Just for optimizing
878 // Resources relative to simulation contexts
879 private static class ScontextPopup extends PopupMenu {
880 private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it.
882 private ScontextPopup() {
884 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
885 .action("edit-context?action=renameContext"));
886 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
887 .action("edit-context?action=editContext"));
889 addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
890 .action("remove-context").confirmation(
891 "message.delete.context"));
895 public boolean isEnabled(final String name) {
896 Item item = Item.valueOf(name);
899 if (item == Item.rename) {
901 } else if (item == Item.edit) {
902 // if (!owner.isEditable())
909 public void setContext(final String name, final Object context) {
910 if (context instanceof SimulationContextFacade) {
911 _owner = (SimulationContextFacade) context; // Just for optimizing
913 super.setContext(name, context);
918 // Resources relative to knowledge
919 private static class FeedbexPopup extends PopupMenu {
920 private transient KnowledgeElement _owner = null;
922 private FeedbexPopup() {
924 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
925 "image.review.png").action("promote-knowledge")
926 .confirmation("message.promote.knowledge"));
927 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
928 "image.invalidate.png").action("demote-knowledge")
929 .confirmation("message.demote.knowledge"));
931 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
932 .action("edit-knowledge?action=renameKnowledge"));
933 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
934 .action("edit-knowledge?action=editKnowledge"));
936 addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
937 .action("remove-knowledge").confirmation(
938 "message.delete.knowledge"));
942 public boolean isEnabled(final String name) {
943 Item item = Item.valueOf(name);
946 if (item == Item.promote) {
947 if (_owner.getProgressState() != ProgressState.inDRAFT) {
950 } else if ((item == Item.demote)
951 && (_owner.getProgressState() != ProgressState.inCHECK)) {
958 public void setContext(final String name, final Object context) {
959 if (context instanceof KnowledgeElement) {
960 _owner = (KnowledgeElement) context; // Just for optimizing
962 super.setContext(name, context);
967 // ==============================================================================================================================
969 // ==============================================================================================================================
971 // ==============================================================================================================================
972 // Public member functions
973 // ==============================================================================================================================
975 public void configure() {
976 // Non customizable settings
978 SimpleMenu menu = new NewMenu();
979 _menus.put(menu.getName(), menu);
980 menu = new SearchMenu();
981 _menus.put(menu.getName(), menu);
982 menu = new DatadminMenu();
983 _menus.put(menu.getName(), menu);
984 menu = new SysadminMenu();
985 _menus.put(menu.getName(), menu);
986 menu = new PropertiesMenu();
987 _menus.put(menu.getName(), menu);
989 _popups = new HashMap<String, PopupMenu>();
990 _popups.put("steditablemarkpublic", new EditableMarkedStudyPopup(false, false));
991 _popups.put("steditableunmarkpublic", new EditableMarkedStudyPopup(false, true));
992 _popups.put("steditablemarkprivate", new EditableMarkedStudyPopup(true, false));
993 _popups.put("steditableunmarkprivate", new EditableMarkedStudyPopup(true, true));
994 _popups.put("editable", new EditableDocumentPopup());
995 _popups.put("notresult", new NotResultDocumentPopup());
996 _popups.put("reviewable", new ReviewableDocumentPopup());
997 _popups.put("approvable", new ApprovableDocumentPopup());
998 _popups.put("approved", new ApprovedPopup());
999 _popups.put("extern", new ExternPopup());
1000 _popups.put("scontext", new ScontextPopup());
1001 _popups.put("feedbex", new FeedbexPopup());
1003 // Default customizable mandatory settings
1004 Map<String, Object> fprop = new HashMap<String, Object>();
1005 fprop.put("visibility", "PRIVATE");
1006 fprop.put("matchamong", ALL);
1007 fprop.put("matcontext", ALL);
1008 fprop.put("state", "APPROVED");
1009 fprop.put("author", "0");
1010 fprop.put("reference", "");
1011 fprop.put("title", "");
1012 fprop.put("context", new ArrayList<SimulationContext>());
1014 Map<String, Object> gprop = new HashMap<String, Object>();
1015 gprop.put("visibility", "PUBLIC");
1016 gprop.put("matchamong", ALL);
1017 gprop.put("matcontext", ALL);
1018 gprop.put("type", "2"); // TODO: Get the index from the type name
1019 gprop.put("author", "0");
1020 gprop.put("reference", "");
1021 gprop.put("title", "");
1022 gprop.put("context", new ArrayList<SimulationContext>());
1024 _filter = new HashMap<String, Map<String, Object>>();
1025 _filter.put("study", fprop);
1026 _filter.put("knowledge", gprop);
1028 // Settings based on the customization
1029 configureToolbars();
1033 * Configure toolbars for steps.
1035 private void configureToolbars() {
1036 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
1038 List<ProjectSettingsService.Step> steps = getProjectSettings()
1040 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
1042 ProjectSettingsService.Step step = i.next();
1043 List<String> formats = getProjectSettings().getDefaultFormats(step);
1044 if (formats.isEmpty()) {
1048 ToolBar bar = new ToolBar(24); // Height of the module-bar
1049 Set<String> module = new HashSet<String>(); // For not duplicating modules
1050 for (String format : formats) {
1051 String command = getApplicationProperty("executable." + format);
1052 if (command == null) {
1053 continue; // Module not installed
1055 if (module.contains(command)) {
1058 module.add(command);
1059 String[] parsed = command.split("/");
1060 String[] name = parsed[parsed.length - 1].split("\\x2E");
1061 DocumentType dtype = getProjectSettings()
1062 .getDefaultDocumentType(step, format);
1063 String docname = "";
1064 if (dtype != null) {
1065 docname = dtype.getName();
1067 if (tempfile.get(docname) == null) { // No available template
1068 String tool = parsed[parsed.length - 1];
1069 String icon = name[0];
1070 if ("index".equals(icon)) {
1071 tool = parsed[parsed.length - 2];
1072 icon = "tool." + tool.toLowerCase() + ".png";
1074 icon = "tool." + icon.toLowerCase() + ".png";
1076 File image = new File(ApplicationSettings
1077 .getApplicationSkinPath()
1079 if (!image.exists()) {
1080 icon = "tool.any.png";
1082 bar.addTool(tool, icon, command);
1084 docname = "/jsp/newDocument.jsp?type=" + docname;
1085 String icon = "tool." + name[0].toLowerCase() + ".png";
1086 File image = new File(ApplicationSettings
1087 .getApplicationSkinPath()
1089 if (!image.exists()) {
1090 icon = "tool.any.png";
1092 bar.addTool(name[0], icon, command, docname);
1095 if (!bar.isEmpty()) {
1096 _bars.put(step.getNumber(), bar);
1101 public static String getApplicationProperty(final String name) {
1102 return _WAPPROPS.getProperty(name); // May be null
1105 public static String getApplicationRootPath() {
1106 // The property is supposed including the Web application name
1110 public String getApplicationURL() {
1111 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1112 .append("/").append(wappname);
1113 return url.toString();
1116 public Map<String, Object> getFilter(final String name) {
1117 return _filter.get(name);
1120 public ToolBar getModuleBar(final Step step) {
1121 return _bars.get(step.getNumber());
1124 static public Properties getNamingProperties() {
1128 // ==============================================================================================================================
1130 // ==============================================================================================================================
1132 public static String getApplicationPluginPath() {
1133 return getApplicationRootPath() + "plugin/";
1136 public static String getApplicationResourcePath() {
1137 return getApplicationRootPath() + "WEB-INF/classes/";
1140 public static String getApplicationSkinPath() {
1141 return getApplicationRootPath() + "skin/";
1144 public static Converter getConverter(final DocumentType type,
1145 final String format) {
1146 return convertmap.get(format + type.getName()); // May be null;
1150 * Get default document type for the given format on the given study step.
1156 * @return default document type or null if not defined in the configuration
1158 public DocumentType getDefaultDocumentType(final Step step,
1159 final String format) {
1160 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1161 format); // May be null
1164 public String getDownloadURL(final User user) {
1165 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1166 .append("/download/").append(user.getUsername()).append("/");
1167 return url.toString(); // The download Tomcat context is supposed being defined
1170 public Locale getCurrentLocale() {
1174 public SimpleMenu getMenu(final String name) {
1175 return _menus.get(name);
1178 public PopupMenu getPopupMenu(final String name) {
1179 return _popups.get(name);
1182 public String getRepositoryURL() {
1183 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1184 .append("/repository/");
1185 return url.toString(); // The repository Tomcat context is supposed being defined
1188 public static Locale[] getSupportedLocales() {
1189 String[] code = _WAPPROPS.getProperty("locale.supported").split(",");
1190 Locale[] result = new Locale[code.length];
1191 for (int i = 0; i < code.length; i++) {
1192 result[i] = new Locale(code[i]);
1197 public static String[] getViewersMapping() {
1201 public static String getWebSiteURL() {
1202 return getApplicationProperty("wapp.website");
1205 public static String getHelpURL() {
1206 return getApplicationProperty("wapp.onlinehelp");
1209 // ==============================================================================================================================
1211 // ==============================================================================================================================
1214 * Load application custom configuration from the given XML file (see conf/my.xml).
1217 * the XML configuration file
1219 private static void loadCustomization(final File config) {
1221 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1223 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1225 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1226 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1227 .getDocumentElement());
1230 loadModules(children);
1233 loadConverters(children);
1236 loadTemplates(children);
1237 } catch (Exception error) {
1238 LOG.info("Error in customization", error);
1243 * Load modules from XML configuration.
1248 private static void loadModules(final Map<String, Node> children) {
1249 Node child = children.get("modules");
1250 NodeList nlist = child.getChildNodes();
1251 for (int i = 0; i < nlist.getLength(); i++) {
1252 child = nlist.item(i);
1253 if (!child.getNodeName().equals("mapping")) {
1257 NamedNodeMap natr = child.getAttributes();
1258 String dext = natr.getNamedItem("extension").getNodeValue();
1259 String exec = natr.getNamedItem("executable").getNodeValue();
1260 _WAPPROPS.put("executable." + dext, exec);
1262 // Viewer mappings tag
1263 child = children.get("viewers");
1264 viewermap = child.getAttributes().getNamedItem("extension")
1265 .getNodeValue().split(",");
1269 * Load converters from XML configuration.
1274 private static void loadConverters(final Map<String, Node> children) {
1275 Node child = children.get("converters");
1276 NodeList nlist = child.getChildNodes();
1277 for (int i = 0; i < nlist.getLength(); i++) {
1278 child = nlist.item(i);
1280 if (child.getNodeName().equals("geometry")) {
1281 NamedNodeMap natr = child.getAttributes();
1282 String from = natr.getNamedItem("from").getNodeValue();
1283 String to = natr.getNamedItem("to").getNodeValue();
1284 String exec = natr.getNamedItem("executable").getNodeValue();
1285 convertmap.put(from + "geometry", new Converter("geometry",
1292 * Load templates from XML configuration.
1297 private static void loadTemplates(final Map<String, Node> children) {
1298 Node child = children.get("templates");
1299 NodeList nlist = child.getChildNodes();
1300 for (int i = 0; i < nlist.getLength(); i++) {
1301 child = nlist.item(i);
1302 if (!child.getNodeName().equals("document")) {
1306 NamedNodeMap natr = child.getAttributes();
1307 String type = natr.getNamedItem("type").getNodeValue();
1308 String file = natr.getNamedItem("file").getNodeValue();
1309 tempfile.put(type, file);
1314 * Get the documentTypeService.
1316 * @return the documentTypeService
1318 public DocumentTypeService getDocumentTypeService() {
1319 return _documentTypeService;
1323 * Set the documentTypeService.
1325 * @param documentTypeService
1326 * the documentTypeService to set
1328 public void setDocumentTypeService(
1329 final DocumentTypeService documentTypeService) {
1330 _documentTypeService = documentTypeService;
1336 * @return the locale
1338 public Locale getLocale() {
1348 public void setLocale(final Locale locale) {