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.ServletContext;
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.ServletContextAware;
38 import org.w3c.dom.NamedNodeMap;
39 import org.w3c.dom.Node;
40 import org.w3c.dom.NodeList;
43 * SIMAN project settings service. Provides settings according to XML customization.
45 public class ApplicationSettings implements ServletContextAware {
48 * Application settings logger.
50 protected final static Logger LOG = Logger
51 .getLogger(ApplicationSettings.class);
54 * Singleton instance of application settings service.
56 private static final ApplicationSettings MY_APP = new ApplicationSettings();
61 private static final String ALL = "all";
64 * Hold icon file name.
66 private static final String IMG_HOLD = "image.hold.gif";
68 * Attach icon file name.
70 private static final String IMG_ATTACH = "image.attach.png";
72 * Version icon file name.
74 private static final String IMG_VERSION = "image.version.png";
76 * Delete icon file name.
78 private static final String IMG_DELETE = "icon.delete.png";
80 * Attach menu item name.
82 private static final String MNU_ATTACH = "attach";
84 * Demote menu item name.
86 private static final String MNU_DEMOTE = "demote";
88 * Promote menu item name.
90 private static final String MNU_PROMOTE = "promote";
92 * Publish menu item name.
94 private static final String MNU_PUBLISH = "publish";
96 * Edit menu item name.
98 private static final String MNU_EDIT = "edit";
100 * Script menu item name.
102 private static final String MNU_SCRIPT = "script";
104 * Version menu item name.
106 private static final String MNU_VERSION = "version";
108 * Purge menu item name.
110 private static final String MNU_PURGE = "purge";
112 * Remove menu item name.
114 private static final String MNU_REMOVE = "remove";
116 * Rename menu item name.
118 private static final String MNU_RENAME = "rename";
121 * Attach menu item name.
123 private static final String MNU_NAME_ATTACH = "menu.attach";
125 * Demote menu item name.
127 private static final String MNU_NAME_DEMOTE = "menu.demote";
129 * Promote menu item name.
131 private static final String MNU_NAME_PROMOTE = "menu.promote";
133 * Publish menu item name.
135 private static final String MNU_NAME_PUBLISH = "menu.publish";
137 * Edit menu item name.
139 private static final String MNU_NAME_EDIT = "menu.edit";
141 * Script menu item name.
143 private static final String MNU_NAME_SCRIPT = "menu.newscenario";
145 * Version menu item name.
147 private static final String MNU_NAME_VERSION = "menu.version";
149 * Purge menu item name.
151 private static final String MNU_NAME_PURGE = "menu.purge";
153 * Remove menu item name.
155 private static final String MNU_NAME_REMOVE = "menu.remove.version";
157 * Rename menu item name.
159 private static final String MNU_NAME_RENAME = "menu.rename";
161 * Not yet implemented action name.
163 private static final String ACT_NOT_YET_IMPLEMENTED = "notyetimplemented";
165 * Attach action name.
167 private static final String ACT_ATTACH = "select-file?nextAction=attach";
169 * Version action name.
171 private static final String ACT_VERSION = "select-file?nextAction=version";
174 * Injected servlet context to get path to resources.
176 private transient ServletContext _servletContext;
179 * Siman application server name.
181 private transient String _wappserver;
183 * Siman web application name.
185 private transient String _wappname;
187 * General properties from the application properties files.
189 private transient final Properties _wapprops = new Properties();
191 * Current user locale.
193 private transient Locale _locale;
197 private transient final Map<String, SimpleMenu> _menus = new HashMap<String, SimpleMenu>();
199 * Study module-bars structured by steps.
201 private transient Map<Integer, ToolBar> _bars = null;
205 private transient Map<String, PopupMenu> _popups = null;
207 * Named search filters.
209 private transient Map<String, Map<String, Object>> _filter = null;
211 * Available template files.
213 private transient Map<String, String> _tempfile = null;
215 * List of file extensions mapped to a viewer.
217 private transient String[] _viewermap = null;
219 * Available document format converters.
221 private transient Map<String, Converter> _convertmap = null;
223 * JNDI context for launching converters.
225 private transient final Properties _jndprops = new Properties();
227 * Injected project settings service.
229 private ProjectSettingsService _projectSettings;
231 * Injected document type service.
233 private DocumentTypeService _documentTypeService;
236 * Get the projectSettingsService.
238 * @return the projectSettingsService
240 public ProjectSettingsService getProjectSettings() {
241 return _projectSettings;
245 * Set the projectSettingsService.
247 * @param projectSettingsService
248 * the projectSettingsService to set
250 public void setProjectSettings(
251 final ProjectSettingsService projectSettingsService) {
252 _projectSettings = projectSettingsService;
255 private static class NewMenu extends SimpleMenu {
258 addItem("new-empty", "menu.new.empty", "image.empty.png",
259 "select?menu=create&item=new-empty");
261 new MenuItem("menu.new.copy").icon("image.copy.png"));
262 addItem("new-instance",
263 new MenuItem("menu.new.instance").icon(IMG_HOLD));
264 addItem("new-import",
265 new MenuItem("menu.new.import").icon("icon.upload.png"));
266 this.selects("new-empty");
270 private static class SearchMenu extends SimpleMenu {
271 private SearchMenu() {
273 addItem("search-study", "menu.search.study", "image.study.png",
274 "select?menu=search&item=search-study");
275 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
276 "select?menu=search&item=search-knowledge");
277 addItem("search-document",
278 new MenuItem("menu.search.document").icon("icon.any.png"));
279 this.selects("search-study");
283 private static class PropertiesMenu extends SimpleMenu {
284 private PropertiesMenu() {
285 super("configuration");
286 addItem("prop-general", "menu.prop.general", IMG_HOLD,
287 "select?menu=properties&item=prop-general");
288 addItem("prop-scenario", "menu.prop.scenario", IMG_HOLD,
289 "select?menu=properties&item=prop-scenario");
290 // These menu items will not be implemented in the current version.
292 * addItem("prop-timestamp", new MenuItem("menu.prop.timestamp") .icon("image.stamp.png")); addItem("prop-comlog", new
293 * MenuItem("menu.prop.comlog") .icon(IMG_HOLD)); addItem("prop-version", new MenuItem("menu.prop.version")
294 * .icon("image.dirclosed.png"));
299 private static class DatadminMenu extends SimpleMenu {
300 private DatadminMenu() {
302 addItem("admin-scontext", "menu.admin.context", IMG_HOLD,
303 "select?menu=datadmin&item=admin-scontext");
304 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
305 "select?menu=datadmin&item=admin-knowelm");
306 addItem("admin-study",
307 new MenuItem("menu.admin.study").icon("image.study.png"));
311 private static class SysadminMenu extends SimpleMenu {
312 private SysadminMenu() {
314 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
315 "select?menu=sysadmin&item=admin-indexing");
316 addItem("admin-importuser", "menu.admin.importuser",
318 "select?menu=sysadmin&item=admin-importuser");
323 publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge
326 // Resources relative to studies
327 private static class EditableStudyPopup extends PopupMenu {
328 private transient StudyRights _user = null;
330 private EditableStudyPopup() {
333 new PopupItem(MNU_NAME_PUBLISH).icon("image.publish.png")
334 .action("edit-study?action=publish")
335 .confirmation("message.publish.study"));
336 addItem(MNU_PROMOTE, new PopupItem("menu.archive"));
339 new PopupItem("menu.properties").icon("icon.ed.png")
340 .action("../select?menu=properties"));
343 new PopupItem(MNU_NAME_SCRIPT).action("add-scenario"));
345 new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action(
346 ACT_NOT_YET_IMPLEMENTED));
349 new PopupItem(MNU_NAME_PURGE)
350 .confirmation("message.purge.study"));
352 new PopupItem("menu.export").icon("image.export.png")); // For future needs
354 new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
355 .action(ACT_NOT_YET_IMPLEMENTED)
356 .confirmation("message.delete.study"));
360 public boolean isEnabled(final String name) {
361 boolean res = (_user != null);
363 Item item = Item.valueOf(name);
366 res = _user.canPublish();
369 res = _user.canEditProperties();
372 res = _user.canAddScenario();
375 res = _user.canVersion();
378 res = _user.canRemove();
381 res = _user.canPurge();
391 public void setContext(final String name, final Object context) {
392 if (context instanceof StudyRights) {
393 _user = (StudyRights) context; // Just for optimizing
394 boolean history = _user.getOperand().isVersioned();
395 PopupItem item = this.item(MNU_REMOVE);
397 item.rename(MNU_NAME_REMOVE);
399 item.rename("menu.remove.study");
405 // Resources relative to documents
407 * Popup of In-Work documents.
409 private static class EditableDocumentPopup extends PopupMenu {
410 private transient DocumentRights _user = null;
412 private EditableDocumentPopup() {
415 new PopupItem("menu.accept").icon("image.accept.png")
416 .action("setDocument?action=accept")
417 .confirmation("message.accept.document"));
419 new PopupItem(MNU_NAME_PROMOTE).icon("image.publish.png")
420 .action("setDocument?action=promote")
421 .confirmation("message.promote.document"));
424 new PopupItem(MNU_NAME_RENAME)
425 .action("edit-document?action=renameDocument"));
426 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
427 .action(ACT_ATTACH));
430 new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action(
433 new PopupItem("menu.replace").icon("image.replace.png")
434 .action("select-file?nextAction=replace"));
437 new PopupItem(MNU_NAME_PURGE).action(
438 ACT_NOT_YET_IMPLEMENTED).confirmation(
439 "message.purge.document"));
441 new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
442 .action("remove-document")
443 .confirmation("message.delete.document"));
447 public boolean isEnabled(final String name) {
448 boolean res = (_user != null);
450 Item item = Item.valueOf(name);
453 res = _user.canAccept();
456 res = _user.canPromote();
459 res = _user.canRename();
462 res = _user.canAttach();
465 res = _user.canVersion();
468 res = _user.canReplace();
471 res = _user.canPurge();
474 res = _user.canRemove();
484 public void setContext(final String name, final Object context) {
485 if (context instanceof DocumentRights) {
486 _user = (DocumentRights) context; // Just for optimizing
487 Document downer = _user.getOperand();
488 PopupItem item = this.item(MNU_REMOVE);
489 if (downer.isVersioned()) {
490 item.rename(MNU_NAME_REMOVE);
492 item.rename("menu.remove.document");
499 * Popup of In-Draft documents.
501 private static class ReviewableDocumentPopup extends PopupMenu {
502 private transient DocumentRights _user = null;
504 private ReviewableDocumentPopup() {
507 new PopupItem(MNU_NAME_DEMOTE).icon("image.demote.png")
508 .action("setDocument?action=demote")
509 .confirmation("message.demote.document"));
511 new PopupItem("menu.review").icon("image.review.png")
512 .action("setDocument?action=review")
513 .confirmation("message.review.document"));
515 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
516 .action(ACT_ATTACH));
519 new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action(
523 new PopupItem(MNU_NAME_PURGE).action(
524 ACT_NOT_YET_IMPLEMENTED).confirmation(
525 "message.purge.document"));
529 public boolean isEnabled(final String name) {
530 boolean res = (_user != null);
532 Item item = Item.valueOf(name);
535 res = _user.canDemote();
538 res = _user.canReview();
541 res = _user.canAttach();
544 res = _user.canVersion();
547 res = _user.canPurge();
557 public void setContext(final String name, final Object context) {
558 if (context instanceof DocumentRights) {
559 _user = (DocumentRights) context; // Just for optimizing
564 private static class NotResultDocumentPopup extends PopupMenu {
565 // private final DocumentRights _user = null;
567 private NotResultDocumentPopup() {
570 new PopupItem(MNU_NAME_DEMOTE).icon("image.demote.png")
571 .action("setDocument?action=demote")
572 .confirmation("message.demote.document"));
574 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
575 .action(ACT_ATTACH));
578 new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action(
582 new PopupItem(MNU_NAME_PURGE).action(
583 ACT_NOT_YET_IMPLEMENTED).confirmation(
584 "message.purge.document"));
586 new PopupItem(MNU_NAME_REMOVE).icon(IMG_DELETE)
587 .action("remove-document")
588 .confirmation("message.delete.document"));
593 * Popup of In-Check documents.
595 private static class ApprovableDocumentPopup extends PopupMenu {
596 private transient DocumentRights _user = null;
598 private ApprovableDocumentPopup() {
601 new PopupItem(MNU_NAME_DEMOTE).icon("image.invalidate.png")
602 .action("setDocument?action=invalidate")
603 .confirmation("message.demote.document"));
605 new PopupItem("menu.disapprove").icon("image.demote.png")
606 .action("setDocument?action=disapprove")
607 .confirmation("message.disapprove.document"));
609 new PopupItem("menu.approve").icon("icon.APPROVED.png")
610 .action("setDocument?action=approve")
611 .confirmation("message.approve.document"));
615 public boolean isEnabled(final String name) {
616 boolean res = (_user != null);
618 Item item = Item.valueOf(name);
621 res = _user.canInvalidate();
624 res = _user.canDemote();
627 res = _user.canApprove();
637 public void setContext(final String name, final Object context) {
638 if (context instanceof DocumentRights) {
639 _user = (DocumentRights) context; // Just for optimizing
645 * Popup of Approved documents.
647 private static class ApprovedPopup extends PopupMenu {
648 private ApprovedPopup() {
650 addItem(MNU_ATTACH, new PopupItem(MNU_NAME_ATTACH).icon(IMG_ATTACH)
651 .action(ACT_ATTACH));
654 new PopupItem(MNU_NAME_VERSION).icon(IMG_VERSION).action(
660 * Popup of Extern documents.
662 private static class ExternPopup extends PopupMenu {
663 private transient DocumentRights _user = null;
665 private ExternPopup() {
668 new PopupItem(MNU_NAME_RENAME)
669 .action("edit-document?action=renameDocument"));
671 new PopupItem("menu.replace").icon("image.replace.png")
672 .action("select-file?nextAction=replace"));
675 new PopupItem("menu.remove.document").icon(IMG_DELETE)
676 .action("remove-document")
677 .confirmation("message.delete.document"));
681 public boolean isEnabled(final String name) {
682 boolean res = (_user != null);
684 Item item = Item.valueOf(name);
687 res = _user.canRename();
690 res = _user.canReplace();
693 res = _user.canRemove();
703 public void setContext(final String name, final Object context) {
704 if (context instanceof DocumentRights) {
705 _user = (DocumentRights) context; // Just for optimizing
710 // Resources relative to simulation contexts
711 private static class ScontextPopup extends PopupMenu {
712 private SimulationContextFacade _owner = null; // RKV: NOPMD: TODO: Refine the usage of this field or remove it.
714 private ScontextPopup() {
717 new PopupItem(MNU_NAME_RENAME)
718 .action("edit-context?action=renameContext"));
720 new PopupItem(MNU_NAME_EDIT)
721 .action("edit-context?action=editContext"));
724 new PopupItem("menu.remove").icon(IMG_DELETE)
725 .action("remove-context")
726 .confirmation("message.delete.context"));
730 public boolean isEnabled(final String name) {
731 Item item = Item.valueOf(name);
734 if (item == Item.rename) {
736 } else if (item == Item.edit) {
737 // if (!owner.isEditable())
744 public void setContext(final String name, final Object context) {
745 if (context instanceof SimulationContextFacade) {
746 _owner = (SimulationContextFacade) context; // Just for optimizing
748 super.setContext(name, context);
753 // Resources relative to knowledge
754 private static class FeedbexPopup extends PopupMenu {
755 private transient KnowledgeElement _owner = null;
757 private FeedbexPopup() {
760 new PopupItem(MNU_NAME_PROMOTE).icon("image.review.png")
761 .action("promote-knowledge")
762 .confirmation("message.promote.knowledge"));
764 new PopupItem(MNU_NAME_DEMOTE).icon("image.invalidate.png")
765 .action("demote-knowledge")
766 .confirmation("message.demote.knowledge"));
769 new PopupItem(MNU_NAME_RENAME)
770 .action("edit-knowledge?action=renameKnowledge"));
772 new PopupItem(MNU_NAME_EDIT)
773 .action("edit-knowledge?action=editKnowledge"));
776 new PopupItem("menu.remove").icon(IMG_DELETE)
777 .action("remove-knowledge")
778 .confirmation("message.delete.knowledge"));
782 public boolean isEnabled(final String name) {
783 Item item = Item.valueOf(name);
786 if (item == Item.promote) {
787 if (_owner.getProgressState() != ProgressState.inDRAFT) {
790 } else if ((item == Item.demote)
791 && (_owner.getProgressState() != ProgressState.inCHECK)) {
798 public void setContext(final String name, final Object context) {
799 if (context instanceof KnowledgeElement) {
800 _owner = (KnowledgeElement) context; // Just for optimizing
802 super.setContext(name, context);
807 // ==============================================================================================================================
809 // ==============================================================================================================================
811 public static ApplicationSettings getMe() {
812 return MY_APP; // The application is supposed being previously created below
820 public ApplicationSettings init(final String wappurl, final Locale lang)
822 ClassLoader cloader = Thread.currentThread().getContextClassLoader();
823 String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
825 synchronized (MY_APP) {
826 MY_APP._locale = lang;
827 MY_APP._wappserver = wurl[2];
828 MY_APP._wappname = wurl[3];
829 MY_APP._wapprops.clear();
830 MY_APP._jndprops.clear();
831 MY_APP._wapprops.load(cloader.getResourceAsStream(_wappname
833 MY_APP._jndprops.load(cloader
834 .getResourceAsStream("jndi.properties"));
837 LOG.info("Application root set to "
838 + _wapprops.getProperty("wapp.root"));
842 // ==============================================================================================================================
843 // Public member functions
844 // ==============================================================================================================================
846 public void configure(final String filename) {
847 // Non customizable settings
849 SimpleMenu menu = new NewMenu();
850 _menus.put(menu.getName(), menu);
851 menu = new SearchMenu();
852 _menus.put(menu.getName(), menu);
853 menu = new DatadminMenu();
854 _menus.put(menu.getName(), menu);
855 menu = new SysadminMenu();
856 _menus.put(menu.getName(), menu);
857 menu = new PropertiesMenu();
858 _menus.put(menu.getName(), menu);
860 _popups = new HashMap<String, PopupMenu>();
861 _popups.put("steditable", new EditableStudyPopup());
862 _popups.put("editable", new EditableDocumentPopup());
863 _popups.put("notresult", new NotResultDocumentPopup());
864 _popups.put("reviewable", new ReviewableDocumentPopup());
865 _popups.put("approvable", new ApprovableDocumentPopup());
866 _popups.put("approved", new ApprovedPopup());
867 _popups.put("extern", new ExternPopup());
868 _popups.put("scontext", new ScontextPopup());
869 _popups.put("feedbex", new FeedbexPopup());
871 // Default customizable mandatory settings
872 Map<String, Object> fprop = new HashMap<String, Object>();
873 fprop.put("visibility", "PRIVATE");
874 fprop.put("matchamong", ALL);
875 fprop.put("matcontext", ALL);
876 fprop.put("state", "APPROVED");
877 fprop.put("author", "0");
878 fprop.put("reference", "");
879 fprop.put("title", "");
880 fprop.put("context", new ArrayList<SimulationContext>());
882 Map<String, Object> gprop = new HashMap<String, Object>();
883 gprop.put("visibility", "PUBLIC");
884 gprop.put("matchamong", ALL);
885 gprop.put("matcontext", ALL);
886 gprop.put("type", "2"); // TODO: Get the index from the type name
887 gprop.put("author", "0");
888 gprop.put("reference", "");
889 gprop.put("title", "");
890 gprop.put("context", new ArrayList<SimulationContext>());
892 _filter = new HashMap<String, Map<String, Object>>();
893 _filter.put("study", fprop);
894 _filter.put("knowledge", gprop);
896 _tempfile = new HashMap<String, String>();
897 _viewermap = new String[0];
898 _convertmap = new HashMap<String, Converter>();
900 // Customization (must be done after above default settings)
901 File config = new File(filename);
902 if (config.exists()) {
903 loadCustomization(config); // Sets default document types, installed modules and available templates
905 LOG.info("Could not find the application configuration file \""
906 + config.getAbsolutePath() + "\", using default settings");
908 // Settings based on the customization
913 * Configure toolbars for steps.
915 private void configureToolbars() {
916 _bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
918 List<ProjectSettingsService.Step> steps = getProjectSettings()
920 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
922 ProjectSettingsService.Step step = i.next();
923 List<String> formats = getProjectSettings().getDefaultFormats(step);
924 if (formats.isEmpty()) {
928 ToolBar bar = new ToolBar(24); // Height of the module-bar
929 Set<String> module = new HashSet<String>(); // For not duplicating modules
930 for (String format : formats) {
931 String command = getApplicationProperty("executable." + format);
932 if (command == null) {
933 continue; // Module not installed
935 if (module.contains(command)) {
939 String[] parsed = command.split("/");
940 String[] name = parsed[parsed.length - 1].split("\\x2E");
941 DocumentType dtype = getProjectSettings()
942 .getDefaultDocumentType(step, format);
945 docname = dtype.getName();
947 if (_tempfile.get(docname) == null) { // No available template
948 String tool = parsed[parsed.length - 1];
949 String icon = name[0];
950 if ("index".equals(icon)) {
951 tool = parsed[parsed.length - 2];
952 icon = "tool." + tool.toLowerCase() + ".png";
954 icon = "tool." + icon.toLowerCase() + ".png";
956 File image = new File(
957 ApplicationSettings.getApplicationSkinPath() + icon);
958 if (!image.exists()) {
959 icon = "tool.any.png";
961 bar.addTool(tool, icon, command);
963 docname = "/jsp/newDocument.jsp?type=" + docname;
964 String icon = "tool." + name[0].toLowerCase() + ".png";
965 File image = new File(
966 ApplicationSettings.getApplicationSkinPath() + icon);
967 if (!image.exists()) {
968 icon = "tool.any.png";
970 bar.addTool(name[0], icon, command, docname);
973 if (!bar.isEmpty()) {
974 _bars.put(step.getNumber(), bar);
979 public String getApplicationProperty(final String name) {
980 return _wapprops.getProperty(name); // May be null
983 public String getApplicationRootPath() {
984 // RKV: return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
985 return _servletContext.getRealPath("/");
988 public String getApplicationURL() {
989 StringBuffer url = new StringBuffer("http://")
990 .append(MY_APP._wappserver).append("/").append(_wappname);
991 return url.toString();
994 public Map<String, Object> getFilter(final String name) {
995 return _filter.get(name);
998 public ToolBar getModuleBar(final Step step) {
999 return _bars.get(step.getNumber());
1002 public Properties getNamingProperties() {
1006 // ==============================================================================================================================
1008 // ==============================================================================================================================
1010 public static String getApplicationPluginPath() {
1011 return MY_APP.getApplicationRootPath() + "plugin/";
1014 public static String getApplicationResourcePath() {
1015 return MY_APP.getApplicationRootPath() + "WEB-INF/classes/";
1018 public static String getApplicationSkinPath() {
1019 return MY_APP.getApplicationRootPath() + "skin/";
1022 public static Converter getConverter(final DocumentType type,
1023 final String format) {
1024 return MY_APP._convertmap.get(format + type.getName()); // May be null;
1027 public DocumentType getDefaultDocumentType(final Step step,
1028 final String format) {
1029 return getProjectSettings().getDefaultDocumentType(step.getStep(),
1030 format); // May be null
1033 public static String getDownloadURL(final User user) {
1034 StringBuffer url = new StringBuffer("http://")
1035 .append(MY_APP._wappserver).append("/download/")
1036 .append(user.getUsername()).append("/");
1037 return url.toString(); // The download Tomcat context is supposed being defined
1040 public static Locale getCurrentLocale() {
1041 return MY_APP._locale;
1044 public static SimpleMenu getMenu(final String name) {
1045 return MY_APP._menus.get(name);
1048 public static PopupMenu getPopupMenu(final String name) {
1049 return MY_APP._popups.get(name);
1052 public static String getRepositoryURL() {
1053 StringBuffer url = new StringBuffer("http://").append(
1054 MY_APP._wappserver).append("/repository/");
1055 return url.toString(); // The repository Tomcat context is supposed being defined
1058 public static Locale[] getSupportedLocales() {
1059 String[] code = MY_APP._wapprops.getProperty("locale.supported").split(
1061 Locale[] result = new Locale[code.length];
1062 for (int i = 0; i < code.length; i++) {
1063 result[i] = new Locale(code[i]);
1068 public static String[] getViewersMapping() {
1069 return MY_APP._viewermap;
1072 public static String getWebSiteURL() {
1073 return MY_APP.getApplicationProperty("wapp.website");
1076 public static String getHelpURL() {
1077 return MY_APP.getApplicationProperty("wapp.onlinehelp");
1080 // ==============================================================================================================================
1082 // ==============================================================================================================================
1085 * Load customization of workflow from the given XML file.
1088 * the XML configuration file
1090 private void loadCustomization(final File config) {
1092 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
1094 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
1096 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
1097 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
1098 .getDocumentElement());
1101 loadModules(children);
1104 loadConverters(children);
1107 loadTemplates(children);
1108 } catch (Exception error) {
1109 LOG.info("Error in customization", error);
1114 * Load modules from XML configuration.
1119 private void loadModules(final Map<String, Node> children) {
1120 Node child = children.get("modules");
1121 NodeList nlist = child.getChildNodes();
1122 for (int i = 0; i < nlist.getLength(); i++) {
1123 child = nlist.item(i);
1124 if (!child.getNodeName().equals("mapping")) {
1128 NamedNodeMap natr = child.getAttributes();
1129 String dext = natr.getNamedItem("extension").getNodeValue();
1130 String exec = natr.getNamedItem("executable").getNodeValue();
1131 _wapprops.put("executable." + dext, exec);
1133 // Viewer mappings tag
1134 child = children.get("viewers");
1135 _viewermap = child.getAttributes().getNamedItem("extension")
1136 .getNodeValue().split(",");
1140 * Load converters from XML configuration.
1145 private void loadConverters(final Map<String, Node> children) {
1146 Node child = children.get("converters");
1147 NodeList nlist = child.getChildNodes();
1148 for (int i = 0; i < nlist.getLength(); i++) {
1149 child = nlist.item(i);
1151 if (child.getNodeName().equals("geometry")) {
1152 NamedNodeMap natr = child.getAttributes();
1153 String from = natr.getNamedItem("from").getNodeValue();
1154 String to = natr.getNamedItem("to").getNodeValue();
1155 String exec = natr.getNamedItem("executable").getNodeValue();
1156 _convertmap.put(from + "geometry", new Converter("geometry",
1163 * Load templates from XML configuration.
1168 private void loadTemplates(final Map<String, Node> children) {
1169 Node child = children.get("templates");
1170 NodeList nlist = child.getChildNodes();
1171 for (int i = 0; i < nlist.getLength(); i++) {
1172 child = nlist.item(i);
1173 if (!child.getNodeName().equals("document")) {
1177 NamedNodeMap natr = child.getAttributes();
1178 String type = natr.getNamedItem("type").getNodeValue();
1179 String file = natr.getNamedItem("file").getNodeValue();
1180 _tempfile.put(type, file);
1185 * Get the documentTypeService.
1187 * @return the documentTypeService
1189 public DocumentTypeService getDocumentTypeService() {
1190 return _documentTypeService;
1194 * Set the documentTypeService.
1196 * @param documentTypeService
1197 * the documentTypeService to set
1199 public void setDocumentTypeService(
1200 final DocumentTypeService documentTypeService) {
1201 _documentTypeService = documentTypeService;
1207 * @see org.apache.struts2.util.ServletContextAware#setServletContext(javax.servlet.ServletContext)
1210 public void setServletContext(final ServletContext context) {
1211 _servletContext = context;