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 // ------------------------------------------
540 return my; // The application is supposed being previously created below
548 public ApplicationSettings init(String wappurl, Locale lang)
550 ClassLoader cloader = getClass().getClassLoader();
551 String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
554 wappserver = wurl[2];
556 wapprops = new Properties();
557 jndprops = new Properties();
558 wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
559 jndprops.load(cloader.getResourceAsStream("jndi.properties"));
561 logger.info("Application root set to "
562 + wapprops.getProperty("wapp.root"));
567 // ==============================================================================================================================
568 // Public member functions
569 // ==============================================================================================================================
571 public void configure(String filename) {
572 // ---------------------------------------
573 // Non customizable settings
574 menus = new HashMap<String, SimpleMenu>();
575 SimpleMenu menu = new NewMenu();
576 menus.put(menu.getName(), menu);
577 menu = new SearchMenu();
578 menus.put(menu.getName(), menu);
579 menu = new DatadminMenu();
580 menus.put(menu.getName(), menu);
581 menu = new SysadminMenu();
582 menus.put(menu.getName(), menu);
583 menu = new PropertiesMenu();
584 menus.put(menu.getName(), menu);
586 popups = new HashMap<String, PopupMenu>();
587 popups.put("steditable", new EditableStudyPopup());
588 popups.put("editable", new EditableDocumentPopup());
589 popups.put("notresult", new NotResultDocumentPopup());
590 popups.put("reviewable", new ReviewableDocumentPopup());
591 popups.put("approvable", new ApprovableDocumentPopup());
592 popups.put("approved", new ApprovedPopup());
593 popups.put("extern", new ExternPopup());
594 popups.put("scontext", new ScontextPopup());
595 popups.put("feedbex", new FeedbexPopup());
597 // Default customizable mandatory settings
598 Map<String, Object> fprop = new HashMap<String, Object>();
599 fprop.put("visibility", "PRIVATE");
600 fprop.put("matchamong", "all");
601 fprop.put("matcontext", "all");
602 fprop.put("state", "END");
603 fprop.put("author", "0");
604 fprop.put("reference", "");
605 fprop.put("title", "");
606 fprop.put("context", new Vector<SimulationContext>());
608 Map<String, Object> gprop = new HashMap<String, Object>();
609 gprop.put("visibility", "PUBLIC");
610 gprop.put("matchamong", "all");
611 gprop.put("matcontext", "all");
612 gprop.put("type", "2"); // TODO: Get the index from the type name
613 gprop.put("author", "0");
614 gprop.put("reference", "");
615 gprop.put("title", "");
616 gprop.put("context", new Vector<SimulationContext>());
618 defdoctype = new LinkedHashMap<String, DocumentType>();
619 tempfile = new HashMap<String, String>();
620 viewermap = new String[0];
621 convertmap = new HashMap<String, Converter>();
622 filter = new HashMap<String, Map<String, Object>>();
623 filter.put("study", fprop);
624 filter.put("knowledge", gprop);
626 // Customization (must be done after above default settings)
627 File config = new File(filename);
628 if (config.exists()) {
629 loadCustomization(config); // Sets default document types, installed modules and available templates
631 logger.info("Could not find the application configuration file \""
632 + config.getAbsolutePath() + "\", using default settings");
634 // Settings based on the customization
635 bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
637 List<ProjectSettingsService.Step> steps = getProjectSettings()
639 for (Iterator<ProjectSettingsService.Step> i = steps.iterator(); i
641 ProjectSettingsService.Step step = i.next();
642 List<String> formats = getDefaultFormats(step);
643 if (formats.size() == 0)
646 ToolBar bar = new ToolBar(24); // Height of the module-bar
647 HashSet<String> module = new HashSet<String>(); // For not duplicating modules
648 for (Iterator<String> j = formats.iterator(); j.hasNext();) {
649 String format = j.next();
650 String command = getApplicationProperty("executable." + format);
652 continue; // Module not installed
653 if (module.contains(command))
656 String[] parsed = command.split("/");
657 String[] name = parsed[parsed.length - 1].split("\\x2E");
658 String docname = my.defdoctype.get(
659 step.getNumber() + "." + format).getName();
660 if (tempfile.get(docname) == null) { // No available template
661 String tool = parsed[parsed.length - 1];
662 String icon = name[0];
663 if (icon.equals("index")) {
664 tool = parsed[parsed.length - 2];
665 icon = "tool." + tool.toLowerCase() + ".png";
667 icon = "tool." + icon.toLowerCase() + ".png";
669 File image = new File(ApplicationSettings
670 .getApplicationSkinPath()
673 icon = "tool.any.png";
674 bar.addTool(tool, icon, command);
676 docname = "/jsp/newDocument.jsp?type=" + docname;
677 String icon = "tool." + name[0].toLowerCase() + ".png";
678 File image = new File(ApplicationSettings
679 .getApplicationSkinPath()
682 icon = "tool.any.png";
683 bar.addTool(name[0], icon, command, docname);
687 bars.put(step.getNumber(), bar);
691 public String getApplicationProperty(String name) {
692 // --------------------------------------------------
693 return wapprops.getProperty(name); // May be null
696 public String getApplicationRootPath() {
697 // ---------------------------------------
698 return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
701 public String getApplicationURL() {
702 // ----------------------------------
703 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
704 .append("/").append(wappname);
705 return url.toString();
708 public Map<String, Object> getFilter(String name) {
709 // --------------------------------------------------
710 return filter.get(name);
713 public ToolBar getModuleBar(Step step) {
714 // -----------------------------------------
715 return bars.get(step.getNumber());
718 public Properties getNamingProperties() {
719 // ----------------------------------------
723 // ==============================================================================================================================
725 // ==============================================================================================================================
727 public static String getApplicationPluginPath() {
728 // ------------------------------------------------
729 return my.getApplicationRootPath() + "plugin/";
732 public static String getApplicationResourcePath() {
733 // --------------------------------------------------
734 return my.getApplicationRootPath() + "WEB-INF/classes/";
737 public static String getApplicationSkinPath() {
738 // ----------------------------------------------
739 return my.getApplicationRootPath() + "skin/";
742 public static Converter getConverter(DocumentType type, String format) {
743 // -----------------------------------------------------------------------
744 return my.convertmap.get(format + type.getName()); // May be null;
747 public static DocumentType getDefaultDocumentType(Step step, String format) {
748 // ----------------------------------------------------------------------------
749 String[] table = format.split("\\x2E");
750 return my.defdoctype.get(step.getNumber() + "."
751 + table[table.length - 1]); // May be null
754 public static String getDownloadURL(User user) {
755 // --------------------------------------------------
756 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
757 .append("/download/").append(user.getUsername()).append("/");
758 return url.toString(); // The download Tomcat context is supposed being defined
761 public static Locale getCurrentLocale() {
762 // ----------------------------------------
766 public static SimpleMenu getMenu(String name) {
767 // ----------------------------------------------
768 return my.menus.get(name);
771 public static PopupMenu getPopupMenu(String name) {
772 // --------------------------------------------------
773 return my.popups.get(name);
776 public static String getRepositoryURL() {
777 // ----------------------------------------
778 StringBuffer url = new StringBuffer("http://").append(my.wappserver)
779 .append("/repository/");
780 return url.toString(); // The repository Tomcat context is supposed being defined
783 public static Locale[] getSupportedLocales() {
784 // ---------------------------------------------
785 String[] code = my.wapprops.getProperty("locale.supported").split(",");
786 Locale[] result = new Locale[code.length];
787 for (int i = 0; i < code.length; i++)
788 result[i] = new Locale(code[i]);
792 public static String[] getViewersMapping() {
793 // -------------------------------------------
797 public static String getWebSiteURL() {
798 // -------------------------------------
799 return my.getApplicationProperty("wapp.website");
802 public static String getHelpURL() {
803 // ----------------------------------
804 return my.getApplicationProperty("wapp.onlinehelp");
807 // ==============================================================================================================================
809 // ==============================================================================================================================
811 private List<String> getDefaultFormats(ProjectSettingsService.Step step) {
812 // ------------------------------------------------------------------
813 Set<String> keys = defdoctype.keySet();
814 int number = step.getNumber();
815 Vector<String> result = new Vector<String>();
817 for (Iterator<String> i = keys.iterator(); i.hasNext();) {
818 String[] key = i.next().split("\\x2E");
819 if (Integer.valueOf(key[0]) != number)
821 if (key[1].equals("pdf"))
822 continue; // PDF is not an authoring format
823 result.add(key[1]); // Formats are unique
828 private void loadCustomization(File config) {
829 // --------------------------------------------
831 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory
833 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
835 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
836 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf
837 .getDocumentElement());
839 // Default document types tag
840 Node child = children.get("default-doctypes");
841 NodeList nlist = child.getChildNodes();
843 List<DocumentType> listype = getDocumentTypeService()
845 HashMap<String, DocumentType> maptype = new HashMap<String, DocumentType>();
846 for (Iterator<DocumentType> i = listype.iterator(); i.hasNext();) {
847 DocumentType type = i.next();
848 maptype.put(type.getName(), type);
850 for (int i = 0; i < nlist.getLength(); i++) {
851 child = nlist.item(i);
852 if (!child.getNodeName().equals("step"))
855 String nstep = child.getAttributes().getNamedItem("number")
857 NodeList map = child.getChildNodes();
858 for (int j = 0; j < map.getLength(); j++) {
860 if (!child.getNodeName().equals("mapping"))
862 NamedNodeMap natr = child.getAttributes();
863 String dext = natr.getNamedItem("extension").getNodeValue();
864 String type = natr.getNamedItem("type").getNodeValue();
865 defdoctype.put(nstep + "." + dext, maptype.get(type));
869 child = children.get("modules");
870 nlist = child.getChildNodes();
871 for (int i = 0; i < nlist.getLength(); i++) {
872 child = nlist.item(i);
873 if (!child.getNodeName().equals("mapping"))
876 NamedNodeMap natr = child.getAttributes();
877 String dext = natr.getNamedItem("extension").getNodeValue();
878 String exec = natr.getNamedItem("executable").getNodeValue();
879 wapprops.put("executable." + dext, exec);
881 // Viewer mappings tag
882 child = children.get("viewers");
883 viewermap = child.getAttributes().getNamedItem("extension")
884 .getNodeValue().split(",");
887 child = children.get("converters");
888 nlist = child.getChildNodes();
889 for (int i = 0; i < nlist.getLength(); i++) {
890 child = nlist.item(i);
892 if (child.getNodeName().equals("geometry")) {
893 NamedNodeMap natr = child.getAttributes();
894 String from = natr.getNamedItem("from").getNodeValue();
895 String to = natr.getNamedItem("to").getNodeValue();
896 String exec = natr.getNamedItem("executable")
898 convertmap.put(from + "geometry", new Converter("geometry",
904 child = children.get("templates");
905 nlist = child.getChildNodes();
906 for (int i = 0; i < nlist.getLength(); i++) {
907 child = nlist.item(i);
908 if (!child.getNodeName().equals("document"))
911 NamedNodeMap natr = child.getAttributes();
912 String type = natr.getNamedItem("type").getNodeValue();
913 String file = natr.getNamedItem("file").getNodeValue();
914 tempfile.put(type, file);
916 } catch (Exception error) {
917 logger.info("Error in customization", error);
922 * Get the documentTypeService.
924 * @return the documentTypeService
926 public DocumentTypeService getDocumentTypeService() {
927 return _documentTypeService;
931 * Set the documentTypeService.
933 * @param documentTypeService
934 * the documentTypeService to set
936 public void setDocumentTypeService(DocumentTypeService documentTypeService) {
937 _documentTypeService = documentTypeService;