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.dal.bo.som.SimulationContext;
33 import org.splat.som.Step;
34 import org.splat.som.StudyRights;
35 import org.splat.wapp.MenuItem;
36 import org.splat.wapp.PopupMenu;
37 import org.splat.wapp.PopupItem;
38 import org.splat.wapp.SimpleMenu;
39 import org.splat.wapp.ToolBar;
41 public class ApplicationSettings {
44 * Application settings logger.
46 protected final static Logger logger = Logger
47 .getLogger(ApplicationSettings.class);
49 private String wappserver;
50 private String wappname;
51 private Properties wapprops; // General properties from the application properties files
52 private Locale locale; // Current user locale
53 private Map<String, SimpleMenu> menus = null; // Application menus
54 private Map<Integer, ToolBar> bars = null; // Study module-bars structured by steps
55 private Map<String, PopupMenu> popups = null;
56 private Map<String, Map<String, Object>> filter = null; // Named search filters
57 private Map<String, DocumentType> defdoctype = null; // Default document types structured by step.formats
58 private Map<String, String> tempfile = null; // Available template files
59 private String[] viewermap = null; // List of file extensions mapped to a viewer
60 private Map<String, Converter> convertmap = null; // Available document format converters
61 private Properties jndprops = null; // JNDI context for launching converters
63 private static ApplicationSettings my = null; // Singleton instance
65 * Injected project settings service.
67 private ProjectSettingsService _projectSettingsService;
69 * Injected document type service.
71 private DocumentTypeService _documentTypeService;
74 * Get the projectSettingsService.
76 * @return the projectSettingsService
78 public ProjectSettingsService getProjectSettings() {
79 return _projectSettingsService;
83 * Set the projectSettingsService.
85 * @param projectSettingsService
86 * the projectSettingsService to set
88 public void setProjectSettings(ProjectSettingsService projectSettingsService) {
89 _projectSettingsService = projectSettingsService;
92 private static class NewMenu extends SimpleMenu {
93 // -----------------------------------------------------------------
96 addItem("new-empty", "menu.new.empty", "image.empty.png",
97 "select?menu=create&item=new-empty");
98 addItem("new-copy", new MenuItem("menu.new.copy")
99 .icon("image.copy.png"));
100 addItem("new-instance", new MenuItem("menu.new.instance")
101 .icon("image.hold.gif"));
102 addItem("new-import", new MenuItem("menu.new.import")
103 .icon("icon.upload.png"));
104 this.selects("new-empty");
108 private static class SearchMenu extends SimpleMenu {
109 // -----------------------------------------------------------------
110 private SearchMenu() {
112 addItem("search-study", "menu.search.study", "image.study.png",
113 "select?menu=search&item=search-study");
114 addItem("search-knowledge", "menu.search.idea", "image.idea.png",
115 "select?menu=search&item=search-knowledge");
116 addItem("search-document", new MenuItem("menu.search.document")
117 .icon("icon.any.png"));
118 this.selects("search-study");
122 private static class PropertiesMenu extends SimpleMenu {
123 // -----------------------------------------------------------------
124 private PropertiesMenu() {
125 super("configuration");
126 addItem("prop-general", "menu.prop.general", "image.hold.gif",
127 "select?menu=properties&item=prop-general");
128 addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif",
129 "select?menu=properties&item=prop-scenario");
130 addItem("prop-timestamp", new MenuItem("menu.prop.timestamp")
131 .icon("image.stamp.png"));
132 addItem("prop-comlog", new MenuItem("menu.prop.comlog")
133 .icon("image.hold.gif"));
134 addItem("prop-version", new MenuItem("menu.prop.version")
135 .icon("image.dirclosed.png"));
139 private static class DatadminMenu extends SimpleMenu {
140 // -----------------------------------------------------------------
141 private DatadminMenu() {
143 addItem("admin-scontext", "menu.admin.context", "image.hold.gif",
144 "select?menu=datadmin&item=admin-scontext");
145 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png",
146 "select?menu=datadmin&item=admin-knowelm");
147 addItem("admin-study", new MenuItem("menu.admin.study")
148 .icon("image.study.png"));
152 private static class SysadminMenu extends SimpleMenu {
153 // -----------------------------------------------------------------
154 private SysadminMenu() {
156 addItem("admin-indexing", "menu.admin.indexing", "image.index.png",
157 "select?menu=sysadmin&item=admin-indexing");
158 addItem("admin-importuser", "menu.admin.importuser",
160 "select?menu=sysadmin&item=admin-importuser");
165 publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge
168 // Resources relative to studies
169 private static class EditableStudyPopup extends PopupMenu {
170 // ----------------------------------------------------------------
171 private StudyRights user = null;
173 private EditableStudyPopup() {
174 addItem("publish", new PopupItem("menu.publish").icon(
175 "image.publish.png").action("edit-study?action=publish")
176 .confirmation("message.publish.study"));
177 addItem("promote", new PopupItem("menu.archive"));
179 addItem("edit", new PopupItem("menu.properties")
180 .icon("icon.ed.png").action("../select?menu=properties"));
182 addItem("script", new PopupItem("menu.newscenario")
183 .action("add-scenario"));
184 addItem("version", new PopupItem("menu.version").icon(
185 "image.version.png").action("notyetimplemented"));
187 addItem("purge", new PopupItem("menu.purge")
188 .confirmation("message.purge.study"));
189 addItem("export", new PopupItem("menu.export")
190 .icon("image.export.png")); // For future needs
191 addItem("remove", new PopupItem("menu.remove.version").icon(
192 "icon.delete.png").action("notyetimplemented")
193 .confirmation("message.delete.study"));
196 public boolean isEnabled(String name) {
198 return false; // Should not happen
199 Item item = Item.valueOf(name);
200 if (item == Item.publish)
201 return user.canPublish();
202 if (item == Item.edit)
203 return user.canEditProperties();
204 if (item == Item.script)
205 return user.canAddScenario();
206 if (item == Item.version)
207 return user.canVersion();
208 if (item == Item.remove)
209 return user.canRemove();
210 if (item == Item.purge)
211 return user.canPurge();
215 public void setContext(String name, Object context) {
216 if (context instanceof StudyRights) {
217 user = (StudyRights) context; // Just for optimizing
218 boolean history = user.getOperand().isVersioned();
219 PopupItem item = this.item("remove");
221 item.rename("menu.remove.version");
223 item.rename("menu.remove.study");
228 // Resources relative to documents
229 private static class EditableDocumentPopup extends PopupMenu { // Popup of In-Work documents
230 // ----------------------------------------------------------------
231 private DocumentRights user = null;
233 private EditableDocumentPopup() {
234 addItem("accept", new PopupItem("menu.accept").icon(
235 "image.accept.png").action("setDocument?action=accept")
236 .confirmation("message.accept.document"));
237 addItem("promote", new PopupItem("menu.promote").icon(
238 "image.publish.png").action("setDocument?action=promote")
239 .confirmation("message.promote.document"));
241 addItem("rename", new PopupItem("menu.rename")
242 .action("edit-document?action=renameDocument"));
243 addItem("attach", new PopupItem("menu.attach").icon(
244 "image.attach.png").action("select-file?nextAction=attach"));
246 addItem("version", new PopupItem("menu.version").icon(
247 "image.version.png").action(
248 "select-file?nextAction=version"));
249 addItem("replace", new PopupItem("menu.replace").icon(
250 "image.replace.png").action(
251 "select-file?nextAction=replace"));
253 addItem("purge", new PopupItem("menu.purge").action(
254 "notyetimplemented").confirmation("message.purge.document"));
255 addItem("remove", new PopupItem("menu.remove.version").icon(
256 "icon.delete.png").action("remove-document").confirmation(
257 "message.delete.document"));
260 public boolean isEnabled(String name) {
262 return false; // Should not happen
263 Item item = Item.valueOf(name);
264 if (item == Item.accept)
265 return user.canAccept();
266 if (item == Item.promote)
267 return user.canPromote();
268 if (item == Item.rename)
269 return user.canRename();
270 if (item == Item.attach)
271 return user.canAttach();
272 if (item == Item.version)
273 return user.canVersion();
274 if (item == Item.replace)
275 return user.canReplace();
276 if (item == Item.purge)
277 return user.canPurge();
278 if (item == Item.remove)
279 return user.canRemove();
283 public void setContext(String name, Object context) {
284 if (context instanceof DocumentRights) {
285 user = (DocumentRights) context; // Just for optimizing
286 Document downer = user.getOperand();
287 PopupItem item = this.item("remove");
288 if (downer.isVersioned())
289 item.rename("menu.remove.version");
291 item.rename("menu.remove.document");
296 private static class ReviewableDocumentPopup extends PopupMenu { // Popup of In-Draft documents
297 // ----------------------------------------------------------------
298 private DocumentRights user = null;
300 private ReviewableDocumentPopup() {
301 addItem("demote", new PopupItem("menu.demote").icon(
302 "image.demote.png").action("setDocument?action=demote")
303 .confirmation("message.demote.document"));
304 addItem("promote", new PopupItem("menu.review").icon(
305 "image.review.png").action("setDocument?action=review")
306 .confirmation("message.review.document"));
308 addItem("attach", new PopupItem("menu.attach").icon(
309 "image.attach.png").action("select-file?nextAction=attach"));
311 addItem("version", new PopupItem("menu.version").icon(
312 "image.version.png").action(
313 "select-file?nextAction=version"));
315 addItem("purge", new PopupItem("menu.purge").action(
316 "notyetimplemented").confirmation("message.purge.document"));
319 public boolean isEnabled(String name) {
321 return false; // Should not happen
322 Item item = Item.valueOf(name);
323 if (item == Item.demote)
324 return user.canDemote();
325 if (item == Item.promote)
326 return user.canReview();
327 if (item == Item.attach)
328 return user.canAttach();
329 if (item == Item.version)
330 return user.canVersion();
331 if (item == Item.purge)
332 return user.canPurge();
336 public void setContext(String name, Object context) {
337 if (context instanceof DocumentRights) {
338 user = (DocumentRights) context; // Just for optimizing
343 private static class NotResultDocumentPopup extends PopupMenu {
344 // ----------------------------------------------------------------
345 private DocumentRights user = null;
347 private NotResultDocumentPopup() {
348 addItem("demote", new PopupItem("menu.demote").icon(
349 "image.demote.png").action("setDocument?action=demote")
350 .confirmation("message.demote.document"));
352 addItem("attach", new PopupItem("menu.attach").icon(
353 "image.attach.png").action("select-file?nextAction=attach"));
355 addItem("version", new PopupItem("menu.version").icon(
356 "image.version.png").action(
357 "select-file?nextAction=version"));
359 addItem("purge", new PopupItem("menu.purge").action(
360 "notyetimplemented").confirmation("message.purge.document"));
361 addItem("remove", new PopupItem("menu.remove.version").icon(
362 "icon.delete.png").action("remove-document").confirmation(
363 "message.delete.document"));
367 private static class ApprovableDocumentPopup extends PopupMenu { // Popup of In-Check documents
368 // ----------------------------------------------------------------
369 private DocumentRights user = null;
371 private ApprovableDocumentPopup() {
372 addItem("undo", new PopupItem("menu.demote").icon(
373 "image.invalidate.png").action(
374 "setDocument?action=invalidate").confirmation(
375 "message.demote.document"));
376 addItem("demote", new PopupItem("menu.disapprove").icon(
377 "image.demote.png").action("setDocument?action=disapprove")
378 .confirmation("message.disapprove.document"));
379 addItem("approve", new PopupItem("menu.approve").icon(
380 "icon.APPROVED.png").action("setDocument?action=approve")
381 .confirmation("message.approve.document"));
384 public boolean isEnabled(String name) {
386 return false; // Should not happen
387 Item item = Item.valueOf(name);
388 if (item == Item.undo)
389 return user.canInvalidate();
390 if (item == Item.demote)
391 return user.canDemote();
392 if (item == Item.approve)
393 return user.canApprove();
397 public void setContext(String name, Object context) {
398 if (context instanceof DocumentRights) {
399 user = (DocumentRights) context; // Just for optimizing
404 private static class ApprovedPopup extends PopupMenu { // Popup of Approved documents
405 // ----------------------------------------------------------------
406 private ApprovedPopup() {
407 addItem("attach", new PopupItem("menu.attach").icon(
408 "image.attach.png").action("select-file?nextAction=attach"));
410 addItem("version", new PopupItem("menu.version").icon(
411 "image.version.png").action(
412 "select-file?nextAction=version"));
416 private static class ExternPopup extends PopupMenu { // Popup of Extern documents
417 // ----------------------------------------------------------------
418 private DocumentRights user = null;
420 private ExternPopup() {
421 addItem("rename", new PopupItem("menu.rename")
422 .action("edit-document?action=renameDocument"));
423 addItem("replace", new PopupItem("menu.replace").icon(
424 "image.replace.png").action(
425 "select-file?nextAction=replace"));
427 addItem("remove", new PopupItem("menu.remove.document").icon(
428 "icon.delete.png").action("remove-document").confirmation(
429 "message.delete.document"));
432 public boolean isEnabled(String name) {
434 return false; // Should not happen
435 Item item = Item.valueOf(name);
436 if (item == Item.rename)
437 return user.canRename();
438 if (item == Item.replace)
439 return user.canReplace();
440 if (item == Item.remove)
441 return user.canRemove();
445 public void setContext(String name, Object context) {
446 if (context instanceof DocumentRights) {
447 user = (DocumentRights) context; // Just for optimizing
452 // Resources relative to simulation contexts
453 private static class ScontextPopup extends PopupMenu {
454 // --------------------------------------------------------
455 private SimulationContextFacade owner = null;
457 private ScontextPopup() {
458 addItem("rename", new PopupItem("menu.rename")
459 .action("edit-context?action=renameContext"));
460 addItem("edit", new PopupItem("menu.edit")
461 .action("edit-context?action=editContext"));
463 addItem("remove", new PopupItem("menu.remove").icon(
464 "icon.delete.png").action("remove-context").confirmation(
465 "message.delete.context"));
468 public boolean isEnabled(String name) {
469 Item item = Item.valueOf(name);
471 if (item == Item.rename) {
473 } else if (item == Item.edit) {
474 // if (!owner.isEditable())
480 public void setContext(String name, Object context) {
481 if (context instanceof SimulationContextFacade) {
482 owner = (SimulationContextFacade) context; // Just for optimizing
484 super.setContext(name, context);
489 // Resources relative to knowledge
490 private static class FeedbexPopup extends PopupMenu {
491 // --------------------------------------------------------
492 private KnowledgeElement owner = null;
494 private FeedbexPopup() {
495 addItem("promote", new PopupItem("menu.promote").icon(
496 "image.review.png").action("promote-knowledge")
497 .confirmation("message.promote.knowledge"));
498 addItem("demote", new PopupItem("menu.demote").icon(
499 "image.invalidate.png").action("demote-knowledge")
500 .confirmation("message.demote.knowledge"));
502 addItem("rename", new PopupItem("menu.rename")
503 .action("edit-knowledge?action=renameKnowledge"));
504 addItem("edit", new PopupItem("menu.edit")
505 .action("edit-knowledge?action=editKnowledge"));
507 addItem("remove", new PopupItem("menu.remove").icon(
508 "icon.delete.png").action("remove-knowledge").confirmation(
509 "message.delete.knowledge"));
512 public boolean isEnabled(String name) {
513 Item item = Item.valueOf(name);
515 if (item == Item.promote) {
516 if (owner.getProgressState() != ProgressState.inDRAFT)
518 } else if (item == Item.demote) {
519 if (owner.getProgressState() != ProgressState.inCHECK)
525 public void setContext(String name, Object context) {
526 if (context instanceof KnowledgeElement)
527 owner = (KnowledgeElement) context; // Just for optimizing
529 super.setContext(name, context);
534 // ==============================================================================================================================
536 // ==============================================================================================================================
538 public static ApplicationSettings getMe() {
539 // ------------------------------------------
541 my = new ApplicationSettings();
543 return my; // The application is supposed being previously created below
551 public ApplicationSettings init(String wappurl, Locale lang)
553 ClassLoader cloader = getClass().getClassLoader();
554 String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
557 wappserver = wurl[2];
559 wapprops = new Properties();
560 jndprops = new Properties();
561 wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
562 jndprops.load(cloader.getResourceAsStream("jndi.properties"));
564 logger.info("Application root set to "
565 + wapprops.getProperty("wapp.root"));
574 // ==============================================================================================================================
575 // Public member functions
576 // ==============================================================================================================================
578 public void configure(String filename) {
579 // ---------------------------------------
580 // Non customizable settings
581 menus = new HashMap<String, SimpleMenu>();
582 SimpleMenu menu = new NewMenu();
583 menus.put(menu.getName(), menu);
584 menu = new SearchMenu();
585 menus.put(menu.getName(), menu);
586 menu = new DatadminMenu();
587 menus.put(menu.getName(), menu);
588 menu = new SysadminMenu();
589 menus.put(menu.getName(), menu);
590 menu = new PropertiesMenu();
591 menus.put(menu.getName(), menu);
593 popups = new HashMap<String, PopupMenu>();
594 popups.put("steditable", new EditableStudyPopup());
595 popups.put("editable", new EditableDocumentPopup());
596 popups.put("notresult", new NotResultDocumentPopup());
597 popups.put("reviewable", new ReviewableDocumentPopup());
598 popups.put("approvable", new ApprovableDocumentPopup());
599 popups.put("approved", new ApprovedPopup());
600 popups.put("extern", new ExternPopup());
601 popups.put("scontext", new ScontextPopup());
602 popups.put("feedbex", new FeedbexPopup());
604 // Default customizable mandatory settings
605 Map<String, Object> fprop = new HashMap<String, Object>();
606 fprop.put("visibility", "PRIVATE");
607 fprop.put("matchamong", "all");
608 fprop.put("matcontext", "all");
609 fprop.put("state", "APPROVED");
610 fprop.put("author", "0");
611 fprop.put("reference", "");
612 fprop.put("title", "");
613 fprop.put("context", new Vector<SimulationContext>());
615 Map<String, Object> gprop = new HashMap<String, Object>();
616 gprop.put("visibility", "PUBLIC");
617 gprop.put("matchamong", "all");
618 gprop.put("matcontext", "all");
619 gprop.put("type", "2"); // TODO: Get the index from the type name
620 gprop.put("author", "0");
621 gprop.put("reference", "");
622 gprop.put("title", "");
623 gprop.put("context", new Vector<SimulationContext>());
625 defdoctype = new LinkedHashMap<String, DocumentType>();
626 tempfile = new HashMap<String, String>();
627 viewermap = new String[0];
628 convertmap = new HashMap<String, Converter>();
629 filter = new HashMap<String, Map<String, Object>>();
630 filter.put("study", fprop);
631 filter.put("knowledge", gprop);
633 // Customization (must be done after above default settings)
634 File config = new File(filename);
635 if (config.exists()) {
636 loadCustomization(config); // Sets default document types, installed modules and available templates
638 logger.info("Could not find the application configuration file \""
639 + config.getAbsolutePath() + "\", using default settings");
641 // Settings based on the customization
642 bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
644 List<ProjectSettingsService.Step> steps = getProjectSettings()
646 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
648 ProjectSettingsService.Step step = i.next();
649 List<String> formats = getDefaultFormats(step);
650 if (formats.size() == 0)
653 ToolBar bar = new ToolBar(24); // Height of the module-bar
654 HashSet<String> module = new HashSet<String>(); // For not duplicating modules
655 for (Iterator<String> j = formats.iterator(); j.hasNext();) {
656 String format = j.next();
657 String command = getApplicationProperty("executable." + format);
659 continue; // Module not installed
660 if (module.contains(command))
663 String[] parsed = command.split("/");
664 String[] name = parsed[parsed.length - 1].split("\\x2E");
665 DocumentType dtype = my.defdoctype.get(
666 step.getNumber() + "." + format);
669 docname = dtype.getName();
671 if (tempfile.get(docname) == null) { // No available template
672 String tool = parsed[parsed.length - 1];
673 String icon = name[0];
674 if (icon.equals("index")) {
675 tool = parsed[parsed.length - 2];
676 icon = "tool." + tool.toLowerCase() + ".png";
678 icon = "tool." + icon.toLowerCase() + ".png";
680 File image = new File(ApplicationSettings
681 .getApplicationSkinPath()
684 icon = "tool.any.png";
685 bar.addTool(tool, icon, command);
687 docname = "/jsp/newDocument.jsp?type=" + docname;
688 String icon = "tool." + name[0].toLowerCase() + ".png";
689 File image = new File(ApplicationSettings
690 .getApplicationSkinPath()
693 icon = "tool.any.png";
694 bar.addTool(name[0], icon, command, docname);
698 bars.put(step.getNumber(), bar);
702 public String getApplicationProperty(String name) {
703 // --------------------------------------------------
704 return wapprops.getProperty(name); // May be null
707 public String getApplicationRootPath() {
708 // ---------------------------------------
709 return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
712 public String getApplicationURL() {
713 // ----------------------------------
714 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
715 .append("/").append(wappname);
716 return url.toString();
719 public Map<String, Object> getFilter(String name) {
720 // --------------------------------------------------
721 return filter.get(name);
724 public ToolBar getModuleBar(Step step) {
725 // -----------------------------------------
726 return bars.get(step.getNumber());
729 public Properties getNamingProperties() {
730 // ----------------------------------------
734 // ==============================================================================================================================
736 // ==============================================================================================================================
738 public static String getApplicationPluginPath() {
739 // ------------------------------------------------
740 return my.getApplicationRootPath() + "plugin/";
743 public static String getApplicationResourcePath() {
744 // --------------------------------------------------
745 return my.getApplicationRootPath() + "WEB-INF/classes/";
748 public static String getApplicationSkinPath() {
749 // ----------------------------------------------
750 return my.getApplicationRootPath() + "skin/";
753 public static Converter getConverter(DocumentType type, String format) {
754 // -----------------------------------------------------------------------
755 return my.convertmap.get(format + type.getName()); // May be null;
758 public static DocumentType getDefaultDocumentType(Step step, String format) {
759 // ----------------------------------------------------------------------------
760 String[] table = format.split("\\x2E");
761 return my.defdoctype.get(step.getNumber() + "."
762 + table[table.length - 1]); // May be null
765 public static String getDownloadURL(User user) {
766 // --------------------------------------------------
767 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
768 .append("/download/").append(user.getUsername()).append("/");
769 return url.toString(); // The download Tomcat context is supposed being defined
772 public static Locale getCurrentLocale() {
773 // ----------------------------------------
777 public static SimpleMenu getMenu(String name) {
778 // ----------------------------------------------
779 return my.menus.get(name);
782 public static PopupMenu getPopupMenu(String name) {
783 // --------------------------------------------------
784 return my.popups.get(name);
787 public static String getRepositoryURL() {
788 // ----------------------------------------
789 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
790 .append("/repository/");
791 return url.toString(); // The repository Tomcat context is supposed being defined
794 public static Locale[] getSupportedLocales() {
795 // ---------------------------------------------
796 String[] code = my.wapprops.getProperty("locale.supported").split(",");
797 Locale[] result = new Locale[code.length];
798 for (int i = 0; i < code.length; i++)
799 result[i] = new Locale(code[i]);
803 public static String[] getViewersMapping() {
804 // -------------------------------------------
808 public static String getWebSiteURL() {
809 // -------------------------------------
810 return my.getApplicationProperty("wapp.website");
813 public static String getHelpURL() {
814 // ----------------------------------
815 return my.getApplicationProperty("wapp.onlinehelp");
818 // ==============================================================================================================================
820 // ==============================================================================================================================
822 private List<String> getDefaultFormats(ProjectSettingsService.Step step) {
823 // ------------------------------------------------------------------
824 Set<String> keys = defdoctype.keySet();
825 int number = step.getNumber();
826 Vector<String> result = new Vector<String>();
828 for (Iterator<String> i = keys.iterator(); i.hasNext();) {
829 String[] key = i.next().split("\\x2E");
830 if (Integer.valueOf(key[0]) != number)
832 if (key[1].equals("pdf"))
833 continue; // PDF is not an authoring format
834 result.add(key[1]); // Formats are unique
839 private void loadCustomization(File config) {
840 // --------------------------------------------
842 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
844 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
846 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
847 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
848 .getDocumentElement());
850 // Default document types tag
851 Node child = children.get("default-doctypes");
852 NodeList nlist = child.getChildNodes();
854 List<DocumentType> listype = getDocumentTypeService()
856 HashMap<String, DocumentType> maptype = new HashMap<String, DocumentType>();
857 for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
858 DocumentType type = i.next();
859 maptype.put(type.getName(), type);
861 for (int i = 0; i < nlist.getLength(); i++) {
862 child = nlist.item(i);
863 if (!child.getNodeName().equals("step"))
866 String nstep = child.getAttributes().getNamedItem("number")
868 NodeList map = child.getChildNodes();
869 for (int j = 0; j < map.getLength(); j++) {
871 if (!child.getNodeName().equals("mapping"))
873 NamedNodeMap natr = child.getAttributes();
874 String dext = natr.getNamedItem("extension").getNodeValue();
875 String type = natr.getNamedItem("type").getNodeValue();
876 defdoctype.put(nstep + "." + dext, maptype.get(type));
880 child = children.get("modules");
881 nlist = child.getChildNodes();
882 for (int i = 0; i < nlist.getLength(); i++) {
883 child = nlist.item(i);
884 if (!child.getNodeName().equals("mapping"))
887 NamedNodeMap natr = child.getAttributes();
888 String dext = natr.getNamedItem("extension").getNodeValue();
889 String exec = natr.getNamedItem("executable").getNodeValue();
890 wapprops.put("executable." + dext, exec);
892 // Viewer mappings tag
893 child = children.get("viewers");
894 viewermap = child.getAttributes().getNamedItem("extension")
895 .getNodeValue().split(",");
898 child = children.get("converters");
899 nlist = child.getChildNodes();
900 for (int i = 0; i < nlist.getLength(); i++) {
901 child = nlist.item(i);
903 if (child.getNodeName().equals("geometry")) {
904 NamedNodeMap natr = child.getAttributes();
905 String from = natr.getNamedItem("from").getNodeValue();
906 String to = natr.getNamedItem("to").getNodeValue();
907 String exec = natr.getNamedItem("executable")
909 convertmap.put(from + "geometry", new Converter("geometry",
915 child = children.get("templates");
916 nlist = child.getChildNodes();
917 for (int i = 0; i < nlist.getLength(); i++) {
918 child = nlist.item(i);
919 if (!child.getNodeName().equals("document"))
922 NamedNodeMap natr = child.getAttributes();
923 String type = natr.getNamedItem("type").getNodeValue();
924 String file = natr.getNamedItem("file").getNodeValue();
925 tempfile.put(type, file);
927 } catch (Exception error) {
928 logger.info("Error in customization", error);
933 * Get the documentTypeService.
935 * @return the documentTypeService
937 public DocumentTypeService getDocumentTypeService() {
938 return _documentTypeService;
942 * Set the documentTypeService.
944 * @param documentTypeService
945 * the documentTypeService to set
947 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
948 _documentTypeService = documentTypeService;