1 package org.splat.simer;
4 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.HashMap;
7 import java.util.HashSet;
8 import java.util.Iterator;
10 import java.util.Locale;
12 import java.util.Properties;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.xml.parsers.DocumentBuilder;
17 import javax.xml.parsers.DocumentBuilderFactory;
19 import org.apache.log4j.Logger;
20 import org.splat.dal.bo.kernel.User;
21 import org.splat.dal.bo.som.Document;
22 import org.splat.dal.bo.som.DocumentType;
23 import org.splat.dal.bo.som.KnowledgeElement;
24 import org.splat.dal.bo.som.SimulationContext;
25 import org.splat.dal.bo.som.Visibility;
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 Logger LOG = Logger
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 res = _user.canPurge();
605 case markasreference:
606 if (_user.getOperand().getMarkreference() == 0) {
607 res = _user.canMarkStudyAsReference();
609 res = _user.canRemoveStudyAsReference();
620 public void setContext(final String name, final Object context) {
621 if (context instanceof StudyRights) {
622 _user = (StudyRights) context; // Just for optimizing
623 boolean history = _user.getOperand().isVersioned();
624 PopupItem item = this.item(MNU_REMOVE);
626 item.rename(MNU_NAME_REMOVE_VERSION);
628 item.rename("menu.remove.study");
634 // Resources relative to documents
636 * Popup of In-Work documents.
638 private static class EditableDocumentPopup extends PopupMenu {
640 * User rights for the selected document.
642 private transient DocumentRights _user = null;
645 * Document popup menu constructor.
647 private EditableDocumentPopup() {
649 /*addItem("accept", new PopupItem("menu.accept").icon(
650 "image.accept.png").action("setDocument?action=accept")
651 .confirmation("message.accept.document"));*/
652 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
653 "image.publish.png").action("setDocument?action=promote")
654 .confirmation("message.promote.document"));
656 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
657 .action("edit-document?action=renameDocument"));
658 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
659 .action(ACT_ATTACH));
661 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
662 IMG_VERSION).action(ACT_VERSION));
663 addItem("replace", new PopupItem("menu.replace").icon(
664 "image.replace.png").action(
665 "select-file?nextAction=replace"));
667 /*addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
668 ACT_NOT_YET_IMPLEMENTED).confirmation(
669 "message.purge.document"));*/
670 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
671 IMG_DELETE).action("remove-document").confirmation(
672 "message.delete.document"));
676 public boolean isEnabled(final String name) {
677 boolean res = (_user != null);
679 Item item = Item.valueOf(name);
682 res = _user.canAccept();
685 res = _user.canPromote();
688 res = _user.canRename();
691 res = _user.canAttach();
694 res = _user.canVersion();
697 res = _user.canReplace();
700 res = _user.canPurge();
703 res = _user.canRemove();
713 public void setContext(final String name, final Object context) {
714 if (context instanceof DocumentRights) {
715 _user = (DocumentRights) context; // Just for optimizing
716 Document downer = _user.getOperand();
717 PopupItem item = this.item(MNU_REMOVE);
718 if (downer.isVersioned()) {
719 item.rename(MNU_NAME_REMOVE_VERSION);
721 item.rename("menu.remove.document");
728 * Popup of In-Draft documents.
730 private static class ReviewableDocumentPopup extends PopupMenu {
732 * User rights for the selected document.
734 private transient DocumentRights _user = null;
737 * Document popup menu constructor.
739 private ReviewableDocumentPopup() {
741 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
742 "image.demote.png").action("setDocument?action=demote")
743 .confirmation("message.demote.document"));
744 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
745 "image.review.png").action("setDocument?action=review")
746 .confirmation("message.review.document"));
748 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
749 .action(ACT_ATTACH));
751 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
752 IMG_VERSION).action(ACT_VERSION));
754 /*addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
755 ACT_NOT_YET_IMPLEMENTED).confirmation(
756 "message.purge.document"));*/
760 public boolean isEnabled(final String name) {
761 boolean res = (_user != null);
763 Item item = Item.valueOf(name);
766 res = _user.canDemote();
769 res = _user.canReview();
772 res = _user.canAttach();
775 res = _user.canVersion();
778 res = _user.canPurge();
788 public void setContext(final String name, final Object context) {
789 if (context instanceof DocumentRights) {
790 _user = (DocumentRights) context; // Just for optimizing
795 private static class NotResultDocumentPopup extends PopupMenu {
796 // private final DocumentRights _user = null;
798 private NotResultDocumentPopup() {
800 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
801 "image.demote.png").action("setDocument?action=demote")
802 .confirmation("message.demote.document"));
804 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
805 .action(ACT_ATTACH));
807 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
808 IMG_VERSION).action(ACT_VERSION));
810 /*addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
811 ACT_NOT_YET_IMPLEMENTED).confirmation(
812 "message.purge.document"));*/
813 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
814 IMG_DELETE).action("remove-document").confirmation(
815 "message.delete.document"));
820 * Popup of In-Check documents.
822 private static class ApprovableDocumentPopup extends PopupMenu {
823 private transient DocumentRights _user = null;
825 private ApprovableDocumentPopup() {
827 addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon(
828 "image.invalidate.png").action(
829 "setDocument?action=invalidate").confirmation(
830 "message.demote.document"));
831 addItem(MNU_DEMOTE, new PopupItem("menu.disapprove").icon(
832 "image.demote.png").action("setDocument?action=disapprove")
833 .confirmation("message.disapprove.document"));
834 addItem("approve", new PopupItem("menu.approve").icon(
835 "icon.APPROVED.png").action("setDocument?action=approve")
836 .confirmation("message.approve.document"));
840 public boolean isEnabled(final String name) {
841 boolean res = (_user != null);
843 Item item = Item.valueOf(name);
846 res = _user.canInvalidate();
849 res = _user.canDemote();
852 res = _user.canApprove();
862 public void setContext(final String name, final Object context) {
863 if (context instanceof DocumentRights) {
864 _user = (DocumentRights) context; // Just for optimizing
870 * Popup of Approved documents.
872 private static class ApprovedPopup extends PopupMenu {
873 private ApprovedPopup() {
875 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
876 .action(ACT_ATTACH));
878 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
879 IMG_VERSION).action(ACT_VERSION));
884 * Popup of Extern documents.
886 private static class ExternPopup extends PopupMenu {
887 private transient DocumentRights _user = null;
889 private ExternPopup() {
891 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
892 .action("edit-document?action=renameDocument"));
894 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
895 IMG_VERSION).action(ACT_VERSION));
897 addItem("replace", new PopupItem("menu.replace").icon(
898 "image.replace.png").action(
899 "select-file?nextAction=replace"));
901 addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon(
902 IMG_DELETE).action("remove-document").confirmation(
903 "message.delete.document"));
907 public boolean isEnabled(final String name) {
908 boolean res = (_user != null);
910 Item item = Item.valueOf(name);
913 res = _user.canRename();
916 res = _user.canVersion();
919 res = _user.canReplace();
922 res = _user.canRemove();
932 public void setContext(final String name, final Object context) {
933 if (context instanceof DocumentRights) {
934 _user = (DocumentRights) context; // Just for optimizing
939 // Resources relative to simulation contexts
940 private static class ScontextPopup extends PopupMenu {
941 private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it.
943 private ScontextPopup() {
945 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
946 .action("edit-context?action=renameContext"));
947 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
948 .action("edit-context?action=editContext"));
950 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
951 .action("remove-context").confirmation(
952 "message.delete.context"));
956 public boolean isEnabled(final String name) {
957 Item item = Item.valueOf(name);
960 if (item == Item.rename) {
962 } else if (item == Item.edit) {
963 // if (!owner.isEditable())
970 public void setContext(final String name, final Object context) {
971 if (context instanceof SimulationContextFacade) {
972 _owner = (SimulationContextFacade) context; // Just for optimizing
974 super.setContext(name, context);
979 // Resources relative to knowledge
980 private static class FeedbexPopup extends PopupMenu {
981 private transient KnowledgeElement _owner = null;
983 private FeedbexPopup() {
985 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
986 .action("edit-knowledge?action=renameKnowledge"));
987 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
988 .action("edit-knowledge?action=editKnowledge"));
990 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
991 .action("remove-knowledge").confirmation(
992 "message.delete.knowledge"));
996 public boolean isEnabled(final String name) {
1002 public void setContext(final String name, final Object context) {
1003 if (context instanceof KnowledgeElement) {
1004 _owner = (KnowledgeElement) context; // Just for optimizing
1006 super.setContext(name, context);
1012 * Pop-up menu for comments.
1014 private static class CommentPopup extends PopupMenu {
1016 * Default constructor.
1018 private CommentPopup() {
1020 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1021 .action("editComment(entity_index)"));
1022 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1023 .action("removeComment(entity_index)").confirmation(
1024 "message.delete.comment"));
1035 public boolean isEnabled(final String name) {
1041 * Pop-up menu for comments.
1043 private static class DescritptionPopup extends PopupMenu {
1045 * Default constructor.
1047 private DescritptionPopup() {
1049 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1050 .action("showDescriptionEditor()"));
1051 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1052 .action("removeDescription()").confirmation(
1053 "message.delete.description"));
1064 public boolean isEnabled(final String name) {
1069 // ==============================================================================================================================
1071 // ==============================================================================================================================
1073 // ==============================================================================================================================
1074 // Public member functions
1075 // ==============================================================================================================================
1077 public void configure() {
1078 // Non customizable settings
1080 SimpleMenu menu = new NewMenu();
1081 _menus.put(menu.getName(), menu);
1082 menu = new SearchMenu();
1083 _menus.put(menu.getName(), menu);
1084 menu = new DatadminMenu();
1085 _menus.put(menu.getName(), menu);
1086 menu = new SysadminMenu();
1087 _menus.put(menu.getName(), menu);
1088 menu = new PropertiesMenu();
1089 _menus.put(menu.getName(), menu);
1091 _popups = new HashMap<String, PopupMenu>();
1092 _popups.put("steditablemarkpublic", new EditableMarkedStudyPopup(false,
1094 _popups.put("steditableunmarkpublic", new EditableMarkedStudyPopup(
1096 _popups.put("steditablemarkprivate", new EditableMarkedStudyPopup(true,
1098 _popups.put("steditableunmarkprivate", new EditableMarkedStudyPopup(
1100 _popups.put("editable", new EditableDocumentPopup());
1101 _popups.put("notresult", new NotResultDocumentPopup());
1102 _popups.put("reviewable", new ReviewableDocumentPopup());
1103 _popups.put("approvable", new ApprovableDocumentPopup());
1104 _popups.put("approved", new ApprovedPopup());
1105 _popups.put("extern", new ExternPopup());
1106 _popups.put("scontext", new ScontextPopup());
1107 _popups.put("feedbex", new FeedbexPopup());
1108 _popups.put("comment", new CommentPopup());
1109 _popups.put("description", new DescritptionPopup());
1111 // Default customizable mandatory settings
1112 Map<String, Object> fprop = new HashMap<String, Object>();
1113 fprop.put("visibility", "PRIVATE");
1114 fprop.put("matchamong", ALL);
1115 fprop.put("matcontext", ALL);
1116 fprop.put("state", "APPROVED");
1117 fprop.put("author", "0");
1118 fprop.put("reference", "");
1119 fprop.put("title", "");
1120 fprop.put("context", new ArrayList<SimulationContext>());
1122 Map<String, Object> gprop = new HashMap<String, Object>();
1123 gprop.put("visibility", "PUBLIC");
1124 gprop.put("matchamong", ALL);
1125 gprop.put("matcontext", ALL);
1126 gprop.put("type", "2"); // TODO: Get the index from the type name
1127 gprop.put("author", "0");
1128 gprop.put("reference", "");
1129 gprop.put("title", "");
1130 gprop.put("context", new ArrayList<SimulationContext>());
1132 _filter = new HashMap<String, Map<String, Object>>();
1133 _filter.put("study", fprop);
1134 _filter.put("knowledge", gprop);
1136 // Settings based on the customization
1137 configureToolbars();
1141 * Configure toolbars for steps.
1143 private void configureToolbars() {
1144 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
1146 List<ProjectSettingsService.Step> steps = getProjectSettings()
1148 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
1150 ProjectSettingsService.Step step = i.next();
1151 List<String> formats = getProjectSettings().getDefaultFormats(step);
1152 if (formats.isEmpty()) {
1156 ToolBar bar = new ToolBar(24); // Height of the module-bar
1157 Set<String> module = new HashSet<String>(); // For not duplicating modules
1158 for (String format : formats) {
1159 String command = getApplicationProperty("executable." + format);
1160 if (command == null) {
1161 continue; // Module not installed
1163 if (module.contains(command)) {
1166 module.add(command);
1167 String[] parsed = command.split("/");
1168 String[] name = parsed[parsed.length - 1].split("\\x2E");
1169 DocumentType dtype = getProjectSettings()
1170 .getDefaultDocumentType(step, format);
1171 String docname = "";
1172 if (dtype != null) {
1173 docname = dtype.getName();
1175 if (tempfile.get(docname) == null) { // No available template
1176 String tool = parsed[parsed.length - 1];
1177 String icon = name[0];
1178 if ("index".equals(icon)) {
1179 tool = parsed[parsed.length - 2];
1180 icon = "tool." + tool.toLowerCase() + ".png";
1182 icon = "tool." + icon.toLowerCase() + ".png";
1184 File image = new File(ApplicationSettings
1185 .getApplicationSkinPath()
1187 if (!image.exists()) {
1188 icon = "tool.any.png";
1190 bar.addTool(tool, icon, command);
1192 docname = "/jsp/newDocument.jsp?type=" + docname;
1193 String icon = "tool." + name[0].toLowerCase() + ".png";
1194 File image = new File(ApplicationSettings
1195 .getApplicationSkinPath()
1197 if (!image.exists()) {
1198 icon = "tool.any.png";
1200 bar.addTool(name[0], icon, command, docname);
1203 if (!bar.isEmpty()) {
1204 _bars.put(step.getNumber(), bar);
1209 public static String getApplicationProperty(final String name) {
1210 return _WAPPROPS.getProperty(name); // May be null
1213 public static String getApplicationRootPath() {
1214 // The property is supposed including the Web application name
1218 public String getApplicationURL() {
1219 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1220 .append("/").append(wappname);
1221 return url.toString();
1224 public Map<String, Object> getFilter(final String name) {
1225 return _filter.get(name);
1228 public ToolBar getModuleBar(final Step step) {
1229 return _bars.get(step.getNumber());
1232 static public Properties getNamingProperties() {
1236 // ==============================================================================================================================
1238 // ==============================================================================================================================
1240 public static String getApplicationPluginPath() {
1241 return getApplicationRootPath() + "plugin/";
1244 public static String getApplicationResourcePath() {
1245 return getApplicationRootPath() + "WEB-INF/classes/";
1248 public static String getApplicationSkinPath() {
1249 return getApplicationRootPath() + "skin/";
1252 public static Converter getConverter(final DocumentType type,
1253 final String format) {
1254 return convertmap.get(format + type.getName()); // May be null;
1258 * Get default document type for the given format on the given study step.
1264 * @return default document type or null if not defined in the configuration
1266 public DocumentType getDefaultDocumentType(final Step step,
1267 final String format) {
1268 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1269 format); // May be null
1272 public String getDownloadURL(final User user) {
1273 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1274 .append("/download/").append(user.getUsername()).append("/");
1275 return url.toString(); // The download Tomcat context is supposed being defined
1278 public Locale getCurrentLocale() {
1282 public SimpleMenu getMenu(final String name) {
1283 return _menus.get(name);
1286 public PopupMenu getPopupMenu(final String name) {
1287 return _popups.get(name);
1290 public String getRepositoryURL() {
1291 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1292 .append("/repository/");
1293 return url.toString(); // The repository Tomcat context is supposed being defined
1296 public static Locale[] getSupportedLocales() {
1297 String[] code = _WAPPROPS.getProperty("locale.supported").split(",");
1298 Locale[] result = new Locale[code.length];
1299 for (int i = 0; i < code.length; i++) {
1300 result[i] = new Locale(code[i]);
1305 public static String[] getViewersMapping() {
1309 public static String getWebSiteURL() {
1310 return getApplicationProperty("wapp.website");
1313 public static String getHelpURL() {
1314 return getApplicationProperty("wapp.onlinehelp");
1317 // ==============================================================================================================================
1319 // ==============================================================================================================================
1322 * Load application custom configuration from the given XML file (see conf/my.xml).
1325 * the XML configuration file
1327 private static void loadCustomization(final File config) {
1329 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1331 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1333 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1334 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1335 .getDocumentElement());
1338 loadModules(children);
1341 loadConverters(children);
1344 loadTemplates(children);
1345 } catch (Exception error) {
1346 LOG.info("Error in customization", error);
1351 * Load modules from XML configuration.
1356 private static void loadModules(final Map<String, Node> children) {
1357 Node child = children.get("modules");
1358 NodeList nlist = child.getChildNodes();
1359 for (int i = 0; i < nlist.getLength(); i++) {
1360 child = nlist.item(i);
1361 if (!child.getNodeName().equals("mapping")) {
1365 NamedNodeMap natr = child.getAttributes();
1366 String dext = natr.getNamedItem("extension").getNodeValue();
1367 String exec = natr.getNamedItem("executable").getNodeValue();
1368 _WAPPROPS.put("executable." + dext, exec);
1370 // Viewer mappings tag
1371 child = children.get("viewers");
1372 viewermap = child.getAttributes().getNamedItem("extension")
1373 .getNodeValue().split(",");
1377 * Load converters from XML configuration.
1382 private static void loadConverters(final Map<String, Node> children) {
1383 Node child = children.get("converters");
1384 NodeList nlist = child.getChildNodes();
1385 for (int i = 0; i < nlist.getLength(); i++) {
1386 child = nlist.item(i);
1388 if (child.getNodeName().equals("geometry")) {
1389 NamedNodeMap natr = child.getAttributes();
1390 String from = natr.getNamedItem("from").getNodeValue();
1391 String to = natr.getNamedItem("to").getNodeValue();
1392 String exec = natr.getNamedItem("executable").getNodeValue();
1393 convertmap.put(from + "geometry", new Converter("geometry",
1400 * Load templates from XML configuration.
1405 private static void loadTemplates(final Map<String, Node> children) {
1406 Node child = children.get("templates");
1407 NodeList nlist = child.getChildNodes();
1408 for (int i = 0; i < nlist.getLength(); i++) {
1409 child = nlist.item(i);
1410 if (!child.getNodeName().equals("document")) {
1414 NamedNodeMap natr = child.getAttributes();
1415 String type = natr.getNamedItem("type").getNodeValue();
1416 String file = natr.getNamedItem("file").getNodeValue();
1417 tempfile.put(type, file);
1422 * Get the documentTypeService.
1424 * @return the documentTypeService
1426 public DocumentTypeService getDocumentTypeService() {
1427 return _documentTypeService;
1431 * Set the documentTypeService.
1433 * @param documentTypeService
1434 * the documentTypeService to set
1436 public void setDocumentTypeService(
1437 final DocumentTypeService documentTypeService) {
1438 _documentTypeService = documentTypeService;
1444 * @return the locale
1446 public Locale getLocale() {
1456 public void setLocale(final Locale locale) {