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 * Script menu item name.
220 private static final String MNU_NAME_SCRIPT = "menu.newscenario";
222 * Version menu item name.
224 private static final String MNU_NAME_VERSION = "menu.version";
226 * Purge menu item name.
228 private static final String MNU_NAME_PURGE = "menu.purge";
230 * Remove menu item name.
232 private static final String MNU_NAME_REMOVE = "menu.remove.version";
234 * Rename menu item name.
236 private static final String MNU_NAME_RENAME = "menu.rename";
238 * Mark as reference menu item name.
240 private static final String MNU_MARK_AS_REFERENCE = "markasreference";
242 * Mark as reference menu item label key.
244 private static final String MNU_NAME_MARK_AS_REFERENCE = "menu.markasreference";
246 * Remove as reference menu item label key.
248 private static final String MNU_NAME_REMOVE_AS_REFERENCE = "menu.removeasreference";
250 * Not yet implemented action name.
252 private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented";
254 * Attach action name.
256 private static final String ACT_ATTACH = "select-file?nextAction=attach";
258 * Version action name.
260 private static final String ACT_VERSION = "select-file?nextAction=version";
262 * Mark as reference action name.
264 private static final String ACT_MARK_AS_REFERENCE = "markasref-study";
266 * Remove as reference action name.
268 private static final String ACT_REMOVE_AS_REFERENCE = "removeasref-study";
271 * Siman application server name.
273 private transient final String _wappserver;
275 * Current user locale.
277 private transient Locale _locale;
281 private transient final Map<String, SimpleMenu> _menus = new HashMap<String, SimpleMenu>();
283 * Study module-bars structured by steps.
285 private transient Map<Integer, ToolBar> _bars = null;
289 private transient Map<String, PopupMenu> _popups = null;
291 * Named search filters.
293 private transient Map<String, Map<String, Object>> _filter = null;
295 * Injected project settings service.
297 private ProjectSettingsService _projectSettings;
299 * Injected document type service.
301 private DocumentTypeService _documentTypeService;
304 * Application settings constructor.
306 public ApplicationSettings() {
307 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
308 .currentRequestAttributes()).getRequest();
309 _wappserver = curRequest.getServerName() + ":"
310 + curRequest.getServerPort();
312 LOG.info("Application server is set to " + _wappserver);
313 LOG.info("Application name is set to " + wappname);
317 * Get the projectSettingsService.
319 * @return the projectSettingsService
321 public ProjectSettingsService getProjectSettings() {
322 return _projectSettings;
326 * Set the projectSettingsService.
328 * @param projectSettingsService
329 * the projectSettingsService to set
331 public void setProjectSettings(
332 final ProjectSettingsService projectSettingsService) {
333 _projectSettings = projectSettingsService;
336 private static class NewMenu extends SimpleMenu {
339 addItem("new-empty", "menu.new.empty", "image.empty.png",
340 "select?menu=create&item=new-empty");
341 addItem("new-copy", new MenuItem("menu.new.copy")
342 .icon("image.copy.png"));
344 * addItem("new-instance", new MenuItem("menu.new.instance") .icon(IMG_HOLD)); addItem("new-import", new
345 * MenuItem("menu.new.import") .icon("icon.upload.png"));
347 this.selects("new-empty");
351 private static class SearchMenu extends SimpleMenu {
352 private SearchMenu() {
354 addItem("search-study", "menu.search.study", "image.study.png",
355 "select?menu=search&item=search-study");
356 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
357 "select?menu=search&item=search-knowledge");
358 addItem("search-document", new MenuItem("menu.search.document")
359 .icon("icon.any.png"));
360 this.selects("search-study");
364 private static class PropertiesMenu extends SimpleMenu {
365 private PropertiesMenu() {
366 super("configuration");
367 addItem("prop-general", "menu.prop.general", IMG_HOLD,
368 "select?menu=configuration&item=prop-general");
369 addItem("prop-scenario", "menu.prop.scenario", IMG_HOLD,
370 "select?menu=configuration&item=prop-scenario");
371 // These menu items will not be implemented in the current version.
373 * addItem("prop-timestamp", new MenuItem("menu.prop.timestamp") .icon("image.stamp.png")); addItem("prop-comlog", new
374 * MenuItem("menu.prop.comlog") .icon(IMG_HOLD)); addItem("prop-version", new MenuItem("menu.prop.version")
375 * .icon("image.dirclosed.png"));
380 private static class DatadminMenu extends SimpleMenu {
381 private DatadminMenu() {
383 addItem("admin-scontext", "menu.admin.context", IMG_HOLD,
384 "select?menu=datadmin&item=admin-scontext");
385 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
386 "select?menu=datadmin&item=admin-knowelm");
387 addItem("admin-study", new MenuItem("menu.admin.study")
388 .icon("image.study.png"));
392 private static class SysadminMenu extends SimpleMenu {
393 private SysadminMenu() {
395 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
396 "select?menu=sysadmin&item=admin-indexing");
397 addItem("admin-importuser", "menu.admin.importuser",
399 "select?menu=sysadmin&item=admin-importuser");
404 * Menu items enumeration.
412 * Accept the document.
416 * Approve the document.
420 * Promote the document.
424 * Demote the docuemnt.
428 * Undo the last operation.
432 * Rename the document.
436 * Attach a file to the document.
448 * Version the document.
460 * Remove the document.
468 * Mark the study as reference.
473 // Resources relative to studies
474 private static class EditableMarkedStudyPopup extends PopupMenu {
475 private transient StudyRights _user = null;
477 private EditableMarkedStudyPopup(final boolean isPublic, final boolean isMarked) {
481 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
482 MNU_NAME_REMOVE_AS_REFERENCE).action(ACT_REMOVE_AS_REFERENCE)
483 .confirmation("message.removeasreference.study"));
485 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(MNU_NAME_MARK_AS_REFERENCE)
486 .action(ACT_MARK_AS_REFERENCE).confirmation(
487 "message.markasreference.study"));
491 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PROTECT).icon(
492 "image.publish.png").action("edit-study?action=protect")
493 .confirmation("message.protect.study"));
495 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon(
496 "image.publish.png").action("edit-study?action=publish")
497 .confirmation("message.publish.study"));
500 /* addItem(MNU_PROMOTE, new PopupItem("menu.archive")); */
502 addItem(MNU_EDIT, new PopupItem("menu.properties").icon(
503 "icon.ed.png").action("../select?menu=configuration&item=prop-general"));
505 addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT)
506 .action("add-scenario"));
508 * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
512 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
513 * PopupItem("menu.export") .icon("image.export.png")); // For future needs
514 */addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(
515 IMG_DELETE).action("remove-study").confirmation(
516 "message.delete.study"));
522 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
525 public boolean isEnabled(final String name) {
526 boolean res = (_user != null);
528 Item item = Item.valueOf(name);
531 if (_user.getOperand().getVisibility() == Visibility.PRIVATE) {
532 res = _user.canPublish();
534 res = _user.canProtect();
538 res = _user.canEditProperties();
541 res = _user.canAddScenario();
544 res = _user.canVersion();
547 res = _user.canRemove();
550 res = _user.canPurge();
552 case markasreference:
553 if (_user.getOperand().getMarkreference() == 0) {
554 res = _user.canMarkStudyAsReference();
556 res = _user.canRemoveStudyAsReference();
567 public void setContext(final String name, final Object context) {
568 if (context instanceof StudyRights) {
569 _user = (StudyRights) context; // Just for optimizing
570 boolean history = _user.getOperand().isVersioned();
571 PopupItem item = this.item(MNU_REMOVE);
573 item.rename(MNU_NAME_REMOVE);
575 item.rename("menu.remove.study");
581 // Resources relative to documents
583 * Popup of In-Work documents.
585 private static class EditableDocumentPopup extends PopupMenu {
586 private transient DocumentRights _user = null;
588 private EditableDocumentPopup() {
590 addItem("accept", new PopupItem("menu.accept").icon(
591 "image.accept.png").action("setDocument?action=accept")
592 .confirmation("message.accept.document"));
593 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
594 "image.publish.png").action("setDocument?action=promote")
595 .confirmation("message.promote.document"));
597 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
598 .action("edit-document?action=renameDocument"));
599 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
600 .action(ACT_ATTACH));
602 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
603 IMG_VERSION).action(ACT_VERSION));
604 addItem("replace", new PopupItem("menu.replace").icon(
605 "image.replace.png").action(
606 "select-file?nextAction=replace"));
608 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
609 ACT_NOT_YET_IMPLEMENTED).confirmation(
610 "message.purge.document"));
611 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
612 .action("remove-document").confirmation(
613 "message.delete.document"));
617 public boolean isEnabled(final String name) {
618 boolean res = (_user != null);
620 Item item = Item.valueOf(name);
623 res = _user.canAccept();
626 res = _user.canPromote();
629 res = _user.canRename();
632 res = _user.canAttach();
635 res = _user.canVersion();
638 res = _user.canReplace();
641 res = _user.canPurge();
644 res = _user.canRemove();
654 public void setContext(final String name, final Object context) {
655 if (context instanceof DocumentRights) {
656 _user = (DocumentRights) context; // Just for optimizing
657 Document downer = _user.getOperand();
658 PopupItem item = this.item(MNU_REMOVE);
659 if (downer.isVersioned()) {
660 item.rename(MNU_NAME_REMOVE);
662 item.rename("menu.remove.document");
669 * Popup of In-Draft documents.
671 private static class ReviewableDocumentPopup extends PopupMenu {
672 private transient DocumentRights _user = null;
674 private ReviewableDocumentPopup() {
676 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
677 "image.demote.png").action("setDocument?action=demote")
678 .confirmation("message.demote.document"));
679 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
680 "image.review.png").action("setDocument?action=review")
681 .confirmation("message.review.document"));
683 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
684 .action(ACT_ATTACH));
686 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
687 IMG_VERSION).action(ACT_VERSION));
689 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
690 ACT_NOT_YET_IMPLEMENTED).confirmation(
691 "message.purge.document"));
695 public boolean isEnabled(final String name) {
696 boolean res = (_user != null);
698 Item item = Item.valueOf(name);
701 res = _user.canDemote();
704 res = _user.canReview();
707 res = _user.canAttach();
710 res = _user.canVersion();
713 res = _user.canPurge();
723 public void setContext(final String name, final Object context) {
724 if (context instanceof DocumentRights) {
725 _user = (DocumentRights) context; // Just for optimizing
730 private static class NotResultDocumentPopup extends PopupMenu {
731 // private final DocumentRights _user = null;
733 private NotResultDocumentPopup() {
735 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
736 "image.demote.png").action("setDocument?action=demote")
737 .confirmation("message.demote.document"));
739 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
740 .action(ACT_ATTACH));
742 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
743 IMG_VERSION).action(ACT_VERSION));
745 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
746 ACT_NOT_YET_IMPLEMENTED).confirmation(
747 "message.purge.document"));
748 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
749 .action("remove-document").confirmation(
750 "message.delete.document"));
755 * Popup of In-Check documents.
757 private static class ApprovableDocumentPopup extends PopupMenu {
758 private transient DocumentRights _user = null;
760 private ApprovableDocumentPopup() {
762 addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon(
763 "image.invalidate.png").action(
764 "setDocument?action=invalidate").confirmation(
765 "message.demote.document"));
766 addItem(MNU_DEMOTE, new PopupItem("menu.disapprove").icon(
767 "image.demote.png").action("setDocument?action=disapprove")
768 .confirmation("message.disapprove.document"));
769 addItem("approve", new PopupItem("menu.approve").icon(
770 "icon.APPROVED.png").action("setDocument?action=approve")
771 .confirmation("message.approve.document"));
775 public boolean isEnabled(final String name) {
776 boolean res = (_user != null);
778 Item item = Item.valueOf(name);
781 res = _user.canInvalidate();
784 res = _user.canDemote();
787 res = _user.canApprove();
797 public void setContext(final String name, final Object context) {
798 if (context instanceof DocumentRights) {
799 _user = (DocumentRights) context; // Just for optimizing
805 * Popup of Approved documents.
807 private static class ApprovedPopup extends PopupMenu {
808 private ApprovedPopup() {
810 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
811 .action(ACT_ATTACH));
813 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
814 IMG_VERSION).action(ACT_VERSION));
819 * Popup of Extern documents.
821 private static class ExternPopup extends PopupMenu {
822 private transient DocumentRights _user = null;
824 private ExternPopup() {
826 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
827 .action("edit-document?action=renameDocument"));
829 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
830 IMG_VERSION).action(ACT_VERSION));
832 addItem("replace", new PopupItem("menu.replace").icon(
833 "image.replace.png").action(
834 "select-file?nextAction=replace"));
836 addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon(
837 IMG_DELETE).action("remove-document").confirmation(
838 "message.delete.document"));
842 public boolean isEnabled(final String name) {
843 boolean res = (_user != null);
845 Item item = Item.valueOf(name);
848 res = _user.canRename();
851 res = _user.canVersion();
854 res = _user.canReplace();
857 res = _user.canRemove();
867 public void setContext(final String name, final Object context) {
868 if (context instanceof DocumentRights) {
869 _user = (DocumentRights) context; // Just for optimizing
874 // Resources relative to simulation contexts
875 private static class ScontextPopup extends PopupMenu {
876 private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it.
878 private ScontextPopup() {
880 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
881 .action("edit-context?action=renameContext"));
882 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
883 .action("edit-context?action=editContext"));
885 addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
886 .action("remove-context").confirmation(
887 "message.delete.context"));
891 public boolean isEnabled(final String name) {
892 Item item = Item.valueOf(name);
895 if (item == Item.rename) {
897 } else if (item == Item.edit) {
898 // if (!owner.isEditable())
905 public void setContext(final String name, final Object context) {
906 if (context instanceof SimulationContextFacade) {
907 _owner = (SimulationContextFacade) context; // Just for optimizing
909 super.setContext(name, context);
914 // Resources relative to knowledge
915 private static class FeedbexPopup extends PopupMenu {
916 private transient KnowledgeElement _owner = null;
918 private FeedbexPopup() {
920 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
921 "image.review.png").action("promote-knowledge")
922 .confirmation("message.promote.knowledge"));
923 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
924 "image.invalidate.png").action("demote-knowledge")
925 .confirmation("message.demote.knowledge"));
927 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
928 .action("edit-knowledge?action=renameKnowledge"));
929 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
930 .action("edit-knowledge?action=editKnowledge"));
932 addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
933 .action("remove-knowledge").confirmation(
934 "message.delete.knowledge"));
938 public boolean isEnabled(final String name) {
939 Item item = Item.valueOf(name);
942 if (item == Item.promote) {
943 if (_owner.getProgressState() != ProgressState.inDRAFT) {
946 } else if ((item == Item.demote)
947 && (_owner.getProgressState() != ProgressState.inCHECK)) {
954 public void setContext(final String name, final Object context) {
955 if (context instanceof KnowledgeElement) {
956 _owner = (KnowledgeElement) context; // Just for optimizing
958 super.setContext(name, context);
964 * Pop-up menu for comments.
966 private static class CommentPopup extends PopupMenu {
968 * Default constructor.
970 private CommentPopup() {
972 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
973 .action("editComment(entity_index)"));
974 addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
975 .action("removeComment(entity_index)").confirmation("message.delete.comment"));
980 * @param name the entry name
984 public boolean isEnabled(final String name) {
990 * Pop-up menu for comments.
992 private static class DescritptionPopup extends PopupMenu {
994 * Default constructor.
996 private DescritptionPopup() {
998 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT).icon("icon.ed.png")
999 .action("showDescriptionEditor()"));
1000 addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
1001 .action("removeDescription()")
1002 .confirmation("message.delete.description"));
1007 * @param name the entry name
1011 public boolean isEnabled(final String name) {
1016 // ==============================================================================================================================
1018 // ==============================================================================================================================
1020 // ==============================================================================================================================
1021 // Public member functions
1022 // ==============================================================================================================================
1024 public void configure() {
1025 // Non customizable settings
1027 SimpleMenu menu = new NewMenu();
1028 _menus.put(menu.getName(), menu);
1029 menu = new SearchMenu();
1030 _menus.put(menu.getName(), menu);
1031 menu = new DatadminMenu();
1032 _menus.put(menu.getName(), menu);
1033 menu = new SysadminMenu();
1034 _menus.put(menu.getName(), menu);
1035 menu = new PropertiesMenu();
1036 _menus.put(menu.getName(), menu);
1038 _popups = new HashMap<String, PopupMenu>();
1039 _popups.put("steditablemarkpublic", new EditableMarkedStudyPopup(false, false));
1040 _popups.put("steditableunmarkpublic", new EditableMarkedStudyPopup(false, true));
1041 _popups.put("steditablemarkprivate", new EditableMarkedStudyPopup(true, false));
1042 _popups.put("steditableunmarkprivate", new EditableMarkedStudyPopup(true, true));
1043 _popups.put("editable", new EditableDocumentPopup());
1044 _popups.put("notresult", new NotResultDocumentPopup());
1045 _popups.put("reviewable", new ReviewableDocumentPopup());
1046 _popups.put("approvable", new ApprovableDocumentPopup());
1047 _popups.put("approved", new ApprovedPopup());
1048 _popups.put("extern", new ExternPopup());
1049 _popups.put("scontext", new ScontextPopup());
1050 _popups.put("feedbex", new FeedbexPopup());
1051 _popups.put("comment", new CommentPopup());
1052 _popups.put("description", new DescritptionPopup());
1054 // Default customizable mandatory settings
1055 Map<String, Object> fprop = new HashMap<String, Object>();
1056 fprop.put("visibility", "PRIVATE");
1057 fprop.put("matchamong", ALL);
1058 fprop.put("matcontext", ALL);
1059 fprop.put("state", "APPROVED");
1060 fprop.put("author", "0");
1061 fprop.put("reference", "");
1062 fprop.put("title", "");
1063 fprop.put("context", new ArrayList<SimulationContext>());
1065 Map<String, Object> gprop = new HashMap<String, Object>();
1066 gprop.put("visibility", "PUBLIC");
1067 gprop.put("matchamong", ALL);
1068 gprop.put("matcontext", ALL);
1069 gprop.put("type", "2"); // TODO: Get the index from the type name
1070 gprop.put("author", "0");
1071 gprop.put("reference", "");
1072 gprop.put("title", "");
1073 gprop.put("context", new ArrayList<SimulationContext>());
1075 _filter = new HashMap<String, Map<String, Object>>();
1076 _filter.put("study", fprop);
1077 _filter.put("knowledge", gprop);
1079 // Settings based on the customization
1080 configureToolbars();
1084 * Configure toolbars for steps.
1086 private void configureToolbars() {
1087 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
1089 List<ProjectSettingsService.Step> steps = getProjectSettings()
1091 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
1093 ProjectSettingsService.Step step = i.next();
1094 List<String> formats = getProjectSettings().getDefaultFormats(step);
1095 if (formats.isEmpty()) {
1099 ToolBar bar = new ToolBar(24); // Height of the module-bar
1100 Set<String> module = new HashSet<String>(); // For not duplicating modules
1101 for (String format : formats) {
1102 String command = getApplicationProperty("executable." + format);
1103 if (command == null) {
1104 continue; // Module not installed
1106 if (module.contains(command)) {
1109 module.add(command);
1110 String[] parsed = command.split("/");
1111 String[] name = parsed[parsed.length - 1].split("\\x2E");
1112 DocumentType dtype = getProjectSettings()
1113 .getDefaultDocumentType(step, format);
1114 String docname = "";
1115 if (dtype != null) {
1116 docname = dtype.getName();
1118 if (tempfile.get(docname) == null) { // No available template
1119 String tool = parsed[parsed.length - 1];
1120 String icon = name[0];
1121 if ("index".equals(icon)) {
1122 tool = parsed[parsed.length - 2];
1123 icon = "tool." + tool.toLowerCase() + ".png";
1125 icon = "tool." + icon.toLowerCase() + ".png";
1127 File image = new File(ApplicationSettings
1128 .getApplicationSkinPath()
1130 if (!image.exists()) {
1131 icon = "tool.any.png";
1133 bar.addTool(tool, icon, command);
1135 docname = "/jsp/newDocument.jsp?type=" + docname;
1136 String icon = "tool." + name[0].toLowerCase() + ".png";
1137 File image = new File(ApplicationSettings
1138 .getApplicationSkinPath()
1140 if (!image.exists()) {
1141 icon = "tool.any.png";
1143 bar.addTool(name[0], icon, command, docname);
1146 if (!bar.isEmpty()) {
1147 _bars.put(step.getNumber(), bar);
1152 public static String getApplicationProperty(final String name) {
1153 return _WAPPROPS.getProperty(name); // May be null
1156 public static String getApplicationRootPath() {
1157 // The property is supposed including the Web application name
1161 public String getApplicationURL() {
1162 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1163 .append("/").append(wappname);
1164 return url.toString();
1167 public Map<String, Object> getFilter(final String name) {
1168 return _filter.get(name);
1171 public ToolBar getModuleBar(final Step step) {
1172 return _bars.get(step.getNumber());
1175 static public Properties getNamingProperties() {
1179 // ==============================================================================================================================
1181 // ==============================================================================================================================
1183 public static String getApplicationPluginPath() {
1184 return getApplicationRootPath() + "plugin/";
1187 public static String getApplicationResourcePath() {
1188 return getApplicationRootPath() + "WEB-INF/classes/";
1191 public static String getApplicationSkinPath() {
1192 return getApplicationRootPath() + "skin/";
1195 public static Converter getConverter(final DocumentType type,
1196 final String format) {
1197 return convertmap.get(format + type.getName()); // May be null;
1201 * Get default document type for the given format on the given study step.
1207 * @return default document type or null if not defined in the configuration
1209 public DocumentType getDefaultDocumentType(final Step step,
1210 final String format) {
1211 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1212 format); // May be null
1215 public String getDownloadURL(final User user) {
1216 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1217 .append("/download/").append(user.getUsername()).append("/");
1218 return url.toString(); // The download Tomcat context is supposed being defined
1221 public Locale getCurrentLocale() {
1225 public SimpleMenu getMenu(final String name) {
1226 return _menus.get(name);
1229 public PopupMenu getPopupMenu(final String name) {
1230 return _popups.get(name);
1233 public String getRepositoryURL() {
1234 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1235 .append("/repository/");
1236 return url.toString(); // The repository Tomcat context is supposed being defined
1239 public static Locale[] getSupportedLocales() {
1240 String[] code = _WAPPROPS.getProperty("locale.supported").split(",");
1241 Locale[] result = new Locale[code.length];
1242 for (int i = 0; i < code.length; i++) {
1243 result[i] = new Locale(code[i]);
1248 public static String[] getViewersMapping() {
1252 public static String getWebSiteURL() {
1253 return getApplicationProperty("wapp.website");
1256 public static String getHelpURL() {
1257 return getApplicationProperty("wapp.onlinehelp");
1260 // ==============================================================================================================================
1262 // ==============================================================================================================================
1265 * Load application custom configuration from the given XML file (see conf/my.xml).
1268 * the XML configuration file
1270 private static void loadCustomization(final File config) {
1272 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1274 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1276 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1277 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1278 .getDocumentElement());
1281 loadModules(children);
1284 loadConverters(children);
1287 loadTemplates(children);
1288 } catch (Exception error) {
1289 LOG.info("Error in customization", error);
1294 * Load modules from XML configuration.
1299 private static void loadModules(final Map<String, Node> children) {
1300 Node child = children.get("modules");
1301 NodeList nlist = child.getChildNodes();
1302 for (int i = 0; i < nlist.getLength(); i++) {
1303 child = nlist.item(i);
1304 if (!child.getNodeName().equals("mapping")) {
1308 NamedNodeMap natr = child.getAttributes();
1309 String dext = natr.getNamedItem("extension").getNodeValue();
1310 String exec = natr.getNamedItem("executable").getNodeValue();
1311 _WAPPROPS.put("executable." + dext, exec);
1313 // Viewer mappings tag
1314 child = children.get("viewers");
1315 viewermap = child.getAttributes().getNamedItem("extension")
1316 .getNodeValue().split(",");
1320 * Load converters from XML configuration.
1325 private static void loadConverters(final Map<String, Node> children) {
1326 Node child = children.get("converters");
1327 NodeList nlist = child.getChildNodes();
1328 for (int i = 0; i < nlist.getLength(); i++) {
1329 child = nlist.item(i);
1331 if (child.getNodeName().equals("geometry")) {
1332 NamedNodeMap natr = child.getAttributes();
1333 String from = natr.getNamedItem("from").getNodeValue();
1334 String to = natr.getNamedItem("to").getNodeValue();
1335 String exec = natr.getNamedItem("executable").getNodeValue();
1336 convertmap.put(from + "geometry", new Converter("geometry",
1343 * Load templates from XML configuration.
1348 private static void loadTemplates(final Map<String, Node> children) {
1349 Node child = children.get("templates");
1350 NodeList nlist = child.getChildNodes();
1351 for (int i = 0; i < nlist.getLength(); i++) {
1352 child = nlist.item(i);
1353 if (!child.getNodeName().equals("document")) {
1357 NamedNodeMap natr = child.getAttributes();
1358 String type = natr.getNamedItem("type").getNodeValue();
1359 String file = natr.getNamedItem("file").getNodeValue();
1360 tempfile.put(type, file);
1365 * Get the documentTypeService.
1367 * @return the documentTypeService
1369 public DocumentTypeService getDocumentTypeService() {
1370 return _documentTypeService;
1374 * Set the documentTypeService.
1376 * @param documentTypeService
1377 * the documentTypeService to set
1379 public void setDocumentTypeService(
1380 final DocumentTypeService documentTypeService) {
1381 _documentTypeService = documentTypeService;
1387 * @return the locale
1389 public Locale getLocale() {
1399 public void setLocale(final Locale locale) {