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.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;
44 * SIMAN project settings service. Provides settings according to XML customization.
46 public class ApplicationSettings {
49 * Application settings logger.
51 protected final static AppLogger LOG = AppLogger
52 .getLogger(ApplicationSettings.class);
54 * JNDI context for launching converters.
56 private transient static final Properties _JNDPROPS;
58 * Siman web application name.
60 private transient static String wappname;
62 * General properties from the application properties files.
64 private transient static final Properties _WAPPROPS = new Properties();
66 * Siman web application root path on the server.
68 private transient static String wapproot;
70 * Available template files.
72 private transient static Map<String, String> tempfile;
74 * List of file extensions mapped to a viewer.
76 private transient static String[] viewermap;
78 * Available document format converters.
80 private transient static Map<String, Converter> convertmap;
83 synchronized (_WAPPROPS) {
84 // Do common configuration for all users
86 _JNDPROPS = new Properties();
87 tempfile = new HashMap<String, String>();
88 viewermap = new String[0];
89 convertmap = new HashMap<String, Converter>();
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);
99 // Set local path on the server to the application root.
100 wapproot = curRequest.getSession().getServletContext().getRealPath(
104 _JNDPROPS.load(cloader.getResourceAsStream("jndi.properties"));
105 _WAPPROPS.load(cloader.getResourceAsStream(wappname
107 } catch (IOException e) {
109 "Can't load application properties: " + e.getMessage(),
113 // Configure login security
114 System.setProperty("java.security.auth.login.config", wapproot
115 + ApplicationSettings.getApplicationProperty("wapp.login"));
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
123 LOG.info("Could not find the application configuration file \""
124 + config.getAbsolutePath()
125 + "\", using default settings");
133 private static final String ALL = "all";
136 * Hold icon file name.
138 private static final String IMG_HOLD = "image.hold.gif";
140 * Attach icon file name.
142 private static final String IMG_ATTACH = "image.attach.png";
144 * Version icon file name.
146 private static final String IMG_VERSION = "image.version.png";
148 * Delete icon file name.
150 private static final String IMG_DELETE = "icon.delete.png";
152 * Attach menu item name.
154 private static final String MNU_ATTACH = "attach";
156 * Demote menu item name.
158 private static final String MNU_DEMOTE = "demote";
160 * Promote menu item name.
162 private static final String MNU_PROMOTE = "promote";
164 * Publish menu item name.
166 private static final String MNU_PUBLISH = "publish";
168 * Edit menu item name.
170 private static final String MNU_EDIT = "edit";
172 * Script menu item name.
174 private static final String MNU_SCRIPT = "script";
176 * Version menu item name.
178 private static final String MNU_VERSION = "version";
180 // * Purge menu item name.
182 // private static final String MNU_PURGE = "purge";
184 * Remove menu item name.
186 private static final String MNU_REMOVE = "remove";
188 * Rename menu item name.
190 private static final String MNU_RENAME = "rename";
193 * Attach menu item name.
195 private static final String MNU_NAME_ATTACH = "menu.attach";
197 * Demote menu item name.
199 private static final String MNU_NAME_DEMOTE = "menu.demote";
201 * Promote menu item name.
203 private static final String MNU_NAME_PROMOTE = "menu.promote";
205 * Publish menu item name.
207 private static final String MNU_NAME_PUBLISH = "menu.publish";
209 * Protect menu item name.
211 private static final String MNU_NAME_PROTECT = "menu.protect";
213 * Edit menu item name.
215 private static final String MNU_NAME_EDIT = "menu.edit";
217 * Edit menu item name.
219 private static final String MNU_NAME_REMOVE = "menu.remove";
221 * Script menu item name.
223 private static final String MNU_NAME_SCRIPT = "menu.newscenario";
225 * Version menu item name.
227 private static final String MNU_NAME_VERSION = "menu.version";
229 * Purge menu item name.
231 // private static final String MNU_NAME_PURGE = "menu.purge";
233 * Remove menu item name.
235 private static final String MNU_NAME_REMOVE_VERSION = "menu.remove.version";
237 * Rename menu item name.
239 private static final String MNU_NAME_RENAME = "menu.rename";
241 * Mark as reference menu item name.
243 private static final String MNU_MARK_AS_REFERENCE = "markasreference";
245 * Mark as reference menu item label key.
247 private static final String MNU_NAME_MARK_AS_REFERENCE = "menu.markasreference";
249 * Remove as reference menu item label key.
251 private static final String MNU_NAME_REMOVE_AS_REFERENCE = "menu.removeasreference";
253 // * Not yet implemented action name.
255 // private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented";
257 * Attach action name.
259 private static final String ACT_ATTACH = "select-file?nextAction=attach";
261 * Version action name.
263 private static final String ACT_VERSION = "select-file?nextAction=version";
265 * Mark as reference action name.
267 private static final String ACT_MARK_AS_REFERENCE = "markasref-study";
269 * Remove as reference action name.
271 private static final String ACT_REMOVE_AS_REFERENCE = "removeasref-study";
274 * Siman application server name.
276 private transient final String _wappserver;
278 * Current user locale.
280 private transient Locale _locale;
284 private transient final Map<String, SimpleMenu> _menus = new HashMap<String, SimpleMenu>();
286 * Study module-bars structured by steps.
288 private transient Map<Integer, ToolBar> _bars = null;
292 private transient Map<String, PopupMenu> _popups = null;
294 * Named search filters.
296 private transient Map<String, Map<String, Object>> _filter = null;
298 * Injected project settings service.
300 private ProjectSettingsService _projectSettings;
302 * Injected document type service.
304 private DocumentTypeService _documentTypeService;
307 * Application settings constructor.
309 public ApplicationSettings() {
310 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
311 .currentRequestAttributes()).getRequest();
312 _wappserver = curRequest.getServerName() + ":"
313 + curRequest.getServerPort();
315 LOG.info("Application server is set to " + _wappserver);
316 LOG.info("Application name is set to " + wappname);
320 * Get the projectSettingsService.
322 * @return the projectSettingsService
324 public ProjectSettingsService getProjectSettings() {
325 return _projectSettings;
329 * Set the projectSettingsService.
331 * @param projectSettingsService
332 * the projectSettingsService to set
334 public void setProjectSettings(
335 final ProjectSettingsService projectSettingsService) {
336 _projectSettings = projectSettingsService;
342 private static class NewMenu extends SimpleMenu {
344 * New study menu constructor.
348 addItem("new-empty", "menu.new.empty", "image.empty.png",
349 "select?menu=create&item=new-empty");
350 addItem("new-copy", "menu.new.copy", "image.copy.png",
351 "select?menu=create&item=new-copy");
353 * addItem("new-instance", new MenuItem("menu.new.instance") .icon(IMG_HOLD)); addItem("new-import", new
354 * MenuItem("menu.new.import") .icon("icon.upload.png"));
356 this.selects("new-empty");
363 private static class SearchMenu extends SimpleMenu {
365 * Search menu constructor.
367 private SearchMenu() {
369 addItem("search-study", "menu.search.study", "image.study.png",
370 "select?menu=search&item=search-study");
371 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
372 "select?menu=search&item=search-knowledge");
373 addItem("search-document", new MenuItem("menu.search.document")
374 .icon("icon.any.png"));
375 this.selects("search-study");
380 * Configuration menu.
382 private static class PropertiesMenu extends SimpleMenu {
384 * Configuration menu constructor.
386 private PropertiesMenu() {
387 super("configuration");
388 addItem("prop-general", "menu.prop.general", IMG_HOLD,
389 "select?menu=configuration&item=prop-general");
390 addItem("prop-scenario", "menu.prop.scenario", IMG_HOLD,
391 "select?menu=configuration&item=prop-scenario");
392 // These menu items will not be implemented in the current version.
394 * addItem("prop-timestamp", new MenuItem("menu.prop.timestamp") .icon("image.stamp.png")); addItem("prop-comlog", new
395 * MenuItem("menu.prop.comlog") .icon(IMG_HOLD)); addItem("prop-version", new MenuItem("menu.prop.version")
396 * .icon("image.dirclosed.png"));
402 * Data administrator menu.
404 private static class DatadminMenu extends SimpleMenu {
406 * Data administrator menu constructor.
408 private DatadminMenu() {
410 addItem("admin-scontext", "menu.admin.context", IMG_HOLD,
411 "select?menu=datadmin&item=admin-scontext");
412 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
413 "select?menu=datadmin&item=admin-knowelm");
414 addItem("admin-study", new MenuItem("menu.admin.study")
415 .icon("image.study.png"));
420 * System administrator menu.
422 private static class SysadminMenu extends SimpleMenu {
424 * System administrator menu constructor.
426 private SysadminMenu() {
428 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
429 "select?menu=sysadmin&item=admin-indexing");
430 addItem("admin-importuser", "menu.admin.importuser",
432 "select?menu=sysadmin&item=admin-importuser");
437 * Menu items enumeration.
445 * Accept the document.
449 * Approve the document.
453 * Promote the document.
457 * Demote the docuemnt.
461 * Undo the last operation.
465 * Rename the document.
469 * Attach a file to the document.
481 * Version the document.
493 * Remove the document.
501 * Mark the study as reference.
506 // Resources relative to studies
510 private static class EditableMarkedStudyPopup extends PopupMenu {
512 * User rights for the selected study.
514 private transient StudyRights _user = null;
517 * Study popup menu constructor.
522 * "marked as reference" study flag
524 private EditableMarkedStudyPopup(final boolean isPublic,
525 final boolean isMarked) {
529 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
530 MNU_NAME_REMOVE_AS_REFERENCE).action(
531 ACT_REMOVE_AS_REFERENCE).confirmation(
532 "message.removeasreference.study"));
534 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
535 MNU_NAME_MARK_AS_REFERENCE).action(
536 ACT_MARK_AS_REFERENCE).confirmation(
537 "message.markasreference.study"));
541 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PROTECT).icon(
543 .action("edit-study?action=protect").confirmation(
544 "message.protect.study"));
546 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon(
548 .action("edit-study?action=publish").confirmation(
549 "message.publish.study"));
552 /* addItem(MNU_PROMOTE, new PopupItem("menu.archive")); */
554 addItem(MNU_EDIT, new PopupItem("menu.properties").icon(
555 "icon.ed.png").action(
556 "../select?menu=configuration&item=prop-general"));
558 addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT)
559 .action("add-scenario"));
561 * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
565 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
566 * PopupItem("menu.export") .icon("image.export.png")); // For future needs
567 */addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
568 IMG_DELETE).action("remove-study").confirmation(
569 "message.delete.study"));
575 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
578 public boolean isEnabled(final String name) {
579 boolean res = (_user != null);
581 Item item = Item.valueOf(name);
584 if (_user.getOperand().getVisibility() == Visibility.PRIVATE) {
585 res = _user.canPublish();
587 res = _user.canProtect();
591 res = _user.canEditProperties();
594 res = _user.canAddScenario();
597 res = _user.canVersion();
600 res = _user.canRemove();
603 * case purge: res = _user.canPurge(); break;
605 case markasreference:
606 if (_user.getOperand().getMarkreference() == 0) {
607 res = _user.canMarkStudyAsReference();
609 res = _user.canRemoveStudyAsReference();
622 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
625 public void setContext(final String name, final Object context) {
626 if (context instanceof StudyRights) {
627 _user = (StudyRights) context; // Just for optimizing
628 boolean history = _user.getOperand().isVersioned();
629 PopupItem item = this.item(MNU_REMOVE);
631 item.rename(MNU_NAME_REMOVE_VERSION);
633 item.rename("menu.remove.study");
639 // Resources relative to documents
641 * Popup of a document.
643 private static class DocumentPopup extends PopupMenu {
645 * Current user rights.
647 private transient DocumentRights _user = null;
652 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
655 public boolean isEnabled(final String name) {
656 boolean res = (_user != null);
658 Item item = Item.valueOf(name);
661 res = _user.canAccept();
664 res = _user.canPromote();
667 res = _user.canRename();
670 res = _user.canAttach();
673 res = _user.canEdit();
676 res = _user.canVersion();
679 res = _user.canReplace();
682 res = _user.canRemove();
685 res = _user.canPurge();
688 res = _user.canInvalidate();
691 res = _user.canDemote();
694 res = _user.canApprove();
706 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
709 public void setContext(final String name, final Object context) {
710 if (context instanceof DocumentRights) {
711 _user = (DocumentRights) context; // Just for optimizing
712 Document downer = _user.getOperand();
713 if (this.hasItem(MNU_REMOVE)) {
714 if (downer.getPreviousVersion() == null) {
715 this.item(MNU_REMOVE).rename("menu.remove.document");
717 this.item(MNU_REMOVE).rename(MNU_NAME_REMOVE_VERSION);
725 * Popup of In-Work documents.
727 private static class EditableDocumentPopup extends DocumentPopup {
729 * Document popup menu constructor.
731 private EditableDocumentPopup() {
734 * addItem("accept", new PopupItem("menu.accept").icon( "image.accept.png").action("setDocument?action=accept")
735 * .confirmation("message.accept.document"));
737 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
738 "image.publish.png").action("setDocument?action=promote")
739 .confirmation("message.promote.document"));
741 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
742 .action("edit-document?action=renameDocument"));
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));
748 addItem("replace", new PopupItem("menu.replace").icon(
749 "image.replace.png").action(
750 "select-file?nextAction=replace"));
753 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
755 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
756 IMG_DELETE).action("remove-document").confirmation(
757 "message.delete.document"));
762 * Popup of In-Draft documents.
764 private static class ReviewableDocumentPopup extends DocumentPopup {
766 * Document popup menu constructor.
768 private ReviewableDocumentPopup() {
770 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
771 "image.demote.png").action("setDocument?action=demote")
772 .confirmation("message.demote.document"));
773 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
774 "image.review.png").action("setDocument?action=review")
775 .confirmation("message.review.document"));
777 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
778 .action(ACT_ATTACH));
780 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
781 IMG_VERSION).action(ACT_VERSION));
784 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
790 * Popup menu for documents which are not results of a step.
792 private static class NotResultDocumentPopup extends DocumentPopup {
794 * Default constructor.
796 private NotResultDocumentPopup() {
798 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
799 "image.demote.png").action("setDocument?action=demote")
800 .confirmation("message.demote.document"));
802 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
803 .action(ACT_ATTACH));
805 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
806 IMG_VERSION).action(ACT_VERSION));
809 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
811 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
812 IMG_DELETE).action("remove-document").confirmation(
813 "message.delete.document"));
818 * Popup of In-Check documents.
820 private static class ApprovableDocumentPopup extends DocumentPopup {
822 * Default constructor.
824 private ApprovableDocumentPopup() {
826 addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon(
827 "image.invalidate.png").action(
828 "setDocument?action=invalidate").confirmation(
829 "message.demote.document"));
830 addItem(MNU_DEMOTE, new PopupItem("menu.disapprove").icon(
831 "image.demote.png").action("setDocument?action=disapprove")
832 .confirmation("message.disapprove.document"));
833 addItem("approve", new PopupItem("menu.approve").icon(
834 "icon.APPROVED.png").action("setDocument?action=approve")
835 .confirmation("message.approve.document"));
840 * Popup of Approved documents.
842 private static class ApprovedPopup extends DocumentPopup {
844 * Default constructor.
846 private ApprovedPopup() {
848 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
849 .action(ACT_ATTACH));
851 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
852 IMG_VERSION).action(ACT_VERSION));
857 * Popup of external documents.
859 private static class ExternPopup extends DocumentPopup {
861 * Default constructor.
863 private ExternPopup() {
865 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
866 .action("edit-document?action=renameDocument"));
868 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
869 IMG_VERSION).action(ACT_VERSION));
871 addItem("replace", new PopupItem("menu.replace").icon(
872 "image.replace.png").action(
873 "select-file?nextAction=replace"));
875 addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon(
876 IMG_DELETE).action("remove-document").confirmation(
877 "message.delete.document"));
882 * Simulation context popup menu.
884 private static class ScontextPopup extends PopupMenu {
888 private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it.
891 * Default constructor.
893 private ScontextPopup() {
895 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
896 .action("edit-context?action=renameContext"));
897 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
898 .action("edit-context?action=editContext"));
900 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
901 .action("remove-context").confirmation(
902 "message.delete.context"));
908 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
911 public boolean isEnabled(final String name) {
912 Item item = Item.valueOf(name);
915 if (item == Item.rename) {
917 } else if (item == Item.edit) {
918 // if (!owner.isEditable())
927 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
930 public void setContext(final String name, final Object context) {
931 if (context instanceof SimulationContextFacade) {
932 _owner = (SimulationContextFacade) context; // Just for optimizing
934 super.setContext(name, context);
939 // Resources relative to knowledge
941 * Knowledge element popup menu.
943 private static class FeedbexPopup extends PopupMenu {
946 * Popup menu owner object.
948 protected transient KnowledgeElement _owner = null;
951 * Default constructor.
953 private FeedbexPopup() {
955 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
956 .action("edit-knowledge?action=renameKnowledge"));
957 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
958 .action("edit-knowledge?action=editKnowledge"));
960 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
961 .action("remove-knowledge").confirmation(
962 "message.delete.knowledge"));
968 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
971 public boolean isEnabled(final String name) {
979 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
982 public void setContext(final String name, final Object context) {
983 if (context instanceof KnowledgeElement) {
984 _owner = (KnowledgeElement) context; // Just for optimizing
986 super.setContext(name, context);
992 * Pop-up menu for comments.
994 private static class CommentPopup extends PopupMenu {
996 * Default constructor.
998 private CommentPopup() {
1000 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1001 .action("editComment(entity_index)"));
1002 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1003 .action("removeComment(entity_index)").confirmation(
1004 "message.delete.comment"));
1015 public boolean isEnabled(final String name) {
1021 * Pop-up menu for comments.
1023 private static class DescritptionPopup extends PopupMenu {
1025 * Default constructor.
1027 private DescritptionPopup() {
1029 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1030 .action("showDescriptionEditor()"));
1031 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1032 .action("removeDescription()").confirmation(
1033 "message.delete.description"));
1044 public boolean isEnabled(final String name) {
1049 // ==============================================================================================================================
1051 // ==============================================================================================================================
1053 // ==============================================================================================================================
1054 // Public member functions
1055 // ==============================================================================================================================
1058 * Initialize application menus.
1060 public void configure() {
1061 // Non customizable settings
1063 SimpleMenu menu = new NewMenu();
1064 _menus.put(menu.getName(), menu);
1065 menu = new SearchMenu();
1066 _menus.put(menu.getName(), menu);
1067 menu = new DatadminMenu();
1068 _menus.put(menu.getName(), menu);
1069 menu = new SysadminMenu();
1070 _menus.put(menu.getName(), menu);
1071 menu = new PropertiesMenu();
1072 _menus.put(menu.getName(), menu);
1074 _popups = new HashMap<String, PopupMenu>();
1075 _popups.put("steditablemarkpublic", new EditableMarkedStudyPopup(false,
1077 _popups.put("steditableunmarkpublic", new EditableMarkedStudyPopup(
1079 _popups.put("steditablemarkprivate", new EditableMarkedStudyPopup(true,
1081 _popups.put("steditableunmarkprivate", new EditableMarkedStudyPopup(
1083 _popups.put("editable", new EditableDocumentPopup());
1084 _popups.put("notresult", new NotResultDocumentPopup());
1085 _popups.put("reviewable", new ReviewableDocumentPopup());
1086 _popups.put("approvable", new ApprovableDocumentPopup());
1087 _popups.put("approved", new ApprovedPopup());
1088 _popups.put("extern", new ExternPopup());
1089 _popups.put("scontext", new ScontextPopup());
1090 _popups.put("feedbex", new FeedbexPopup());
1091 _popups.put("comment", new CommentPopup());
1092 _popups.put("description", new DescritptionPopup());
1094 // Default customizable mandatory settings
1095 Map<String, Object> fprop = new HashMap<String, Object>();
1096 fprop.put("visibility", "PRIVATE");
1097 fprop.put("matchamong", ALL);
1098 fprop.put("matcontext", ALL);
1099 fprop.put("state", "APPROVED");
1100 fprop.put("author", "0");
1101 fprop.put("reference", "");
1102 fprop.put("title", "");
1103 fprop.put("context", new ArrayList<SimulationContext>());
1105 Map<String, Object> gprop = new HashMap<String, Object>();
1106 gprop.put("visibility", "PUBLIC");
1107 gprop.put("matchamong", ALL);
1108 gprop.put("matcontext", ALL);
1109 gprop.put("type", "2"); // TODO: Get the index from the type name
1110 gprop.put("author", "0");
1111 gprop.put("reference", "");
1112 gprop.put("title", "");
1113 gprop.put("context", new ArrayList<SimulationContext>());
1115 _filter = new HashMap<String, Map<String, Object>>();
1116 _filter.put("study", fprop);
1117 _filter.put("knowledge", gprop);
1119 // Settings based on the customization
1120 configureToolbars();
1124 * Configure toolbars for steps.
1126 private void configureToolbars() {
1127 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
1129 List<ProjectSettingsService.Step> steps = getProjectSettings()
1131 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
1133 ProjectSettingsService.Step step = i.next();
1134 List<String> formats = getProjectSettings().getDefaultFormats(step);
1135 if (formats.isEmpty()) {
1139 ToolBar bar = new ToolBar(24); // Height of the module-bar
1140 Set<String> module = new HashSet<String>(); // For not duplicating modules
1141 for (String format : formats) {
1142 String command = getApplicationProperty("executable." + format);
1143 if (command == null) {
1144 continue; // Module not installed
1146 if (module.contains(command)) {
1149 module.add(command);
1150 String[] parsed = command.split("/");
1151 String[] name = parsed[parsed.length - 1].split("\\x2E");
1152 DocumentType dtype = getProjectSettings()
1153 .getDefaultDocumentType(step, format);
1154 String docname = "";
1155 if (dtype != null) {
1156 docname = dtype.getName();
1158 if (tempfile.get(docname) == null) { // No available template
1159 String tool = parsed[parsed.length - 1];
1160 String icon = name[0];
1161 if ("index".equals(icon)) {
1162 tool = parsed[parsed.length - 2];
1163 icon = "tool." + tool.toLowerCase() + ".png";
1165 icon = "tool." + icon.toLowerCase() + ".png";
1167 File image = new File(ApplicationSettings
1168 .getApplicationSkinPath()
1170 if (!image.exists()) {
1171 icon = "tool.any.png";
1173 bar.addTool(tool, icon, command);
1175 docname = "/jsp/newDocument.jsp?type=" + docname;
1176 String icon = "tool." + name[0].toLowerCase() + ".png";
1177 File image = new File(ApplicationSettings
1178 .getApplicationSkinPath()
1180 if (!image.exists()) {
1181 icon = "tool.any.png";
1183 bar.addTool(name[0], icon, command, docname);
1186 if (!bar.isEmpty()) {
1187 _bars.put(step.getNumber(), bar);
1192 public static String getApplicationProperty(final String name) {
1193 return _WAPPROPS.getProperty(name); // May be null
1196 public static String getApplicationRootPath() {
1197 // The property is supposed including the Web application name
1201 public String getApplicationURL() {
1202 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1203 .append("/").append(wappname);
1204 return url.toString();
1207 public Map<String, Object> getFilter(final String name) {
1208 return _filter.get(name);
1211 public ToolBar getModuleBar(final Step step) {
1212 return _bars.get(step.getNumber());
1215 static public Properties getNamingProperties() {
1219 // ==============================================================================================================================
1221 // ==============================================================================================================================
1223 public static String getApplicationPluginPath() {
1224 return getApplicationRootPath() + "plugin/";
1227 public static String getApplicationResourcePath() {
1228 return getApplicationRootPath() + "WEB-INF/classes/";
1231 public static String getApplicationSkinPath() {
1232 return getApplicationRootPath() + "skin/";
1235 public static Converter getConverter(final DocumentType type,
1236 final String format) {
1237 return convertmap.get(format + type.getName()); // May be null;
1241 * Get default document type for the given format on the given study step.
1247 * @return default document type or null if not defined in the configuration
1249 public DocumentType getDefaultDocumentType(final Step step,
1250 final String format) {
1251 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1252 format); // May be null
1255 public String getDownloadURL(final User user) {
1256 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1257 .append("/download/").append(user.getUsername()).append("/");
1258 return url.toString(); // The download Tomcat context is supposed being defined
1261 public Locale getCurrentLocale() {
1265 public SimpleMenu getMenu(final String name) {
1266 return _menus.get(name);
1269 public PopupMenu getPopupMenu(final String name) {
1270 return _popups.get(name);
1273 public String getRepositoryURL() {
1274 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1275 .append("/repository/");
1276 return url.toString(); // The repository Tomcat context is supposed being defined
1279 public static Locale[] getSupportedLocales() {
1280 String[] code = _WAPPROPS.getProperty("locale.supported").split(",");
1281 Locale[] result = new Locale[code.length];
1282 for (int i = 0; i < code.length; i++) {
1283 result[i] = new Locale(code[i]);
1288 public static String[] getViewersMapping() {
1292 public static String getWebSiteURL() {
1293 return getApplicationProperty("wapp.website");
1296 public static String getHelpURL() {
1297 return getApplicationProperty("wapp.onlinehelp");
1300 // ==============================================================================================================================
1302 // ==============================================================================================================================
1305 * Load application custom configuration from the given XML file (see conf/my.xml).
1308 * the XML configuration file
1310 private static void loadCustomization(final File config) {
1312 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1314 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1316 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1317 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1318 .getDocumentElement());
1321 loadModules(children);
1324 loadConverters(children);
1327 loadTemplates(children);
1328 } catch (Exception error) {
1329 LOG.info("Error in customization", error);
1334 * Load modules from XML configuration.
1339 private static void loadModules(final Map<String, Node> children) {
1340 Node child = children.get("modules");
1341 NodeList nlist = child.getChildNodes();
1342 for (int i = 0; i < nlist.getLength(); i++) {
1343 child = nlist.item(i);
1344 if (!child.getNodeName().equals("mapping")) {
1348 NamedNodeMap natr = child.getAttributes();
1349 String dext = natr.getNamedItem("extension").getNodeValue();
1350 String exec = natr.getNamedItem("executable").getNodeValue();
1351 _WAPPROPS.put("executable." + dext, exec);
1353 // Viewer mappings tag
1354 child = children.get("viewers");
1355 viewermap = child.getAttributes().getNamedItem("extension")
1356 .getNodeValue().split(",");
1360 * Load converters from XML configuration.
1365 private static void loadConverters(final Map<String, Node> children) {
1366 Node child = children.get("converters");
1367 NodeList nlist = child.getChildNodes();
1368 for (int i = 0; i < nlist.getLength(); i++) {
1369 child = nlist.item(i);
1371 if (child.getNodeName().equals("geometry")) {
1372 NamedNodeMap natr = child.getAttributes();
1373 String from = natr.getNamedItem("from").getNodeValue();
1374 String to = natr.getNamedItem("to").getNodeValue();
1375 String exec = natr.getNamedItem("executable").getNodeValue();
1376 convertmap.put(from + "geometry", new Converter("geometry",
1383 * Load templates from XML configuration.
1388 private static void loadTemplates(final Map<String, Node> children) {
1389 Node child = children.get("templates");
1390 NodeList nlist = child.getChildNodes();
1391 for (int i = 0; i < nlist.getLength(); i++) {
1392 child = nlist.item(i);
1393 if (!child.getNodeName().equals("document")) {
1397 NamedNodeMap natr = child.getAttributes();
1398 String type = natr.getNamedItem("type").getNodeValue();
1399 String file = natr.getNamedItem("file").getNodeValue();
1400 tempfile.put(type, file);
1405 * Get the documentTypeService.
1407 * @return the documentTypeService
1409 public DocumentTypeService getDocumentTypeService() {
1410 return _documentTypeService;
1414 * Set the documentTypeService.
1416 * @param documentTypeService
1417 * the documentTypeService to set
1419 public void setDocumentTypeService(
1420 final DocumentTypeService documentTypeService) {
1421 _documentTypeService = documentTypeService;
1427 * @return the locale
1429 public Locale getLocale() {
1439 public void setLocale(final Locale locale) {