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.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 * Edit menu item name.
211 private static final String MNU_NAME_EDIT = "menu.edit";
213 * Script menu item name.
215 private static final String MNU_NAME_SCRIPT = "menu.newscenario";
217 * Version menu item name.
219 private static final String MNU_NAME_VERSION = "menu.version";
221 * Purge menu item name.
223 private static final String MNU_NAME_PURGE = "menu.purge";
225 * Remove menu item name.
227 private static final String MNU_NAME_REMOVE = "menu.remove.version";
229 * Rename menu item name.
231 private static final String MNU_NAME_RENAME = "menu.rename";
233 * Mark as reference menu item name.
235 private static final String MNU_MARK_AS_REFERENCE = "markasreference";
237 * Remove as reference menu item name.
239 private static final String MNU_REMOVE_AS_REFERENCE = "removeasreference";
241 * Mark as reference menu item label key.
243 private static final String MNU_NAME_MARK_AS_REFERENCE = "menu.markasreference";
245 * Remove as reference menu item label key.
247 private static final String MNU_NAME_REMOVE_AS_REFERENCE = "menu.removeasreference";
249 * Not yet implemented action name.
251 private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented";
253 * Attach action name.
255 private static final String ACT_ATTACH = "select-file?nextAction=attach";
257 * Version action name.
259 private static final String ACT_VERSION = "select-file?nextAction=version";
261 * Mark as reference action name.
263 private static final String ACT_MARK_AS_REFERENCE = "markasref-study";
265 * Remove as reference action name.
267 private static final String ACT_REMOVE_AS_REFERENCE = "removeasref-study";
270 * Siman application server name.
272 private transient final String _wappserver;
274 * Current user locale.
276 private transient Locale _locale;
280 private transient final Map<String, SimpleMenu> _menus = new HashMap<String, SimpleMenu>();
282 * Study module-bars structured by steps.
284 private transient Map<Integer, ToolBar> _bars = null;
288 private transient Map<String, PopupMenu> _popups = null;
290 * Named search filters.
292 private transient Map<String, Map<String, Object>> _filter = null;
294 * Injected project settings service.
296 private ProjectSettingsService _projectSettings;
298 * Injected document type service.
300 private DocumentTypeService _documentTypeService;
303 * Application settings constructor.
305 public ApplicationSettings() {
306 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
307 .currentRequestAttributes()).getRequest();
308 _wappserver = curRequest.getServerName() + ":"
309 + curRequest.getServerPort();
311 LOG.info("Application server is set to " + _wappserver);
312 LOG.info("Application name is set to " + wappname);
316 * Get the projectSettingsService.
318 * @return the projectSettingsService
320 public ProjectSettingsService getProjectSettings() {
321 return _projectSettings;
325 * Set the projectSettingsService.
327 * @param projectSettingsService
328 * the projectSettingsService to set
330 public void setProjectSettings(
331 final ProjectSettingsService projectSettingsService) {
332 _projectSettings = projectSettingsService;
335 private static class NewMenu extends SimpleMenu {
338 addItem("new-empty", "menu.new.empty", "image.empty.png",
339 "select?menu=create&item=new-empty");
340 addItem("new-copy", new MenuItem("menu.new.copy")
341 .icon("image.copy.png"));
343 * addItem("new-instance", new MenuItem("menu.new.instance") .icon(IMG_HOLD)); addItem("new-import", new
344 * MenuItem("menu.new.import") .icon("icon.upload.png"));
346 this.selects("new-empty");
350 private static class SearchMenu extends SimpleMenu {
351 private SearchMenu() {
353 addItem("search-study", "menu.search.study", "image.study.png",
354 "select?menu=search&item=search-study");
355 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
356 "select?menu=search&item=search-knowledge");
357 addItem("search-document", new MenuItem("menu.search.document")
358 .icon("icon.any.png"));
359 this.selects("search-study");
363 private static class PropertiesMenu extends SimpleMenu {
364 private PropertiesMenu() {
365 super("configuration");
366 addItem("prop-general", "menu.prop.general", IMG_HOLD,
367 "select?menu=configuration&item=prop-general");
368 addItem("prop-scenario", "menu.prop.scenario", IMG_HOLD,
369 "select?menu=configuration&item=prop-scenario");
370 // These menu items will not be implemented in the current version.
372 * addItem("prop-timestamp", new MenuItem("menu.prop.timestamp") .icon("image.stamp.png")); addItem("prop-comlog", new
373 * MenuItem("menu.prop.comlog") .icon(IMG_HOLD)); addItem("prop-version", new MenuItem("menu.prop.version")
374 * .icon("image.dirclosed.png"));
379 private static class DatadminMenu extends SimpleMenu {
380 private DatadminMenu() {
382 addItem("admin-scontext", "menu.admin.context", IMG_HOLD,
383 "select?menu=datadmin&item=admin-scontext");
384 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
385 "select?menu=datadmin&item=admin-knowelm");
386 addItem("admin-study", new MenuItem("menu.admin.study")
387 .icon("image.study.png"));
391 private static class SysadminMenu extends SimpleMenu {
392 private SysadminMenu() {
394 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
395 "select?menu=sysadmin&item=admin-indexing");
396 addItem("admin-importuser", "menu.admin.importuser",
398 "select?menu=sysadmin&item=admin-importuser");
403 * Menu items enumeration.
411 * Accept the document.
415 * Approve the document.
419 * Promote the document.
423 * Demote the docuemnt.
427 * Undo the last operation.
431 * Rename the document.
435 * Attach a file to the document.
447 * Version the document.
459 * Remove the document.
467 * Mark the study as reference.
472 // Resources relative to studies
473 private static class EditableMarkedStudyPopup extends PopupMenu {
474 private transient StudyRights _user = null;
476 private EditableMarkedStudyPopup() {
478 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(MNU_NAME_MARK_AS_REFERENCE)
479 .action(ACT_MARK_AS_REFERENCE).confirmation(
480 "message.markasreference.study"));
481 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon(
482 "image.publish.png").action("edit-study?action=publish")
483 .confirmation("message.publish.study"));
484 /* addItem(MNU_PROMOTE, new PopupItem("menu.archive")); */
486 addItem(MNU_EDIT, new PopupItem("menu.properties").icon(
487 "icon.ed.png").action("../select?menu=properties"));
489 addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT)
490 .action("add-scenario"));
492 * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
496 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
497 * PopupItem("menu.export") .icon("image.export.png")); // For future needs
498 */addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(
499 IMG_DELETE).action(ACT_NOT_YET_IMPLEMENTED).confirmation(
500 "message.delete.study"));
506 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
509 public boolean isEnabled(final String name) {
510 boolean res = (_user != null);
512 Item item = Item.valueOf(name);
515 res = _user.canPublish();
518 res = _user.canEditProperties();
521 res = _user.canAddScenario();
524 res = _user.canVersion();
527 res = _user.canRemove();
530 res = _user.canPurge();
532 case markasreference:
533 res = _user.canMarkStudyAsReference();
543 public void setContext(final String name, final Object context) {
544 if (context instanceof StudyRights) {
545 _user = (StudyRights) context; // Just for optimizing
546 boolean history = _user.getOperand().isVersioned();
547 PopupItem item = this.item(MNU_REMOVE);
549 item.rename(MNU_NAME_REMOVE);
551 item.rename("menu.remove.study");
557 // Resources relative to studies
558 private static class EditableUnmarkedStudyPopup extends PopupMenu {
559 private transient StudyRights _user = null;
561 private EditableUnmarkedStudyPopup() {
563 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(
564 MNU_NAME_REMOVE_AS_REFERENCE).action(ACT_REMOVE_AS_REFERENCE)
565 .confirmation("message.removeasreference.study"));
567 new PopupItem(MNU_NAME_PUBLISH).icon("image.publish.png")
568 .action("edit-study?action=publish")
569 .confirmation("message.publish.study"));
570 /* addItem(MNU_PROMOTE, new PopupItem("menu.archive")); */
573 new PopupItem("menu.properties").icon("icon.ed.png")
574 .action("../select?menu=properties"));
577 new PopupItem(MNU_NAME_SCRIPT).action("add-scenario"));
579 * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
583 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
584 * PopupItem("menu.export") .icon("image.export.png")); // For future needs
587 new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
588 .action(ACT_NOT_YET_IMPLEMENTED)
589 .confirmation("message.delete.study"));
595 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
598 public boolean isEnabled(final String name) {
599 boolean res = (_user != null);
601 Item item = Item.valueOf(name);
604 res = _user.canPublish();
607 res = _user.canEditProperties();
610 res = _user.canAddScenario();
613 res = _user.canVersion();
616 res = _user.canRemove();
619 res = _user.canPurge();
621 case markasreference:
622 res = _user.canRemoveStudyAsReference();
632 public void setContext(final String name, final Object context) {
633 if (context instanceof StudyRights) {
634 _user = (StudyRights) context; // Just for optimizing
635 boolean history = _user.getOperand().isVersioned();
636 PopupItem item = this.item(MNU_REMOVE);
638 item.rename(MNU_NAME_REMOVE);
640 item.rename("menu.remove.study");
646 // Resources relative to documents
648 * Popup of In-Work documents.
650 private static class EditableDocumentPopup extends PopupMenu {
651 private transient DocumentRights _user = null;
653 private EditableDocumentPopup() {
655 addItem("accept", new PopupItem("menu.accept").icon(
656 "image.accept.png").action("setDocument?action=accept")
657 .confirmation("message.accept.document"));
658 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
659 "image.publish.png").action("setDocument?action=promote")
660 .confirmation("message.promote.document"));
662 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
663 .action("edit-document?action=renameDocument"));
664 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
665 .action(ACT_ATTACH));
667 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
668 IMG_VERSION).action(ACT_VERSION));
669 addItem("replace", new PopupItem("menu.replace").icon(
670 "image.replace.png").action(
671 "select-file?nextAction=replace"));
673 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
674 ACT_NOT_YET_IMPLEMENTED).confirmation(
675 "message.purge.document"));
676 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
677 .action("remove-document").confirmation(
678 "message.delete.document"));
682 public boolean isEnabled(final String name) {
683 boolean res = (_user != null);
685 Item item = Item.valueOf(name);
688 res = _user.canAccept();
691 res = _user.canPromote();
694 res = _user.canRename();
697 res = _user.canAttach();
700 res = _user.canVersion();
703 res = _user.canReplace();
706 res = _user.canPurge();
709 res = _user.canRemove();
719 public void setContext(final String name, final Object context) {
720 if (context instanceof DocumentRights) {
721 _user = (DocumentRights) context; // Just for optimizing
722 Document downer = _user.getOperand();
723 PopupItem item = this.item(MNU_REMOVE);
724 if (downer.isVersioned()) {
725 item.rename(MNU_NAME_REMOVE);
727 item.rename("menu.remove.document");
734 * Popup of In-Draft documents.
736 private static class ReviewableDocumentPopup extends PopupMenu {
737 private transient DocumentRights _user = null;
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).icon(IMG_DELETE)
814 .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("menu.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_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
986 "image.review.png").action("promote-knowledge")
987 .confirmation("message.promote.knowledge"));
988 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
989 "image.invalidate.png").action("demote-knowledge")
990 .confirmation("message.demote.knowledge"));
992 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
993 .action("edit-knowledge?action=renameKnowledge"));
994 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
995 .action("edit-knowledge?action=editKnowledge"));
997 addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
998 .action("remove-knowledge").confirmation(
999 "message.delete.knowledge"));
1003 public boolean isEnabled(final String name) {
1004 Item item = Item.valueOf(name);
1007 if (item == Item.promote) {
1008 if (_owner.getProgressState() != ProgressState.inDRAFT) {
1011 } else if ((item == Item.demote)
1012 && (_owner.getProgressState() != ProgressState.inCHECK)) {
1019 public void setContext(final String name, final Object context) {
1020 if (context instanceof KnowledgeElement) {
1021 _owner = (KnowledgeElement) context; // Just for optimizing
1023 super.setContext(name, context);
1028 // ==============================================================================================================================
1030 // ==============================================================================================================================
1032 // ==============================================================================================================================
1033 // Public member functions
1034 // ==============================================================================================================================
1036 public void configure() {
1037 // Non customizable settings
1039 SimpleMenu menu = new NewMenu();
1040 _menus.put(menu.getName(), menu);
1041 menu = new SearchMenu();
1042 _menus.put(menu.getName(), menu);
1043 menu = new DatadminMenu();
1044 _menus.put(menu.getName(), menu);
1045 menu = new SysadminMenu();
1046 _menus.put(menu.getName(), menu);
1047 menu = new PropertiesMenu();
1048 _menus.put(menu.getName(), menu);
1050 _popups = new HashMap<String, PopupMenu>();
1051 _popups.put("steditablemark", new EditableMarkedStudyPopup());
1052 _popups.put("steditableunmark", new EditableUnmarkedStudyPopup());
1053 _popups.put("editable", new EditableDocumentPopup());
1054 _popups.put("notresult", new NotResultDocumentPopup());
1055 _popups.put("reviewable", new ReviewableDocumentPopup());
1056 _popups.put("approvable", new ApprovableDocumentPopup());
1057 _popups.put("approved", new ApprovedPopup());
1058 _popups.put("extern", new ExternPopup());
1059 _popups.put("scontext", new ScontextPopup());
1060 _popups.put("feedbex", new FeedbexPopup());
1062 // Default customizable mandatory settings
1063 Map<String, Object> fprop = new HashMap<String, Object>();
1064 fprop.put("visibility", "PRIVATE");
1065 fprop.put("matchamong", ALL);
1066 fprop.put("matcontext", ALL);
1067 fprop.put("state", "APPROVED");
1068 fprop.put("author", "0");
1069 fprop.put("reference", "");
1070 fprop.put("title", "");
1071 fprop.put("context", new ArrayList<SimulationContext>());
1073 Map<String, Object> gprop = new HashMap<String, Object>();
1074 gprop.put("visibility", "PUBLIC");
1075 gprop.put("matchamong", ALL);
1076 gprop.put("matcontext", ALL);
1077 gprop.put("type", "2"); // TODO: Get the index from the type name
1078 gprop.put("author", "0");
1079 gprop.put("reference", "");
1080 gprop.put("title", "");
1081 gprop.put("context", new ArrayList<SimulationContext>());
1083 _filter = new HashMap<String, Map<String, Object>>();
1084 _filter.put("study", fprop);
1085 _filter.put("knowledge", gprop);
1087 // Settings based on the customization
1088 configureToolbars();
1092 * Configure toolbars for steps.
1094 private void configureToolbars() {
1095 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
1097 List<ProjectSettingsService.Step> steps = getProjectSettings()
1099 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
1101 ProjectSettingsService.Step step = i.next();
1102 List<String> formats = getProjectSettings().getDefaultFormats(step);
1103 if (formats.isEmpty()) {
1107 ToolBar bar = new ToolBar(24); // Height of the module-bar
1108 Set<String> module = new HashSet<String>(); // For not duplicating modules
1109 for (String format : formats) {
1110 String command = getApplicationProperty("executable." + format);
1111 if (command == null) {
1112 continue; // Module not installed
1114 if (module.contains(command)) {
1117 module.add(command);
1118 String[] parsed = command.split("/");
1119 String[] name = parsed[parsed.length - 1].split("\\x2E");
1120 DocumentType dtype = getProjectSettings()
1121 .getDefaultDocumentType(step, format);
1122 String docname = "";
1123 if (dtype != null) {
1124 docname = dtype.getName();
1126 if (tempfile.get(docname) == null) { // No available template
1127 String tool = parsed[parsed.length - 1];
1128 String icon = name[0];
1129 if ("index".equals(icon)) {
1130 tool = parsed[parsed.length - 2];
1131 icon = "tool." + tool.toLowerCase() + ".png";
1133 icon = "tool." + icon.toLowerCase() + ".png";
1135 File image = new File(ApplicationSettings
1136 .getApplicationSkinPath()
1138 if (!image.exists()) {
1139 icon = "tool.any.png";
1141 bar.addTool(tool, icon, command);
1143 docname = "/jsp/newDocument.jsp?type=" + docname;
1144 String icon = "tool." + name[0].toLowerCase() + ".png";
1145 File image = new File(ApplicationSettings
1146 .getApplicationSkinPath()
1148 if (!image.exists()) {
1149 icon = "tool.any.png";
1151 bar.addTool(name[0], icon, command, docname);
1154 if (!bar.isEmpty()) {
1155 _bars.put(step.getNumber(), bar);
1160 public static String getApplicationProperty(final String name) {
1161 return _WAPPROPS.getProperty(name); // May be null
1164 public static String getApplicationRootPath() {
1165 // The property is supposed including the Web application name
1169 public String getApplicationURL() {
1170 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1171 .append("/").append(wappname);
1172 return url.toString();
1175 public Map<String, Object> getFilter(final String name) {
1176 return _filter.get(name);
1179 public ToolBar getModuleBar(final Step step) {
1180 return _bars.get(step.getNumber());
1183 static public Properties getNamingProperties() {
1187 // ==============================================================================================================================
1189 // ==============================================================================================================================
1191 public static String getApplicationPluginPath() {
1192 return getApplicationRootPath() + "plugin/";
1195 public static String getApplicationResourcePath() {
1196 return getApplicationRootPath() + "WEB-INF/classes/";
1199 public static String getApplicationSkinPath() {
1200 return getApplicationRootPath() + "skin/";
1203 public static Converter getConverter(final DocumentType type,
1204 final String format) {
1205 return convertmap.get(format + type.getName()); // May be null;
1209 * Get default document type for the given format on the given study step.
1215 * @return default document type or null if not defined in the configuration
1217 public DocumentType getDefaultDocumentType(final Step step,
1218 final String format) {
1219 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1220 format); // May be null
1223 public String getDownloadURL(final User user) {
1224 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1225 .append("/download/").append(user.getUsername()).append("/");
1226 return url.toString(); // The download Tomcat context is supposed being defined
1229 public Locale getCurrentLocale() {
1233 public SimpleMenu getMenu(final String name) {
1234 return _menus.get(name);
1237 public PopupMenu getPopupMenu(final String name) {
1238 return _popups.get(name);
1241 public String getRepositoryURL() {
1242 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1243 .append("/repository/");
1244 return url.toString(); // The repository Tomcat context is supposed being defined
1247 public static Locale[] getSupportedLocales() {
1248 String[] code = _WAPPROPS.getProperty("locale.supported").split(",");
1249 Locale[] result = new Locale[code.length];
1250 for (int i = 0; i < code.length; i++) {
1251 result[i] = new Locale(code[i]);
1256 public static String[] getViewersMapping() {
1260 public static String getWebSiteURL() {
1261 return getApplicationProperty("wapp.website");
1264 public static String getHelpURL() {
1265 return getApplicationProperty("wapp.onlinehelp");
1268 // ==============================================================================================================================
1270 // ==============================================================================================================================
1273 * Load application custom configuration from the given XML file (see conf/my.xml).
1276 * the XML configuration file
1278 private static void loadCustomization(final File config) {
1280 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1282 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1284 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1285 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1286 .getDocumentElement());
1289 loadModules(children);
1292 loadConverters(children);
1295 loadTemplates(children);
1296 } catch (Exception error) {
1297 LOG.info("Error in customization", error);
1302 * Load modules from XML configuration.
1307 private static void loadModules(final Map<String, Node> children) {
1308 Node child = children.get("modules");
1309 NodeList nlist = child.getChildNodes();
1310 for (int i = 0; i < nlist.getLength(); i++) {
1311 child = nlist.item(i);
1312 if (!child.getNodeName().equals("mapping")) {
1316 NamedNodeMap natr = child.getAttributes();
1317 String dext = natr.getNamedItem("extension").getNodeValue();
1318 String exec = natr.getNamedItem("executable").getNodeValue();
1319 _WAPPROPS.put("executable." + dext, exec);
1321 // Viewer mappings tag
1322 child = children.get("viewers");
1323 viewermap = child.getAttributes().getNamedItem("extension")
1324 .getNodeValue().split(",");
1328 * Load converters from XML configuration.
1333 private static void loadConverters(final Map<String, Node> children) {
1334 Node child = children.get("converters");
1335 NodeList nlist = child.getChildNodes();
1336 for (int i = 0; i < nlist.getLength(); i++) {
1337 child = nlist.item(i);
1339 if (child.getNodeName().equals("geometry")) {
1340 NamedNodeMap natr = child.getAttributes();
1341 String from = natr.getNamedItem("from").getNodeValue();
1342 String to = natr.getNamedItem("to").getNodeValue();
1343 String exec = natr.getNamedItem("executable").getNodeValue();
1344 convertmap.put(from + "geometry", new Converter("geometry",
1351 * Load templates from XML configuration.
1356 private static void loadTemplates(final Map<String, Node> children) {
1357 Node child = children.get("templates");
1358 NodeList nlist = child.getChildNodes();
1359 for (int i = 0; i < nlist.getLength(); i++) {
1360 child = nlist.item(i);
1361 if (!child.getNodeName().equals("document")) {
1365 NamedNodeMap natr = child.getAttributes();
1366 String type = natr.getNamedItem("type").getNodeValue();
1367 String file = natr.getNamedItem("file").getNodeValue();
1368 tempfile.put(type, file);
1373 * Get the documentTypeService.
1375 * @return the documentTypeService
1377 public DocumentTypeService getDocumentTypeService() {
1378 return _documentTypeService;
1382 * Set the documentTypeService.
1384 * @param documentTypeService
1385 * the documentTypeService to set
1387 public void setDocumentTypeService(
1388 final DocumentTypeService documentTypeService) {
1389 _documentTypeService = documentTypeService;
1395 * @return the locale
1397 public Locale getLocale() {
1407 public void setLocale(final Locale locale) {