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 * Mark as reference menu item label key.
239 private static final String MNU_NAME_MARK_AS_REFERENCE = "menu.markasreference";
241 * Not yet implemented action name.
243 private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented";
245 * Attach action name.
247 private static final String ACT_ATTACH = "select-file?nextAction=attach";
249 * Version action name.
251 private static final String ACT_VERSION = "select-file?nextAction=version";
254 * Siman application server name.
256 private transient final String _wappserver;
258 * Current user locale.
260 private transient Locale _locale;
264 private transient final Map<String, SimpleMenu> _menus = new HashMap<String, SimpleMenu>();
266 * Study module-bars structured by steps.
268 private transient Map<Integer, ToolBar> _bars = null;
272 private transient Map<String, PopupMenu> _popups = null;
274 * Named search filters.
276 private transient Map<String, Map<String, Object>> _filter = null;
278 * Injected project settings service.
280 private ProjectSettingsService _projectSettings;
282 * Injected document type service.
284 private DocumentTypeService _documentTypeService;
287 * Application settings constructor.
289 public ApplicationSettings() {
290 HttpServletRequest curRequest = ((ServletRequestAttributes) RequestContextHolder
291 .currentRequestAttributes()).getRequest();
292 _wappserver = curRequest.getServerName() + ":"
293 + curRequest.getServerPort();
295 LOG.info("Application server is set to " + _wappserver);
296 LOG.info("Application name is set to " + wappname);
300 * Get the projectSettingsService.
302 * @return the projectSettingsService
304 public ProjectSettingsService getProjectSettings() {
305 return _projectSettings;
309 * Set the projectSettingsService.
311 * @param projectSettingsService
312 * the projectSettingsService to set
314 public void setProjectSettings(
315 final ProjectSettingsService projectSettingsService) {
316 _projectSettings = projectSettingsService;
319 private static class NewMenu extends SimpleMenu {
322 addItem("new-empty", "menu.new.empty", "image.empty.png",
323 "select?menu=create&item=new-empty");
324 addItem("new-copy", new MenuItem("menu.new.copy")
325 .icon("image.copy.png"));
327 * addItem("new-instance", new MenuItem("menu.new.instance") .icon(IMG_HOLD)); addItem("new-import", new
328 * MenuItem("menu.new.import") .icon("icon.upload.png"));
330 this.selects("new-empty");
334 private static class SearchMenu extends SimpleMenu {
335 private SearchMenu() {
337 addItem("search-study", "menu.search.study", "image.study.png",
338 "select?menu=search&item=search-study");
339 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
340 "select?menu=search&item=search-knowledge");
341 addItem("search-document", new MenuItem("menu.search.document")
342 .icon("icon.any.png"));
343 this.selects("search-study");
347 private static class PropertiesMenu extends SimpleMenu {
348 private PropertiesMenu() {
349 super("configuration");
350 addItem("prop-general", "menu.prop.general", IMG_HOLD,
351 "select?menu=configuration&item=prop-general");
352 addItem("prop-scenario", "menu.prop.scenario", IMG_HOLD,
353 "select?menu=configuration&item=prop-scenario");
354 // These menu items will not be implemented in the current version.
356 * addItem("prop-timestamp", new MenuItem("menu.prop.timestamp") .icon("image.stamp.png")); addItem("prop-comlog", new
357 * MenuItem("menu.prop.comlog") .icon(IMG_HOLD)); addItem("prop-version", new MenuItem("menu.prop.version")
358 * .icon("image.dirclosed.png"));
363 private static class DatadminMenu extends SimpleMenu {
364 private DatadminMenu() {
366 addItem("admin-scontext", "menu.admin.context", IMG_HOLD,
367 "select?menu=datadmin&item=admin-scontext");
368 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
369 "select?menu=datadmin&item=admin-knowelm");
370 addItem("admin-study", new MenuItem("menu.admin.study")
371 .icon("image.study.png"));
375 private static class SysadminMenu extends SimpleMenu {
376 private SysadminMenu() {
378 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
379 "select?menu=sysadmin&item=admin-indexing");
380 addItem("admin-importuser", "menu.admin.importuser",
382 "select?menu=sysadmin&item=admin-importuser");
387 * Menu items enumeration.
395 * Accept the document.
399 * Approve the document.
403 * Promote the document.
407 * Demote the docuemnt.
411 * Undo the last operation.
415 * Rename the document.
419 * Attach a file to the document.
431 * Version the document.
443 * Remove the document.
451 * Mark the study as reference.
456 // Resources relative to studies
457 private static class EditableStudyPopup extends PopupMenu {
458 private transient StudyRights _user = null;
460 private EditableStudyPopup() {
462 addItem(MNU_MARK_AS_REFERENCE, new PopupItem(MNU_NAME_MARK_AS_REFERENCE)
463 .action(ACT_NOT_YET_IMPLEMENTED).confirmation(
464 "message.markasreference.study"));
465 addItem(MNU_PUBLISH, new PopupItem(MNU_NAME_PUBLISH).icon(
466 "image.publish.png").action("edit-study?action=publish")
467 .confirmation("message.publish.study"));
468 /* addItem(MNU_PROMOTE, new PopupItem("menu.archive")); */
470 addItem(MNU_EDIT, new PopupItem("menu.properties").icon(
471 "icon.ed.png").action("../select?menu=properties"));
473 addItem(MNU_SCRIPT, new PopupItem(MNU_NAME_SCRIPT)
474 .action("add-scenario"));
476 * addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon( IMG_VERSION).action(ACT_NOT_YET_IMPLEMENTED));
480 * addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE) .confirmation("message.purge.study")); addItem("export", new
481 * PopupItem("menu.export") .icon("image.export.png")); // For future needs
482 */addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(
483 IMG_DELETE).action(ACT_NOT_YET_IMPLEMENTED).confirmation(
484 "message.delete.study"));
489 * @see org.splat.wapp.ContextualMenu#isEnabled(java.lang.String)
492 public boolean isEnabled(final String name) {
493 boolean res = (_user != null);
495 Item item = Item.valueOf(name);
498 res = _user.canPublish();
501 res = _user.canEditProperties();
504 res = _user.canAddScenario();
507 res = _user.canVersion();
510 res = _user.canRemove();
513 res = _user.canPurge();
523 public void setContext(final String name, final Object context) {
524 if (context instanceof StudyRights) {
525 _user = (StudyRights) context; // Just for optimizing
526 boolean history = _user.getOperand().isVersioned();
527 PopupItem item = this.item(MNU_REMOVE);
529 item.rename(MNU_NAME_REMOVE);
531 item.rename("menu.remove.study");
537 // Resources relative to documents
539 * Popup of In-Work documents.
541 private static class EditableDocumentPopup extends PopupMenu {
542 private transient DocumentRights _user = null;
544 private EditableDocumentPopup() {
546 addItem("accept", new PopupItem("menu.accept").icon(
547 "image.accept.png").action("setDocument?action=accept")
548 .confirmation("message.accept.document"));
549 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
550 "image.publish.png").action("setDocument?action=promote")
551 .confirmation("message.promote.document"));
553 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
554 .action("edit-document?action=renameDocument"));
555 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
556 .action(ACT_ATTACH));
558 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
559 IMG_VERSION).action(ACT_VERSION));
560 addItem("replace", new PopupItem("menu.replace").icon(
561 "image.replace.png").action(
562 "select-file?nextAction=replace"));
564 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
565 ACT_NOT_YET_IMPLEMENTED).confirmation(
566 "message.purge.document"));
567 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
568 .action("remove-document").confirmation(
569 "message.delete.document"));
573 public boolean isEnabled(final String name) {
574 boolean res = (_user != null);
576 Item item = Item.valueOf(name);
579 res = _user.canAccept();
582 res = _user.canPromote();
585 res = _user.canRename();
588 res = _user.canAttach();
591 res = _user.canVersion();
594 res = _user.canReplace();
597 res = _user.canPurge();
600 res = _user.canRemove();
610 public void setContext(final String name, final Object context) {
611 if (context instanceof DocumentRights) {
612 _user = (DocumentRights) context; // Just for optimizing
613 Document downer = _user.getOperand();
614 PopupItem item = this.item(MNU_REMOVE);
615 if (downer.isVersioned()) {
616 item.rename(MNU_NAME_REMOVE);
618 item.rename("menu.remove.document");
625 * Popup of In-Draft documents.
627 private static class ReviewableDocumentPopup extends PopupMenu {
628 private transient DocumentRights _user = null;
630 private ReviewableDocumentPopup() {
632 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
633 "image.demote.png").action("setDocument?action=demote")
634 .confirmation("message.demote.document"));
635 addItem(MNU_PROMOTE, new PopupItem("menu.review").icon(
636 "image.review.png").action("setDocument?action=review")
637 .confirmation("message.review.document"));
639 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
640 .action(ACT_ATTACH));
642 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
643 IMG_VERSION).action(ACT_VERSION));
645 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
646 ACT_NOT_YET_IMPLEMENTED).confirmation(
647 "message.purge.document"));
651 public boolean isEnabled(final String name) {
652 boolean res = (_user != null);
654 Item item = Item.valueOf(name);
657 res = _user.canDemote();
660 res = _user.canReview();
663 res = _user.canAttach();
666 res = _user.canVersion();
669 res = _user.canPurge();
679 public void setContext(final String name, final Object context) {
680 if (context instanceof DocumentRights) {
681 _user = (DocumentRights) context; // Just for optimizing
686 private static class NotResultDocumentPopup extends PopupMenu {
687 // private final DocumentRights _user = null;
689 private NotResultDocumentPopup() {
691 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
692 "image.demote.png").action("setDocument?action=demote")
693 .confirmation("message.demote.document"));
695 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
696 .action(ACT_ATTACH));
698 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
699 IMG_VERSION).action(ACT_VERSION));
701 addItem(MNU_PURGE, new PopupItem(MNU_NAME_PURGE).action(
702 ACT_NOT_YET_IMPLEMENTED).confirmation(
703 "message.purge.document"));
704 addItem(MNU_REMOVE, new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
705 .action("remove-document").confirmation(
706 "message.delete.document"));
711 * Popup of In-Check documents.
713 private static class ApprovableDocumentPopup extends PopupMenu {
714 private transient DocumentRights _user = null;
716 private ApprovableDocumentPopup() {
718 addItem("undo", new PopupItem(MNU_NAME_DEMOTE).icon(
719 "image.invalidate.png").action(
720 "setDocument?action=invalidate").confirmation(
721 "message.demote.document"));
722 addItem(MNU_DEMOTE, new PopupItem("menu.disapprove").icon(
723 "image.demote.png").action("setDocument?action=disapprove")
724 .confirmation("message.disapprove.document"));
725 addItem("approve", new PopupItem("menu.approve").icon(
726 "icon.APPROVED.png").action("setDocument?action=approve")
727 .confirmation("message.approve.document"));
731 public boolean isEnabled(final String name) {
732 boolean res = (_user != null);
734 Item item = Item.valueOf(name);
737 res = _user.canInvalidate();
740 res = _user.canDemote();
743 res = _user.canApprove();
753 public void setContext(final String name, final Object context) {
754 if (context instanceof DocumentRights) {
755 _user = (DocumentRights) context; // Just for optimizing
761 * Popup of Approved documents.
763 private static class ApprovedPopup extends PopupMenu {
764 private ApprovedPopup() {
766 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
767 .action(ACT_ATTACH));
769 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
770 IMG_VERSION).action(ACT_VERSION));
775 * Popup of Extern documents.
777 private static class ExternPopup extends PopupMenu {
778 private transient DocumentRights _user = null;
780 private ExternPopup() {
782 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
783 .action("edit-document?action=renameDocument"));
785 addItem(MNU_VERSION, new PopupItem(MNU_NAME_VERSION).icon(
786 IMG_VERSION).action(ACT_VERSION));
788 addItem("replace", new PopupItem("menu.replace").icon(
789 "image.replace.png").action(
790 "select-file?nextAction=replace"));
792 addItem(MNU_REMOVE, new PopupItem("menu.remove.document").icon(
793 IMG_DELETE).action("remove-document").confirmation(
794 "message.delete.document"));
798 public boolean isEnabled(final String name) {
799 boolean res = (_user != null);
801 Item item = Item.valueOf(name);
804 res = _user.canRename();
807 res = _user.canVersion();
810 res = _user.canReplace();
813 res = _user.canRemove();
823 public void setContext(final String name, final Object context) {
824 if (context instanceof DocumentRights) {
825 _user = (DocumentRights) context; // Just for optimizing
830 // Resources relative to simulation contexts
831 private static class ScontextPopup extends PopupMenu {
832 private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it.
834 private ScontextPopup() {
836 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
837 .action("edit-context?action=renameContext"));
838 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
839 .action("edit-context?action=editContext"));
841 addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
842 .action("remove-context").confirmation(
843 "message.delete.context"));
847 public boolean isEnabled(final String name) {
848 Item item = Item.valueOf(name);
851 if (item == Item.rename) {
853 } else if (item == Item.edit) {
854 // if (!owner.isEditable())
861 public void setContext(final String name, final Object context) {
862 if (context instanceof SimulationContextFacade) {
863 _owner = (SimulationContextFacade) context; // Just for optimizing
865 super.setContext(name, context);
870 // Resources relative to knowledge
871 private static class FeedbexPopup extends PopupMenu {
872 private transient KnowledgeElement _owner = null;
874 private FeedbexPopup() {
876 addItem(MNU_PROMOTE, new PopupItem(MNU_NAME_PROMOTE).icon(
877 "image.review.png").action("promote-knowledge")
878 .confirmation("message.promote.knowledge"));
879 addItem(MNU_DEMOTE, new PopupItem(MNU_NAME_DEMOTE).icon(
880 "image.invalidate.png").action("demote-knowledge")
881 .confirmation("message.demote.knowledge"));
883 addItem(MNU_RENAME, new PopupItem(MNU_NAME_RENAME)
884 .action("edit-knowledge?action=renameKnowledge"));
885 addItem(MNU_EDIT, new PopupItem(MNU_NAME_EDIT)
886 .action("edit-knowledge?action=editKnowledge"));
888 addItem(MNU_REMOVE, new PopupItem("menu.remove").icon(IMG_DELETE)
889 .action("remove-knowledge").confirmation(
890 "message.delete.knowledge"));
894 public boolean isEnabled(final String name) {
895 Item item = Item.valueOf(name);
898 if (item == Item.promote) {
899 if (_owner.getProgressState() != ProgressState.inDRAFT) {
902 } else if ((item == Item.demote)
903 && (_owner.getProgressState() != ProgressState.inCHECK)) {
910 public void setContext(final String name, final Object context) {
911 if (context instanceof KnowledgeElement) {
912 _owner = (KnowledgeElement) context; // Just for optimizing
914 super.setContext(name, context);
919 // ==============================================================================================================================
921 // ==============================================================================================================================
923 // ==============================================================================================================================
924 // Public member functions
925 // ==============================================================================================================================
927 public void configure() {
928 // Non customizable settings
930 SimpleMenu menu = new NewMenu();
931 _menus.put(menu.getName(), menu);
932 menu = new SearchMenu();
933 _menus.put(menu.getName(), menu);
934 menu = new DatadminMenu();
935 _menus.put(menu.getName(), menu);
936 menu = new SysadminMenu();
937 _menus.put(menu.getName(), menu);
938 menu = new PropertiesMenu();
939 _menus.put(menu.getName(), menu);
941 _popups = new HashMap<String, PopupMenu>();
942 _popups.put("steditable", new EditableStudyPopup());
943 _popups.put("editable", new EditableDocumentPopup());
944 _popups.put("notresult", new NotResultDocumentPopup());
945 _popups.put("reviewable", new ReviewableDocumentPopup());
946 _popups.put("approvable", new ApprovableDocumentPopup());
947 _popups.put("approved", new ApprovedPopup());
948 _popups.put("extern", new ExternPopup());
949 _popups.put("scontext", new ScontextPopup());
950 _popups.put("feedbex", new FeedbexPopup());
952 // Default customizable mandatory settings
953 Map<String, Object> fprop = new HashMap<String, Object>();
954 fprop.put("visibility", "PRIVATE");
955 fprop.put("matchamong", ALL);
956 fprop.put("matcontext", ALL);
957 fprop.put("state", "APPROVED");
958 fprop.put("author", "0");
959 fprop.put("reference", "");
960 fprop.put("title", "");
961 fprop.put("context", new ArrayList<SimulationContext>());
963 Map<String, Object> gprop = new HashMap<String, Object>();
964 gprop.put("visibility", "PUBLIC");
965 gprop.put("matchamong", ALL);
966 gprop.put("matcontext", ALL);
967 gprop.put("type", "2"); // TODO: Get the index from the type name
968 gprop.put("author", "0");
969 gprop.put("reference", "");
970 gprop.put("title", "");
971 gprop.put("context", new ArrayList<SimulationContext>());
973 _filter = new HashMap<String, Map<String, Object>>();
974 _filter.put("study", fprop);
975 _filter.put("knowledge", gprop);
977 // Settings based on the customization
982 * Configure toolbars for steps.
984 private void configureToolbars() {
985 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
987 List<ProjectSettingsService.Step> steps = getProjectSettings()
989 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
991 ProjectSettingsService.Step step = i.next();
992 List<String> formats = getProjectSettings().getDefaultFormats(step);
993 if (formats.isEmpty()) {
997 ToolBar bar = new ToolBar(24); // Height of the module-bar
998 Set<String> module = new HashSet<String>(); // For not duplicating modules
999 for (String format : formats) {
1000 String command = getApplicationProperty("executable." + format);
1001 if (command == null) {
1002 continue; // Module not installed
1004 if (module.contains(command)) {
1007 module.add(command);
1008 String[] parsed = command.split("/");
1009 String[] name = parsed[parsed.length - 1].split("\\x2E");
1010 DocumentType dtype = getProjectSettings()
1011 .getDefaultDocumentType(step, format);
1012 String docname = "";
1013 if (dtype != null) {
1014 docname = dtype.getName();
1016 if (tempfile.get(docname) == null) { // No available template
1017 String tool = parsed[parsed.length - 1];
1018 String icon = name[0];
1019 if ("index".equals(icon)) {
1020 tool = parsed[parsed.length - 2];
1021 icon = "tool." + tool.toLowerCase() + ".png";
1023 icon = "tool." + icon.toLowerCase() + ".png";
1025 File image = new File(ApplicationSettings
1026 .getApplicationSkinPath()
1028 if (!image.exists()) {
1029 icon = "tool.any.png";
1031 bar.addTool(tool, icon, command);
1033 docname = "/jsp/newDocument.jsp?type=" + docname;
1034 String icon = "tool." + name[0].toLowerCase() + ".png";
1035 File image = new File(ApplicationSettings
1036 .getApplicationSkinPath()
1038 if (!image.exists()) {
1039 icon = "tool.any.png";
1041 bar.addTool(name[0], icon, command, docname);
1044 if (!bar.isEmpty()) {
1045 _bars.put(step.getNumber(), bar);
1050 public static String getApplicationProperty(final String name) {
1051 return _WAPPROPS.getProperty(name); // May be null
1054 public static String getApplicationRootPath() {
1055 // The property is supposed including the Web application name
1059 public String getApplicationURL() {
1060 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1061 .append("/").append(wappname);
1062 return url.toString();
1065 public Map<String, Object> getFilter(final String name) {
1066 return _filter.get(name);
1069 public ToolBar getModuleBar(final Step step) {
1070 return _bars.get(step.getNumber());
1073 static public Properties getNamingProperties() {
1077 // ==============================================================================================================================
1079 // ==============================================================================================================================
1081 public static String getApplicationPluginPath() {
1082 return getApplicationRootPath() + "plugin/";
1085 public static String getApplicationResourcePath() {
1086 return getApplicationRootPath() + "WEB-INF/classes/";
1089 public static String getApplicationSkinPath() {
1090 return getApplicationRootPath() + "skin/";
1093 public static Converter getConverter(final DocumentType type,
1094 final String format) {
1095 return convertmap.get(format + type.getName()); // May be null;
1098 public DocumentType getDefaultDocumentType(final Step step,
1099 final String format) {
1100 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1101 format); // May be null
1104 public String getDownloadURL(final User user) {
1105 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1106 .append("/download/").append(user.getUsername()).append("/");
1107 return url.toString(); // The download Tomcat context is supposed being defined
1110 public Locale getCurrentLocale() {
1114 public SimpleMenu getMenu(final String name) {
1115 return _menus.get(name);
1118 public PopupMenu getPopupMenu(final String name) {
1119 return _popups.get(name);
1122 public String getRepositoryURL() {
1123 StringBuffer url = new StringBuffer("http://").append(_wappserver)
1124 .append("/repository/");
1125 return url.toString(); // The repository Tomcat context is supposed being defined
1128 public static Locale[] getSupportedLocales() {
1129 String[] code = _WAPPROPS.getProperty("locale.supported").split(",");
1130 Locale[] result = new Locale[code.length];
1131 for (int i = 0; i < code.length; i++) {
1132 result[i] = new Locale(code[i]);
1137 public static String[] getViewersMapping() {
1141 public static String getWebSiteURL() {
1142 return getApplicationProperty("wapp.website");
1145 public static String getHelpURL() {
1146 return getApplicationProperty("wapp.onlinehelp");
1149 // ==============================================================================================================================
1151 // ==============================================================================================================================
1154 * Load application custom configuration from the given XML file (see conf/my.xml).
1157 * the XML configuration file
1159 private static void loadCustomization(final File config) {
1161 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1163 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1165 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1166 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1167 .getDocumentElement());
1170 loadModules(children);
1173 loadConverters(children);
1176 loadTemplates(children);
1177 } catch (Exception error) {
1178 LOG.info("Error in customization", error);
1183 * Load modules from XML configuration.
1188 private static void loadModules(final Map<String, Node> children) {
1189 Node child = children.get("modules");
1190 NodeList nlist = child.getChildNodes();
1191 for (int i = 0; i < nlist.getLength(); i++) {
1192 child = nlist.item(i);
1193 if (!child.getNodeName().equals("mapping")) {
1197 NamedNodeMap natr = child.getAttributes();
1198 String dext = natr.getNamedItem("extension").getNodeValue();
1199 String exec = natr.getNamedItem("executable").getNodeValue();
1200 _WAPPROPS.put("executable." + dext, exec);
1202 // Viewer mappings tag
1203 child = children.get("viewers");
1204 viewermap = child.getAttributes().getNamedItem("extension")
1205 .getNodeValue().split(",");
1209 * Load converters from XML configuration.
1214 private static void loadConverters(final Map<String, Node> children) {
1215 Node child = children.get("converters");
1216 NodeList nlist = child.getChildNodes();
1217 for (int i = 0; i < nlist.getLength(); i++) {
1218 child = nlist.item(i);
1220 if (child.getNodeName().equals("geometry")) {
1221 NamedNodeMap natr = child.getAttributes();
1222 String from = natr.getNamedItem("from").getNodeValue();
1223 String to = natr.getNamedItem("to").getNodeValue();
1224 String exec = natr.getNamedItem("executable").getNodeValue();
1225 convertmap.put(from + "geometry", new Converter("geometry",
1232 * Load templates from XML configuration.
1237 private static void loadTemplates(final Map<String, Node> children) {
1238 Node child = children.get("templates");
1239 NodeList nlist = child.getChildNodes();
1240 for (int i = 0; i < nlist.getLength(); i++) {
1241 child = nlist.item(i);
1242 if (!child.getNodeName().equals("document")) {
1246 NamedNodeMap natr = child.getAttributes();
1247 String type = natr.getNamedItem("type").getNodeValue();
1248 String file = natr.getNamedItem("file").getNodeValue();
1249 tempfile.put(type, file);
1254 * Get the documentTypeService.
1256 * @return the documentTypeService
1258 public DocumentTypeService getDocumentTypeService() {
1259 return _documentTypeService;
1263 * Set the documentTypeService.
1265 * @param documentTypeService
1266 * the documentTypeService to set
1268 public void setDocumentTypeService(
1269 final DocumentTypeService documentTypeService) {
1270 _documentTypeService = documentTypeService;
1276 * @return the locale
1278 public Locale getLocale() {
1288 public void setLocale(final Locale locale) {