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.technical.ProjectSettingsService;
31 import org.splat.dal.bo.som.SimulationContext;
32 import org.splat.som.Step;
33 import org.splat.som.StudyRights;
34 import org.splat.wapp.MenuItem;
35 import org.splat.wapp.PopupMenu;
36 import org.splat.wapp.PopupItem;
37 import org.splat.wapp.SimpleMenu;
38 import org.splat.wapp.ToolBar;
41 public class ApplicationSettings {
43 private String wappserver;
44 private String wappname;
45 private Properties wapprops; // General properties from the application properties files
46 private Locale locale; // Current user locale
47 private Map<String,SimpleMenu> menus = null; // Application menus
48 private Map<Integer,ToolBar> bars = null; // Study module-bars structured by steps
49 private Map<String,PopupMenu> popups = null;
50 private Map<String,Map<String,Object>> filter = null; // Named search filters
51 private Map<String,DocumentType> defdoctype = null; // Default document types structured by step.formats
52 private Map<String,String> tempfile = null; // Available template files
53 private String[] viewermap = null; // List of file extensions mapped to a viewer
54 private Map<String,Converter> convertmap = null; // Available document format converters
55 private Properties jndprops = null; // JNDI context for launching converters
57 private static ApplicationSettings my = null; // Singleton instance
59 * Application settings logger.
61 protected final static Logger logger = Logger.getLogger(ApplicationSettings.class);
64 * Injected project settings service.
66 private ProjectSettingsService _projectSettingsService;
69 * Get the projectSettingsService.
70 * @return the projectSettingsService
72 public ProjectSettingsService getProjectSettings() {
73 return _projectSettingsService;
76 * Set the projectSettingsService.
77 * @param projectSettingsService the projectSettingsService to set
79 public void setProjectSettings(
80 ProjectSettingsService projectSettingsService) {
81 _projectSettingsService = projectSettingsService;
84 private static class NewMenu extends SimpleMenu {
85 // -----------------------------------------------------------------
89 addItem("new-empty", "menu.new.empty", "image.empty.png", "select?menu=create&item=new-empty");
90 addItem("new-copy", new MenuItem("menu.new.copy").icon("image.copy.png") );
91 addItem("new-instance", new MenuItem("menu.new.instance").icon("image.hold.gif") );
92 addItem("new-import", new MenuItem("menu.new.import").icon("icon.upload.png") );
93 this.selects("new-empty");
96 private static class SearchMenu extends SimpleMenu {
97 // -----------------------------------------------------------------
101 addItem("search-study", "menu.search.study", "image.study.png", "select?menu=search&item=search-study");
102 addItem("search-knowledge", "menu.search.idea", "image.idea.png", "select?menu=search&item=search-knowledge");
103 addItem("search-document", new MenuItem("menu.search.document").icon("icon.any.png") );
104 this.selects("search-study");
107 private static class PropertiesMenu extends SimpleMenu {
108 // -----------------------------------------------------------------
109 private PropertiesMenu ()
111 super("configuration");
112 addItem("prop-general", "menu.prop.general", "image.hold.gif", "select?menu=properties&item=prop-general");
113 addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif", "select?menu=properties&item=prop-scenario");
114 addItem("prop-timestamp", new MenuItem("menu.prop.timestamp").icon("image.stamp.png") );
115 addItem("prop-comlog", new MenuItem("menu.prop.comlog").icon("image.hold.gif") );
116 addItem("prop-version", new MenuItem("menu.prop.version").icon("image.dirclosed.png") );
119 private static class DatadminMenu extends SimpleMenu {
120 // -----------------------------------------------------------------
121 private DatadminMenu ()
124 addItem("admin-scontext", "menu.admin.context", "image.hold.gif", "select?menu=datadmin&item=admin-scontext");
125 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png", "select?menu=datadmin&item=admin-knowelm");
126 addItem("admin-study", new MenuItem("menu.admin.study").icon("image.study.png") );
129 private static class SysadminMenu extends SimpleMenu {
130 // -----------------------------------------------------------------
131 private SysadminMenu ()
134 addItem("admin-indexing", "menu.admin.indexing", "image.index.png", "select?menu=sysadmin&item=admin-indexing");
135 addItem("admin-importuser", "menu.admin.importuser", "image.group.png", "select?menu=sysadmin&item=admin-importuser");
138 private enum Item { publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge };
139 // Resources relative to studies
140 private static class EditableStudyPopup extends PopupMenu {
141 // ----------------------------------------------------------------
142 private StudyRights user = null;
144 private EditableStudyPopup ()
146 addItem("publish", new PopupItem("menu.publish").icon("image.publish.png").action("edit-study?action=publish").confirmation("message.publish.study"));
147 addItem("promote", new PopupItem("menu.archive"));
149 addItem("edit", new PopupItem("menu.properties").icon("icon.ed.png").action("../select?menu=properties"));
151 addItem("script", new PopupItem("menu.newscenario").action("add-scenario"));
152 addItem("version", new PopupItem("menu.version").icon("image.version.png").action("notyetimplemented"));
154 addItem("purge", new PopupItem("menu.purge").confirmation("message.purge.study"));
155 addItem("export", new PopupItem("menu.export").icon("image.export.png")); // For future needs
156 addItem("remove", new PopupItem("menu.remove.version").icon("icon.delete.png").action("notyetimplemented").confirmation("message.delete.study"));
158 public boolean isEnabled (String name)
160 if (user == null) return false; // Should not happen
161 Item item = Item.valueOf(name);
162 if (item == Item.publish) return user.canPublish();
163 if (item == Item.edit) return user.canEditProperties();
164 if (item == Item.script) return user.canAddScenario();
165 if (item == Item.version) return user.canVersion();
166 if (item == Item.remove) return user.canRemove();
167 if (item == Item.purge) return user.canPurge();
170 public void setContext (String name, Object context)
172 if (context instanceof StudyRights) {
173 user = (StudyRights)context; // Just for optimizing
174 boolean history = user.getOperand().isVersioned();
175 PopupItem item = this.item("remove");
176 if (history) item.rename("menu.remove.version");
177 else item.rename("menu.remove.study");
181 // Resources relative to documents
182 private static class EditableDocumentPopup extends PopupMenu { // Popup of In-Work documents
183 // ----------------------------------------------------------------
184 private DocumentRights user = null;
186 private EditableDocumentPopup ()
188 addItem("accept", new PopupItem("menu.accept").icon("image.accept.png").action("setDocument?action=accept").confirmation("message.accept.document"));
189 addItem("promote", new PopupItem("menu.promote").icon("image.publish.png").action("setDocument?action=promote").confirmation("message.promote.document"));
191 addItem("rename", new PopupItem("menu.rename").action("edit-document?action=renameDocument"));
192 addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
194 addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
195 addItem("replace", new PopupItem("menu.replace").icon("image.replace.png").action("select-file?nextAction=replace"));
197 addItem("purge", new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
198 addItem("remove", new PopupItem("menu.remove.version").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
200 public boolean isEnabled (String name)
202 if (user == null) return false; // Should not happen
203 Item item = Item.valueOf(name);
204 if (item == Item.accept) return user.canAccept();
205 if (item == Item.promote) return user.canPromote();
206 if (item == Item.rename) return user.canRename();
207 if (item == Item.attach) return user.canAttach();
208 if (item == Item.version) return user.canVersion();
209 if (item == Item.replace) return user.canReplace();
210 if (item == Item.purge) return user.canPurge();
211 if (item == Item.remove) return user.canRemove();
214 public void setContext (String name, Object context)
216 if (context instanceof DocumentRights) {
217 user = (DocumentRights)context; // Just for optimizing
218 Document downer = user.getOperand();
219 PopupItem item = this.item("remove");
220 if (downer.isVersioned()) item.rename("menu.remove.version");
221 else item.rename("menu.remove.document");
225 private static class ReviewableDocumentPopup extends PopupMenu { // Popup of In-Draft documents
226 // ----------------------------------------------------------------
227 private DocumentRights user = null;
229 private ReviewableDocumentPopup ()
231 addItem("demote", new PopupItem("menu.demote").icon("image.demote.png").action("setDocument?action=demote").confirmation("message.demote.document"));
232 addItem("promote", new PopupItem("menu.review").icon("image.review.png").action("setDocument?action=review").confirmation("message.review.document"));
234 addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
236 addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
238 addItem("purge", new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
240 public boolean isEnabled (String name)
242 if (user == null) return false; // Should not happen
243 Item item = Item.valueOf(name);
244 if (item == Item.demote) return user.canDemote();
245 if (item == Item.promote) return user.canReview();
246 if (item == Item.attach) return user.canAttach();
247 if (item == Item.version) return user.canVersion();
248 if (item == Item.purge) return user.canPurge();
251 public void setContext (String name, Object context)
253 if (context instanceof DocumentRights) {
254 user = (DocumentRights)context; // Just for optimizing
258 private static class NotResultDocumentPopup extends PopupMenu {
259 // ----------------------------------------------------------------
260 private DocumentRights user = null;
262 private NotResultDocumentPopup ()
264 addItem("demote", new PopupItem("menu.demote").icon("image.demote.png").action("setDocument?action=demote").confirmation("message.demote.document"));
266 addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
268 addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
270 addItem("purge", new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
271 addItem("remove", new PopupItem("menu.remove.version").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
274 private static class ApprovableDocumentPopup extends PopupMenu { // Popup of In-Check documents
275 // ----------------------------------------------------------------
276 private DocumentRights user = null;
278 private ApprovableDocumentPopup ()
280 addItem("undo", new PopupItem("menu.demote").icon("image.invalidate.png").action("setDocument?action=invalidate").confirmation("message.demote.document"));
281 addItem("demote", new PopupItem("menu.disapprove").icon("image.demote.png").action("setDocument?action=disapprove").confirmation("message.disapprove.document"));
282 addItem("approve", new PopupItem("menu.approve").icon("icon.APPROVED.png").action("setDocument?action=approve").confirmation("message.approve.document"));
284 public boolean isEnabled (String name)
286 if (user == null) return false; // Should not happen
287 Item item = Item.valueOf(name);
288 if (item == Item.undo) return user.canInvalidate();
289 if (item == Item.demote) return user.canDemote();
290 if (item == Item.approve) return user.canApprove();
293 public void setContext (String name, Object context)
295 if (context instanceof DocumentRights) {
296 user = (DocumentRights)context; // Just for optimizing
300 private static class ApprovedPopup extends PopupMenu { // Popup of Approved documents
301 // ----------------------------------------------------------------
302 private ApprovedPopup ()
304 addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
306 addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
309 private static class ExternPopup extends PopupMenu { // Popup of Extern documents
310 // ----------------------------------------------------------------
311 private DocumentRights user = null;
313 private ExternPopup ()
315 addItem("rename", new PopupItem("menu.rename").action("edit-document?action=renameDocument"));
316 addItem("replace", new PopupItem("menu.replace").icon("image.replace.png").action("select-file?nextAction=replace"));
318 addItem("remove", new PopupItem("menu.remove.document").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
320 public boolean isEnabled (String name)
322 if (user == null) return false; // Should not happen
323 Item item = Item.valueOf(name);
324 if (item == Item.rename) return user.canRename();
325 if (item == Item.replace) return user.canReplace();
326 if (item == Item.remove) return user.canRemove();
329 public void setContext (String name, Object context)
331 if (context instanceof DocumentRights) {
332 user = (DocumentRights)context; // Just for optimizing
336 // Resources relative to simulation contexts
337 private static class ScontextPopup extends PopupMenu {
338 // --------------------------------------------------------
339 private SimulationContextFacade owner = null;
341 private ScontextPopup ()
343 addItem("rename", new PopupItem("menu.rename").action("edit-context?action=renameContext"));
344 addItem("edit", new PopupItem("menu.edit").action("edit-context?action=editContext"));
346 addItem("remove", new PopupItem("menu.remove").icon("icon.delete.png").action("remove-context").confirmation("message.delete.context"));
348 public boolean isEnabled (String name)
350 Item item = Item.valueOf(name);
352 if (item == Item.rename) {
355 if (item == Item.edit) {
356 // if (!owner.isEditable())
361 public void setContext (String name, Object context)
363 if (context instanceof SimulationContextFacade) {
364 owner = (SimulationContextFacade)context; // Just for optimizing
367 super.setContext(name, context);
371 // Resources relative to knowledge
372 private static class FeedbexPopup extends PopupMenu {
373 // --------------------------------------------------------
374 private KnowledgeElement owner = null;
376 private FeedbexPopup ()
378 addItem("promote", new PopupItem("menu.promote").icon("image.review.png").action("promote-knowledge").confirmation("message.promote.knowledge"));
379 addItem("demote", new PopupItem("menu.demote").icon("image.invalidate.png").action("demote-knowledge").confirmation("message.demote.knowledge"));
381 addItem("rename", new PopupItem("menu.rename").action("edit-knowledge?action=renameKnowledge"));
382 addItem("edit", new PopupItem("menu.edit").action("edit-knowledge?action=editKnowledge"));
384 addItem("remove", new PopupItem("menu.remove").icon("icon.delete.png").action("remove-knowledge").confirmation("message.delete.knowledge"));
386 public boolean isEnabled (String name)
388 Item item = Item.valueOf(name);
390 if (item == Item.promote) {
391 if (owner.getProgressState() != ProgressState.inDRAFT) return false;
393 if (item == Item.demote) {
394 if (owner.getProgressState() != ProgressState.inCHECK) return false;
398 public void setContext (String name, Object context)
400 if (context instanceof KnowledgeElement) owner = (KnowledgeElement)context; // Just for optimizing
402 super.setContext(name, context);
407 // ==============================================================================================================================
409 // ==============================================================================================================================
411 public static ApplicationSettings getMe () {
412 // ------------------------------------------
413 return my; // The application is supposed being previously created below
420 public ApplicationSettings init(String wappurl, Locale lang) throws IOException {
421 ClassLoader cloader = getClass().getClassLoader();
422 String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
425 wappserver = wurl[2];
427 wapprops = new Properties();
428 jndprops = new Properties();
429 wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
430 jndprops.load(cloader.getResourceAsStream("jndi.properties"));
432 logger.info("Application root set to " + wapprops.getProperty("wapp.root"));
437 // ==============================================================================================================================
438 // Public member functions
439 // ==============================================================================================================================
441 public void configure (String filename) {
442 // ---------------------------------------
443 // Non customizable settings
444 menus = new HashMap<String, SimpleMenu>();
445 SimpleMenu menu = new NewMenu();
446 menus.put( menu.getName(), menu );
447 menu = new SearchMenu();
448 menus.put( menu.getName(), menu );
449 menu = new DatadminMenu();
450 menus.put( menu.getName(), menu );
451 menu = new SysadminMenu();
452 menus.put( menu.getName(), menu );
453 menu = new PropertiesMenu();
454 menus.put( menu.getName(), menu );
456 popups = new HashMap<String, PopupMenu>();
457 popups.put("steditable", new EditableStudyPopup());
458 popups.put("editable", new EditableDocumentPopup());
459 popups.put("notresult", new NotResultDocumentPopup());
460 popups.put("reviewable", new ReviewableDocumentPopup());
461 popups.put("approvable", new ApprovableDocumentPopup());
462 popups.put("approved", new ApprovedPopup());
463 popups.put("extern", new ExternPopup());
464 popups.put("scontext", new ScontextPopup());
465 popups.put("feedbex", new FeedbexPopup());
467 // Default customizable mandatory settings
468 Map<String, Object> fprop = new HashMap<String, Object>();
469 fprop.put("visibility", "PRIVATE");
470 fprop.put("matchamong", "all");
471 fprop.put("matcontext", "all");
472 fprop.put("state", "END");
473 fprop.put("author", "0");
474 fprop.put("reference", "");
475 fprop.put("title", "");
476 fprop.put("context", new Vector<SimulationContext>());
478 Map<String, Object> gprop = new HashMap<String, Object>();
479 gprop.put("visibility", "PUBLIC");
480 gprop.put("matchamong", "all");
481 gprop.put("matcontext", "all");
482 gprop.put("type", "2"); //TODO: Get the index from the type name
483 gprop.put("author", "0");
484 gprop.put("reference", "");
485 gprop.put("title", "");
486 gprop.put("context", new Vector<SimulationContext>());
488 defdoctype = new LinkedHashMap<String, DocumentType>();
489 tempfile = new HashMap<String, String>();
490 viewermap = new String[0];
491 convertmap = new HashMap<String, Converter>();
492 filter = new HashMap<String, Map<String, Object>>();
493 filter.put("study", fprop);
494 filter.put("knowledge", gprop);
496 // Customization (must be done after above default settings)
497 File config = new File(filename);
498 if (config.exists()) {
499 loadCustomization(config); // Sets default document types, installed modules and available templates
501 logger.info("Could not find the application configuration file \"" + config.getAbsolutePath() + "\", using default settings");
503 // Settings based on the customization
504 bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
506 List<ProjectSettingsService.Step> steps = getProjectSettings().getAllSteps();
507 for (Iterator<ProjectSettingsService.Step> i=steps.iterator(); i.hasNext();) {
508 ProjectSettingsService.Step step = i.next();
509 List<String> formats = getDefaultFormats(step);
510 if (formats.size() == 0) continue;
512 ToolBar bar = new ToolBar(24); // Height of the module-bar
513 HashSet<String> module = new HashSet<String>(); // For not duplicating modules
514 for (Iterator<String> j=formats.iterator(); j.hasNext();) {
515 String format = j.next();
516 String command = getApplicationProperty("executable." + format);
517 if (command == null) continue; // Module not installed
518 if (module.contains(command)) continue;
520 String[] parsed = command.split("/");
521 String[] name = parsed[parsed.length-1].split("\\x2E");
522 String docname = my.defdoctype.get(step.getNumber() + "." + format).getName();
523 if (tempfile.get(docname) == null) { // No available template
524 String tool = parsed[parsed.length-1];
525 String icon = name[0];
526 if (icon.equals("index")) {
527 tool = parsed[parsed.length-2];
528 icon = "tool." + tool.toLowerCase() + ".png";
531 icon = "tool." + icon.toLowerCase() + ".png";
533 File image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
534 if (!image.exists()) icon = "tool.any.png";
535 bar.addTool(tool, icon, command);
537 docname = "/jsp/newDocument.jsp?type=" + docname;
538 String icon = "tool." + name[0].toLowerCase() + ".png";
539 File image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
540 if (!image.exists()) icon = "tool.any.png";
541 bar.addTool(name[0], icon, command, docname);
544 if (!bar.isEmpty()) bars.put(step.getNumber(), bar);
548 public String getApplicationProperty (String name) {
549 // --------------------------------------------------
550 return wapprops.getProperty(name); // May be null
553 public String getApplicationRootPath () {
554 // ---------------------------------------
555 return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
558 public String getApplicationURL () {
559 // ----------------------------------
560 StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/").append(wappname);
561 return url.toString();
564 public Map<String, Object> getFilter (String name) {
565 // --------------------------------------------------
566 return filter.get(name);
569 public ToolBar getModuleBar (Step step) {
570 // -----------------------------------------
571 return bars.get(step.getNumber());
574 public Properties getNamingProperties () {
575 // ----------------------------------------
579 // ==============================================================================================================================
581 // ==============================================================================================================================
583 public static String getApplicationPluginPath () {
584 // ------------------------------------------------
585 return my.getApplicationRootPath() + "plugin/";
587 public static String getApplicationResourcePath () {
588 // --------------------------------------------------
589 return my.getApplicationRootPath() + "WEB-INF/classes/";
591 public static String getApplicationSkinPath () {
592 // ----------------------------------------------
593 return my.getApplicationRootPath() + "skin/";
595 public static Converter getConverter (DocumentType type, String format) {
596 // -----------------------------------------------------------------------
597 return my.convertmap.get(format + type.getName()); // May be null;
599 public static DocumentType getDefaultDocumentType (Step step, String format) {
600 // ----------------------------------------------------------------------------
601 String[] table = format.split("\\x2E");
602 return my.defdoctype.get(step.getNumber() + "." + table[table.length-1]); // May be null
604 public static String getDownloadURL (User user) {
605 // --------------------------------------------------
606 StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/download/").append(user.getUsername()).append("/");
607 return url.toString(); // The download Tomcat context is supposed being defined
609 public static Locale getCurrentLocale () {
610 // ----------------------------------------
613 public static SimpleMenu getMenu (String name) {
614 // ----------------------------------------------
615 return my.menus.get(name);
617 public static PopupMenu getPopupMenu (String name) {
618 // --------------------------------------------------
619 return my.popups.get(name);
621 public static String getRepositoryURL () {
622 // ----------------------------------------
623 StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/repository/");
624 return url.toString(); // The repository Tomcat context is supposed being defined
626 public static Locale[] getSupportedLocales () {
627 // ---------------------------------------------
628 String[] code = my.wapprops.getProperty("locale.supported").split(",");
629 Locale[] result = new Locale[code.length];
630 for (int i=0; i<code.length; i++) result[i] = new Locale(code[i]);
633 public static String[] getViewersMapping () {
634 // -------------------------------------------
637 public static String getWebSiteURL () {
638 // -------------------------------------
639 return my.getApplicationProperty("wapp.website");
641 public static String getHelpURL () {
642 // ----------------------------------
643 return my.getApplicationProperty("wapp.onlinehelp");
645 // ==============================================================================================================================
647 // ==============================================================================================================================
649 private List<String> getDefaultFormats (ProjectSettingsService.Step step) {
650 // ------------------------------------------------------------------
651 Set<String> keys = defdoctype.keySet();
652 int number = step.getNumber();
653 Vector<String> result = new Vector<String>();
655 for (Iterator<String> i=keys.iterator(); i.hasNext();) {
656 String[] key = i.next().split("\\x2E");
657 if (Integer.valueOf(key[0]) != number) continue;
658 if (key[1].equals("pdf")) continue; // PDF is not an authoring format
659 result.add(key[1]); // Formats are unique
664 private void loadCustomization (File config) {
665 // --------------------------------------------
667 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
668 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
670 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
671 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf.getDocumentElement());
673 // Default document types tag
674 Node child = children.get("default-doctypes");
675 NodeList nlist = child.getChildNodes();
677 List<DocumentType> listype = Document.selectAllTypes();
678 HashMap<String,DocumentType> maptype = new HashMap<String,DocumentType>();
679 for (Iterator<DocumentType> i=listype.iterator(); i.hasNext();) {
680 DocumentType type = i.next();
681 maptype.put(type.getName(), type);
683 for (int i=0; i<nlist.getLength(); i++) {
684 child = nlist.item(i);
685 if (!child.getNodeName().equals("step")) continue;
687 String nstep = child.getAttributes().getNamedItem("number").getNodeValue();
688 NodeList map = child.getChildNodes();
689 for (int j=0; j<map.getLength(); j++) {
691 if (!child.getNodeName().equals("mapping")) continue;
692 NamedNodeMap natr = child.getAttributes();
693 String dext = natr.getNamedItem("extension").getNodeValue();
694 String type = natr.getNamedItem("type").getNodeValue();
695 defdoctype.put(nstep + "." + dext, maptype.get(type));
699 child = children.get("modules");
700 nlist = child.getChildNodes();
701 for (int i=0; i<nlist.getLength(); i++) {
702 child = nlist.item(i);
703 if (!child.getNodeName().equals("mapping")) continue;
705 NamedNodeMap natr = child.getAttributes();
706 String dext = natr.getNamedItem("extension").getNodeValue();
707 String exec = natr.getNamedItem("executable").getNodeValue();
708 wapprops.put("executable." + dext, exec);
710 // Viewer mappings tag
711 child = children.get("viewers");
712 viewermap = child.getAttributes().getNamedItem("extension").getNodeValue().split(",");
715 child = children.get("converters");
716 nlist = child.getChildNodes();
717 for (int i=0; i<nlist.getLength(); i++) {
718 child = nlist.item(i);
720 if (child.getNodeName().equals("geometry")) {
721 NamedNodeMap natr = child.getAttributes();
722 String from = natr.getNamedItem("from").getNodeValue();
723 String to = natr.getNamedItem("to").getNodeValue();
724 String exec = natr.getNamedItem("executable").getNodeValue();
725 convertmap.put(from + "geometry", new Converter("geometry", from, to, exec));
730 child = children.get("templates");
731 nlist = child.getChildNodes();
732 for (int i=0; i<nlist.getLength(); i++) {
733 child = nlist.item(i);
734 if (!child.getNodeName().equals("document")) continue;
736 NamedNodeMap natr = child.getAttributes();
737 String type = natr.getNamedItem("type").getNodeValue();
738 String file = natr.getNamedItem("file").getNodeValue();
739 tempfile.put(type, file);
742 catch (Exception error) {
743 logger.info("Error in customization", error);