1 package org.splat.simer;
4 import java.io.IOException;
5 import java.util.HashMap;
6 import java.util.HashSet;
7 import java.util.Iterator;
8 import java.util.LinkedHashMap;
10 import java.util.Locale;
12 import java.util.Properties;
14 import java.util.Vector;
16 import javax.servlet.ServletContext;
17 import javax.xml.parsers.DocumentBuilder;
18 import javax.xml.parsers.DocumentBuilderFactory;
19 import org.w3c.dom.Node;
20 import org.w3c.dom.NodeList;
21 import org.w3c.dom.NamedNodeMap;
23 import org.apache.log4j.Logger;
24 import org.splat.dal.bo.kernel.User;
25 import org.splat.manox.XDOM;
26 import org.splat.dal.bo.som.Document;
27 import org.splat.som.DocumentRights;
28 import org.splat.dal.bo.som.DocumentType;
29 import org.splat.dal.bo.som.KnowledgeElement;
30 import org.splat.dal.bo.som.ProgressState;
31 import org.splat.service.DocumentTypeService;
32 import org.splat.service.technical.ProjectSettingsService;
33 import org.splat.simer.Converter;
34 import org.splat.dal.bo.som.SimulationContext;
35 import org.splat.som.Step;
36 import org.splat.som.StudyRights;
37 import org.splat.wapp.MenuItem;
38 import org.splat.wapp.PopupMenu;
39 import org.splat.wapp.PopupItem;
40 import org.splat.wapp.SimpleMenu;
41 import org.splat.wapp.ToolBar;
42 import org.springframework.web.context.ServletContextAware;
44 public class ApplicationSettings implements ServletContextAware {
47 * Application settings logger.
49 protected final static Logger logger = Logger
50 .getLogger(ApplicationSettings.class);
53 * Injected servlet context to get path to resources.
55 private ServletContext _servletContext;
57 private String wappserver;
58 private String wappname;
59 private Properties wapprops = new Properties(); // General properties from the application properties files
60 private Locale locale; // Current user locale
61 private Map<String, SimpleMenu> menus = new HashMap<String, SimpleMenu>(); // Application menus
62 private Map<Integer, ToolBar> bars = null; // Study module-bars structured by steps
63 private Map<String, PopupMenu> popups = null;
64 private Map<String, Map<String, Object>> filter = null; // Named search filters
65 private Map<String, DocumentType> defdoctype = null; // Default document types structured by step.formats
66 private Map<String, String> tempfile = null; // Available template files
67 private String[] viewermap = null; // List of file extensions mapped to a viewer
68 private Map<String, Converter> convertmap = null; // Available document format converters
69 private Properties jndprops = new Properties(); // JNDI context for launching converters
71 private static ApplicationSettings my = null; // Singleton instance
73 * Injected project settings service.
75 private ProjectSettingsService _projectSettingsService;
77 * Injected document type service.
79 private DocumentTypeService _documentTypeService;
82 * Get the projectSettingsService.
84 * @return the projectSettingsService
86 public ProjectSettingsService getProjectSettings() {
87 return _projectSettingsService;
91 * Set the projectSettingsService.
93 * @param projectSettingsService
94 * the projectSettingsService to set
96 public void setProjectSettings(ProjectSettingsService projectSettingsService) {
97 _projectSettingsService = projectSettingsService;
100 private static class NewMenu extends SimpleMenu {
101 // -----------------------------------------------------------------
104 addItem("new-empty", "menu.new.empty", "image.empty.png",
105 "select?menu=create&item=new-empty");
106 addItem("new-copy", new MenuItem("menu.new.copy")
107 .icon("image.copy.png"));
108 addItem("new-instance", new MenuItem("menu.new.instance")
109 .icon("image.hold.gif"));
110 addItem("new-import", new MenuItem("menu.new.import")
111 .icon("icon.upload.png"));
112 this.selects("new-empty");
116 private static class SearchMenu extends SimpleMenu {
117 // -----------------------------------------------------------------
118 private SearchMenu() {
120 addItem("search-study", "menu.search.study", "image.study.png",
121 "select?menu=search&item=search-study");
122 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
123 "select?menu=search&item=search-knowledge");
124 addItem("search-document", new MenuItem("menu.search.document")
125 .icon("icon.any.png"));
126 this.selects("search-study");
130 private static class PropertiesMenu extends SimpleMenu {
131 // -----------------------------------------------------------------
132 private PropertiesMenu() {
133 super("configuration");
134 addItem("prop-general", "menu.prop.general", "image.hold.gif",
135 "select?menu=properties&item=prop-general");
136 addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif",
137 "select?menu=properties&item=prop-scenario");
138 //These menu items will not be implemented in the current version.
139 /*addItem("prop-timestamp", new MenuItem("menu.prop.timestamp")
140 .icon("image.stamp.png"));
141 addItem("prop-comlog", new MenuItem("menu.prop.comlog")
142 .icon("image.hold.gif"));
143 addItem("prop-version", new MenuItem("menu.prop.version")
144 .icon("image.dirclosed.png"));*/
148 private static class DatadminMenu extends SimpleMenu {
149 // -----------------------------------------------------------------
150 private DatadminMenu() {
152 addItem("admin-scontext", "menu.admin.context", "image.hold.gif",
153 "select?menu=datadmin&item=admin-scontext");
154 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
155 "select?menu=datadmin&item=admin-knowelm");
156 addItem("admin-study", new MenuItem("menu.admin.study")
157 .icon("image.study.png"));
161 private static class SysadminMenu extends SimpleMenu {
162 // -----------------------------------------------------------------
163 private SysadminMenu() {
165 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
166 "select?menu=sysadmin&item=admin-indexing");
167 addItem("admin-importuser", "menu.admin.importuser",
169 "select?menu=sysadmin&item=admin-importuser");
174 publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge
177 // Resources relative to studies
178 private static class EditableStudyPopup extends PopupMenu {
179 // ----------------------------------------------------------------
180 private StudyRights user = null;
182 private EditableStudyPopup() {
183 addItem("publish", new PopupItem("menu.publish").icon(
184 "image.publish.png").action("edit-study?action=publish")
185 .confirmation("message.publish.study"));
186 addItem("promote", new PopupItem("menu.archive"));
188 addItem("edit", new PopupItem("menu.properties")
189 .icon("icon.ed.png").action("../select?menu=properties"));
191 addItem("script", new PopupItem("menu.newscenario")
192 .action("add-scenario"));
193 addItem("version", new PopupItem("menu.version").icon(
194 "image.version.png").action("notyetimplemented"));
196 addItem("purge", new PopupItem("menu.purge")
197 .confirmation("message.purge.study"));
198 addItem("export", new PopupItem("menu.export")
199 .icon("image.export.png")); // For future needs
200 addItem("remove", new PopupItem("menu.remove.version").icon(
201 "icon.delete.png").action("notyetimplemented")
202 .confirmation("message.delete.study"));
205 public boolean isEnabled(String name) {
207 return false; // Should not happen
208 Item item = Item.valueOf(name);
209 if (item == Item.publish)
210 return user.canPublish();
211 if (item == Item.edit)
212 return user.canEditProperties();
213 if (item == Item.script)
214 return user.canAddScenario();
215 if (item == Item.version)
216 return user.canVersion();
217 if (item == Item.remove)
218 return user.canRemove();
219 if (item == Item.purge)
220 return user.canPurge();
224 public void setContext(String name, Object context) {
225 if (context instanceof StudyRights) {
226 user = (StudyRights) context; // Just for optimizing
227 boolean history = user.getOperand().isVersioned();
228 PopupItem item = this.item("remove");
230 item.rename("menu.remove.version");
232 item.rename("menu.remove.study");
237 // Resources relative to documents
238 private static class EditableDocumentPopup extends PopupMenu { // Popup of In-Work documents
239 // ----------------------------------------------------------------
240 private DocumentRights user = null;
242 private EditableDocumentPopup() {
243 addItem("accept", new PopupItem("menu.accept").icon(
244 "image.accept.png").action("setDocument?action=accept")
245 .confirmation("message.accept.document"));
246 addItem("promote", new PopupItem("menu.promote").icon(
247 "image.publish.png").action("setDocument?action=promote")
248 .confirmation("message.promote.document"));
250 addItem("rename", new PopupItem("menu.rename")
251 .action("edit-document?action=renameDocument"));
252 addItem("attach", new PopupItem("menu.attach").icon(
253 "image.attach.png").action("select-file?nextAction=attach"));
255 addItem("version", new PopupItem("menu.version").icon(
256 "image.version.png").action(
257 "select-file?nextAction=version"));
258 addItem("replace", new PopupItem("menu.replace").icon(
259 "image.replace.png").action(
260 "select-file?nextAction=replace"));
262 addItem("purge", new PopupItem("menu.purge").action(
263 "notyetimplemented").confirmation("message.purge.document"));
264 addItem("remove", new PopupItem("menu.remove.version").icon(
265 "icon.delete.png").action("remove-document").confirmation(
266 "message.delete.document"));
269 public boolean isEnabled(String name) {
271 return false; // Should not happen
272 Item item = Item.valueOf(name);
273 if (item == Item.accept)
274 return user.canAccept();
275 if (item == Item.promote)
276 return user.canPromote();
277 if (item == Item.rename)
278 return user.canRename();
279 if (item == Item.attach)
280 return user.canAttach();
281 if (item == Item.version)
282 return user.canVersion();
283 if (item == Item.replace)
284 return user.canReplace();
285 if (item == Item.purge)
286 return user.canPurge();
287 if (item == Item.remove)
288 return user.canRemove();
292 public void setContext(String name, Object context) {
293 if (context instanceof DocumentRights) {
294 user = (DocumentRights) context; // Just for optimizing
295 Document downer = user.getOperand();
296 PopupItem item = this.item("remove");
297 if (downer.isVersioned())
298 item.rename("menu.remove.version");
300 item.rename("menu.remove.document");
305 private static class ReviewableDocumentPopup extends PopupMenu { // Popup of In-Draft documents
306 // ----------------------------------------------------------------
307 private DocumentRights user = null;
309 private ReviewableDocumentPopup() {
310 addItem("demote", new PopupItem("menu.demote").icon(
311 "image.demote.png").action("setDocument?action=demote")
312 .confirmation("message.demote.document"));
313 addItem("promote", new PopupItem("menu.review").icon(
314 "image.review.png").action("setDocument?action=review")
315 .confirmation("message.review.document"));
317 addItem("attach", new PopupItem("menu.attach").icon(
318 "image.attach.png").action("select-file?nextAction=attach"));
320 addItem("version", new PopupItem("menu.version").icon(
321 "image.version.png").action(
322 "select-file?nextAction=version"));
324 addItem("purge", new PopupItem("menu.purge").action(
325 "notyetimplemented").confirmation("message.purge.document"));
328 public boolean isEnabled(String name) {
330 return false; // Should not happen
331 Item item = Item.valueOf(name);
332 if (item == Item.demote)
333 return user.canDemote();
334 if (item == Item.promote)
335 return user.canReview();
336 if (item == Item.attach)
337 return user.canAttach();
338 if (item == Item.version)
339 return user.canVersion();
340 if (item == Item.purge)
341 return user.canPurge();
345 public void setContext(String name, Object context) {
346 if (context instanceof DocumentRights) {
347 user = (DocumentRights) context; // Just for optimizing
352 private static class NotResultDocumentPopup extends PopupMenu {
353 // ----------------------------------------------------------------
354 private DocumentRights user = null;
356 private NotResultDocumentPopup() {
357 addItem("demote", new PopupItem("menu.demote").icon(
358 "image.demote.png").action("setDocument?action=demote")
359 .confirmation("message.demote.document"));
361 addItem("attach", new PopupItem("menu.attach").icon(
362 "image.attach.png").action("select-file?nextAction=attach"));
364 addItem("version", new PopupItem("menu.version").icon(
365 "image.version.png").action(
366 "select-file?nextAction=version"));
368 addItem("purge", new PopupItem("menu.purge").action(
369 "notyetimplemented").confirmation("message.purge.document"));
370 addItem("remove", new PopupItem("menu.remove.version").icon(
371 "icon.delete.png").action("remove-document").confirmation(
372 "message.delete.document"));
376 private static class ApprovableDocumentPopup extends PopupMenu { // Popup of In-Check documents
377 // ----------------------------------------------------------------
378 private DocumentRights user = null;
380 private ApprovableDocumentPopup() {
381 addItem("undo", new PopupItem("menu.demote").icon(
382 "image.invalidate.png").action(
383 "setDocument?action=invalidate").confirmation(
384 "message.demote.document"));
385 addItem("demote", new PopupItem("menu.disapprove").icon(
386 "image.demote.png").action("setDocument?action=disapprove")
387 .confirmation("message.disapprove.document"));
388 addItem("approve", new PopupItem("menu.approve").icon(
389 "icon.APPROVED.png").action("setDocument?action=approve")
390 .confirmation("message.approve.document"));
393 public boolean isEnabled(String name) {
395 return false; // Should not happen
396 Item item = Item.valueOf(name);
397 if (item == Item.undo)
398 return user.canInvalidate();
399 if (item == Item.demote)
400 return user.canDemote();
401 if (item == Item.approve)
402 return user.canApprove();
406 public void setContext(String name, Object context) {
407 if (context instanceof DocumentRights) {
408 user = (DocumentRights) context; // Just for optimizing
413 private static class ApprovedPopup extends PopupMenu { // Popup of Approved documents
414 // ----------------------------------------------------------------
415 private ApprovedPopup() {
416 addItem("attach", new PopupItem("menu.attach").icon(
417 "image.attach.png").action("select-file?nextAction=attach"));
419 addItem("version", new PopupItem("menu.version").icon(
420 "image.version.png").action(
421 "select-file?nextAction=version"));
425 private static class ExternPopup extends PopupMenu { // Popup of Extern documents
426 // ----------------------------------------------------------------
427 private DocumentRights user = null;
429 private ExternPopup() {
430 addItem("rename", new PopupItem("menu.rename")
431 .action("edit-document?action=renameDocument"));
432 addItem("replace", new PopupItem("menu.replace").icon(
433 "image.replace.png").action(
434 "select-file?nextAction=replace"));
436 addItem("remove", new PopupItem("menu.remove.document").icon(
437 "icon.delete.png").action("remove-document").confirmation(
438 "message.delete.document"));
441 public boolean isEnabled(String name) {
443 return false; // Should not happen
444 Item item = Item.valueOf(name);
445 if (item == Item.rename)
446 return user.canRename();
447 if (item == Item.replace)
448 return user.canReplace();
449 if (item == Item.remove)
450 return user.canRemove();
454 public void setContext(String name, Object context) {
455 if (context instanceof DocumentRights) {
456 user = (DocumentRights) context; // Just for optimizing
461 // Resources relative to simulation contexts
462 private static class ScontextPopup extends PopupMenu {
463 // --------------------------------------------------------
464 private SimulationContextFacade owner = null;
466 private ScontextPopup() {
467 addItem("rename", new PopupItem("menu.rename")
468 .action("edit-context?action=renameContext"));
469 addItem("edit", new PopupItem("menu.edit")
470 .action("edit-context?action=editContext"));
472 addItem("remove", new PopupItem("menu.remove").icon(
473 "icon.delete.png").action("remove-context").confirmation(
474 "message.delete.context"));
477 public boolean isEnabled(String name) {
478 Item item = Item.valueOf(name);
480 if (item == Item.rename) {
482 } else if (item == Item.edit) {
483 // if (!owner.isEditable())
489 public void setContext(String name, Object context) {
490 if (context instanceof SimulationContextFacade) {
491 owner = (SimulationContextFacade) context; // Just for optimizing
493 super.setContext(name, context);
498 // Resources relative to knowledge
499 private static class FeedbexPopup extends PopupMenu {
500 // --------------------------------------------------------
501 private KnowledgeElement owner = null;
503 private FeedbexPopup() {
504 addItem("promote", new PopupItem("menu.promote").icon(
505 "image.review.png").action("promote-knowledge")
506 .confirmation("message.promote.knowledge"));
507 addItem("demote", new PopupItem("menu.demote").icon(
508 "image.invalidate.png").action("demote-knowledge")
509 .confirmation("message.demote.knowledge"));
511 addItem("rename", new PopupItem("menu.rename")
512 .action("edit-knowledge?action=renameKnowledge"));
513 addItem("edit", new PopupItem("menu.edit")
514 .action("edit-knowledge?action=editKnowledge"));
516 addItem("remove", new PopupItem("menu.remove").icon(
517 "icon.delete.png").action("remove-knowledge").confirmation(
518 "message.delete.knowledge"));
521 public boolean isEnabled(String name) {
522 Item item = Item.valueOf(name);
524 if (item == Item.promote) {
525 if (owner.getProgressState() != ProgressState.inDRAFT)
527 } else if (item == Item.demote) {
528 if (owner.getProgressState() != ProgressState.inCHECK)
534 public void setContext(String name, Object context) {
535 if (context instanceof KnowledgeElement)
536 owner = (KnowledgeElement) context; // Just for optimizing
538 super.setContext(name, context);
543 // ==============================================================================================================================
545 // ==============================================================================================================================
547 public static ApplicationSettings getMe() {
548 // ------------------------------------------
550 my = new ApplicationSettings();
552 return my; // The application is supposed being previously created below
560 public ApplicationSettings init(String wappurl, Locale lang)
562 ClassLoader cloader = getClass().getClassLoader();
563 String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
566 wappserver = wurl[2];
570 wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
571 jndprops.load(cloader.getResourceAsStream("jndi.properties"));
573 logger.info("Application root set to "
574 + wapprops.getProperty("wapp.root"));
583 // ==============================================================================================================================
584 // Public member functions
585 // ==============================================================================================================================
587 public void configure(String filename) {
588 // ---------------------------------------
589 // Non customizable settings
591 SimpleMenu menu = new NewMenu();
592 menus.put(menu.getName(), menu);
593 menu = new SearchMenu();
594 menus.put(menu.getName(), menu);
595 menu = new DatadminMenu();
596 menus.put(menu.getName(), menu);
597 menu = new SysadminMenu();
598 menus.put(menu.getName(), menu);
599 menu = new PropertiesMenu();
600 menus.put(menu.getName(), menu);
602 popups = new HashMap<String, PopupMenu>();
603 popups.put("steditable", new EditableStudyPopup());
604 popups.put("editable", new EditableDocumentPopup());
605 popups.put("notresult", new NotResultDocumentPopup());
606 popups.put("reviewable", new ReviewableDocumentPopup());
607 popups.put("approvable", new ApprovableDocumentPopup());
608 popups.put("approved", new ApprovedPopup());
609 popups.put("extern", new ExternPopup());
610 popups.put("scontext", new ScontextPopup());
611 popups.put("feedbex", new FeedbexPopup());
613 // Default customizable mandatory settings
614 Map<String, Object> fprop = new HashMap<String, Object>();
615 fprop.put("visibility", "PRIVATE");
616 fprop.put("matchamong", "all");
617 fprop.put("matcontext", "all");
618 fprop.put("state", "APPROVED");
619 fprop.put("author", "0");
620 fprop.put("reference", "");
621 fprop.put("title", "");
622 fprop.put("context", new Vector<SimulationContext>());
624 Map<String, Object> gprop = new HashMap<String, Object>();
625 gprop.put("visibility", "PUBLIC");
626 gprop.put("matchamong", "all");
627 gprop.put("matcontext", "all");
628 gprop.put("type", "2"); // TODO: Get the index from the type name
629 gprop.put("author", "0");
630 gprop.put("reference", "");
631 gprop.put("title", "");
632 gprop.put("context", new Vector<SimulationContext>());
634 defdoctype = new LinkedHashMap<String, DocumentType>();
635 tempfile = new HashMap<String, String>();
636 viewermap = new String[0];
637 convertmap = new HashMap<String, Converter>();
638 filter = new HashMap<String, Map<String, Object>>();
639 filter.put("study", fprop);
640 filter.put("knowledge", gprop);
642 // Customization (must be done after above default settings)
643 File config = new File(filename);
644 if (config.exists()) {
645 loadCustomization(config); // Sets default document types, installed modules and available templates
647 logger.info("Could not find the application configuration file \""
648 + config.getAbsolutePath() + "\", using default settings");
650 // Settings based on the customization
651 bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
653 List<ProjectSettingsService.Step> steps = getProjectSettings()
655 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
657 ProjectSettingsService.Step step = i.next();
658 List<String> formats = getDefaultFormats(step);
659 if (formats.size() == 0)
662 ToolBar bar = new ToolBar(24); // Height of the module-bar
663 HashSet<String> module = new HashSet<String>(); // For not duplicating modules
664 for (Iterator<String> j = formats.iterator(); j.hasNext();) {
665 String format = j.next();
666 String command = getApplicationProperty("executable." + format);
668 continue; // Module not installed
669 if (module.contains(command))
672 String[] parsed = command.split("/");
673 String[] name = parsed[parsed.length - 1].split("\\x2E");
674 DocumentType dtype = my.defdoctype.get(
675 step.getNumber() + "." + format);
678 docname = dtype.getName();
680 if (tempfile.get(docname) == null) { // No available template
681 String tool = parsed[parsed.length - 1];
682 String icon = name[0];
683 if (icon.equals("index")) {
684 tool = parsed[parsed.length - 2];
685 icon = "tool." + tool.toLowerCase() + ".png";
687 icon = "tool." + icon.toLowerCase() + ".png";
689 File image = new File(ApplicationSettings
690 .getApplicationSkinPath()
693 icon = "tool.any.png";
694 bar.addTool(tool, icon, command);
696 docname = "/jsp/newDocument.jsp?type=" + docname;
697 String icon = "tool." + name[0].toLowerCase() + ".png";
698 File image = new File(ApplicationSettings
699 .getApplicationSkinPath()
702 icon = "tool.any.png";
703 bar.addTool(name[0], icon, command, docname);
707 bars.put(step.getNumber(), bar);
711 public String getApplicationProperty(String name) {
712 return wapprops.getProperty(name); // May be null
715 public String getApplicationRootPath() {
716 //RKV: return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
717 return _servletContext.getRealPath("/");
720 public String getApplicationURL() {
721 // ----------------------------------
722 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
723 .append("/").append(wappname);
724 return url.toString();
727 public Map<String, Object> getFilter(String name) {
728 // --------------------------------------------------
729 return filter.get(name);
732 public ToolBar getModuleBar(Step step) {
733 // -----------------------------------------
734 return bars.get(step.getNumber());
737 public Properties getNamingProperties() {
738 // ----------------------------------------
742 // ==============================================================================================================================
744 // ==============================================================================================================================
746 public static String getApplicationPluginPath() {
747 // ------------------------------------------------
748 return my.getApplicationRootPath() + "plugin/";
751 public static String getApplicationResourcePath() {
752 // --------------------------------------------------
753 return my.getApplicationRootPath() + "WEB-INF/classes/";
756 public static String getApplicationSkinPath() {
757 // ----------------------------------------------
758 return my.getApplicationRootPath() + "skin/";
761 public static Converter getConverter(DocumentType type, String format) {
762 // -----------------------------------------------------------------------
763 return my.convertmap.get(format + type.getName()); // May be null;
766 public static DocumentType getDefaultDocumentType(Step step, String format) {
767 // ----------------------------------------------------------------------------
768 String[] table = format.split("\\x2E");
769 return my.defdoctype.get(step.getNumber() + "."
770 + table[table.length - 1]); // May be null
773 public static String getDownloadURL(User user) {
774 // --------------------------------------------------
775 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
776 .append("/download/").append(user.getUsername()).append("/");
777 return url.toString(); // The download Tomcat context is supposed being defined
780 public static Locale getCurrentLocale() {
781 // ----------------------------------------
785 public static SimpleMenu getMenu(String name) {
786 // ----------------------------------------------
787 return my.menus.get(name);
790 public static PopupMenu getPopupMenu(String name) {
791 // --------------------------------------------------
792 return my.popups.get(name);
795 public static String getRepositoryURL() {
796 // ----------------------------------------
797 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
798 .append("/repository/");
799 return url.toString(); // The repository Tomcat context is supposed being defined
802 public static Locale[] getSupportedLocales() {
803 // ---------------------------------------------
804 String[] code = my.wapprops.getProperty("locale.supported").split(",");
805 Locale[] result = new Locale[code.length];
806 for (int i = 0; i < code.length; i++)
807 result[i] = new Locale(code[i]);
811 public static String[] getViewersMapping() {
812 // -------------------------------------------
816 public static String getWebSiteURL() {
817 // -------------------------------------
818 return my.getApplicationProperty("wapp.website");
821 public static String getHelpURL() {
822 // ----------------------------------
823 return my.getApplicationProperty("wapp.onlinehelp");
826 // ==============================================================================================================================
828 // ==============================================================================================================================
830 private List<String> getDefaultFormats(ProjectSettingsService.Step step) {
831 // ------------------------------------------------------------------
832 Set<String> keys = defdoctype.keySet();
833 int number = step.getNumber();
834 Vector<String> result = new Vector<String>();
836 for (Iterator<String> i = keys.iterator(); i.hasNext();) {
837 String[] key = i.next().split("\\x2E");
838 if (Integer.valueOf(key[0]) != number)
840 if (key[1].equals("pdf"))
841 continue; // PDF is not an authoring format
842 result.add(key[1]); // Formats are unique
847 private void loadCustomization(File config) {
848 // --------------------------------------------
850 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
852 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
854 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
855 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
856 .getDocumentElement());
858 // Default document types tag
859 Node child = children.get("default-doctypes");
860 NodeList nlist = child.getChildNodes();
862 List<DocumentType> listype = getDocumentTypeService()
864 HashMap<String, DocumentType> maptype = new HashMap<String, DocumentType>();
865 for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
866 DocumentType type = i.next();
867 maptype.put(type.getName(), type);
869 for (int i = 0; i < nlist.getLength(); i++) {
870 child = nlist.item(i);
871 if (!child.getNodeName().equals("step"))
874 String nstep = child.getAttributes().getNamedItem("number")
876 NodeList map = child.getChildNodes();
877 for (int j = 0; j < map.getLength(); j++) {
879 if (!child.getNodeName().equals("mapping"))
881 NamedNodeMap natr = child.getAttributes();
882 String dext = natr.getNamedItem("extension").getNodeValue();
883 String type = natr.getNamedItem("type").getNodeValue();
884 defdoctype.put(nstep + "." + dext, maptype.get(type));
888 child = children.get("modules");
889 nlist = child.getChildNodes();
890 for (int i = 0; i < nlist.getLength(); i++) {
891 child = nlist.item(i);
892 if (!child.getNodeName().equals("mapping"))
895 NamedNodeMap natr = child.getAttributes();
896 String dext = natr.getNamedItem("extension").getNodeValue();
897 String exec = natr.getNamedItem("executable").getNodeValue();
898 wapprops.put("executable." + dext, exec);
900 // Viewer mappings tag
901 child = children.get("viewers");
902 viewermap = child.getAttributes().getNamedItem("extension")
903 .getNodeValue().split(",");
906 child = children.get("converters");
907 nlist = child.getChildNodes();
908 for (int i = 0; i < nlist.getLength(); i++) {
909 child = nlist.item(i);
911 if (child.getNodeName().equals("geometry")) {
912 NamedNodeMap natr = child.getAttributes();
913 String from = natr.getNamedItem("from").getNodeValue();
914 String to = natr.getNamedItem("to").getNodeValue();
915 String exec = natr.getNamedItem("executable")
917 convertmap.put(from + "geometry", new Converter("geometry",
923 child = children.get("templates");
924 nlist = child.getChildNodes();
925 for (int i = 0; i < nlist.getLength(); i++) {
926 child = nlist.item(i);
927 if (!child.getNodeName().equals("document"))
930 NamedNodeMap natr = child.getAttributes();
931 String type = natr.getNamedItem("type").getNodeValue();
932 String file = natr.getNamedItem("file").getNodeValue();
933 tempfile.put(type, file);
935 } catch (Exception error) {
936 logger.info("Error in customization", error);
941 * Get the documentTypeService.
943 * @return the documentTypeService
945 public DocumentTypeService getDocumentTypeService() {
946 return _documentTypeService;
950 * Set the documentTypeService.
952 * @param documentTypeService
953 * the documentTypeService to set
955 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
956 _documentTypeService = documentTypeService;
961 * @see org.apache.struts2.util.ServletContextAware#setServletContext(javax.servlet.ServletContext)
964 public void setServletContext(ServletContext context) {
965 _servletContext = context;