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 * Promote icon file name.
154 private static final String IMG_PROMOTE = "image.publish.png";
156 * Demote icon file name.
158 private static final String IMG_DEMOTE = "image.demote.png";
160 * Accept icon file name.
162 private static final String IMG_ACCEPT = "image.accept.png";
165 * Attach menu item name.
167 private static final String MNU_ATTACH = "attach";
169 * Demote menu item name.
171 private static final String MNU_DEMOTE = "demote";
173 * Promote menu item name.
175 private static final String MNU_PROMOTE = "promote";
177 * Publish menu item name.
179 private static final String MNU_PUBLISH = "publish";
181 * Edit menu item name.
183 private static final String MNU_EDIT = "edit";
185 * Script menu item name.
187 private static final String MNU_SCRIPT = "script";
189 * Version menu item name.
191 private static final String MNU_VERSION = "version";
193 // * Purge menu item name.
195 // private static final String MNU_PURGE = "purge";
197 * Remove menu item name.
199 private static final String MNU_REMOVE = "remove";
201 * Rename menu item name.
203 private static final String MNU_RENAME = "rename";
205 * Set up-to-date menu item name.
207 private static final String MNU_ACTUALIZE = "accept";
210 * Attach menu item name.
212 private static final String MNU_NAME_ATTACH = "menu.attach";
214 * Demote menu item name.
216 private static final String MNU_NAME_DEMOTE = "menu.demote";
218 * Promote menu item name.
220 private static final String MNU_NAME_PROMOTE = "menu.promote";
222 * Publish menu item name.
224 private static final String MNU_NAME_PUBLISH = "menu.publish";
226 * Protect menu item name.
228 private static final String MNU_NAME_PROTECT = "menu.protect";
230 * Edit menu item name.
232 private static final String MNU_NAME_EDIT = "menu.edit";
234 * Edit menu item name.
236 private static final String MNU_NAME_REMOVE = "menu.remove";
238 * Script menu item name.
240 private static final String MNU_NAME_SCRIPT = "menu.newscenario";
242 * Version menu item name.
244 private static final String MNU_NAME_VERSION = "menu.version";
246 * Purge menu item name.
248 // private static final String MNU_NAME_PURGE = "menu.purge";
250 * Remove menu item name.
252 private static final String MNU_NAME_REMOVE_VERSION = "menu.remove.version";
254 * Remove scenario menu item name.
256 private static final String MNU_NAME_REMOVE_SCENARIO = "menu.remove.scenario";
258 * Rename menu item name.
260 private static final String MNU_NAME_RENAME = "menu.rename";
262 * Mark as reference menu item name.
264 private static final String MNU_MARK_AS_REFERENCE = "markasreference";
266 * Mark as reference menu item label key.
268 private static final String MNU_NAME_MARK_AS_REFERENCE = "menu.markasreference";
270 * Remove as reference menu item label key.
272 private static final String MNU_NAME_REMOVE_AS_REFERENCE = "menu.removeasreference";
274 * Set up-to-date menu item label key.
276 private static final String MNU_NAME_ACTUALIZE = "menu.actualize";
278 // * Not yet implemented action name.
280 // private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented";
282 * Attach action name.
284 private static final String ACT_ATTACH = "select-file?nextAction=attach";
286 * Version action name.
288 private static final String ACT_VERSION = "select-file?nextAction=version";
290 * Mark as reference action name.
292 private static final String ACT_MARK_AS_REFERENCE = "markasref-study";
294 * Remove as reference action name.
296 private static final String ACT_REMOVE_AS_REFERENCE = "removeasref-study";
298 * Remove scenario action name.
300 private static final String ACT_REMOVE_SCENARIO = "remove-study";
302 * Promote the study action name.
304 private static final String ACT_PROMOTE_STUDY = "edit-study?action=promote";
306 * Set up-to-date action name.
308 private static final String ACT_ACTUALIZE = "setDocument?action=accept";
311 * Siman application server name.
313 private transient final String _wappserver;
315 * Current user locale.
317 private transient Locale _locale;
321 private transient final Map<String, SimpleMenu> _menus = new HashMap<String, SimpleMenu>();
323 * Study module-bars structured by steps.
325 private transient Map<Integer, ToolBar> _bars = null;
329 private transient Map<String, PopupMenu> _popups = null;
331 * Named search filters.
333 private transient Map<String, Map<String, Object>> _filter = null;
335 * Injected project settings service.
337 private ProjectSettingsService _projectSettings;
339 * Injected document type service.
341 private DocumentTypeService _documentTypeService;
344 * Application settings constructor.
346 public ApplicationSettings() {
347 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
348 .currentRequestAttributes()).getRequest();
349 _wappserver = curRequest.getServerName() + ":"
350 + curRequest.getServerPort();
352 LOG.info("Application server is set to " + _wappserver);
353 LOG.info("Application name is set to " + wappname);
357 * Get the projectSettingsService.
359 * @return the projectSettingsService
361 public ProjectSettingsService getProjectSettings() {
362 return _projectSettings;
366 * Set the projectSettingsService.
368 * @param projectSettingsService
369 * the projectSettingsService to set
371 public void setProjectSettings(
372 final ProjectSettingsService projectSettingsService) {
373 _projectSettings = projectSettingsService;
379 private static class NewMenu extends SimpleMenu {
381 * New study menu constructor.
385 addItem("new-empty", "menu.new.empty", "image.empty.png",
386 "select?menu=create&item=new-empty");
387 addItem("new-copy", "menu.new.copy", "image.copy.png",
388 "select?menu=create&item=new-copy");
390 * addItem("new-instance", new MenuItem("menu.new.instance") .icon(IMG_HOLD)); addItem("new-import", new
391 * MenuItem("menu.new.import") .icon("icon.upload.png"));
393 this.selects("new-empty");
400 private static class SearchMenu extends SimpleMenu {
402 * Search menu constructor.
404 private SearchMenu() {
406 addItem("search-study", "menu.search.study", "image.study.png",
407 "select?menu=search&item=search-study");
408 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
409 "select?menu=search&item=search-knowledge");
410 addItem("search-document", new MenuItem("menu.search.document")
411 .icon("icon.any.png"));
412 this.selects("search-study");
417 * Configuration menu.
419 private static class PropertiesMenu extends SimpleMenu {
421 * Configuration menu constructor.
423 private PropertiesMenu() {
424 super("configuration");
425 addItem("prop-general", "menu.prop.general", IMG_HOLD,
426 "select?menu=configuration&item=prop-general");
427 addItem("prop-scenario", "menu.prop.scenario", IMG_HOLD,
428 "select?menu=configuration&item=prop-scenario");
429 // These menu items will not be implemented in the current version.
431 * addItem("prop-timestamp", new MenuItem("menu.prop.timestamp") .icon("image.stamp.png")); addItem("prop-comlog", new
432 * MenuItem("menu.prop.comlog") .icon(IMG_HOLD)); addItem("prop-version", new MenuItem("menu.prop.version")
433 * .icon("image.dirclosed.png"));
439 * Data administrator menu.
441 private static class DatadminMenu extends SimpleMenu {
443 * Data administrator menu constructor.
445 private DatadminMenu() {
447 addItem("admin-scontext", "menu.admin.context", IMG_HOLD,
448 "select?menu=datadmin&item=admin-scontext");
449 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
450 "select?menu=datadmin&item=admin-knowelm");
451 addItem("admin-study", new MenuItem("menu.admin.study")
452 .icon("image.study.png"));
457 * System administrator menu.
459 private static class SysadminMenu extends SimpleMenu {
461 * System administrator menu constructor.
463 private SysadminMenu() {
465 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
466 "select?menu=sysadmin&item=admin-indexing");
467 addItem("admin-importuser", "menu.admin.importuser",
469 "select?menu=sysadmin&item=admin-importuser");
474 * Menu items enumeration.
482 * Accept the document.
486 * Approve the document.
490 * Promote the document.
494 * Demote the docuemnt.
498 * Undo the last operation.
502 * Rename the document.
506 * Attach a file to the document.
518 * Version the document.
530 * Remove the document.
538 * Mark the study as reference.
542 * Remove selected scenario.
547 // Resources relative to studies
549 * Base study popup menu.
551 private static class StudyPopup extends PopupMenu {
553 * User rights for the selected study.
555 protected transient StudyRights _user = null;
558 * Specifies if a scenario is selected, hence the "remove scenario" menu item can be enabled.
560 private boolean _scenarioSlected = false;
563 * Add items which are common for all study popup menus.
565 protected void addCommonItems() {
567 addItem(MNU_EDIT, new PopupItem("menu.properties").icon(
568 "icon.ed.png").action(
569 "../select.action?menu=configuration"));
571 addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT)
572 .action("add-scenario"));
574 * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
575 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
576 * PopupItem("menu.export") .icon("image.export.png")); // For future needs
578 addItem(Item.removescenario.toString(),
579 new PopupItem(MNU_NAME_REMOVE_SCENARIO)
580 .icon(IMG_DELETE).action("remove-scenario"/*"ACT_REMOVE_SCENARIO"*/)
581 .confirmation("message.delete.scenario"));
583 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
584 IMG_DELETE).action(ACT_REMOVE_SCENARIO).confirmation(
585 "message.delete.study"));
591 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
594 public boolean isEnabled(final String name) {
595 boolean res = (_user != null);
597 Item item = Item.valueOf(name);
600 if (_user.getOperand().getVisibility() == Visibility.PRIVATE) {
601 res = _user.canPublish();
603 res = _user.canProtect();
607 res = _user.canEditProperties();
610 res = _user.canAddScenario();
613 res = _user.canVersion();
616 res = _user.canRemove();
619 res = _user.canPromote();
622 res = _user.canDemote();
625 res = _user.canApprove();
627 case markasreference:
628 if (_user.getOperand().getMarkreference() == 0) {
629 res = _user.canMarkStudyAsReference();
631 res = _user.canRemoveStudyAsReference();
635 if(_scenarioSlected) {
636 res = _user.canRemoveScenario();
651 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
654 public void setContext(final String name, final Object context) {
655 if (context instanceof StudyRights) {
656 _user = (StudyRights) context; // Just for optimizing
657 boolean history = _user.getOperand().isVersioned();
658 PopupItem item = this.item(MNU_REMOVE);
660 item.rename(MNU_NAME_REMOVE_VERSION);
662 item.rename("menu.remove.study");
668 * Set the scenarioSlected.
669 * @param scenarioSlected the scenarioSlected to set
671 public StudyPopup setScenarioSlected(final boolean scenarioSlected) {
672 _scenarioSlected = scenarioSlected;
678 * Approved study popup menu.
680 private static class EditableMarkedStudyPopup extends StudyPopup {
683 * Study popup menu constructor.
688 * "marked as reference" study flag
690 private EditableMarkedStudyPopup(final boolean isPublic,
691 final boolean isMarked) {
695 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
696 MNU_NAME_REMOVE_AS_REFERENCE).action(
697 ACT_REMOVE_AS_REFERENCE).confirmation(
698 "message.removeasreference.study"));
700 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
701 MNU_NAME_MARK_AS_REFERENCE).action(
702 ACT_MARK_AS_REFERENCE).confirmation(
703 "message.markasreference.study"));
707 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PROTECT).icon(
709 .action("edit-study?action=protect").confirmation(
710 "message.protect.study"));
712 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon(
714 .action("edit-study?action=publish").confirmation(
715 "message.publish.study"));
724 * In-Work study popup menu.
726 private static class EditableStudyPopup extends StudyPopup {
728 * Study popup menu constructor.
730 private EditableStudyPopup() {
733 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
734 IMG_PROMOTE).action(ACT_PROMOTE_STUDY)
735 .confirmation("message.promote.study"));
742 * In-Work study popup menu.
744 private static class ReviewableStudyPopup extends StudyPopup {
746 * Study popup menu constructor.
748 private ReviewableStudyPopup() {
751 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
752 IMG_DEMOTE).action("edit-study?action=demote")
753 .confirmation("message.demote.study"));
754 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
755 "image.review.png").action(ACT_PROMOTE_STUDY)
756 .confirmation("message.review.study"));
763 * In-Work study popup menu.
765 private static class ApprovableStudyPopup extends StudyPopup {
767 * Study popup menu constructor.
769 private ApprovableStudyPopup() {
772 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
773 IMG_PROMOTE).action(ACT_PROMOTE_STUDY)
774 .confirmation("message.promote.study"));
776 addItem(MNU_DEMOTE, new PopupItem("menu.demote").icon(
777 IMG_DEMOTE).action("edit-study?action=demote")
778 .confirmation("message.demote.study"));
779 addItem("approve", new PopupItem("menu.approve").icon(
780 "icon.APPROVED.png").action(ACT_PROMOTE_STUDY)
781 .confirmation("message.approve.study"));
787 // Resources relative to documents
789 * Popup of a document.
791 private static class DocumentPopup extends PopupMenu {
793 * Current user rights.
795 private transient DocumentRights _user = null;
800 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
803 public boolean isEnabled(final String name) {
804 boolean res = (_user != null);
806 Item item = Item.valueOf(name);
809 res = _user.canAccept();
812 res = _user.canPromote();
815 res = _user.canRename();
818 res = _user.canAttach();
821 res = _user.canEdit();
824 res = _user.canVersion();
827 res = _user.canReplace();
830 res = _user.canRemove();
833 res = _user.canPurge();
836 res = _user.canInvalidate();
839 res = _user.canDemote();
842 res = _user.canApprove();
854 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
857 public void setContext(final String name, final Object context) {
858 if (context instanceof DocumentRights) {
859 _user = (DocumentRights) context; // Just for optimizing
860 Document downer = _user.getOperand();
861 if (this.hasItem(MNU_REMOVE)) {
862 if (downer.getPreviousVersion() == null) {
863 this.item(MNU_REMOVE).rename("menu.remove.document");
865 this.item(MNU_REMOVE).rename(MNU_NAME_REMOVE_VERSION);
872 * Add Actualize menu item.
874 protected void addActualize() {
875 addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE)
876 .icon(IMG_ACCEPT).action(ACT_ACTUALIZE)
877 .confirmation("message.actualize.document"));
880 * Add Review menu item.
882 protected void addReview() {
883 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
884 "image.review.png").action("setDocument?action=review")
885 .confirmation("message.review.document"));
888 * Add Demote menu item.
890 * indicates if the connected user is the author of the document.
892 protected void addDemote(final boolean author) {
895 itemName = MNU_NAME_DEMOTE;
897 itemName = "menu.reject";
899 addItem(MNU_DEMOTE, new PopupItem(itemName).icon(
900 IMG_DEMOTE).action("setDocument?action=demote")
901 .confirmation("message.demote.document"));
904 * Add Version menu item.
906 protected void addVersion() {
907 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
908 IMG_VERSION).action(ACT_VERSION));
911 * Add Attach menu item.
913 protected void addAttach() {
914 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
915 .action(ACT_ATTACH));
918 * Add Remove menu item.
920 protected void addRemove() {
921 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
922 IMG_DELETE).action("remove-document").confirmation(
923 "message.delete.document"));
926 * Add Approve menu item.
928 protected void addApprove() {
929 addItem("approve", new PopupItem("menu.approve").icon(
930 "icon.APPROVED.png").action("setDocument?action=approve")
931 .confirmation("message.approve.document"));
937 * Popup of In-Work documents.
939 private static class EditableDocumentPopup extends DocumentPopup {
941 * Document popup menu constructor.
943 private EditableDocumentPopup() {
945 addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE)
946 .icon(IMG_ACCEPT).action(ACT_ACTUALIZE)
947 .confirmation("message.actualize.document"));
948 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
949 IMG_PROMOTE).action("setDocument?action=promote")
950 .confirmation("message.promote.document"));
952 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
953 .action("edit-document?action=renameDocument"));
954 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
955 .action(ACT_ATTACH));
957 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
958 IMG_VERSION).action(ACT_VERSION));
959 addItem("replace", new PopupItem("menu.replace").icon(
960 "image.replace.png").action(
961 "select-file?nextAction=replace"));
964 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
966 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
967 IMG_DELETE).action("remove-document").confirmation(
968 "message.delete.document"));
973 * Popup of In-Draft documents when connected user is the author of the document.
975 private static class ReviewableDocumentPopupAuthor extends DocumentPopup {
977 * Document popup menu constructor.
979 private ReviewableDocumentPopupAuthor() {
981 addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE)
982 .icon(IMG_ACCEPT).action(ACT_ACTUALIZE)
983 .confirmation("message.actualize.document"));
984 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
985 IMG_DEMOTE).action("setDocument?action=demote")
986 .confirmation("message.demote.document"));
987 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
988 "image.review.png").action("setDocument?action=review")
989 .confirmation("message.review.document"));
991 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
992 .action(ACT_ATTACH));
994 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
995 IMG_VERSION).action(ACT_VERSION));
998 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
1004 * Popup of In-Draft documents when connected user is not the author of the document.
1006 private static class ReviewableDocumentPopupNonAuthor extends DocumentPopup {
1008 * Default constructor.
1010 private ReviewableDocumentPopupNonAuthor() {
1023 * Popup menu for documents which are not results of a step
1024 * when connected user is the author of the document.
1026 private static class NotResultDocumentPopupAuthor extends DocumentPopup {
1028 * Default constructor.
1030 private NotResultDocumentPopupAuthor() {
1032 addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE)
1033 .icon(IMG_ACCEPT).action(ACT_ACTUALIZE)
1034 .confirmation("message.actualize.document"));
1035 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
1036 IMG_DEMOTE).action("setDocument?action=demote")
1037 .confirmation("message.demote.document"));
1039 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
1040 .action(ACT_ATTACH));
1042 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
1043 IMG_VERSION).action(ACT_VERSION));
1046 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
1048 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
1049 IMG_DELETE).action("remove-document").confirmation(
1050 "message.delete.document"));
1055 * Popup menu for documents which are not results of a step
1056 * when connected user is not the author of the document.
1058 private static class NotResultDocumentPopupNonAuthor extends DocumentPopup {
1060 * Default constructor.
1062 private NotResultDocumentPopupNonAuthor() {
1076 * Popup of In-Check documents
1077 * when connected user is the author of the document.
1079 private static class ApprovableDocumentPopupAuthor extends DocumentPopup {
1081 * Default constructor.
1083 private ApprovableDocumentPopupAuthor() {
1085 addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE)
1086 .icon(IMG_ACCEPT).action(ACT_ACTUALIZE)
1087 .confirmation("message.actualize.document"));
1089 /*addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon(
1090 "image.invalidate.png").action(
1091 "setDocument?action=invalidate").confirmation(
1092 "message.demote.document"));*/
1093 addItem(MNU_DEMOTE, new PopupItem("menu.demote").icon(
1094 IMG_DEMOTE).action("setDocument?action=demote")
1095 .confirmation("message.demote.document"));
1096 addItem("approve", new PopupItem("menu.approve").icon(
1097 "icon.APPROVED.png").action("setDocument?action=approve")
1098 .confirmation("message.approve.document"));
1103 * Popup of In-Check documents
1104 * when connected user is not the author of the document.
1106 private static class ApprovableDocumentPopupNonAuthor extends DocumentPopup {
1108 * Default constructor.
1110 private ApprovableDocumentPopupNonAuthor() {
1119 * Popup of Approved documents.
1121 private static class ApprovedPopup extends DocumentPopup {
1123 * Default constructor.
1125 private ApprovedPopup() {
1127 addItem(MNU_ACTUALIZE, new PopupItem(MNU_NAME_ACTUALIZE)
1128 .icon(IMG_ACCEPT).action(ACT_ACTUALIZE)
1129 .confirmation("message.actualize.document"));
1130 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
1131 .action(ACT_ATTACH));
1133 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
1134 IMG_VERSION).action(ACT_VERSION));
1139 * Popup of external documents.
1141 private static class ExternPopup extends DocumentPopup {
1143 * Default constructor.
1145 private ExternPopup() {
1147 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
1148 .action("edit-document?action=renameDocument"));
1150 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
1151 IMG_VERSION).action(ACT_VERSION));
1153 addItem("replace", new PopupItem("menu.replace").icon(
1154 "image.replace.png").action(
1155 "select-file?nextAction=replace"));
1157 addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon(
1158 IMG_DELETE).action("remove-document").confirmation(
1159 "message.delete.document"));
1164 * Simulation context popup menu.
1166 private static class ScontextPopup extends PopupMenu {
1170 private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it.
1173 * Default constructor.
1175 private ScontextPopup() {
1177 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
1178 .action("edit-context?action=renameContext"));
1179 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
1180 .action("edit-context?action=editContext"));
1182 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1183 .action("remove-context").confirmation(
1184 "message.delete.context"));
1190 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
1193 public boolean isEnabled(final String name) {
1194 Item item = Item.valueOf(name);
1197 if (item == Item.rename) {
1199 } else if (item == Item.edit) {
1200 // if (!owner.isEditable())
1209 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
1212 public void setContext(final String name, final Object context) {
1213 if (context instanceof SimulationContextFacade) {
1214 _owner = (SimulationContextFacade) context; // Just for optimizing
1216 super.setContext(name, context);
1221 // Resources relative to knowledge
1223 * Knowledge element popup menu.
1225 private static class FeedbexPopup extends PopupMenu {
1228 * Popup menu owner object.
1230 protected transient KnowledgeElement _owner = null;
1233 * Default constructor.
1235 private FeedbexPopup() {
1237 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
1238 .action("edit-knowledge?action=renameKnowledge"));
1239 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
1240 .action("edit-knowledge?action=editKnowledge"));
1242 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1243 .action("remove-knowledge").confirmation(
1244 "message.delete.knowledge"));
1250 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
1253 public boolean isEnabled(final String name) {
1261 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
1264 public void setContext(final String name, final Object context) {
1265 if (context instanceof KnowledgeElement) {
1266 _owner = (KnowledgeElement) context; // Just for optimizing
1268 super.setContext(name, context);
1274 * Pop-up menu for comments.
1276 private static class CommentPopup extends PopupMenu {
1278 * Default constructor.
1280 private CommentPopup() {
1282 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1283 .action("editComment(entity_index)"));
1284 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1285 .action("removeComment(entity_index)").confirmation(
1286 "message.delete.comment"));
1297 public boolean isEnabled(final String name) {
1303 * Pop-up menu for comments.
1305 private static class DescritptionPopup extends PopupMenu {
1307 * Default constructor.
1309 private DescritptionPopup() {
1311 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1312 .action("showDescriptionEditor()"));
1313 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1314 .action("removeDescription()").confirmation(
1315 "message.delete.description"));
1326 public boolean isEnabled(final String name) {
1331 // ==============================================================================================================================
1333 // ==============================================================================================================================
1335 // ==============================================================================================================================
1336 // Public member functions
1337 // ==============================================================================================================================
1340 * Initialize application menus.
1342 public void configure() {
1343 // Non customizable settings
1345 SimpleMenu menu = new NewMenu();
1346 _menus.put(menu.getName(), menu);
1347 menu = new SearchMenu();
1348 _menus.put(menu.getName(), menu);
1349 menu = new DatadminMenu();
1350 _menus.put(menu.getName(), menu);
1351 menu = new SysadminMenu();
1352 _menus.put(menu.getName(), menu);
1353 menu = new PropertiesMenu();
1354 _menus.put(menu.getName(), menu);
1356 _popups = new HashMap<String, PopupMenu>();
1357 _popups.put("steditablemarkpublic", new EditableMarkedStudyPopup(false,
1359 _popups.put("steditableunmarkpublic", new EditableMarkedStudyPopup(
1361 _popups.put("steditablemarkprivate", new EditableMarkedStudyPopup(true,
1363 _popups.put("steditableunmarkprivate", new EditableMarkedStudyPopup(
1365 _popups.put("steditable", new EditableStudyPopup());
1366 _popups.put("streviewable", new ReviewableStudyPopup());
1367 _popups.put("stapprovable", new ApprovableStudyPopup());
1369 _popups.put("steditablemarkpublicScenarioSelected",
1370 new EditableMarkedStudyPopup(false, false).setScenarioSlected(true));
1371 _popups.put("steditableScenarioSelected", new EditableStudyPopup().setScenarioSlected(true));
1372 _popups.put("streviewableScenarioSelected", new ReviewableStudyPopup().setScenarioSlected(true));
1373 _popups.put("stapprovableScenarioSelected", new ApprovableStudyPopup().setScenarioSlected(true));
1375 _popups.put("editable", new EditableDocumentPopup());
1376 _popups.put("notresult", new NotResultDocumentPopupAuthor());
1377 _popups.put("reviewable", new ReviewableDocumentPopupAuthor());
1378 _popups.put("approvable", new ApprovableDocumentPopupAuthor());
1379 _popups.put("notresultNonAuthor", new NotResultDocumentPopupNonAuthor());
1380 _popups.put("reviewableNonAuthor", new ReviewableDocumentPopupNonAuthor());
1381 _popups.put("approvableNonAuthor", new ApprovableDocumentPopupNonAuthor());
1382 _popups.put("approved", new ApprovedPopup());
1383 _popups.put("extern", new ExternPopup());
1384 _popups.put("scontext", new ScontextPopup());
1385 _popups.put("feedbex", new FeedbexPopup());
1386 _popups.put("comment", new CommentPopup());
1387 _popups.put("description", new DescritptionPopup());
1389 // Default customizable mandatory settings
1390 Map<String, Object> fprop = new HashMap<String, Object>();
1391 fprop.put("visibility", "PRIVATE");
1392 fprop.put("matchamong", ALL);
1393 fprop.put("matcontext", ALL);
1394 fprop.put("state", "APPROVED");
1395 fprop.put("author", "0");
1396 fprop.put("reference", "");
1397 fprop.put("title", "");
1398 fprop.put("context", new ArrayList<SimulationContext>());
1400 Map<String, Object> gprop = new HashMap<String, Object>();
1401 gprop.put("visibility", "PUBLIC");
1402 gprop.put("matchamong", ALL);
1403 gprop.put("matcontext", ALL);
1404 gprop.put("type", "2"); // TODO: Get the index from the type name
1405 gprop.put("author", "0");
1406 gprop.put("reference", "");
1407 gprop.put("title", "");
1408 gprop.put("context", new ArrayList<SimulationContext>());
1410 _filter = new HashMap<String, Map<String, Object>>();
1411 _filter.put("study", fprop);
1412 _filter.put("knowledge", gprop);
1414 // Settings based on the customization
1415 configureToolbars();
1419 * Configure toolbars for steps.
1421 private void configureToolbars() {
1422 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
1424 List<ProjectSettingsService.Step> steps = getProjectSettings()
1426 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
1428 ProjectSettingsService.Step step = i.next();
1429 List<String> formats = getProjectSettings().getDefaultFormats(step);
1430 if (formats.isEmpty()) {
1434 ToolBar bar = new ToolBar(24); // Height of the module-bar
1435 Set<String> module = new HashSet<String>(); // For not duplicating modules
1436 for (String format : formats) {
1437 String command = getApplicationProperty("executable." + format);
1438 if (command == null) {
1439 continue; // Module not installed
1441 if (module.contains(command)) {
1444 module.add(command);
1445 String[] parsed = command.split("/");
1446 String[] name = parsed[parsed.length - 1].split("\\x2E");
1447 DocumentType dtype = getProjectSettings()
1448 .getDefaultDocumentType(step, format);
1449 String docname = "";
1450 if (dtype != null) {
1451 docname = dtype.getName();
1453 if (tempfile.get(docname) == null) { // No available template
1454 String tool = parsed[parsed.length - 1];
1455 String icon = name[0];
1456 if ("index".equals(icon)) {
1457 tool = parsed[parsed.length - 2];
1458 icon = "tool." + tool.toLowerCase() + ".png";
1460 icon = "tool." + icon.toLowerCase() + ".png";
1462 File image = new File(ApplicationSettings
1463 .getApplicationSkinPath()
1465 if (!image.exists()) {
1466 icon = "tool.any.png";
1468 bar.addTool(tool, icon, command);
1470 docname = "/jsp/newDocument.jsp?type=" + docname;
1471 String icon = "tool." + name[0].toLowerCase() + ".png";
1472 File image = new File(ApplicationSettings
1473 .getApplicationSkinPath()
1475 if (!image.exists()) {
1476 icon = "tool.any.png";
1478 bar.addTool(name[0], icon, command, docname);
1481 if (!bar.isEmpty()) {
1482 _bars.put(step.getNumber(), bar);
1487 public static String getApplicationProperty(final String name) {
1488 return _WAPPROPS.getProperty(name); // May be null
1491 public static String getApplicationRootPath() {
1492 // The property is supposed including the Web application name
1496 public String getApplicationURL() {
1497 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1498 .append("/").append(wappname);
1499 return url.toString();
1502 public Map<String, Object> getFilter(final String name) {
1503 return _filter.get(name);
1506 public ToolBar getModuleBar(final Step step) {
1507 return _bars.get(step.getNumber());
1510 static public Properties getNamingProperties() {
1514 // ==============================================================================================================================
1516 // ==============================================================================================================================
1518 public static String getApplicationPluginPath() {
1519 return getApplicationRootPath() + "plugin/";
1522 public static String getApplicationResourcePath() {
1523 return getApplicationRootPath() + "WEB-INF/classes/";
1526 public static String getApplicationSkinPath() {
1527 return getApplicationRootPath() + "skin/";
1530 public static Converter getConverter(final DocumentType type,
1531 final String format) {
1532 return convertmap.get(format + type.getName()); // May be null;
1536 * Get default document type for the given format on the given study step.
1542 * @return default document type or null if not defined in the configuration
1544 public DocumentType getDefaultDocumentType(final Step step,
1545 final String format) {
1546 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1547 format); // May be null
1550 public String getDownloadURL(final User user) {
1551 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1552 .append("/download/").append(user.getUsername()).append("/");
1553 return url.toString(); // The download Tomcat context is supposed being defined
1556 public Locale getCurrentLocale() {
1560 public SimpleMenu getMenu(final String name) {
1561 return _menus.get(name);
1564 public PopupMenu getPopupMenu(final String name) {
1565 return _popups.get(name);
1568 public String getRepositoryURL() {
1569 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1570 .append("/repository/");
1571 return url.toString(); // The repository Tomcat context is supposed being defined
1574 public static Locale[] getSupportedLocales() {
1575 String[] code = _WAPPROPS.getProperty("locale.supported").split(",");
1576 Locale[] result = new Locale[code.length];
1577 for (int i = 0; i < code.length; i++) {
1578 result[i] = new Locale(code[i]);
1583 public static String[] getViewersMapping() {
1587 public static String getWebSiteURL() {
1588 return getApplicationProperty("wapp.website");
1591 public static String getHelpURL() {
1592 return getApplicationProperty("wapp.onlinehelp");
1595 // ==============================================================================================================================
1597 // ==============================================================================================================================
1600 * Load application custom configuration from the given XML file (see conf/my.xml).
1603 * the XML configuration file
1605 private static void loadCustomization(final File config) {
1607 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1609 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1611 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1612 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1613 .getDocumentElement());
1616 loadModules(children);
1619 loadConverters(children);
1622 loadTemplates(children);
1623 } catch (Exception error) {
1624 LOG.info("Error in customization", error);
1629 * Load modules from XML configuration.
1634 private static void loadModules(final Map<String, Node> children) {
1635 Node child = children.get("modules");
1636 NodeList nlist = child.getChildNodes();
1637 for (int i = 0; i < nlist.getLength(); i++) {
1638 child = nlist.item(i);
1639 if (!child.getNodeName().equals("mapping")) {
1643 NamedNodeMap natr = child.getAttributes();
1644 String dext = natr.getNamedItem("extension").getNodeValue();
1645 String exec = natr.getNamedItem("executable").getNodeValue();
1646 _WAPPROPS.put("executable." + dext, exec);
1648 // Viewer mappings tag
1649 child = children.get("viewers");
1650 viewermap = child.getAttributes().getNamedItem("extension")
1651 .getNodeValue().split(",");
1655 * Load converters from XML configuration.
1660 private static void loadConverters(final Map<String, Node> children) {
1661 Node child = children.get("converters");
1662 NodeList nlist = child.getChildNodes();
1663 for (int i = 0; i < nlist.getLength(); i++) {
1664 child = nlist.item(i);
1666 if (child.getNodeName().equals("geometry")) {
1667 NamedNodeMap natr = child.getAttributes();
1668 String from = natr.getNamedItem("from").getNodeValue();
1669 String to = natr.getNamedItem("to").getNodeValue();
1670 String exec = natr.getNamedItem("executable").getNodeValue();
1671 convertmap.put(from + "geometry", new Converter("geometry",
1678 * Load templates from XML configuration.
1683 private static void loadTemplates(final Map<String, Node> children) {
1684 Node child = children.get("templates");
1685 NodeList nlist = child.getChildNodes();
1686 for (int i = 0; i < nlist.getLength(); i++) {
1687 child = nlist.item(i);
1688 if (!child.getNodeName().equals("document")) {
1692 NamedNodeMap natr = child.getAttributes();
1693 String type = natr.getNamedItem("type").getNodeValue();
1694 String file = natr.getNamedItem("file").getNodeValue();
1695 tempfile.put(type, file);
1700 * Get the documentTypeService.
1702 * @return the documentTypeService
1704 public DocumentTypeService getDocumentTypeService() {
1705 return _documentTypeService;
1709 * Set the documentTypeService.
1711 * @param documentTypeService
1712 * the documentTypeService to set
1714 public void setDocumentTypeService(
1715 final DocumentTypeService documentTypeService) {
1716 _documentTypeService = documentTypeService;
1722 * @return the locale
1724 public Locale getLocale() {
1734 public void setLocale(final Locale locale) {