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";
161 * Attach menu item name.
163 private static final String MNU_ATTACH = "attach";
165 * Demote menu item name.
167 private static final String MNU_DEMOTE = "demote";
169 * Promote menu item name.
171 private static final String MNU_PROMOTE = "promote";
173 * Publish menu item name.
175 private static final String MNU_PUBLISH = "publish";
177 * Edit menu item name.
179 private static final String MNU_EDIT = "edit";
181 * Script menu item name.
183 private static final String MNU_SCRIPT = "script";
185 * Version menu item name.
187 private static final String MNU_VERSION = "version";
189 // * Purge menu item name.
191 // private static final String MNU_PURGE = "purge";
193 * Remove menu item name.
195 private static final String MNU_REMOVE = "remove";
197 * Rename menu item name.
199 private static final String MNU_RENAME = "rename";
202 * Attach menu item name.
204 private static final String MNU_NAME_ATTACH = "menu.attach";
206 * Demote menu item name.
208 private static final String MNU_NAME_DEMOTE = "menu.demote";
210 * Promote menu item name.
212 private static final String MNU_NAME_PROMOTE = "menu.promote";
214 * Publish menu item name.
216 private static final String MNU_NAME_PUBLISH = "menu.publish";
218 * Protect menu item name.
220 private static final String MNU_NAME_PROTECT = "menu.protect";
222 * Edit menu item name.
224 private static final String MNU_NAME_EDIT = "menu.edit";
226 * Edit menu item name.
228 private static final String MNU_NAME_REMOVE = "menu.remove";
230 * Script menu item name.
232 private static final String MNU_NAME_SCRIPT = "menu.newscenario";
234 * Version menu item name.
236 private static final String MNU_NAME_VERSION = "menu.version";
238 * Purge menu item name.
240 // private static final String MNU_NAME_PURGE = "menu.purge";
242 * Remove menu item name.
244 private static final String MNU_NAME_REMOVE_VERSION = "menu.remove.version";
246 * Rename menu item name.
248 private static final String MNU_NAME_RENAME = "menu.rename";
250 * Mark as reference menu item name.
252 private static final String MNU_MARK_AS_REFERENCE = "markasreference";
254 * Mark as reference menu item label key.
256 private static final String MNU_NAME_MARK_AS_REFERENCE = "menu.markasreference";
258 * Remove as reference menu item label key.
260 private static final String MNU_NAME_REMOVE_AS_REFERENCE = "menu.removeasreference";
262 // * Not yet implemented action name.
264 // private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented";
266 * Attach action name.
268 private static final String ACT_ATTACH = "select-file?nextAction=attach";
270 * Version action name.
272 private static final String ACT_VERSION = "select-file?nextAction=version";
274 * Mark as reference action name.
276 private static final String ACT_MARK_AS_REFERENCE = "markasref-study";
278 * Remove as reference action name.
280 private static final String ACT_REMOVE_AS_REFERENCE = "removeasref-study";
282 * Promote the study action name.
284 private static final String ACT_PROMOTE_STUDY = "edit-study?action=promote";
287 * Siman application server name.
289 private transient final String _wappserver;
291 * Current user locale.
293 private transient Locale _locale;
297 private transient final Map<String, SimpleMenu> _menus = new HashMap<String, SimpleMenu>();
299 * Study module-bars structured by steps.
301 private transient Map<Integer, ToolBar> _bars = null;
305 private transient Map<String, PopupMenu> _popups = null;
307 * Named search filters.
309 private transient Map<String, Map<String, Object>> _filter = null;
311 * Injected project settings service.
313 private ProjectSettingsService _projectSettings;
315 * Injected document type service.
317 private DocumentTypeService _documentTypeService;
320 * Application settings constructor.
322 public ApplicationSettings() {
323 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
324 .currentRequestAttributes()).getRequest();
325 _wappserver = curRequest.getServerName() + ":"
326 + curRequest.getServerPort();
328 LOG.info("Application server is set to " + _wappserver);
329 LOG.info("Application name is set to " + wappname);
333 * Get the projectSettingsService.
335 * @return the projectSettingsService
337 public ProjectSettingsService getProjectSettings() {
338 return _projectSettings;
342 * Set the projectSettingsService.
344 * @param projectSettingsService
345 * the projectSettingsService to set
347 public void setProjectSettings(
348 final ProjectSettingsService projectSettingsService) {
349 _projectSettings = projectSettingsService;
355 private static class NewMenu extends SimpleMenu {
357 * New study menu constructor.
361 addItem("new-empty", "menu.new.empty", "image.empty.png",
362 "select?menu=create&item=new-empty");
363 addItem("new-copy", "menu.new.copy", "image.copy.png",
364 "select?menu=create&item=new-copy");
366 * addItem("new-instance", new MenuItem("menu.new.instance") .icon(IMG_HOLD)); addItem("new-import", new
367 * MenuItem("menu.new.import") .icon("icon.upload.png"));
369 this.selects("new-empty");
376 private static class SearchMenu extends SimpleMenu {
378 * Search menu constructor.
380 private SearchMenu() {
382 addItem("search-study", "menu.search.study", "image.study.png",
383 "select?menu=search&item=search-study");
384 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
385 "select?menu=search&item=search-knowledge");
386 addItem("search-document", new MenuItem("menu.search.document")
387 .icon("icon.any.png"));
388 this.selects("search-study");
393 * Configuration menu.
395 private static class PropertiesMenu extends SimpleMenu {
397 * Configuration menu constructor.
399 private PropertiesMenu() {
400 super("configuration");
401 addItem("prop-general", "menu.prop.general", IMG_HOLD,
402 "select?menu=configuration&item=prop-general");
403 addItem("prop-scenario", "menu.prop.scenario", IMG_HOLD,
404 "select?menu=configuration&item=prop-scenario");
405 // These menu items will not be implemented in the current version.
407 * addItem("prop-timestamp", new MenuItem("menu.prop.timestamp") .icon("image.stamp.png")); addItem("prop-comlog", new
408 * MenuItem("menu.prop.comlog") .icon(IMG_HOLD)); addItem("prop-version", new MenuItem("menu.prop.version")
409 * .icon("image.dirclosed.png"));
415 * Data administrator menu.
417 private static class DatadminMenu extends SimpleMenu {
419 * Data administrator menu constructor.
421 private DatadminMenu() {
423 addItem("admin-scontext", "menu.admin.context", IMG_HOLD,
424 "select?menu=datadmin&item=admin-scontext");
425 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
426 "select?menu=datadmin&item=admin-knowelm");
427 addItem("admin-study", new MenuItem("menu.admin.study")
428 .icon("image.study.png"));
433 * System administrator menu.
435 private static class SysadminMenu extends SimpleMenu {
437 * System administrator menu constructor.
439 private SysadminMenu() {
441 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
442 "select?menu=sysadmin&item=admin-indexing");
443 addItem("admin-importuser", "menu.admin.importuser",
445 "select?menu=sysadmin&item=admin-importuser");
450 * Menu items enumeration.
458 * Accept the document.
462 * Approve the document.
466 * Promote the document.
470 * Demote the docuemnt.
474 * Undo the last operation.
478 * Rename the document.
482 * Attach a file to the document.
494 * Version the document.
506 * Remove the document.
514 * Mark the study as reference.
519 // Resources relative to studies
521 * Base study popup menu.
523 private static class StudyPopup extends PopupMenu {
525 * User rights for the selected study.
527 protected transient StudyRights _user = null;
530 * Add items which are common for all study popup menus.
532 protected void addCommonItems() {
534 addItem(MNU_EDIT, new PopupItem("menu.properties").icon(
535 "icon.ed.png").action(
536 "../select?menu=configuration&item=prop-general"));
538 addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT)
539 .action("add-scenario"));
541 * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
545 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
546 * PopupItem("menu.export") .icon("image.export.png")); // For future needs
547 */addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
548 IMG_DELETE).action("remove-study").confirmation(
549 "message.delete.study"));
555 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
558 public boolean isEnabled(final String name) {
559 boolean res = (_user != null);
561 Item item = Item.valueOf(name);
564 if (_user.getOperand().getVisibility() == Visibility.PRIVATE) {
565 res = _user.canPublish();
567 res = _user.canProtect();
571 res = _user.canEditProperties();
574 res = _user.canAddScenario();
577 res = _user.canVersion();
580 res = _user.canRemove();
583 res = _user.canPromote();
586 res = _user.canDemote();
589 res = _user.canApprove();
591 case markasreference:
592 if (_user.getOperand().getMarkreference() == 0) {
593 res = _user.canMarkStudyAsReference();
595 res = _user.canRemoveStudyAsReference();
608 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
611 public void setContext(final String name, final Object context) {
612 if (context instanceof StudyRights) {
613 _user = (StudyRights) context; // Just for optimizing
614 boolean history = _user.getOperand().isVersioned();
615 PopupItem item = this.item(MNU_REMOVE);
617 item.rename(MNU_NAME_REMOVE_VERSION);
619 item.rename("menu.remove.study");
626 * Approved study popup menu.
628 private static class EditableMarkedStudyPopup extends StudyPopup {
631 * Study popup menu constructor.
636 * "marked as reference" study flag
638 private EditableMarkedStudyPopup(final boolean isPublic,
639 final boolean isMarked) {
643 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
644 MNU_NAME_REMOVE_AS_REFERENCE).action(
645 ACT_REMOVE_AS_REFERENCE).confirmation(
646 "message.removeasreference.study"));
648 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
649 MNU_NAME_MARK_AS_REFERENCE).action(
650 ACT_MARK_AS_REFERENCE).confirmation(
651 "message.markasreference.study"));
655 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PROTECT).icon(
657 .action("edit-study?action=protect").confirmation(
658 "message.protect.study"));
660 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon(
662 .action("edit-study?action=publish").confirmation(
663 "message.publish.study"));
672 * In-Work study popup menu.
674 private static class EditableStudyPopup extends StudyPopup {
676 * Study popup menu constructor.
678 private EditableStudyPopup() {
681 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
682 IMG_PROMOTE).action(ACT_PROMOTE_STUDY)
683 .confirmation("message.promote.study"));
690 * In-Work study popup menu.
692 private static class ReviewableStudyPopup extends StudyPopup {
694 * Study popup menu constructor.
696 private ReviewableStudyPopup() {
699 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
700 IMG_DEMOTE).action("edit-study?action=demote")
701 .confirmation("message.demote.study"));
702 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
703 "image.review.png").action(ACT_PROMOTE_STUDY)
704 .confirmation("message.review.study"));
711 * In-Work study popup menu.
713 private static class ApprovableStudyPopup extends StudyPopup {
715 * Study popup menu constructor.
717 private ApprovableStudyPopup() {
720 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
721 IMG_PROMOTE).action(ACT_PROMOTE_STUDY)
722 .confirmation("message.promote.study"));
724 addItem(MNU_DEMOTE, new PopupItem("menu.disapprove").icon(
725 IMG_DEMOTE).action("edit-study?action=demote")
726 .confirmation("message.disapprove.study"));
727 addItem("approve", new PopupItem("menu.approve").icon(
728 "icon.APPROVED.png").action(ACT_PROMOTE_STUDY)
729 .confirmation("message.approve.study"));
735 // Resources relative to documents
737 * Popup of a document.
739 private static class DocumentPopup extends PopupMenu {
741 * Current user rights.
743 private transient DocumentRights _user = null;
748 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
751 public boolean isEnabled(final String name) {
752 boolean res = (_user != null);
754 Item item = Item.valueOf(name);
757 res = _user.canAccept();
760 res = _user.canPromote();
763 res = _user.canRename();
766 res = _user.canAttach();
769 res = _user.canEdit();
772 res = _user.canVersion();
775 res = _user.canReplace();
778 res = _user.canRemove();
781 res = _user.canPurge();
784 res = _user.canInvalidate();
787 res = _user.canDemote();
790 res = _user.canApprove();
802 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
805 public void setContext(final String name, final Object context) {
806 if (context instanceof DocumentRights) {
807 _user = (DocumentRights) context; // Just for optimizing
808 Document downer = _user.getOperand();
809 if (this.hasItem(MNU_REMOVE)) {
810 if (downer.getPreviousVersion() == null) {
811 this.item(MNU_REMOVE).rename("menu.remove.document");
813 this.item(MNU_REMOVE).rename(MNU_NAME_REMOVE_VERSION);
821 * Popup of In-Work documents.
823 private static class EditableDocumentPopup extends DocumentPopup {
825 * Document popup menu constructor.
827 private EditableDocumentPopup() {
830 * addItem("accept", new PopupItem("menu.accept").icon( "image.accept.png").action("setDocument?action=accept")
831 * .confirmation("message.accept.document"));
833 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
834 IMG_PROMOTE).action("setDocument?action=promote")
835 .confirmation("message.promote.document"));
837 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
838 .action("edit-document?action=renameDocument"));
839 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
840 .action(ACT_ATTACH));
842 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
843 IMG_VERSION).action(ACT_VERSION));
844 addItem("replace", new PopupItem("menu.replace").icon(
845 "image.replace.png").action(
846 "select-file?nextAction=replace"));
849 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
851 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
852 IMG_DELETE).action("remove-document").confirmation(
853 "message.delete.document"));
858 * Popup of In-Draft documents.
860 private static class ReviewableDocumentPopup extends DocumentPopup {
862 * Document popup menu constructor.
864 private ReviewableDocumentPopup() {
866 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
867 IMG_DEMOTE).action("setDocument?action=demote")
868 .confirmation("message.demote.document"));
869 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
870 "image.review.png").action("setDocument?action=review")
871 .confirmation("message.review.document"));
873 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
874 .action(ACT_ATTACH));
876 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
877 IMG_VERSION).action(ACT_VERSION));
880 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
886 * Popup menu for documents which are not results of a step.
888 private static class NotResultDocumentPopup extends DocumentPopup {
890 * Default constructor.
892 private NotResultDocumentPopup() {
894 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
895 IMG_DEMOTE).action("setDocument?action=demote")
896 .confirmation("message.demote.document"));
898 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
899 .action(ACT_ATTACH));
901 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
902 IMG_VERSION).action(ACT_VERSION));
905 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action( ACT_NOT_YET_IMPLEMENTED).confirmation( "message.purge.document"));
907 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
908 IMG_DELETE).action("remove-document").confirmation(
909 "message.delete.document"));
914 * Popup of In-Check documents.
916 private static class ApprovableDocumentPopup extends DocumentPopup {
918 * Default constructor.
920 private ApprovableDocumentPopup() {
922 addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon(
923 "image.invalidate.png").action(
924 "setDocument?action=invalidate").confirmation(
925 "message.demote.document"));
926 addItem(MNU_DEMOTE, new PopupItem("menu.disapprove").icon(
927 IMG_DEMOTE).action("setDocument?action=disapprove")
928 .confirmation("message.disapprove.document"));
929 addItem("approve", new PopupItem("menu.approve").icon(
930 "icon.APPROVED.png").action("setDocument?action=approve")
931 .confirmation("message.approve.document"));
936 * Popup of Approved documents.
938 private static class ApprovedPopup extends DocumentPopup {
940 * Default constructor.
942 private ApprovedPopup() {
944 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
945 .action(ACT_ATTACH));
947 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
948 IMG_VERSION).action(ACT_VERSION));
953 * Popup of external documents.
955 private static class ExternPopup extends DocumentPopup {
957 * Default constructor.
959 private ExternPopup() {
961 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
962 .action("edit-document?action=renameDocument"));
964 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
965 IMG_VERSION).action(ACT_VERSION));
967 addItem("replace", new PopupItem("menu.replace").icon(
968 "image.replace.png").action(
969 "select-file?nextAction=replace"));
971 addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon(
972 IMG_DELETE).action("remove-document").confirmation(
973 "message.delete.document"));
978 * Simulation context popup menu.
980 private static class ScontextPopup extends PopupMenu {
984 private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it.
987 * Default constructor.
989 private ScontextPopup() {
991 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
992 .action("edit-context?action=renameContext"));
993 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
994 .action("edit-context?action=editContext"));
996 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
997 .action("remove-context").confirmation(
998 "message.delete.context"));
1004 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
1007 public boolean isEnabled(final String name) {
1008 Item item = Item.valueOf(name);
1011 if (item == Item.rename) {
1013 } else if (item == Item.edit) {
1014 // if (!owner.isEditable())
1023 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
1026 public void setContext(final String name, final Object context) {
1027 if (context instanceof SimulationContextFacade) {
1028 _owner = (SimulationContextFacade) context; // Just for optimizing
1030 super.setContext(name, context);
1035 // Resources relative to knowledge
1037 * Knowledge element popup menu.
1039 private static class FeedbexPopup extends PopupMenu {
1042 * Popup menu owner object.
1044 protected transient KnowledgeElement _owner = null;
1047 * Default constructor.
1049 private FeedbexPopup() {
1051 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
1052 .action("edit-knowledge?action=renameKnowledge"));
1053 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
1054 .action("edit-knowledge?action=editKnowledge"));
1056 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1057 .action("remove-knowledge").confirmation(
1058 "message.delete.knowledge"));
1064 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
1067 public boolean isEnabled(final String name) {
1075 * @see org.splat.wapp.ContextualMenu#setContext(java.lang.String, java.lang.Object)
1078 public void setContext(final String name, final Object context) {
1079 if (context instanceof KnowledgeElement) {
1080 _owner = (KnowledgeElement) context; // Just for optimizing
1082 super.setContext(name, context);
1088 * Pop-up menu for comments.
1090 private static class CommentPopup extends PopupMenu {
1092 * Default constructor.
1094 private CommentPopup() {
1096 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1097 .action("editComment(entity_index)"));
1098 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1099 .action("removeComment(entity_index)").confirmation(
1100 "message.delete.comment"));
1111 public boolean isEnabled(final String name) {
1117 * Pop-up menu for comments.
1119 private static class DescritptionPopup extends PopupMenu {
1121 * Default constructor.
1123 private DescritptionPopup() {
1125 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1126 .action("showDescriptionEditor()"));
1127 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1128 .action("removeDescription()").confirmation(
1129 "message.delete.description"));
1140 public boolean isEnabled(final String name) {
1145 // ==============================================================================================================================
1147 // ==============================================================================================================================
1149 // ==============================================================================================================================
1150 // Public member functions
1151 // ==============================================================================================================================
1154 * Initialize application menus.
1156 public void configure() {
1157 // Non customizable settings
1159 SimpleMenu menu = new NewMenu();
1160 _menus.put(menu.getName(), menu);
1161 menu = new SearchMenu();
1162 _menus.put(menu.getName(), menu);
1163 menu = new DatadminMenu();
1164 _menus.put(menu.getName(), menu);
1165 menu = new SysadminMenu();
1166 _menus.put(menu.getName(), menu);
1167 menu = new PropertiesMenu();
1168 _menus.put(menu.getName(), menu);
1170 _popups = new HashMap<String, PopupMenu>();
1171 _popups.put("steditablemarkpublic", new EditableMarkedStudyPopup(false,
1173 _popups.put("steditableunmarkpublic", new EditableMarkedStudyPopup(
1175 _popups.put("steditablemarkprivate", new EditableMarkedStudyPopup(true,
1177 _popups.put("steditableunmarkprivate", new EditableMarkedStudyPopup(
1179 _popups.put("steditable", new EditableStudyPopup());
1180 _popups.put("streviewable", new ReviewableStudyPopup());
1181 _popups.put("stapprovable", new ApprovableStudyPopup());
1183 _popups.put("editable", new EditableDocumentPopup());
1184 _popups.put("notresult", new NotResultDocumentPopup());
1185 _popups.put("reviewable", new ReviewableDocumentPopup());
1186 _popups.put("approvable", new ApprovableDocumentPopup());
1187 _popups.put("approved", new ApprovedPopup());
1188 _popups.put("extern", new ExternPopup());
1189 _popups.put("scontext", new ScontextPopup());
1190 _popups.put("feedbex", new FeedbexPopup());
1191 _popups.put("comment", new CommentPopup());
1192 _popups.put("description", new DescritptionPopup());
1194 // Default customizable mandatory settings
1195 Map<String, Object> fprop = new HashMap<String, Object>();
1196 fprop.put("visibility", "PRIVATE");
1197 fprop.put("matchamong", ALL);
1198 fprop.put("matcontext", ALL);
1199 fprop.put("state", "APPROVED");
1200 fprop.put("author", "0");
1201 fprop.put("reference", "");
1202 fprop.put("title", "");
1203 fprop.put("context", new ArrayList<SimulationContext>());
1205 Map<String, Object> gprop = new HashMap<String, Object>();
1206 gprop.put("visibility", "PUBLIC");
1207 gprop.put("matchamong", ALL);
1208 gprop.put("matcontext", ALL);
1209 gprop.put("type", "2"); // TODO: Get the index from the type name
1210 gprop.put("author", "0");
1211 gprop.put("reference", "");
1212 gprop.put("title", "");
1213 gprop.put("context", new ArrayList<SimulationContext>());
1215 _filter = new HashMap<String, Map<String, Object>>();
1216 _filter.put("study", fprop);
1217 _filter.put("knowledge", gprop);
1219 // Settings based on the customization
1220 configureToolbars();
1224 * Configure toolbars for steps.
1226 private void configureToolbars() {
1227 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
1229 List<ProjectSettingsService.Step> steps = getProjectSettings()
1231 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
1233 ProjectSettingsService.Step step = i.next();
1234 List<String> formats = getProjectSettings().getDefaultFormats(step);
1235 if (formats.isEmpty()) {
1239 ToolBar bar = new ToolBar(24); // Height of the module-bar
1240 Set<String> module = new HashSet<String>(); // For not duplicating modules
1241 for (String format : formats) {
1242 String command = getApplicationProperty("executable." + format);
1243 if (command == null) {
1244 continue; // Module not installed
1246 if (module.contains(command)) {
1249 module.add(command);
1250 String[] parsed = command.split("/");
1251 String[] name = parsed[parsed.length - 1].split("\\x2E");
1252 DocumentType dtype = getProjectSettings()
1253 .getDefaultDocumentType(step, format);
1254 String docname = "";
1255 if (dtype != null) {
1256 docname = dtype.getName();
1258 if (tempfile.get(docname) == null) { // No available template
1259 String tool = parsed[parsed.length - 1];
1260 String icon = name[0];
1261 if ("index".equals(icon)) {
1262 tool = parsed[parsed.length - 2];
1263 icon = "tool." + tool.toLowerCase() + ".png";
1265 icon = "tool." + icon.toLowerCase() + ".png";
1267 File image = new File(ApplicationSettings
1268 .getApplicationSkinPath()
1270 if (!image.exists()) {
1271 icon = "tool.any.png";
1273 bar.addTool(tool, icon, command);
1275 docname = "/jsp/newDocument.jsp?type=" + docname;
1276 String icon = "tool." + name[0].toLowerCase() + ".png";
1277 File image = new File(ApplicationSettings
1278 .getApplicationSkinPath()
1280 if (!image.exists()) {
1281 icon = "tool.any.png";
1283 bar.addTool(name[0], icon, command, docname);
1286 if (!bar.isEmpty()) {
1287 _bars.put(step.getNumber(), bar);
1292 public static String getApplicationProperty(final String name) {
1293 return _WAPPROPS.getProperty(name); // May be null
1296 public static String getApplicationRootPath() {
1297 // The property is supposed including the Web application name
1301 public String getApplicationURL() {
1302 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1303 .append("/").append(wappname);
1304 return url.toString();
1307 public Map<String, Object> getFilter(final String name) {
1308 return _filter.get(name);
1311 public ToolBar getModuleBar(final Step step) {
1312 return _bars.get(step.getNumber());
1315 static public Properties getNamingProperties() {
1319 // ==============================================================================================================================
1321 // ==============================================================================================================================
1323 public static String getApplicationPluginPath() {
1324 return getApplicationRootPath() + "plugin/";
1327 public static String getApplicationResourcePath() {
1328 return getApplicationRootPath() + "WEB-INF/classes/";
1331 public static String getApplicationSkinPath() {
1332 return getApplicationRootPath() + "skin/";
1335 public static Converter getConverter(final DocumentType type,
1336 final String format) {
1337 return convertmap.get(format + type.getName()); // May be null;
1341 * Get default document type for the given format on the given study step.
1347 * @return default document type or null if not defined in the configuration
1349 public DocumentType getDefaultDocumentType(final Step step,
1350 final String format) {
1351 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1352 format); // May be null
1355 public String getDownloadURL(final User user) {
1356 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1357 .append("/download/").append(user.getUsername()).append("/");
1358 return url.toString(); // The download Tomcat context is supposed being defined
1361 public Locale getCurrentLocale() {
1365 public SimpleMenu getMenu(final String name) {
1366 return _menus.get(name);
1369 public PopupMenu getPopupMenu(final String name) {
1370 return _popups.get(name);
1373 public String getRepositoryURL() {
1374 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1375 .append("/repository/");
1376 return url.toString(); // The repository Tomcat context is supposed being defined
1379 public static Locale[] getSupportedLocales() {
1380 String[] code = _WAPPROPS.getProperty("locale.supported").split(",");
1381 Locale[] result = new Locale[code.length];
1382 for (int i = 0; i < code.length; i++) {
1383 result[i] = new Locale(code[i]);
1388 public static String[] getViewersMapping() {
1392 public static String getWebSiteURL() {
1393 return getApplicationProperty("wapp.website");
1396 public static String getHelpURL() {
1397 return getApplicationProperty("wapp.onlinehelp");
1400 // ==============================================================================================================================
1402 // ==============================================================================================================================
1405 * Load application custom configuration from the given XML file (see conf/my.xml).
1408 * the XML configuration file
1410 private static void loadCustomization(final File config) {
1412 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1414 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1416 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1417 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1418 .getDocumentElement());
1421 loadModules(children);
1424 loadConverters(children);
1427 loadTemplates(children);
1428 } catch (Exception error) {
1429 LOG.info("Error in customization", error);
1434 * Load modules from XML configuration.
1439 private static void loadModules(final Map<String, Node> children) {
1440 Node child = children.get("modules");
1441 NodeList nlist = child.getChildNodes();
1442 for (int i = 0; i < nlist.getLength(); i++) {
1443 child = nlist.item(i);
1444 if (!child.getNodeName().equals("mapping")) {
1448 NamedNodeMap natr = child.getAttributes();
1449 String dext = natr.getNamedItem("extension").getNodeValue();
1450 String exec = natr.getNamedItem("executable").getNodeValue();
1451 _WAPPROPS.put("executable." + dext, exec);
1453 // Viewer mappings tag
1454 child = children.get("viewers");
1455 viewermap = child.getAttributes().getNamedItem("extension")
1456 .getNodeValue().split(",");
1460 * Load converters from XML configuration.
1465 private static void loadConverters(final Map<String, Node> children) {
1466 Node child = children.get("converters");
1467 NodeList nlist = child.getChildNodes();
1468 for (int i = 0; i < nlist.getLength(); i++) {
1469 child = nlist.item(i);
1471 if (child.getNodeName().equals("geometry")) {
1472 NamedNodeMap natr = child.getAttributes();
1473 String from = natr.getNamedItem("from").getNodeValue();
1474 String to = natr.getNamedItem("to").getNodeValue();
1475 String exec = natr.getNamedItem("executable").getNodeValue();
1476 convertmap.put(from + "geometry", new Converter("geometry",
1483 * Load templates from XML configuration.
1488 private static void loadTemplates(final Map<String, Node> children) {
1489 Node child = children.get("templates");
1490 NodeList nlist = child.getChildNodes();
1491 for (int i = 0; i < nlist.getLength(); i++) {
1492 child = nlist.item(i);
1493 if (!child.getNodeName().equals("document")) {
1497 NamedNodeMap natr = child.getAttributes();
1498 String type = natr.getNamedItem("type").getNodeValue();
1499 String file = natr.getNamedItem("file").getNodeValue();
1500 tempfile.put(type, file);
1505 * Get the documentTypeService.
1507 * @return the documentTypeService
1509 public DocumentTypeService getDocumentTypeService() {
1510 return _documentTypeService;
1514 * Set the documentTypeService.
1516 * @param documentTypeService
1517 * the documentTypeService to set
1519 public void setDocumentTypeService(
1520 final DocumentTypeService documentTypeService) {
1521 _documentTypeService = documentTypeService;
1527 * @return the locale
1529 public Locale getLocale() {
1539 public void setLocale(final Locale locale) {