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.xml.parsers.DocumentBuilder;
17 import javax.xml.parsers.DocumentBuilderFactory;
18 import org.w3c.dom.Node;
19 import org.w3c.dom.NodeList;
20 import org.w3c.dom.NamedNodeMap;
22 import org.apache.log4j.Logger;
23 import org.splat.dal.bo.kernel.User;
24 import org.splat.manox.XDOM;
25 import org.splat.dal.bo.som.Document;
26 import org.splat.som.DocumentRights;
27 import org.splat.dal.bo.som.DocumentType;
28 import org.splat.dal.bo.som.KnowledgeElement;
29 import org.splat.dal.bo.som.ProgressState;
30 import org.splat.service.DocumentTypeService;
31 import org.splat.service.technical.ProjectSettingsService;
32 import org.splat.simer.Converter;
33 import org.splat.dal.bo.som.SimulationContext;
34 import org.splat.som.Step;
35 import org.splat.som.StudyRights;
36 import org.splat.wapp.MenuItem;
37 import org.splat.wapp.PopupMenu;
38 import org.splat.wapp.PopupItem;
39 import org.splat.wapp.SimpleMenu;
40 import org.splat.wapp.ToolBar;
42 public class ApplicationSettings {
45 * Application settings logger.
47 protected final static Logger logger = Logger
48 .getLogger(ApplicationSettings.class);
50 private String wappserver;
51 private String wappname;
52 private Properties wapprops; // General properties from the application properties files
53 private Locale locale; // Current user locale
54 private Map<String, SimpleMenu> menus = null; // Application menus
55 private Map<Integer, ToolBar> bars = null; // Study module-bars structured by steps
56 private Map<String, PopupMenu> popups = null;
57 private Map<String, Map<String, Object>> filter = null; // Named search filters
58 private Map<String, DocumentType> defdoctype = null; // Default document types structured by step.formats
59 private Map<String, String> tempfile = null; // Available template files
60 private String[] viewermap = null; // List of file extensions mapped to a viewer
61 private Map<String, Converter> convertmap = null; // Available document format converters
62 private Properties jndprops = null; // JNDI context for launching converters
64 private static ApplicationSettings my = null; // Singleton instance
66 * Injected project settings service.
68 private ProjectSettingsService _projectSettingsService;
70 * Injected document type service.
72 private DocumentTypeService _documentTypeService;
75 * Get the projectSettingsService.
77 * @return the projectSettingsService
79 public ProjectSettingsService getProjectSettings() {
80 return _projectSettingsService;
84 * Set the projectSettingsService.
86 * @param projectSettingsService
87 * the projectSettingsService to set
89 public void setProjectSettings(ProjectSettingsService projectSettingsService) {
90 _projectSettingsService = projectSettingsService;
93 private static class NewMenu extends SimpleMenu {
94 // -----------------------------------------------------------------
97 addItem("new-empty", "menu.new.empty", "image.empty.png",
98 "select?menu=create&item=new-empty");
99 addItem("new-copy", new MenuItem("menu.new.copy")
100 .icon("image.copy.png"));
101 addItem("new-instance", new MenuItem("menu.new.instance")
102 .icon("image.hold.gif"));
103 addItem("new-import", new MenuItem("menu.new.import")
104 .icon("icon.upload.png"));
105 this.selects("new-empty");
109 private static class SearchMenu extends SimpleMenu {
110 // -----------------------------------------------------------------
111 private SearchMenu() {
113 addItem("search-study", "menu.search.study", "image.study.png",
114 "select?menu=search&item=search-study");
115 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
116 "select?menu=search&item=search-knowledge");
117 addItem("search-document", new MenuItem("menu.search.document")
118 .icon("icon.any.png"));
119 this.selects("search-study");
123 private static class PropertiesMenu extends SimpleMenu {
124 // -----------------------------------------------------------------
125 private PropertiesMenu() {
126 super("configuration");
127 addItem("prop-general", "menu.prop.general", "image.hold.gif",
128 "select?menu=properties&item=prop-general");
129 addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif",
130 "select?menu=properties&item=prop-scenario");
131 addItem("prop-timestamp", new MenuItem("menu.prop.timestamp")
132 .icon("image.stamp.png"));
133 addItem("prop-comlog", new MenuItem("menu.prop.comlog")
134 .icon("image.hold.gif"));
135 addItem("prop-version", new MenuItem("menu.prop.version")
136 .icon("image.dirclosed.png"));
140 private static class DatadminMenu extends SimpleMenu {
141 // -----------------------------------------------------------------
142 private DatadminMenu() {
144 addItem("admin-scontext", "menu.admin.context", "image.hold.gif",
145 "select?menu=datadmin&item=admin-scontext");
146 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
147 "select?menu=datadmin&item=admin-knowelm");
148 addItem("admin-study", new MenuItem("menu.admin.study")
149 .icon("image.study.png"));
153 private static class SysadminMenu extends SimpleMenu {
154 // -----------------------------------------------------------------
155 private SysadminMenu() {
157 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
158 "select?menu=sysadmin&item=admin-indexing");
159 addItem("admin-importuser", "menu.admin.importuser",
161 "select?menu=sysadmin&item=admin-importuser");
166 publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge
169 // Resources relative to studies
170 private static class EditableStudyPopup extends PopupMenu {
171 // ----------------------------------------------------------------
172 private StudyRights user = null;
174 private EditableStudyPopup() {
175 addItem("publish", new PopupItem("menu.publish").icon(
176 "image.publish.png").action("edit-study?action=publish")
177 .confirmation("message.publish.study"));
178 addItem("promote", new PopupItem("menu.archive"));
180 addItem("edit", new PopupItem("menu.properties")
181 .icon("icon.ed.png").action("../select?menu=properties"));
183 addItem("script", new PopupItem("menu.newscenario")
184 .action("add-scenario"));
185 addItem("version", new PopupItem("menu.version").icon(
186 "image.version.png").action("notyetimplemented"));
188 addItem("purge", new PopupItem("menu.purge")
189 .confirmation("message.purge.study"));
190 addItem("export", new PopupItem("menu.export")
191 .icon("image.export.png")); // For future needs
192 addItem("remove", new PopupItem("menu.remove.version").icon(
193 "icon.delete.png").action("notyetimplemented")
194 .confirmation("message.delete.study"));
197 public boolean isEnabled(String name) {
199 return false; // Should not happen
200 Item item = Item.valueOf(name);
201 if (item == Item.publish)
202 return user.canPublish();
203 if (item == Item.edit)
204 return user.canEditProperties();
205 if (item == Item.script)
206 return user.canAddScenario();
207 if (item == Item.version)
208 return user.canVersion();
209 if (item == Item.remove)
210 return user.canRemove();
211 if (item == Item.purge)
212 return user.canPurge();
216 public void setContext(String name, Object context) {
217 if (context instanceof StudyRights) {
218 user = (StudyRights) context; // Just for optimizing
219 boolean history = user.getOperand().isVersioned();
220 PopupItem item = this.item("remove");
222 item.rename("menu.remove.version");
224 item.rename("menu.remove.study");
229 // Resources relative to documents
230 private static class EditableDocumentPopup extends PopupMenu { // Popup of In-Work documents
231 // ----------------------------------------------------------------
232 private DocumentRights user = null;
234 private EditableDocumentPopup() {
235 addItem("accept", new PopupItem("menu.accept").icon(
236 "image.accept.png").action("setDocument?action=accept")
237 .confirmation("message.accept.document"));
238 addItem("promote", new PopupItem("menu.promote").icon(
239 "image.publish.png").action("setDocument?action=promote")
240 .confirmation("message.promote.document"));
242 addItem("rename", new PopupItem("menu.rename")
243 .action("edit-document?action=renameDocument"));
244 addItem("attach", new PopupItem("menu.attach").icon(
245 "image.attach.png").action("select-file?nextAction=attach"));
247 addItem("version", new PopupItem("menu.version").icon(
248 "image.version.png").action(
249 "select-file?nextAction=version"));
250 addItem("replace", new PopupItem("menu.replace").icon(
251 "image.replace.png").action(
252 "select-file?nextAction=replace"));
254 addItem("purge", new PopupItem("menu.purge").action(
255 "notyetimplemented").confirmation("message.purge.document"));
256 addItem("remove", new PopupItem("menu.remove.version").icon(
257 "icon.delete.png").action("remove-document").confirmation(
258 "message.delete.document"));
261 public boolean isEnabled(String name) {
263 return false; // Should not happen
264 Item item = Item.valueOf(name);
265 if (item == Item.accept)
266 return user.canAccept();
267 if (item == Item.promote)
268 return user.canPromote();
269 if (item == Item.rename)
270 return user.canRename();
271 if (item == Item.attach)
272 return user.canAttach();
273 if (item == Item.version)
274 return user.canVersion();
275 if (item == Item.replace)
276 return user.canReplace();
277 if (item == Item.purge)
278 return user.canPurge();
279 if (item == Item.remove)
280 return user.canRemove();
284 public void setContext(String name, Object context) {
285 if (context instanceof DocumentRights) {
286 user = (DocumentRights) context; // Just for optimizing
287 Document downer = user.getOperand();
288 PopupItem item = this.item("remove");
289 if (downer.isVersioned())
290 item.rename("menu.remove.version");
292 item.rename("menu.remove.document");
297 private static class ReviewableDocumentPopup extends PopupMenu { // Popup of In-Draft documents
298 // ----------------------------------------------------------------
299 private DocumentRights user = null;
301 private ReviewableDocumentPopup() {
302 addItem("demote", new PopupItem("menu.demote").icon(
303 "image.demote.png").action("setDocument?action=demote")
304 .confirmation("message.demote.document"));
305 addItem("promote", new PopupItem("menu.review").icon(
306 "image.review.png").action("setDocument?action=review")
307 .confirmation("message.review.document"));
309 addItem("attach", new PopupItem("menu.attach").icon(
310 "image.attach.png").action("select-file?nextAction=attach"));
312 addItem("version", new PopupItem("menu.version").icon(
313 "image.version.png").action(
314 "select-file?nextAction=version"));
316 addItem("purge", new PopupItem("menu.purge").action(
317 "notyetimplemented").confirmation("message.purge.document"));
320 public boolean isEnabled(String name) {
322 return false; // Should not happen
323 Item item = Item.valueOf(name);
324 if (item == Item.demote)
325 return user.canDemote();
326 if (item == Item.promote)
327 return user.canReview();
328 if (item == Item.attach)
329 return user.canAttach();
330 if (item == Item.version)
331 return user.canVersion();
332 if (item == Item.purge)
333 return user.canPurge();
337 public void setContext(String name, Object context) {
338 if (context instanceof DocumentRights) {
339 user = (DocumentRights) context; // Just for optimizing
344 private static class NotResultDocumentPopup extends PopupMenu {
345 // ----------------------------------------------------------------
346 private DocumentRights user = null;
348 private NotResultDocumentPopup() {
349 addItem("demote", new PopupItem("menu.demote").icon(
350 "image.demote.png").action("setDocument?action=demote")
351 .confirmation("message.demote.document"));
353 addItem("attach", new PopupItem("menu.attach").icon(
354 "image.attach.png").action("select-file?nextAction=attach"));
356 addItem("version", new PopupItem("menu.version").icon(
357 "image.version.png").action(
358 "select-file?nextAction=version"));
360 addItem("purge", new PopupItem("menu.purge").action(
361 "notyetimplemented").confirmation("message.purge.document"));
362 addItem("remove", new PopupItem("menu.remove.version").icon(
363 "icon.delete.png").action("remove-document").confirmation(
364 "message.delete.document"));
368 private static class ApprovableDocumentPopup extends PopupMenu { // Popup of In-Check documents
369 // ----------------------------------------------------------------
370 private DocumentRights user = null;
372 private ApprovableDocumentPopup() {
373 addItem("undo", new PopupItem("menu.demote").icon(
374 "image.invalidate.png").action(
375 "setDocument?action=invalidate").confirmation(
376 "message.demote.document"));
377 addItem("demote", new PopupItem("menu.disapprove").icon(
378 "image.demote.png").action("setDocument?action=disapprove")
379 .confirmation("message.disapprove.document"));
380 addItem("approve", new PopupItem("menu.approve").icon(
381 "icon.APPROVED.png").action("setDocument?action=approve")
382 .confirmation("message.approve.document"));
385 public boolean isEnabled(String name) {
387 return false; // Should not happen
388 Item item = Item.valueOf(name);
389 if (item == Item.undo)
390 return user.canInvalidate();
391 if (item == Item.demote)
392 return user.canDemote();
393 if (item == Item.approve)
394 return user.canApprove();
398 public void setContext(String name, Object context) {
399 if (context instanceof DocumentRights) {
400 user = (DocumentRights) context; // Just for optimizing
405 private static class ApprovedPopup extends PopupMenu { // Popup of Approved documents
406 // ----------------------------------------------------------------
407 private ApprovedPopup() {
408 addItem("attach", new PopupItem("menu.attach").icon(
409 "image.attach.png").action("select-file?nextAction=attach"));
411 addItem("version", new PopupItem("menu.version").icon(
412 "image.version.png").action(
413 "select-file?nextAction=version"));
417 private static class ExternPopup extends PopupMenu { // Popup of Extern documents
418 // ----------------------------------------------------------------
419 private DocumentRights user = null;
421 private ExternPopup() {
422 addItem("rename", new PopupItem("menu.rename")
423 .action("edit-document?action=renameDocument"));
424 addItem("replace", new PopupItem("menu.replace").icon(
425 "image.replace.png").action(
426 "select-file?nextAction=replace"));
428 addItem("remove", new PopupItem("menu.remove.document").icon(
429 "icon.delete.png").action("remove-document").confirmation(
430 "message.delete.document"));
433 public boolean isEnabled(String name) {
435 return false; // Should not happen
436 Item item = Item.valueOf(name);
437 if (item == Item.rename)
438 return user.canRename();
439 if (item == Item.replace)
440 return user.canReplace();
441 if (item == Item.remove)
442 return user.canRemove();
446 public void setContext(String name, Object context) {
447 if (context instanceof DocumentRights) {
448 user = (DocumentRights) context; // Just for optimizing
453 // Resources relative to simulation contexts
454 private static class ScontextPopup extends PopupMenu {
455 // --------------------------------------------------------
456 private SimulationContextFacade owner = null;
458 private ScontextPopup() {
459 addItem("rename", new PopupItem("menu.rename")
460 .action("edit-context?action=renameContext"));
461 addItem("edit", new PopupItem("menu.edit")
462 .action("edit-context?action=editContext"));
464 addItem("remove", new PopupItem("menu.remove").icon(
465 "icon.delete.png").action("remove-context").confirmation(
466 "message.delete.context"));
469 public boolean isEnabled(String name) {
470 Item item = Item.valueOf(name);
472 if (item == Item.rename) {
474 } else if (item == Item.edit) {
475 // if (!owner.isEditable())
481 public void setContext(String name, Object context) {
482 if (context instanceof SimulationContextFacade) {
483 owner = (SimulationContextFacade) context; // Just for optimizing
485 super.setContext(name, context);
490 // Resources relative to knowledge
491 private static class FeedbexPopup extends PopupMenu {
492 // --------------------------------------------------------
493 private KnowledgeElement owner = null;
495 private FeedbexPopup() {
496 addItem("promote", new PopupItem("menu.promote").icon(
497 "image.review.png").action("promote-knowledge")
498 .confirmation("message.promote.knowledge"));
499 addItem("demote", new PopupItem("menu.demote").icon(
500 "image.invalidate.png").action("demote-knowledge")
501 .confirmation("message.demote.knowledge"));
503 addItem("rename", new PopupItem("menu.rename")
504 .action("edit-knowledge?action=renameKnowledge"));
505 addItem("edit", new PopupItem("menu.edit")
506 .action("edit-knowledge?action=editKnowledge"));
508 addItem("remove", new PopupItem("menu.remove").icon(
509 "icon.delete.png").action("remove-knowledge").confirmation(
510 "message.delete.knowledge"));
513 public boolean isEnabled(String name) {
514 Item item = Item.valueOf(name);
516 if (item == Item.promote) {
517 if (owner.getProgressState() != ProgressState.inDRAFT)
519 } else if (item == Item.demote) {
520 if (owner.getProgressState() != ProgressState.inCHECK)
526 public void setContext(String name, Object context) {
527 if (context instanceof KnowledgeElement)
528 owner = (KnowledgeElement) context; // Just for optimizing
530 super.setContext(name, context);
535 // ==============================================================================================================================
537 // ==============================================================================================================================
539 public static ApplicationSettings getMe() {
540 // ------------------------------------------
542 my = new ApplicationSettings();
544 return my; // The application is supposed being previously created below
552 public ApplicationSettings init(String wappurl, Locale lang)
554 ClassLoader cloader = getClass().getClassLoader();
555 String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
558 wappserver = wurl[2];
560 wapprops = new Properties();
561 jndprops = new Properties();
562 wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
563 jndprops.load(cloader.getResourceAsStream("jndi.properties"));
565 logger.info("Application root set to "
566 + wapprops.getProperty("wapp.root"));
575 // ==============================================================================================================================
576 // Public member functions
577 // ==============================================================================================================================
579 public void configure(String filename) {
580 // ---------------------------------------
581 // Non customizable settings
582 menus = new HashMap<String, SimpleMenu>();
583 SimpleMenu menu = new NewMenu();
584 menus.put(menu.getName(), menu);
585 menu = new SearchMenu();
586 menus.put(menu.getName(), menu);
587 menu = new DatadminMenu();
588 menus.put(menu.getName(), menu);
589 menu = new SysadminMenu();
590 menus.put(menu.getName(), menu);
591 menu = new PropertiesMenu();
592 menus.put(menu.getName(), menu);
594 popups = new HashMap<String, PopupMenu>();
595 popups.put("steditable", new EditableStudyPopup());
596 popups.put("editable", new EditableDocumentPopup());
597 popups.put("notresult", new NotResultDocumentPopup());
598 popups.put("reviewable", new ReviewableDocumentPopup());
599 popups.put("approvable", new ApprovableDocumentPopup());
600 popups.put("approved", new ApprovedPopup());
601 popups.put("extern", new ExternPopup());
602 popups.put("scontext", new ScontextPopup());
603 popups.put("feedbex", new FeedbexPopup());
605 // Default customizable mandatory settings
606 Map<String, Object> fprop = new HashMap<String, Object>();
607 fprop.put("visibility", "PRIVATE");
608 fprop.put("matchamong", "all");
609 fprop.put("matcontext", "all");
610 fprop.put("state", "APPROVED");
611 fprop.put("author", "0");
612 fprop.put("reference", "");
613 fprop.put("title", "");
614 fprop.put("context", new Vector<SimulationContext>());
616 Map<String, Object> gprop = new HashMap<String, Object>();
617 gprop.put("visibility", "PUBLIC");
618 gprop.put("matchamong", "all");
619 gprop.put("matcontext", "all");
620 gprop.put("type", "2"); // TODO: Get the index from the type name
621 gprop.put("author", "0");
622 gprop.put("reference", "");
623 gprop.put("title", "");
624 gprop.put("context", new Vector<SimulationContext>());
626 defdoctype = new LinkedHashMap<String, DocumentType>();
627 tempfile = new HashMap<String, String>();
628 viewermap = new String[0];
629 convertmap = new HashMap<String, Converter>();
630 filter = new HashMap<String, Map<String, Object>>();
631 filter.put("study", fprop);
632 filter.put("knowledge", gprop);
634 // Customization (must be done after above default settings)
635 File config = new File(filename);
636 if (config.exists()) {
637 loadCustomization(config); // Sets default document types, installed modules and available templates
639 logger.info("Could not find the application configuration file \""
640 + config.getAbsolutePath() + "\", using default settings");
642 // Settings based on the customization
643 bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
645 List<ProjectSettingsService.Step> steps = getProjectSettings()
647 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
649 ProjectSettingsService.Step step = i.next();
650 List<String> formats = getDefaultFormats(step);
651 if (formats.size() == 0)
654 ToolBar bar = new ToolBar(24); // Height of the module-bar
655 HashSet<String> module = new HashSet<String>(); // For not duplicating modules
656 for (Iterator<String> j = formats.iterator(); j.hasNext();) {
657 String format = j.next();
658 String command = getApplicationProperty("executable." + format);
660 continue; // Module not installed
661 if (module.contains(command))
664 String[] parsed = command.split("/");
665 String[] name = parsed[parsed.length - 1].split("\\x2E");
666 DocumentType dtype = my.defdoctype.get(
667 step.getNumber() + "." + format);
670 docname = dtype.getName();
672 if (tempfile.get(docname) == null) { // No available template
673 String tool = parsed[parsed.length - 1];
674 String icon = name[0];
675 if (icon.equals("index")) {
676 tool = parsed[parsed.length - 2];
677 icon = "tool." + tool.toLowerCase() + ".png";
679 icon = "tool." + icon.toLowerCase() + ".png";
681 File image = new File(ApplicationSettings
682 .getApplicationSkinPath()
685 icon = "tool.any.png";
686 bar.addTool(tool, icon, command);
688 docname = "/jsp/newDocument.jsp?type=" + docname;
689 String icon = "tool." + name[0].toLowerCase() + ".png";
690 File image = new File(ApplicationSettings
691 .getApplicationSkinPath()
694 icon = "tool.any.png";
695 bar.addTool(name[0], icon, command, docname);
699 bars.put(step.getNumber(), bar);
703 public String getApplicationProperty(String name) {
704 // --------------------------------------------------
705 return wapprops.getProperty(name); // May be null
708 public String getApplicationRootPath() {
709 // ---------------------------------------
710 return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
713 public String getApplicationURL() {
714 // ----------------------------------
715 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
716 .append("/").append(wappname);
717 return url.toString();
720 public Map<String, Object> getFilter(String name) {
721 // --------------------------------------------------
722 return filter.get(name);
725 public ToolBar getModuleBar(Step step) {
726 // -----------------------------------------
727 return bars.get(step.getNumber());
730 public Properties getNamingProperties() {
731 // ----------------------------------------
735 // ==============================================================================================================================
737 // ==============================================================================================================================
739 public static String getApplicationPluginPath() {
740 // ------------------------------------------------
741 return my.getApplicationRootPath() + "plugin/";
744 public static String getApplicationResourcePath() {
745 // --------------------------------------------------
746 return my.getApplicationRootPath() + "WEB-INF/classes/";
749 public static String getApplicationSkinPath() {
750 // ----------------------------------------------
751 return my.getApplicationRootPath() + "skin/";
754 public static Converter getConverter(DocumentType type, String format) {
755 // -----------------------------------------------------------------------
756 return my.convertmap.get(format + type.getName()); // May be null;
759 public static DocumentType getDefaultDocumentType(Step step, String format) {
760 // ----------------------------------------------------------------------------
761 String[] table = format.split("\\x2E");
762 return my.defdoctype.get(step.getNumber() + "."
763 + table[table.length - 1]); // May be null
766 public static String getDownloadURL(User user) {
767 // --------------------------------------------------
768 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
769 .append("/download/").append(user.getUsername()).append("/");
770 return url.toString(); // The download Tomcat context is supposed being defined
773 public static Locale getCurrentLocale() {
774 // ----------------------------------------
778 public static SimpleMenu getMenu(String name) {
779 // ----------------------------------------------
780 return my.menus.get(name);
783 public static PopupMenu getPopupMenu(String name) {
784 // --------------------------------------------------
785 return my.popups.get(name);
788 public static String getRepositoryURL() {
789 // ----------------------------------------
790 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
791 .append("/repository/");
792 return url.toString(); // The repository Tomcat context is supposed being defined
795 public static Locale[] getSupportedLocales() {
796 // ---------------------------------------------
797 String[] code = my.wapprops.getProperty("locale.supported").split(",");
798 Locale[] result = new Locale[code.length];
799 for (int i = 0; i < code.length; i++)
800 result[i] = new Locale(code[i]);
804 public static String[] getViewersMapping() {
805 // -------------------------------------------
809 public static String getWebSiteURL() {
810 // -------------------------------------
811 return my.getApplicationProperty("wapp.website");
814 public static String getHelpURL() {
815 // ----------------------------------
816 return my.getApplicationProperty("wapp.onlinehelp");
819 // ==============================================================================================================================
821 // ==============================================================================================================================
823 private List<String> getDefaultFormats(ProjectSettingsService.Step step) {
824 // ------------------------------------------------------------------
825 Set<String> keys = defdoctype.keySet();
826 int number = step.getNumber();
827 Vector<String> result = new Vector<String>();
829 for (Iterator<String> i = keys.iterator(); i.hasNext();) {
830 String[] key = i.next().split("\\x2E");
831 if (Integer.valueOf(key[0]) != number)
833 if (key[1].equals("pdf"))
834 continue; // PDF is not an authoring format
835 result.add(key[1]); // Formats are unique
840 private void loadCustomization(File config) {
841 // --------------------------------------------
843 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
845 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
847 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
848 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
849 .getDocumentElement());
851 // Default document types tag
852 Node child = children.get("default-doctypes");
853 NodeList nlist = child.getChildNodes();
855 List<DocumentType> listype = getDocumentTypeService()
857 HashMap<String, DocumentType> maptype = new HashMap<String, DocumentType>();
858 for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
859 DocumentType type = i.next();
860 maptype.put(type.getName(), type);
862 for (int i = 0; i < nlist.getLength(); i++) {
863 child = nlist.item(i);
864 if (!child.getNodeName().equals("step"))
867 String nstep = child.getAttributes().getNamedItem("number")
869 NodeList map = child.getChildNodes();
870 for (int j = 0; j < map.getLength(); j++) {
872 if (!child.getNodeName().equals("mapping"))
874 NamedNodeMap natr = child.getAttributes();
875 String dext = natr.getNamedItem("extension").getNodeValue();
876 String type = natr.getNamedItem("type").getNodeValue();
877 defdoctype.put(nstep + "." + dext, maptype.get(type));
881 child = children.get("modules");
882 nlist = child.getChildNodes();
883 for (int i = 0; i < nlist.getLength(); i++) {
884 child = nlist.item(i);
885 if (!child.getNodeName().equals("mapping"))
888 NamedNodeMap natr = child.getAttributes();
889 String dext = natr.getNamedItem("extension").getNodeValue();
890 String exec = natr.getNamedItem("executable").getNodeValue();
891 wapprops.put("executable." + dext, exec);
893 // Viewer mappings tag
894 child = children.get("viewers");
895 viewermap = child.getAttributes().getNamedItem("extension")
896 .getNodeValue().split(",");
899 child = children.get("converters");
900 nlist = child.getChildNodes();
901 for (int i = 0; i < nlist.getLength(); i++) {
902 child = nlist.item(i);
904 if (child.getNodeName().equals("geometry")) {
905 NamedNodeMap natr = child.getAttributes();
906 String from = natr.getNamedItem("from").getNodeValue();
907 String to = natr.getNamedItem("to").getNodeValue();
908 String exec = natr.getNamedItem("executable")
910 convertmap.put(from + "geometry", new Converter("geometry",
916 child = children.get("templates");
917 nlist = child.getChildNodes();
918 for (int i = 0; i < nlist.getLength(); i++) {
919 child = nlist.item(i);
920 if (!child.getNodeName().equals("document"))
923 NamedNodeMap natr = child.getAttributes();
924 String type = natr.getNamedItem("type").getNodeValue();
925 String file = natr.getNamedItem("file").getNodeValue();
926 tempfile.put(type, file);
928 } catch (Exception error) {
929 logger.info("Error in customization", error);
934 * Get the documentTypeService.
936 * @return the documentTypeService
938 public DocumentTypeService getDocumentTypeService() {
939 return _documentTypeService;
943 * Set the documentTypeService.
945 * @param documentTypeService
946 * the documentTypeService to set
948 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
949 _documentTypeService = documentTypeService;