1 package org.splat.simer;
4 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.HashMap;
7 import java.util.HashSet;
8 import java.util.Iterator;
10 import java.util.Locale;
12 import java.util.Properties;
15 import javax.servlet.http.HttpServletRequest;
16 import javax.xml.parsers.DocumentBuilder;
17 import javax.xml.parsers.DocumentBuilderFactory;
19 import org.apache.log4j.Logger;
20 import org.splat.dal.bo.kernel.User;
21 import org.splat.dal.bo.som.Document;
22 import org.splat.dal.bo.som.DocumentType;
23 import org.splat.dal.bo.som.KnowledgeElement;
24 import org.splat.dal.bo.som.ProgressState;
25 import org.splat.dal.bo.som.SimulationContext;
26 import org.splat.dal.bo.som.Visibility;
27 import org.splat.manox.XDOM;
28 import org.splat.service.DocumentTypeService;
29 import org.splat.service.technical.ProjectSettingsService;
30 import org.splat.som.DocumentRights;
31 import org.splat.som.Step;
32 import org.splat.som.StudyRights;
33 import org.splat.wapp.MenuItem;
34 import org.splat.wapp.PopupItem;
35 import org.splat.wapp.PopupMenu;
36 import org.splat.wapp.SimpleMenu;
37 import org.splat.wapp.ToolBar;
38 import org.springframework.web.context.request.RequestContextHolder;
39 import org.springframework.web.context.request.ServletRequestAttributes;
40 import org.w3c.dom.NamedNodeMap;
41 import org.w3c.dom.Node;
42 import org.w3c.dom.NodeList;
45 * SIMAN project settings service. Provides settings according to XML customization.
47 public class ApplicationSettings {
50 * Application settings logger.
52 protected final static Logger LOG = Logger
53 .getLogger(ApplicationSettings.class);
55 * JNDI context for launching converters.
57 private transient static final Properties _JNDPROPS;
59 * Siman web application name.
61 private transient static String wappname;
63 * General properties from the application properties files.
65 private transient static final Properties _WAPPROPS = new Properties();
67 * Siman web application root path on the server.
69 private transient static String wapproot;
71 * Available template files.
73 private transient static Map<String, String> tempfile;
75 * List of file extensions mapped to a viewer.
77 private transient static String[] viewermap;
79 * Available document format converters.
81 private transient static Map<String, Converter> convertmap;
84 synchronized (_WAPPROPS) {
85 // Do common configuration for all users
87 _JNDPROPS = new Properties();
88 tempfile = new HashMap<String, String>();
89 viewermap = new String[0];
90 convertmap = new HashMap<String, Converter>();
92 ClassLoader cloader = Thread.currentThread()
93 .getContextClassLoader();
94 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
95 .currentRequestAttributes()).getRequest();
96 String appname = curRequest.getContextPath();
97 if (appname.startsWith("/")) {
98 wappname = appname.substring(1);
100 // Set local path on the server to the application root.
101 wapproot = curRequest.getSession().getServletContext().getRealPath(
105 _JNDPROPS.load(cloader.getResourceAsStream("jndi.properties"));
106 _WAPPROPS.load(cloader.getResourceAsStream(wappname
108 } catch (IOException e) {
110 "Can't load application properties: " + e.getMessage(),
114 // Configure login security
115 System.setProperty("java.security.auth.login.config", wapproot
116 + ApplicationSettings.getApplicationProperty("wapp.login"));
118 // Customization (must be done after above default settings)
119 File config = new File(wapproot
120 + getApplicationProperty("wapp.customization"));
121 if (config.exists()) {
122 loadCustomization(config); // Sets default document types, installed modules and available templates
124 LOG.info("Could not find the application configuration file \""
125 + config.getAbsolutePath()
126 + "\", using default settings");
134 private static final String ALL = "all";
137 * Hold icon file name.
139 private static final String IMG_HOLD = "image.hold.gif";
141 * Attach icon file name.
143 private static final String IMG_ATTACH = "image.attach.png";
145 * Version icon file name.
147 private static final String IMG_VERSION = "image.version.png";
149 * Delete icon file name.
151 private static final String IMG_DELETE = "icon.delete.png";
153 * Attach menu item name.
155 private static final String MNU_ATTACH = "attach";
157 * Demote menu item name.
159 private static final String MNU_DEMOTE = "demote";
161 * Promote menu item name.
163 private static final String MNU_PROMOTE = "promote";
165 * Publish menu item name.
167 private static final String MNU_PUBLISH = "publish";
169 * Edit menu item name.
171 private static final String MNU_EDIT = "edit";
173 * Script menu item name.
175 private static final String MNU_SCRIPT = "script";
177 * Version menu item name.
179 private static final String MNU_VERSION = "version";
181 * Purge menu item name.
183 private static final String MNU_PURGE = "purge";
185 * Remove menu item name.
187 private static final String MNU_REMOVE = "remove";
189 * Rename menu item name.
191 private static final String MNU_RENAME = "rename";
194 * Attach menu item name.
196 private static final String MNU_NAME_ATTACH = "menu.attach";
198 * Demote menu item name.
200 private static final String MNU_NAME_DEMOTE = "menu.demote";
202 * Promote menu item name.
204 private static final String MNU_NAME_PROMOTE = "menu.promote";
206 * Publish menu item name.
208 private static final String MNU_NAME_PUBLISH = "menu.publish";
210 * Protect menu item name.
212 private static final String MNU_NAME_PROTECT = "menu.protect";
214 * Edit menu item name.
216 private static final String MNU_NAME_EDIT = "menu.edit";
218 * Edit menu item name.
220 private static final String MNU_NAME_REMOVE = "menu.remove";
222 * Script menu item name.
224 private static final String MNU_NAME_SCRIPT = "menu.newscenario";
226 * Version menu item name.
228 private static final String MNU_NAME_VERSION = "menu.version";
230 * Purge menu item name.
232 private static final String MNU_NAME_PURGE = "menu.purge";
234 * Remove menu item name.
236 private static final String MNU_NAME_REMOVE_VERSION = "menu.remove.version";
238 * Rename menu item name.
240 private static final String MNU_NAME_RENAME = "menu.rename";
242 * Mark as reference menu item name.
244 private static final String MNU_MARK_AS_REFERENCE = "markasreference";
246 * Mark as reference menu item label key.
248 private static final String MNU_NAME_MARK_AS_REFERENCE = "menu.markasreference";
250 * Remove as reference menu item label key.
252 private static final String MNU_NAME_REMOVE_AS_REFERENCE = "menu.removeasreference";
254 * Not yet implemented action name.
256 private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented";
258 * Attach action name.
260 private static final String ACT_ATTACH = "select-file?nextAction=attach";
262 * Version action name.
264 private static final String ACT_VERSION = "select-file?nextAction=version";
266 * Mark as reference action name.
268 private static final String ACT_MARK_AS_REFERENCE = "markasref-study";
270 * Remove as reference action name.
272 private static final String ACT_REMOVE_AS_REFERENCE = "removeasref-study";
275 * Siman application server name.
277 private transient final String _wappserver;
279 * Current user locale.
281 private transient Locale _locale;
285 private transient final Map<String, SimpleMenu> _menus = new HashMap<String, SimpleMenu>();
287 * Study module-bars structured by steps.
289 private transient Map<Integer, ToolBar> _bars = null;
293 private transient Map<String, PopupMenu> _popups = null;
295 * Named search filters.
297 private transient Map<String, Map<String, Object>> _filter = null;
299 * Injected project settings service.
301 private ProjectSettingsService _projectSettings;
303 * Injected document type service.
305 private DocumentTypeService _documentTypeService;
308 * Application settings constructor.
310 public ApplicationSettings() {
311 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
312 .currentRequestAttributes()).getRequest();
313 _wappserver = curRequest.getServerName() + ":"
314 + curRequest.getServerPort();
316 LOG.info("Application server is set to " + _wappserver);
317 LOG.info("Application name is set to " + wappname);
321 * Get the projectSettingsService.
323 * @return the projectSettingsService
325 public ProjectSettingsService getProjectSettings() {
326 return _projectSettings;
330 * Set the projectSettingsService.
332 * @param projectSettingsService
333 * the projectSettingsService to set
335 public void setProjectSettings(
336 final ProjectSettingsService projectSettingsService) {
337 _projectSettings = projectSettingsService;
343 private static class NewMenu extends SimpleMenu {
345 * New study menu constructor.
349 addItem("new-empty", "menu.new.empty", "image.empty.png",
350 "select?menu=create&item=new-empty");
351 addItem("new-copy", "menu.new.copy", "image.copy.png",
352 "select?menu=create&item=new-copy");
354 * addItem("new-instance", new MenuItem("menu.new.instance") .icon(IMG_HOLD)); addItem("new-import", new
355 * MenuItem("menu.new.import") .icon("icon.upload.png"));
357 this.selects("new-empty");
364 private static class SearchMenu extends SimpleMenu {
366 * Search menu constructor.
368 private SearchMenu() {
370 addItem("search-study", "menu.search.study", "image.study.png",
371 "select?menu=search&item=search-study");
372 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
373 "select?menu=search&item=search-knowledge");
374 addItem("search-document", new MenuItem("menu.search.document")
375 .icon("icon.any.png"));
376 this.selects("search-study");
381 * Configuration menu.
383 private static class PropertiesMenu extends SimpleMenu {
385 * Configuration menu constructor.
387 private PropertiesMenu() {
388 super("configuration");
389 addItem("prop-general", "menu.prop.general", IMG_HOLD,
390 "select?menu=configuration&item=prop-general");
391 addItem("prop-scenario", "menu.prop.scenario", IMG_HOLD,
392 "select?menu=configuration&item=prop-scenario");
393 // These menu items will not be implemented in the current version.
395 * addItem("prop-timestamp", new MenuItem("menu.prop.timestamp") .icon("image.stamp.png")); addItem("prop-comlog", new
396 * MenuItem("menu.prop.comlog") .icon(IMG_HOLD)); addItem("prop-version", new MenuItem("menu.prop.version")
397 * .icon("image.dirclosed.png"));
403 * Data administrator menu.
405 private static class DatadminMenu extends SimpleMenu {
407 * Data administrator menu constructor.
409 private DatadminMenu() {
411 addItem("admin-scontext", "menu.admin.context", IMG_HOLD,
412 "select?menu=datadmin&item=admin-scontext");
413 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
414 "select?menu=datadmin&item=admin-knowelm");
415 addItem("admin-study", new MenuItem("menu.admin.study")
416 .icon("image.study.png"));
421 * System administrator menu.
423 private static class SysadminMenu extends SimpleMenu {
425 * System administrator menu constructor.
427 private SysadminMenu() {
429 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
430 "select?menu=sysadmin&item=admin-indexing");
431 addItem("admin-importuser", "menu.admin.importuser",
433 "select?menu=sysadmin&item=admin-importuser");
438 * Menu items enumeration.
446 * Accept the document.
450 * Approve the document.
454 * Promote the document.
458 * Demote the docuemnt.
462 * Undo the last operation.
466 * Rename the document.
470 * Attach a file to the document.
482 * Version the document.
494 * Remove the document.
502 * Mark the study as reference.
507 // Resources relative to studies
511 private static class EditableMarkedStudyPopup extends PopupMenu {
513 * User rights for the selected study.
515 private transient StudyRights _user = null;
518 * Study popup menu constructor.
523 * "marked as reference" study flag
525 private EditableMarkedStudyPopup(final boolean isPublic,
526 final boolean isMarked) {
530 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
531 MNU_NAME_REMOVE_AS_REFERENCE).action(
532 ACT_REMOVE_AS_REFERENCE).confirmation(
533 "message.removeasreference.study"));
535 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
536 MNU_NAME_MARK_AS_REFERENCE).action(
537 ACT_MARK_AS_REFERENCE).confirmation(
538 "message.markasreference.study"));
542 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PROTECT).icon(
544 .action("edit-study?action=protect").confirmation(
545 "message.protect.study"));
547 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon(
549 .action("edit-study?action=publish").confirmation(
550 "message.publish.study"));
553 /* addItem(MNU_PROMOTE, new PopupItem("menu.archive")); */
555 addItem(MNU_EDIT, new PopupItem("menu.properties").icon(
556 "icon.ed.png").action(
557 "../select?menu=configuration&item=prop-general"));
559 addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT)
560 .action("add-scenario"));
562 * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
566 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
567 * PopupItem("menu.export") .icon("image.export.png")); // For future needs
568 */addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
569 IMG_DELETE).action("remove-study").confirmation(
570 "message.delete.study"));
576 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
579 public boolean isEnabled(final String name) {
580 boolean res = (_user != null);
582 Item item = Item.valueOf(name);
585 if (_user.getOperand().getVisibility() == Visibility.PRIVATE) {
586 res = _user.canPublish();
588 res = _user.canProtect();
592 res = _user.canEditProperties();
595 res = _user.canAddScenario();
598 res = _user.canVersion();
601 res = _user.canRemove();
604 res = _user.canPurge();
606 case markasreference:
607 if (_user.getOperand().getMarkreference() == 0) {
608 res = _user.canMarkStudyAsReference();
610 res = _user.canRemoveStudyAsReference();
621 public void setContext(final String name, final Object context) {
622 if (context instanceof StudyRights) {
623 _user = (StudyRights) context; // Just for optimizing
624 boolean history = _user.getOperand().isVersioned();
625 PopupItem item = this.item(MNU_REMOVE);
627 item.rename(MNU_NAME_REMOVE_VERSION);
629 item.rename("menu.remove.study");
635 // Resources relative to documents
637 * Popup of In-Work documents.
639 private static class EditableDocumentPopup extends PopupMenu {
641 * User rights for the selected document.
643 private transient DocumentRights _user = null;
646 * Document popup menu constructor.
648 private EditableDocumentPopup() {
650 addItem("accept", new PopupItem("menu.accept").icon(
651 "image.accept.png").action("setDocument?action=accept")
652 .confirmation("message.accept.document"));
653 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
654 "image.publish.png").action("setDocument?action=promote")
655 .confirmation("message.promote.document"));
657 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
658 .action("edit-document?action=renameDocument"));
659 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
660 .action(ACT_ATTACH));
662 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
663 IMG_VERSION).action(ACT_VERSION));
664 addItem("replace", new PopupItem("menu.replace").icon(
665 "image.replace.png").action(
666 "select-file?nextAction=replace"));
668 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
669 ACT_NOT_YET_IMPLEMENTED).confirmation(
670 "message.purge.document"));
671 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
672 IMG_DELETE).action("remove-document").confirmation(
673 "message.delete.document"));
677 public boolean isEnabled(final String name) {
678 boolean res = (_user != null);
680 Item item = Item.valueOf(name);
683 res = _user.canAccept();
686 res = _user.canPromote();
689 res = _user.canRename();
692 res = _user.canAttach();
695 res = _user.canVersion();
698 res = _user.canReplace();
701 res = _user.canPurge();
704 res = _user.canRemove();
714 public void setContext(final String name, final Object context) {
715 if (context instanceof DocumentRights) {
716 _user = (DocumentRights) context; // Just for optimizing
717 Document downer = _user.getOperand();
718 PopupItem item = this.item(MNU_REMOVE);
719 if (downer.isVersioned()) {
720 item.rename(MNU_NAME_REMOVE_VERSION);
722 item.rename("menu.remove.document");
729 * Popup of In-Draft documents.
731 private static class ReviewableDocumentPopup extends PopupMenu {
733 * User rights for the selected document.
735 private transient DocumentRights _user = null;
738 * Document popup menu constructor.
740 private ReviewableDocumentPopup() {
742 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
743 "image.demote.png").action("setDocument?action=demote")
744 .confirmation("message.demote.document"));
745 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
746 "image.review.png").action("setDocument?action=review")
747 .confirmation("message.review.document"));
749 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
750 .action(ACT_ATTACH));
752 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
753 IMG_VERSION).action(ACT_VERSION));
755 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
756 ACT_NOT_YET_IMPLEMENTED).confirmation(
757 "message.purge.document"));
761 public boolean isEnabled(final String name) {
762 boolean res = (_user != null);
764 Item item = Item.valueOf(name);
767 res = _user.canDemote();
770 res = _user.canReview();
773 res = _user.canAttach();
776 res = _user.canVersion();
779 res = _user.canPurge();
789 public void setContext(final String name, final Object context) {
790 if (context instanceof DocumentRights) {
791 _user = (DocumentRights) context; // Just for optimizing
796 private static class NotResultDocumentPopup extends PopupMenu {
797 // private final DocumentRights _user = null;
799 private NotResultDocumentPopup() {
801 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
802 "image.demote.png").action("setDocument?action=demote")
803 .confirmation("message.demote.document"));
805 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
806 .action(ACT_ATTACH));
808 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
809 IMG_VERSION).action(ACT_VERSION));
811 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
812 ACT_NOT_YET_IMPLEMENTED).confirmation(
813 "message.purge.document"));
814 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE_VERSION).icon(
815 IMG_DELETE).action("remove-document").confirmation(
816 "message.delete.document"));
821 * Popup of In-Check documents.
823 private static class ApprovableDocumentPopup extends PopupMenu {
824 private transient DocumentRights _user = null;
826 private ApprovableDocumentPopup() {
828 addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon(
829 "image.invalidate.png").action(
830 "setDocument?action=invalidate").confirmation(
831 "message.demote.document"));
832 addItem(MNU_DEMOTE, new PopupItem("menu.disapprove").icon(
833 "image.demote.png").action("setDocument?action=disapprove")
834 .confirmation("message.disapprove.document"));
835 addItem("approve", new PopupItem("menu.approve").icon(
836 "icon.APPROVED.png").action("setDocument?action=approve")
837 .confirmation("message.approve.document"));
841 public boolean isEnabled(final String name) {
842 boolean res = (_user != null);
844 Item item = Item.valueOf(name);
847 res = _user.canInvalidate();
850 res = _user.canDemote();
853 res = _user.canApprove();
863 public void setContext(final String name, final Object context) {
864 if (context instanceof DocumentRights) {
865 _user = (DocumentRights) context; // Just for optimizing
871 * Popup of Approved documents.
873 private static class ApprovedPopup extends PopupMenu {
874 private ApprovedPopup() {
876 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
877 .action(ACT_ATTACH));
879 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
880 IMG_VERSION).action(ACT_VERSION));
885 * Popup of Extern documents.
887 private static class ExternPopup extends PopupMenu {
888 private transient DocumentRights _user = null;
890 private ExternPopup() {
892 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
893 .action("edit-document?action=renameDocument"));
895 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
896 IMG_VERSION).action(ACT_VERSION));
898 addItem("replace", new PopupItem("menu.replace").icon(
899 "image.replace.png").action(
900 "select-file?nextAction=replace"));
902 addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon(
903 IMG_DELETE).action("remove-document").confirmation(
904 "message.delete.document"));
908 public boolean isEnabled(final String name) {
909 boolean res = (_user != null);
911 Item item = Item.valueOf(name);
914 res = _user.canRename();
917 res = _user.canVersion();
920 res = _user.canReplace();
923 res = _user.canRemove();
933 public void setContext(final String name, final Object context) {
934 if (context instanceof DocumentRights) {
935 _user = (DocumentRights) context; // Just for optimizing
940 // Resources relative to simulation contexts
941 private static class ScontextPopup extends PopupMenu {
942 private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it.
944 private ScontextPopup() {
946 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
947 .action("edit-context?action=renameContext"));
948 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
949 .action("edit-context?action=editContext"));
951 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
952 .action("remove-context").confirmation(
953 "message.delete.context"));
957 public boolean isEnabled(final String name) {
958 Item item = Item.valueOf(name);
961 if (item == Item.rename) {
963 } else if (item == Item.edit) {
964 // if (!owner.isEditable())
971 public void setContext(final String name, final Object context) {
972 if (context instanceof SimulationContextFacade) {
973 _owner = (SimulationContextFacade) context; // Just for optimizing
975 super.setContext(name, context);
980 // Resources relative to knowledge
981 private static class FeedbexPopup extends PopupMenu {
982 private transient KnowledgeElement _owner = null;
984 private FeedbexPopup() {
986 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
987 "image.review.png").action("promote-knowledge")
988 .confirmation("message.promote.knowledge"));
989 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
990 "image.invalidate.png").action("demote-knowledge")
991 .confirmation("message.demote.knowledge"));
993 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
994 .action("edit-knowledge?action=renameKnowledge"));
995 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
996 .action("edit-knowledge?action=editKnowledge"));
998 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
999 .action("remove-knowledge").confirmation(
1000 "message.delete.knowledge"));
1004 public boolean isEnabled(final String name) {
1005 Item item = Item.valueOf(name);
1008 if (item == Item.promote) {
1009 if (_owner.getProgressState() != ProgressState.inDRAFT) {
1012 } else if ((item == Item.demote)
1013 && (_owner.getProgressState() != ProgressState.inCHECK)) {
1020 public void setContext(final String name, final Object context) {
1021 if (context instanceof KnowledgeElement) {
1022 _owner = (KnowledgeElement) context; // Just for optimizing
1024 super.setContext(name, context);
1030 * Pop-up menu for comments.
1032 private static class CommentPopup extends PopupMenu {
1034 * Default constructor.
1036 private CommentPopup() {
1038 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1039 .action("editComment(entity_index)"));
1040 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1041 .action("removeComment(entity_index)").confirmation(
1042 "message.delete.comment"));
1053 public boolean isEnabled(final String name) {
1059 * Pop-up menu for comments.
1061 private static class DescritptionPopup extends PopupMenu {
1063 * Default constructor.
1065 private DescritptionPopup() {
1067 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
1068 .action("showDescriptionEditor()"));
1069 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
1070 .action("removeDescription()").confirmation(
1071 "message.delete.description"));
1082 public boolean isEnabled(final String name) {
1087 // ==============================================================================================================================
1089 // ==============================================================================================================================
1091 // ==============================================================================================================================
1092 // Public member functions
1093 // ==============================================================================================================================
1095 public void configure() {
1096 // Non customizable settings
1098 SimpleMenu menu = new NewMenu();
1099 _menus.put(menu.getName(), menu);
1100 menu = new SearchMenu();
1101 _menus.put(menu.getName(), menu);
1102 menu = new DatadminMenu();
1103 _menus.put(menu.getName(), menu);
1104 menu = new SysadminMenu();
1105 _menus.put(menu.getName(), menu);
1106 menu = new PropertiesMenu();
1107 _menus.put(menu.getName(), menu);
1109 _popups = new HashMap<String, PopupMenu>();
1110 _popups.put("steditablemarkpublic", new EditableMarkedStudyPopup(false,
1112 _popups.put("steditableunmarkpublic", new EditableMarkedStudyPopup(
1114 _popups.put("steditablemarkprivate", new EditableMarkedStudyPopup(true,
1116 _popups.put("steditableunmarkprivate", new EditableMarkedStudyPopup(
1118 _popups.put("editable", new EditableDocumentPopup());
1119 _popups.put("notresult", new NotResultDocumentPopup());
1120 _popups.put("reviewable", new ReviewableDocumentPopup());
1121 _popups.put("approvable", new ApprovableDocumentPopup());
1122 _popups.put("approved", new ApprovedPopup());
1123 _popups.put("extern", new ExternPopup());
1124 _popups.put("scontext", new ScontextPopup());
1125 _popups.put("feedbex", new FeedbexPopup());
1126 _popups.put("comment", new CommentPopup());
1127 _popups.put("description", new DescritptionPopup());
1129 // Default customizable mandatory settings
1130 Map<String, Object> fprop = new HashMap<String, Object>();
1131 fprop.put("visibility", "PRIVATE");
1132 fprop.put("matchamong", ALL);
1133 fprop.put("matcontext", ALL);
1134 fprop.put("state", "APPROVED");
1135 fprop.put("author", "0");
1136 fprop.put("reference", "");
1137 fprop.put("title", "");
1138 fprop.put("context", new ArrayList<SimulationContext>());
1140 Map<String, Object> gprop = new HashMap<String, Object>();
1141 gprop.put("visibility", "PUBLIC");
1142 gprop.put("matchamong", ALL);
1143 gprop.put("matcontext", ALL);
1144 gprop.put("type", "2"); // TODO: Get the index from the type name
1145 gprop.put("author", "0");
1146 gprop.put("reference", "");
1147 gprop.put("title", "");
1148 gprop.put("context", new ArrayList<SimulationContext>());
1150 _filter = new HashMap<String, Map<String, Object>>();
1151 _filter.put("study", fprop);
1152 _filter.put("knowledge", gprop);
1154 // Settings based on the customization
1155 configureToolbars();
1159 * Configure toolbars for steps.
1161 private void configureToolbars() {
1162 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
1164 List<ProjectSettingsService.Step> steps = getProjectSettings()
1166 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
1168 ProjectSettingsService.Step step = i.next();
1169 List<String> formats = getProjectSettings().getDefaultFormats(step);
1170 if (formats.isEmpty()) {
1174 ToolBar bar = new ToolBar(24); // Height of the module-bar
1175 Set<String> module = new HashSet<String>(); // For not duplicating modules
1176 for (String format : formats) {
1177 String command = getApplicationProperty("executable." + format);
1178 if (command == null) {
1179 continue; // Module not installed
1181 if (module.contains(command)) {
1184 module.add(command);
1185 String[] parsed = command.split("/");
1186 String[] name = parsed[parsed.length - 1].split("\\x2E");
1187 DocumentType dtype = getProjectSettings()
1188 .getDefaultDocumentType(step, format);
1189 String docname = "";
1190 if (dtype != null) {
1191 docname = dtype.getName();
1193 if (tempfile.get(docname) == null) { // No available template
1194 String tool = parsed[parsed.length - 1];
1195 String icon = name[0];
1196 if ("index".equals(icon)) {
1197 tool = parsed[parsed.length - 2];
1198 icon = "tool." + tool.toLowerCase() + ".png";
1200 icon = "tool." + icon.toLowerCase() + ".png";
1202 File image = new File(ApplicationSettings
1203 .getApplicationSkinPath()
1205 if (!image.exists()) {
1206 icon = "tool.any.png";
1208 bar.addTool(tool, icon, command);
1210 docname = "/jsp/newDocument.jsp?type=" + docname;
1211 String icon = "tool." + name[0].toLowerCase() + ".png";
1212 File image = new File(ApplicationSettings
1213 .getApplicationSkinPath()
1215 if (!image.exists()) {
1216 icon = "tool.any.png";
1218 bar.addTool(name[0], icon, command, docname);
1221 if (!bar.isEmpty()) {
1222 _bars.put(step.getNumber(), bar);
1227 public static String getApplicationProperty(final String name) {
1228 return _WAPPROPS.getProperty(name); // May be null
1231 public static String getApplicationRootPath() {
1232 // The property is supposed including the Web application name
1236 public String getApplicationURL() {
1237 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1238 .append("/").append(wappname);
1239 return url.toString();
1242 public Map<String, Object> getFilter(final String name) {
1243 return _filter.get(name);
1246 public ToolBar getModuleBar(final Step step) {
1247 return _bars.get(step.getNumber());
1250 static public Properties getNamingProperties() {
1254 // ==============================================================================================================================
1256 // ==============================================================================================================================
1258 public static String getApplicationPluginPath() {
1259 return getApplicationRootPath() + "plugin/";
1262 public static String getApplicationResourcePath() {
1263 return getApplicationRootPath() + "WEB-INF/classes/";
1266 public static String getApplicationSkinPath() {
1267 return getApplicationRootPath() + "skin/";
1270 public static Converter getConverter(final DocumentType type,
1271 final String format) {
1272 return convertmap.get(format + type.getName()); // May be null;
1276 * Get default document type for the given format on the given study step.
1282 * @return default document type or null if not defined in the configuration
1284 public DocumentType getDefaultDocumentType(final Step step,
1285 final String format) {
1286 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1287 format); // May be null
1290 public String getDownloadURL(final User user) {
1291 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1292 .append("/download/").append(user.getUsername()).append("/");
1293 return url.toString(); // The download Tomcat context is supposed being defined
1296 public Locale getCurrentLocale() {
1300 public SimpleMenu getMenu(final String name) {
1301 return _menus.get(name);
1304 public PopupMenu getPopupMenu(final String name) {
1305 return _popups.get(name);
1308 public String getRepositoryURL() {
1309 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1310 .append("/repository/");
1311 return url.toString(); // The repository Tomcat context is supposed being defined
1314 public static Locale[] getSupportedLocales() {
1315 String[] code = _WAPPROPS.getProperty("locale.supported").split(",");
1316 Locale[] result = new Locale[code.length];
1317 for (int i = 0; i < code.length; i++) {
1318 result[i] = new Locale(code[i]);
1323 public static String[] getViewersMapping() {
1327 public static String getWebSiteURL() {
1328 return getApplicationProperty("wapp.website");
1331 public static String getHelpURL() {
1332 return getApplicationProperty("wapp.onlinehelp");
1335 // ==============================================================================================================================
1337 // ==============================================================================================================================
1340 * Load application custom configuration from the given XML file (see conf/my.xml).
1343 * the XML configuration file
1345 private static void loadCustomization(final File config) {
1347 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1349 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1351 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1352 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1353 .getDocumentElement());
1356 loadModules(children);
1359 loadConverters(children);
1362 loadTemplates(children);
1363 } catch (Exception error) {
1364 LOG.info("Error in customization", error);
1369 * Load modules from XML configuration.
1374 private static void loadModules(final Map<String, Node> children) {
1375 Node child = children.get("modules");
1376 NodeList nlist = child.getChildNodes();
1377 for (int i = 0; i < nlist.getLength(); i++) {
1378 child = nlist.item(i);
1379 if (!child.getNodeName().equals("mapping")) {
1383 NamedNodeMap natr = child.getAttributes();
1384 String dext = natr.getNamedItem("extension").getNodeValue();
1385 String exec = natr.getNamedItem("executable").getNodeValue();
1386 _WAPPROPS.put("executable." + dext, exec);
1388 // Viewer mappings tag
1389 child = children.get("viewers");
1390 viewermap = child.getAttributes().getNamedItem("extension")
1391 .getNodeValue().split(",");
1395 * Load converters from XML configuration.
1400 private static void loadConverters(final Map<String, Node> children) {
1401 Node child = children.get("converters");
1402 NodeList nlist = child.getChildNodes();
1403 for (int i = 0; i < nlist.getLength(); i++) {
1404 child = nlist.item(i);
1406 if (child.getNodeName().equals("geometry")) {
1407 NamedNodeMap natr = child.getAttributes();
1408 String from = natr.getNamedItem("from").getNodeValue();
1409 String to = natr.getNamedItem("to").getNodeValue();
1410 String exec = natr.getNamedItem("executable").getNodeValue();
1411 convertmap.put(from + "geometry", new Converter("geometry",
1418 * Load templates from XML configuration.
1423 private static void loadTemplates(final Map<String, Node> children) {
1424 Node child = children.get("templates");
1425 NodeList nlist = child.getChildNodes();
1426 for (int i = 0; i < nlist.getLength(); i++) {
1427 child = nlist.item(i);
1428 if (!child.getNodeName().equals("document")) {
1432 NamedNodeMap natr = child.getAttributes();
1433 String type = natr.getNamedItem("type").getNodeValue();
1434 String file = natr.getNamedItem("file").getNodeValue();
1435 tempfile.put(type, file);
1440 * Get the documentTypeService.
1442 * @return the documentTypeService
1444 public DocumentTypeService getDocumentTypeService() {
1445 return _documentTypeService;
1449 * Set the documentTypeService.
1451 * @param documentTypeService
1452 * the documentTypeService to set
1454 public void setDocumentTypeService(
1455 final DocumentTypeService documentTypeService) {
1456 _documentTypeService = documentTypeService;
1462 * @return the locale
1464 public Locale getLocale() {
1474 public void setLocale(final Locale locale) {