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;
9 import java.util.LinkedHashMap;
10 import java.util.List;
11 import java.util.Locale;
13 import java.util.Properties;
16 import javax.servlet.ServletContext;
17 import javax.xml.parsers.DocumentBuilder;
18 import javax.xml.parsers.DocumentBuilderFactory;
20 import org.apache.log4j.Logger;
21 import org.splat.dal.bo.kernel.User;
22 import org.splat.dal.bo.som.Document;
23 import org.splat.dal.bo.som.DocumentType;
24 import org.splat.dal.bo.som.KnowledgeElement;
25 import org.splat.dal.bo.som.ProgressState;
26 import org.splat.dal.bo.som.SimulationContext;
27 import org.splat.manox.XDOM;
28 import org.splat.service.DocumentTypeService;
29 import org.splat.service.technical.ProjectSettingsService;
30 import org.splat.som.DocumentRights;
31 import org.splat.som.Step;
32 import org.splat.som.StudyRights;
33 import org.splat.wapp.MenuItem;
34 import org.splat.wapp.PopupItem;
35 import org.splat.wapp.PopupMenu;
36 import org.splat.wapp.SimpleMenu;
37 import org.splat.wapp.ToolBar;
38 import org.springframework.web.context.ServletContextAware;
39 import org.w3c.dom.NamedNodeMap;
40 import org.w3c.dom.Node;
41 import org.w3c.dom.NodeList;
43 public class ApplicationSettings implements ServletContextAware {
46 * Application settings logger.
48 protected final static Logger LOG = Logger
49 .getLogger(ApplicationSettings.class);
52 * Injected servlet context to get path to resources.
54 private ServletContext _servletContext;
56 private String wappserver;
57 private String wappname;
58 private final Properties wapprops = new Properties(); // General properties from the application properties files
59 private Locale locale; // Current user locale
60 private final Map<String, SimpleMenu> menus = new HashMap<String, SimpleMenu>(); // Application menus
61 private Map<Integer, ToolBar> bars = null; // Study module-bars structured by steps
62 private Map<String, PopupMenu> popups = null;
63 private Map<String, Map<String, Object>> filter = null; // Named search filters
64 private Map<String, DocumentType> defdoctype = null; // Default document types structured by step.formats
65 private Map<String, String> tempfile = null; // Available template files
66 private String[] viewermap = null; // List of file extensions mapped to a viewer
67 private Map<String, Converter> convertmap = null; // Available document format converters
68 private final Properties jndprops = new Properties(); // JNDI context for launching converters
70 private static ApplicationSettings my = new ApplicationSettings(); // Singleton instance
72 * Injected project settings service.
74 private ProjectSettingsService _projectSettingsService;
76 * Injected document type service.
78 private DocumentTypeService _documentTypeService;
81 * Get the projectSettingsService.
83 * @return the projectSettingsService
85 public ProjectSettingsService getProjectSettings() {
86 return _projectSettingsService;
90 * Set the projectSettingsService.
92 * @param projectSettingsService
93 * the projectSettingsService to set
95 public void setProjectSettings(final ProjectSettingsService projectSettingsService) {
96 _projectSettingsService = projectSettingsService;
99 private static class NewMenu extends SimpleMenu {
100 // -----------------------------------------------------------------
103 addItem("new-empty", "menu.new.empty", "image.empty.png",
104 "select?menu=create&item=new-empty");
105 addItem("new-copy", new MenuItem("menu.new.copy")
106 .icon("image.copy.png"));
107 addItem("new-instance", new MenuItem("menu.new.instance")
108 .icon("image.hold.gif"));
109 addItem("new-import", new MenuItem("menu.new.import")
110 .icon("icon.upload.png"));
111 this.selects("new-empty");
115 private static class SearchMenu extends SimpleMenu {
116 // -----------------------------------------------------------------
117 private SearchMenu() {
119 addItem("search-study", "menu.search.study", "image.study.png",
120 "select?menu=search&item=search-study");
121 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
122 "select?menu=search&item=search-knowledge");
123 addItem("search-document", new MenuItem("menu.search.document")
124 .icon("icon.any.png"));
125 this.selects("search-study");
129 private static class PropertiesMenu extends SimpleMenu {
130 // -----------------------------------------------------------------
131 private PropertiesMenu() {
132 super("configuration");
133 addItem("prop-general", "menu.prop.general", "image.hold.gif",
134 "select?menu=properties&item=prop-general");
135 addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif",
136 "select?menu=properties&item=prop-scenario");
137 //These menu items will not be implemented in the current version.
138 /*addItem("prop-timestamp", new MenuItem("menu.prop.timestamp")
139 .icon("image.stamp.png"));
140 addItem("prop-comlog", new MenuItem("menu.prop.comlog")
141 .icon("image.hold.gif"));
142 addItem("prop-version", new MenuItem("menu.prop.version")
143 .icon("image.dirclosed.png"));*/
147 private static class DatadminMenu extends SimpleMenu {
148 // -----------------------------------------------------------------
149 private DatadminMenu() {
151 addItem("admin-scontext", "menu.admin.context", "image.hold.gif",
152 "select?menu=datadmin&item=admin-scontext");
153 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
154 "select?menu=datadmin&item=admin-knowelm");
155 addItem("admin-study", new MenuItem("menu.admin.study")
156 .icon("image.study.png"));
160 private static class SysadminMenu extends SimpleMenu {
161 // -----------------------------------------------------------------
162 private SysadminMenu() {
164 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
165 "select?menu=sysadmin&item=admin-indexing");
166 addItem("admin-importuser", "menu.admin.importuser",
168 "select?menu=sysadmin&item=admin-importuser");
173 publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge
176 // Resources relative to studies
177 private static class EditableStudyPopup extends PopupMenu {
178 // ----------------------------------------------------------------
179 private StudyRights user = null;
181 private EditableStudyPopup() {
182 addItem("publish", new PopupItem("menu.publish").icon(
183 "image.publish.png").action("edit-study?action=publish")
184 .confirmation("message.publish.study"));
185 addItem("promote", new PopupItem("menu.archive"));
187 addItem("edit", new PopupItem("menu.properties")
188 .icon("icon.ed.png").action("../select?menu=properties"));
190 addItem("script", new PopupItem("menu.newscenario")
191 .action("add-scenario"));
192 addItem("version", new PopupItem("menu.version").icon(
193 "image.version.png").action("notyetimplemented"));
195 addItem("purge", new PopupItem("menu.purge")
196 .confirmation("message.purge.study"));
197 addItem("export", new PopupItem("menu.export")
198 .icon("image.export.png")); // For future needs
199 addItem("remove", new PopupItem("menu.remove.version").icon(
200 "icon.delete.png").action("notyetimplemented")
201 .confirmation("message.delete.study"));
205 public boolean isEnabled(final String name) {
207 return false; // Should not happen
209 Item item = Item.valueOf(name);
210 if (item == Item.publish) {
211 return user.canPublish();
213 if (item == Item.edit) {
214 return user.canEditProperties();
216 if (item == Item.script) {
217 return user.canAddScenario();
219 if (item == Item.version) {
220 return user.canVersion();
222 if (item == Item.remove) {
223 return user.canRemove();
225 if (item == Item.purge) {
226 return user.canPurge();
232 public void setContext(final String name, final Object context) {
233 if (context instanceof StudyRights) {
234 user = (StudyRights) context; // Just for optimizing
235 boolean history = user.getOperand().isVersioned();
236 PopupItem item = this.item("remove");
238 item.rename("menu.remove.version");
240 item.rename("menu.remove.study");
246 // Resources relative to documents
247 private static class EditableDocumentPopup extends PopupMenu { // Popup of In-Work documents
248 // ----------------------------------------------------------------
249 private DocumentRights user = null;
251 private EditableDocumentPopup() {
252 addItem("accept", new PopupItem("menu.accept").icon(
253 "image.accept.png").action("setDocument?action=accept")
254 .confirmation("message.accept.document"));
255 addItem("promote", new PopupItem("menu.promote").icon(
256 "image.publish.png").action("setDocument?action=promote")
257 .confirmation("message.promote.document"));
259 addItem("rename", new PopupItem("menu.rename")
260 .action("edit-document?action=renameDocument"));
261 addItem("attach", new PopupItem("menu.attach").icon(
262 "image.attach.png").action("select-file?nextAction=attach"));
264 addItem("version", new PopupItem("menu.version").icon(
265 "image.version.png").action(
266 "select-file?nextAction=version"));
267 addItem("replace", new PopupItem("menu.replace").icon(
268 "image.replace.png").action(
269 "select-file?nextAction=replace"));
271 addItem("purge", new PopupItem("menu.purge").action(
272 "notyetimplemented").confirmation("message.purge.document"));
273 addItem("remove", new PopupItem("menu.remove.version").icon(
274 "icon.delete.png").action("remove-document").confirmation(
275 "message.delete.document"));
279 public boolean isEnabled(final String name) {
281 return false; // Should not happen
283 Item item = Item.valueOf(name);
284 if (item == Item.accept) {
285 return user.canAccept();
287 if (item == Item.promote) {
288 return user.canPromote();
290 if (item == Item.rename) {
291 return user.canRename();
293 if (item == Item.attach) {
294 return user.canAttach();
296 if (item == Item.version) {
297 return user.canVersion();
299 if (item == Item.replace) {
300 return user.canReplace();
302 if (item == Item.purge) {
303 return user.canPurge();
305 if (item == Item.remove) {
306 return user.canRemove();
312 public void setContext(final String name, final Object context) {
313 if (context instanceof DocumentRights) {
314 user = (DocumentRights) context; // Just for optimizing
315 Document downer = user.getOperand();
316 PopupItem item = this.item("remove");
317 if (downer.isVersioned()) {
318 item.rename("menu.remove.version");
320 item.rename("menu.remove.document");
326 private static class ReviewableDocumentPopup extends PopupMenu { // Popup of In-Draft documents
327 // ----------------------------------------------------------------
328 private DocumentRights user = null;
330 private ReviewableDocumentPopup() {
331 addItem("demote", new PopupItem("menu.demote").icon(
332 "image.demote.png").action("setDocument?action=demote")
333 .confirmation("message.demote.document"));
334 addItem("promote", new PopupItem("menu.review").icon(
335 "image.review.png").action("setDocument?action=review")
336 .confirmation("message.review.document"));
338 addItem("attach", new PopupItem("menu.attach").icon(
339 "image.attach.png").action("select-file?nextAction=attach"));
341 addItem("version", new PopupItem("menu.version").icon(
342 "image.version.png").action(
343 "select-file?nextAction=version"));
345 addItem("purge", new PopupItem("menu.purge").action(
346 "notyetimplemented").confirmation("message.purge.document"));
350 public boolean isEnabled(final String name) {
352 return false; // Should not happen
354 Item item = Item.valueOf(name);
355 if (item == Item.demote) {
356 return user.canDemote();
358 if (item == Item.promote) {
359 return user.canReview();
361 if (item == Item.attach) {
362 return user.canAttach();
364 if (item == Item.version) {
365 return user.canVersion();
367 if (item == Item.purge) {
368 return user.canPurge();
374 public void setContext(final String name, final Object context) {
375 if (context instanceof DocumentRights) {
376 user = (DocumentRights) context; // Just for optimizing
381 private static class NotResultDocumentPopup extends PopupMenu {
382 // ----------------------------------------------------------------
383 private final DocumentRights user = null;
385 private NotResultDocumentPopup() {
386 addItem("demote", new PopupItem("menu.demote").icon(
387 "image.demote.png").action("setDocument?action=demote")
388 .confirmation("message.demote.document"));
390 addItem("attach", new PopupItem("menu.attach").icon(
391 "image.attach.png").action("select-file?nextAction=attach"));
393 addItem("version", new PopupItem("menu.version").icon(
394 "image.version.png").action(
395 "select-file?nextAction=version"));
397 addItem("purge", new PopupItem("menu.purge").action(
398 "notyetimplemented").confirmation("message.purge.document"));
399 addItem("remove", new PopupItem("menu.remove.version").icon(
400 "icon.delete.png").action("remove-document").confirmation(
401 "message.delete.document"));
405 private static class ApprovableDocumentPopup extends PopupMenu { // Popup of In-Check documents
406 // ----------------------------------------------------------------
407 private DocumentRights user = null;
409 private ApprovableDocumentPopup() {
410 addItem("undo", new PopupItem("menu.demote").icon(
411 "image.invalidate.png").action(
412 "setDocument?action=invalidate").confirmation(
413 "message.demote.document"));
414 addItem("demote", new PopupItem("menu.disapprove").icon(
415 "image.demote.png").action("setDocument?action=disapprove")
416 .confirmation("message.disapprove.document"));
417 addItem("approve", new PopupItem("menu.approve").icon(
418 "icon.APPROVED.png").action("setDocument?action=approve")
419 .confirmation("message.approve.document"));
423 public boolean isEnabled(final String name) {
425 return false; // Should not happen
427 Item item = Item.valueOf(name);
428 if (item == Item.undo) {
429 return user.canInvalidate();
431 if (item == Item.demote) {
432 return user.canDemote();
434 if (item == Item.approve) {
435 return user.canApprove();
441 public void setContext(final String name, final Object context) {
442 if (context instanceof DocumentRights) {
443 user = (DocumentRights) context; // Just for optimizing
448 private static class ApprovedPopup extends PopupMenu { // Popup of Approved documents
449 // ----------------------------------------------------------------
450 private ApprovedPopup() {
451 addItem("attach", new PopupItem("menu.attach").icon(
452 "image.attach.png").action("select-file?nextAction=attach"));
454 addItem("version", new PopupItem("menu.version").icon(
455 "image.version.png").action(
456 "select-file?nextAction=version"));
460 private static class ExternPopup extends PopupMenu { // Popup of Extern documents
461 // ----------------------------------------------------------------
462 private DocumentRights user = null;
464 private ExternPopup() {
465 addItem("rename", new PopupItem("menu.rename")
466 .action("edit-document?action=renameDocument"));
467 addItem("replace", new PopupItem("menu.replace").icon(
468 "image.replace.png").action(
469 "select-file?nextAction=replace"));
471 addItem("remove", new PopupItem("menu.remove.document").icon(
472 "icon.delete.png").action("remove-document").confirmation(
473 "message.delete.document"));
477 public boolean isEnabled(final String name) {
479 return false; // Should not happen
481 Item item = Item.valueOf(name);
482 if (item == Item.rename) {
483 return user.canRename();
485 if (item == Item.replace) {
486 return user.canReplace();
488 if (item == Item.remove) {
489 return user.canRemove();
495 public void setContext(final String name, final Object context) {
496 if (context instanceof DocumentRights) {
497 user = (DocumentRights) context; // Just for optimizing
502 // Resources relative to simulation contexts
503 private static class ScontextPopup extends PopupMenu {
504 // --------------------------------------------------------
505 private SimulationContextFacade owner = null;
507 private ScontextPopup() {
508 addItem("rename", new PopupItem("menu.rename")
509 .action("edit-context?action=renameContext"));
510 addItem("edit", new PopupItem("menu.edit")
511 .action("edit-context?action=editContext"));
513 addItem("remove", new PopupItem("menu.remove").icon(
514 "icon.delete.png").action("remove-context").confirmation(
515 "message.delete.context"));
519 public boolean isEnabled(final String name) {
520 Item item = Item.valueOf(name);
522 if (item == Item.rename) {
524 } else if (item == Item.edit) {
525 // if (!owner.isEditable())
532 public void setContext(final String name, final Object context) {
533 if (context instanceof SimulationContextFacade) {
534 owner = (SimulationContextFacade) context; // Just for optimizing
536 super.setContext(name, context);
541 // Resources relative to knowledge
542 private static class FeedbexPopup extends PopupMenu {
543 // --------------------------------------------------------
544 private KnowledgeElement owner = null;
546 private FeedbexPopup() {
547 addItem("promote", new PopupItem("menu.promote").icon(
548 "image.review.png").action("promote-knowledge")
549 .confirmation("message.promote.knowledge"));
550 addItem("demote", new PopupItem("menu.demote").icon(
551 "image.invalidate.png").action("demote-knowledge")
552 .confirmation("message.demote.knowledge"));
554 addItem("rename", new PopupItem("menu.rename")
555 .action("edit-knowledge?action=renameKnowledge"));
556 addItem("edit", new PopupItem("menu.edit")
557 .action("edit-knowledge?action=editKnowledge"));
559 addItem("remove", new PopupItem("menu.remove").icon(
560 "icon.delete.png").action("remove-knowledge").confirmation(
561 "message.delete.knowledge"));
565 public boolean isEnabled(final String name) {
566 Item item = Item.valueOf(name);
568 if (item == Item.promote) {
569 if (owner.getProgressState() != ProgressState.inDRAFT) {
572 } else if (item == Item.demote) {
573 if (owner.getProgressState() != ProgressState.inCHECK) {
581 public void setContext(final String name, final Object context) {
582 if (context instanceof KnowledgeElement) {
583 owner = (KnowledgeElement) context; // Just for optimizing
585 super.setContext(name, context);
590 // ==============================================================================================================================
592 // ==============================================================================================================================
594 public static ApplicationSettings getMe() {
595 return my; // The application is supposed being previously created below
603 public ApplicationSettings init(final String wappurl, final Locale lang)
605 ClassLoader cloader = getClass().getClassLoader();
606 String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
609 wappserver = wurl[2];
613 wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
614 jndprops.load(cloader.getResourceAsStream("jndi.properties"));
616 LOG.info("Application root set to "
617 + wapprops.getProperty("wapp.root"));
626 // ==============================================================================================================================
627 // Public member functions
628 // ==============================================================================================================================
630 public void configure(final String filename) {
631 // ---------------------------------------
632 // Non customizable settings
634 SimpleMenu menu = new NewMenu();
635 menus.put(menu.getName(), menu);
636 menu = new SearchMenu();
637 menus.put(menu.getName(), menu);
638 menu = new DatadminMenu();
639 menus.put(menu.getName(), menu);
640 menu = new SysadminMenu();
641 menus.put(menu.getName(), menu);
642 menu = new PropertiesMenu();
643 menus.put(menu.getName(), menu);
645 popups = new HashMap<String, PopupMenu>();
646 popups.put("steditable", new EditableStudyPopup());
647 popups.put("editable", new EditableDocumentPopup());
648 popups.put("notresult", new NotResultDocumentPopup());
649 popups.put("reviewable", new ReviewableDocumentPopup());
650 popups.put("approvable", new ApprovableDocumentPopup());
651 popups.put("approved", new ApprovedPopup());
652 popups.put("extern", new ExternPopup());
653 popups.put("scontext", new ScontextPopup());
654 popups.put("feedbex", new FeedbexPopup());
656 // Default customizable mandatory settings
657 Map<String, Object> fprop = new HashMap<String, Object>();
658 fprop.put("visibility", "PRIVATE");
659 fprop.put("matchamong", "all");
660 fprop.put("matcontext", "all");
661 fprop.put("state", "APPROVED");
662 fprop.put("author", "0");
663 fprop.put("reference", "");
664 fprop.put("title", "");
665 fprop.put("context", new ArrayList<SimulationContext>());
667 Map<String, Object> gprop = new HashMap<String, Object>();
668 gprop.put("visibility", "PUBLIC");
669 gprop.put("matchamong", "all");
670 gprop.put("matcontext", "all");
671 gprop.put("type", "2"); // TODO: Get the index from the type name
672 gprop.put("author", "0");
673 gprop.put("reference", "");
674 gprop.put("title", "");
675 gprop.put("context", new ArrayList<SimulationContext>());
677 defdoctype = new LinkedHashMap<String, DocumentType>();
678 tempfile = new HashMap<String, String>();
679 viewermap = new String[0];
680 convertmap = new HashMap<String, Converter>();
681 filter = new HashMap<String, Map<String, Object>>();
682 filter.put("study", fprop);
683 filter.put("knowledge", gprop);
685 // Customization (must be done after above default settings)
686 File config = new File(filename);
687 if (config.exists()) {
688 loadCustomization(config); // Sets default document types, installed modules and available templates
690 LOG.info("Could not find the application configuration file \""
691 + config.getAbsolutePath() + "\", using default settings");
693 // Settings based on the customization
694 bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
696 List<ProjectSettingsService.Step> steps = getProjectSettings()
698 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
700 ProjectSettingsService.Step step = i.next();
701 List<String> formats = getDefaultFormats(step);
702 if (formats.size() == 0) {
706 ToolBar bar = new ToolBar(24); // Height of the module-bar
707 HashSet<String> module = new HashSet<String>(); // For not duplicating modules
708 for (Iterator<String> j = formats.iterator(); j.hasNext();) {
709 String format = j.next();
710 String command = getApplicationProperty("executable." + format);
711 if (command == null) {
712 continue; // Module not installed
714 if (module.contains(command)) {
718 String[] parsed = command.split("/");
719 String[] name = parsed[parsed.length - 1].split("\\x2E");
720 DocumentType dtype = my.defdoctype.get(
721 step.getNumber() + "." + format);
724 docname = dtype.getName();
726 if (tempfile.get(docname) == null) { // No available template
727 String tool = parsed[parsed.length - 1];
728 String icon = name[0];
729 if (icon.equals("index")) {
730 tool = parsed[parsed.length - 2];
731 icon = "tool." + tool.toLowerCase() + ".png";
733 icon = "tool." + icon.toLowerCase() + ".png";
735 File image = new File(ApplicationSettings
736 .getApplicationSkinPath()
738 if (!image.exists()) {
739 icon = "tool.any.png";
741 bar.addTool(tool, icon, command);
743 docname = "/jsp/newDocument.jsp?type=" + docname;
744 String icon = "tool." + name[0].toLowerCase() + ".png";
745 File image = new File(ApplicationSettings
746 .getApplicationSkinPath()
748 if (!image.exists()) {
749 icon = "tool.any.png";
751 bar.addTool(name[0], icon, command, docname);
754 if (!bar.isEmpty()) {
755 bars.put(step.getNumber(), bar);
760 public String getApplicationProperty(final String name) {
761 return wapprops.getProperty(name); // May be null
764 public String getApplicationRootPath() {
765 //RKV: return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
766 return _servletContext.getRealPath("/");
769 public String getApplicationURL() {
770 // ----------------------------------
771 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
772 .append("/").append(wappname);
773 return url.toString();
776 public Map<String, Object> getFilter(final String name) {
777 // --------------------------------------------------
778 return filter.get(name);
781 public ToolBar getModuleBar(final Step step) {
782 // -----------------------------------------
783 return bars.get(step.getNumber());
786 public Properties getNamingProperties() {
787 // ----------------------------------------
791 // ==============================================================================================================================
793 // ==============================================================================================================================
795 public static String getApplicationPluginPath() {
796 // ------------------------------------------------
797 return my.getApplicationRootPath() + "plugin/";
800 public static String getApplicationResourcePath() {
801 // --------------------------------------------------
802 return my.getApplicationRootPath() + "WEB-INF/classes/";
805 public static String getApplicationSkinPath() {
806 // ----------------------------------------------
807 return my.getApplicationRootPath() + "skin/";
810 public static Converter getConverter(final DocumentType type, final String format) {
811 // -----------------------------------------------------------------------
812 return my.convertmap.get(format + type.getName()); // May be null;
815 public static DocumentType getDefaultDocumentType(final Step step, final String format) {
816 // ----------------------------------------------------------------------------
817 String[] table = format.split("\\x2E");
818 return my.defdoctype.get(step.getNumber() + "."
819 + table[table.length - 1]); // May be null
822 public static String getDownloadURL(final User user) {
823 // --------------------------------------------------
824 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
825 .append("/download/").append(user.getUsername()).append("/");
826 return url.toString(); // The download Tomcat context is supposed being defined
829 public static Locale getCurrentLocale() {
830 // ----------------------------------------
834 public static SimpleMenu getMenu(final String name) {
835 // ----------------------------------------------
836 return my.menus.get(name);
839 public static PopupMenu getPopupMenu(final String name) {
840 // --------------------------------------------------
841 return my.popups.get(name);
844 public static String getRepositoryURL() {
845 // ----------------------------------------
846 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
847 .append("/repository/");
848 return url.toString(); // The repository Tomcat context is supposed being defined
851 public static Locale[] getSupportedLocales() {
852 // ---------------------------------------------
853 String[] code = my.wapprops.getProperty("locale.supported").split(",");
854 Locale[] result = new Locale[code.length];
855 for (int i = 0; i < code.length; i++) {
856 result[i] = new Locale(code[i]);
861 public static String[] getViewersMapping() {
862 // -------------------------------------------
866 public static String getWebSiteURL() {
867 // -------------------------------------
868 return my.getApplicationProperty("wapp.website");
871 public static String getHelpURL() {
872 // ----------------------------------
873 return my.getApplicationProperty("wapp.onlinehelp");
876 // ==============================================================================================================================
878 // ==============================================================================================================================
880 private List<String> getDefaultFormats(final ProjectSettingsService.Step step) {
881 // ------------------------------------------------------------------
882 Set<String> keys = defdoctype.keySet();
883 int number = step.getNumber();
884 List<String> result = new ArrayList<String>();
886 for (Iterator<String> i = keys.iterator(); i.hasNext();) {
887 String[] key = i.next().split("\\x2E");
888 if (Integer.valueOf(key[0]) != number) {
891 if (key[1].equals("pdf")) {
892 continue; // PDF is not an authoring format
894 result.add(key[1]); // Formats are unique
899 private void loadCustomization(final File config) {
900 // --------------------------------------------
902 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
904 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
906 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
907 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
908 .getDocumentElement());
910 // Default document types tag
911 Node child = children.get("default-doctypes");
912 NodeList nlist = child.getChildNodes();
914 List<DocumentType> listype = getDocumentTypeService()
916 HashMap<String, DocumentType> maptype = new HashMap<String, DocumentType>();
917 for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
918 DocumentType type = i.next();
919 maptype.put(type.getName(), type);
921 for (int i = 0; i < nlist.getLength(); i++) {
922 child = nlist.item(i);
923 if (!child.getNodeName().equals("step")) {
927 String nstep = child.getAttributes().getNamedItem("number")
929 NodeList map = child.getChildNodes();
930 for (int j = 0; j < map.getLength(); j++) {
932 if (!child.getNodeName().equals("mapping")) {
935 NamedNodeMap natr = child.getAttributes();
936 String dext = natr.getNamedItem("extension").getNodeValue();
937 String type = natr.getNamedItem("type").getNodeValue();
938 defdoctype.put(nstep + "." + dext, maptype.get(type));
942 child = children.get("modules");
943 nlist = child.getChildNodes();
944 for (int i = 0; i < nlist.getLength(); i++) {
945 child = nlist.item(i);
946 if (!child.getNodeName().equals("mapping")) {
950 NamedNodeMap natr = child.getAttributes();
951 String dext = natr.getNamedItem("extension").getNodeValue();
952 String exec = natr.getNamedItem("executable").getNodeValue();
953 wapprops.put("executable." + dext, exec);
955 // Viewer mappings tag
956 child = children.get("viewers");
957 viewermap = child.getAttributes().getNamedItem("extension")
958 .getNodeValue().split(",");
961 child = children.get("converters");
962 nlist = child.getChildNodes();
963 for (int i = 0; i < nlist.getLength(); i++) {
964 child = nlist.item(i);
966 if (child.getNodeName().equals("geometry")) {
967 NamedNodeMap natr = child.getAttributes();
968 String from = natr.getNamedItem("from").getNodeValue();
969 String to = natr.getNamedItem("to").getNodeValue();
970 String exec = natr.getNamedItem("executable")
972 convertmap.put(from + "geometry", new Converter("geometry",
978 child = children.get("templates");
979 nlist = child.getChildNodes();
980 for (int i = 0; i < nlist.getLength(); i++) {
981 child = nlist.item(i);
982 if (!child.getNodeName().equals("document")) {
986 NamedNodeMap natr = child.getAttributes();
987 String type = natr.getNamedItem("type").getNodeValue();
988 String file = natr.getNamedItem("file").getNodeValue();
989 tempfile.put(type, file);
991 } catch (Exception error) {
992 LOG.info("Error in customization", error);
997 * Get the documentTypeService.
999 * @return the documentTypeService
1001 public DocumentTypeService getDocumentTypeService() {
1002 return _documentTypeService;
1006 * Set the documentTypeService.
1008 * @param documentTypeService
1009 * the documentTypeService to set
1011 public void setDocumentTypeService(final DocumentTypeService documentTypeService) {
1012 _documentTypeService = documentTypeService;
1017 * @see org.apache.struts2.util.ServletContextAware#setServletContext(javax.servlet.ServletContext)
1020 public void setServletContext(final ServletContext context) {
1021 _servletContext = context;