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
58 protected final static Logger logger = Logger.getLogger(ApplicationSettings.class);
60 private ProjectSettingsService _projectSettingsService;
63 * Get the projectSettingsService.
64 * @return the projectSettingsService
66 public ProjectSettingsService getProjectSettings() {
67 return _projectSettingsService;
70 * Set the projectSettingsService.
71 * @param projectSettingsService the projectSettingsService to set
73 public void setProjectSettings(
74 ProjectSettingsService projectSettingsService) {
75 _projectSettingsService = projectSettingsService;
78 private static class NewMenu extends SimpleMenu {
79 // -----------------------------------------------------------------
83 addItem("new-empty", "menu.new.empty", "image.empty.png", "select?menu=create&item=new-empty");
84 addItem("new-copy", new MenuItem("menu.new.copy").icon("image.copy.png") );
85 addItem("new-instance", new MenuItem("menu.new.instance").icon("image.hold.gif") );
86 addItem("new-import", new MenuItem("menu.new.import").icon("icon.upload.png") );
87 this.selects("new-empty");
90 private static class SearchMenu extends SimpleMenu {
91 // -----------------------------------------------------------------
95 addItem("search-study", "menu.search.study", "image.study.png", "select?menu=search&item=search-study");
96 addItem("search-knowledge", "menu.search.idea", "image.idea.png", "select?menu=search&item=search-knowledge");
97 addItem("search-document", new MenuItem("menu.search.document").icon("icon.any.png") );
98 this.selects("search-study");
101 private static class PropertiesMenu extends SimpleMenu {
102 // -----------------------------------------------------------------
103 private PropertiesMenu ()
105 super("configuration");
106 addItem("prop-general", "menu.prop.general", "image.hold.gif", "select?menu=properties&item=prop-general");
107 addItem("prop-scenario", "menu.prop.scenario", "image.hold.gif", "select?menu=properties&item=prop-scenario");
108 addItem("prop-timestamp", new MenuItem("menu.prop.timestamp").icon("image.stamp.png") );
109 addItem("prop-comlog", new MenuItem("menu.prop.comlog").icon("image.hold.gif") );
110 addItem("prop-version", new MenuItem("menu.prop.version").icon("image.dirclosed.png") );
113 private static class DatadminMenu extends SimpleMenu {
114 // -----------------------------------------------------------------
115 private DatadminMenu ()
118 addItem("admin-scontext", "menu.admin.context", "image.hold.gif", "select?menu=datadmin&item=admin-scontext");
119 addItem("admin-knowelm", "menu.admin.knowledge", "image.idea.png", "select?menu=datadmin&item=admin-knowelm");
120 addItem("admin-study", new MenuItem("menu.admin.study").icon("image.study.png") );
123 private static class SysadminMenu extends SimpleMenu {
124 // -----------------------------------------------------------------
125 private SysadminMenu ()
128 addItem("admin-indexing", "menu.admin.indexing", "image.index.png", "select?menu=sysadmin&item=admin-indexing");
129 addItem("admin-importuser", "menu.admin.importuser", "image.group.png", "select?menu=sysadmin&item=admin-importuser");
132 private enum Item { publish, accept, approve, promote, demote, undo, rename, attach, edit, script, version, replace, export, remove, purge };
133 // Resources relative to studies
134 private static class EditableStudyPopup extends PopupMenu {
135 // ----------------------------------------------------------------
136 private StudyRights user = null;
138 private EditableStudyPopup ()
140 addItem("publish", new PopupItem("menu.publish").icon("image.publish.png").action("edit-study?action=publish").confirmation("message.publish.study"));
141 addItem("promote", new PopupItem("menu.archive"));
143 addItem("edit", new PopupItem("menu.properties").icon("icon.ed.png").action("../select?menu=properties"));
145 addItem("script", new PopupItem("menu.newscenario").action("add-scenario"));
146 addItem("version", new PopupItem("menu.version").icon("image.version.png").action("notyetimplemented"));
148 addItem("purge", new PopupItem("menu.purge").confirmation("message.purge.study"));
149 addItem("export", new PopupItem("menu.export").icon("image.export.png")); // For future needs
150 addItem("remove", new PopupItem("menu.remove.version").icon("icon.delete.png").action("notyetimplemented").confirmation("message.delete.study"));
152 public boolean isEnabled (String name)
154 if (user == null) return false; // Should not happen
155 Item item = Item.valueOf(name);
156 if (item == Item.publish) return user.canPublish();
157 if (item == Item.edit) return user.canEditProperties();
158 if (item == Item.script) return user.canAddScenario();
159 if (item == Item.version) return user.canVersion();
160 if (item == Item.remove) return user.canRemove();
161 if (item == Item.purge) return user.canPurge();
164 public void setContext (String name, Object context)
166 if (context instanceof StudyRights) {
167 user = (StudyRights)context; // Just for optimizing
168 boolean history = user.getOperand().isVersioned();
169 PopupItem item = this.item("remove");
170 if (history) item.rename("menu.remove.version");
171 else item.rename("menu.remove.study");
175 // Resources relative to documents
176 private static class EditableDocumentPopup extends PopupMenu { // Popup of In-Work documents
177 // ----------------------------------------------------------------
178 private DocumentRights user = null;
180 private EditableDocumentPopup ()
182 addItem("accept", new PopupItem("menu.accept").icon("image.accept.png").action("setDocument?action=accept").confirmation("message.accept.document"));
183 addItem("promote", new PopupItem("menu.promote").icon("image.publish.png").action("setDocument?action=promote").confirmation("message.promote.document"));
185 addItem("rename", new PopupItem("menu.rename").action("edit-document?action=renameDocument"));
186 addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
188 addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
189 addItem("replace", new PopupItem("menu.replace").icon("image.replace.png").action("select-file?nextAction=replace"));
191 addItem("purge", new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
192 addItem("remove", new PopupItem("menu.remove.version").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
194 public boolean isEnabled (String name)
196 if (user == null) return false; // Should not happen
197 Item item = Item.valueOf(name);
198 if (item == Item.accept) return user.canAccept();
199 if (item == Item.promote) return user.canPromote();
200 if (item == Item.rename) return user.canRename();
201 if (item == Item.attach) return user.canAttach();
202 if (item == Item.version) return user.canVersion();
203 if (item == Item.replace) return user.canReplace();
204 if (item == Item.purge) return user.canPurge();
205 if (item == Item.remove) return user.canRemove();
208 public void setContext (String name, Object context)
210 if (context instanceof DocumentRights) {
211 user = (DocumentRights)context; // Just for optimizing
212 Document downer = user.getOperand();
213 PopupItem item = this.item("remove");
214 if (downer.isVersioned()) item.rename("menu.remove.version");
215 else item.rename("menu.remove.document");
219 private static class ReviewableDocumentPopup extends PopupMenu { // Popup of In-Draft documents
220 // ----------------------------------------------------------------
221 private DocumentRights user = null;
223 private ReviewableDocumentPopup ()
225 addItem("demote", new PopupItem("menu.demote").icon("image.demote.png").action("setDocument?action=demote").confirmation("message.demote.document"));
226 addItem("promote", new PopupItem("menu.review").icon("image.review.png").action("setDocument?action=review").confirmation("message.review.document"));
228 addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
230 addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
232 addItem("purge", new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
234 public boolean isEnabled (String name)
236 if (user == null) return false; // Should not happen
237 Item item = Item.valueOf(name);
238 if (item == Item.demote) return user.canDemote();
239 if (item == Item.promote) return user.canReview();
240 if (item == Item.attach) return user.canAttach();
241 if (item == Item.version) return user.canVersion();
242 if (item == Item.purge) return user.canPurge();
245 public void setContext (String name, Object context)
247 if (context instanceof DocumentRights) {
248 user = (DocumentRights)context; // Just for optimizing
252 private static class NotResultDocumentPopup extends PopupMenu {
253 // ----------------------------------------------------------------
254 private DocumentRights user = null;
256 private NotResultDocumentPopup ()
258 addItem("demote", new PopupItem("menu.demote").icon("image.demote.png").action("setDocument?action=demote").confirmation("message.demote.document"));
260 addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
262 addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
264 addItem("purge", new PopupItem("menu.purge").action("notyetimplemented").confirmation("message.purge.document"));
265 addItem("remove", new PopupItem("menu.remove.version").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
268 private static class ApprovableDocumentPopup extends PopupMenu { // Popup of In-Check documents
269 // ----------------------------------------------------------------
270 private DocumentRights user = null;
272 private ApprovableDocumentPopup ()
274 addItem("undo", new PopupItem("menu.demote").icon("image.invalidate.png").action("setDocument?action=invalidate").confirmation("message.demote.document"));
275 addItem("demote", new PopupItem("menu.disapprove").icon("image.demote.png").action("setDocument?action=disapprove").confirmation("message.disapprove.document"));
276 addItem("approve", new PopupItem("menu.approve").icon("icon.APPROVED.png").action("setDocument?action=approve").confirmation("message.approve.document"));
278 public boolean isEnabled (String name)
280 if (user == null) return false; // Should not happen
281 Item item = Item.valueOf(name);
282 if (item == Item.undo) return user.canInvalidate();
283 if (item == Item.demote) return user.canDemote();
284 if (item == Item.approve) return user.canApprove();
287 public void setContext (String name, Object context)
289 if (context instanceof DocumentRights) {
290 user = (DocumentRights)context; // Just for optimizing
294 private static class ApprovedPopup extends PopupMenu { // Popup of Approved documents
295 // ----------------------------------------------------------------
296 private ApprovedPopup ()
298 addItem("attach", new PopupItem("menu.attach").icon("image.attach.png").action("select-file?nextAction=attach"));
300 addItem("version", new PopupItem("menu.version").icon("image.version.png").action("select-file?nextAction=version"));
303 private static class ExternPopup extends PopupMenu { // Popup of Extern documents
304 // ----------------------------------------------------------------
305 private DocumentRights user = null;
307 private ExternPopup ()
309 addItem("rename", new PopupItem("menu.rename").action("edit-document?action=renameDocument"));
310 addItem("replace", new PopupItem("menu.replace").icon("image.replace.png").action("select-file?nextAction=replace"));
312 addItem("remove", new PopupItem("menu.remove.document").icon("icon.delete.png").action("remove-document").confirmation("message.delete.document"));
314 public boolean isEnabled (String name)
316 if (user == null) return false; // Should not happen
317 Item item = Item.valueOf(name);
318 if (item == Item.rename) return user.canRename();
319 if (item == Item.replace) return user.canReplace();
320 if (item == Item.remove) return user.canRemove();
323 public void setContext (String name, Object context)
325 if (context instanceof DocumentRights) {
326 user = (DocumentRights)context; // Just for optimizing
330 // Resources relative to simulation contexts
331 private static class ScontextPopup extends PopupMenu {
332 // --------------------------------------------------------
333 private SimulationContextFacade owner = null;
335 private ScontextPopup ()
337 addItem("rename", new PopupItem("menu.rename").action("edit-context?action=renameContext"));
338 addItem("edit", new PopupItem("menu.edit").action("edit-context?action=editContext"));
340 addItem("remove", new PopupItem("menu.remove").icon("icon.delete.png").action("remove-context").confirmation("message.delete.context"));
342 public boolean isEnabled (String name)
344 Item item = Item.valueOf(name);
346 if (item == Item.rename) {
349 if (item == Item.edit) {
350 // if (!owner.isEditable())
355 public void setContext (String name, Object context)
357 if (context instanceof SimulationContextFacade) {
358 owner = (SimulationContextFacade)context; // Just for optimizing
361 super.setContext(name, context);
365 // Resources relative to knowledge
366 private static class FeedbexPopup extends PopupMenu {
367 // --------------------------------------------------------
368 private KnowledgeElement owner = null;
370 private FeedbexPopup ()
372 addItem("promote", new PopupItem("menu.promote").icon("image.review.png").action("promote-knowledge").confirmation("message.promote.knowledge"));
373 addItem("demote", new PopupItem("menu.demote").icon("image.invalidate.png").action("demote-knowledge").confirmation("message.demote.knowledge"));
375 addItem("rename", new PopupItem("menu.rename").action("edit-knowledge?action=renameKnowledge"));
376 addItem("edit", new PopupItem("menu.edit").action("edit-knowledge?action=editKnowledge"));
378 addItem("remove", new PopupItem("menu.remove").icon("icon.delete.png").action("remove-knowledge").confirmation("message.delete.knowledge"));
380 public boolean isEnabled (String name)
382 Item item = Item.valueOf(name);
384 if (item == Item.promote) {
385 if (owner.getProgressState() != ProgressState.inDRAFT) return false;
387 if (item == Item.demote) {
388 if (owner.getProgressState() != ProgressState.inCHECK) return false;
392 public void setContext (String name, Object context)
394 if (context instanceof KnowledgeElement) owner = (KnowledgeElement)context; // Just for optimizing
396 super.setContext(name, context);
401 // ==============================================================================================================================
403 // ==============================================================================================================================
405 public static ApplicationSettings getMe () {
406 // ------------------------------------------
407 return my; // The application is supposed being previously created below
414 public ApplicationSettings init(String wappurl, Locale lang) throws IOException {
415 ClassLoader cloader = getClass().getClassLoader();
416 String[] wurl = wappurl.split("/"); // [0]="http:", [1]="", [2]="{server}:{port}", [3]="name"
419 wappserver = wurl[2];
421 wapprops = new Properties();
422 jndprops = new Properties();
423 wapprops.load(cloader.getResourceAsStream(wappname + ".properties"));
424 jndprops.load(cloader.getResourceAsStream("jndi.properties"));
426 logger.info("Application root set to " + wapprops.getProperty("wapp.root"));
431 // ==============================================================================================================================
432 // Public member functions
433 // ==============================================================================================================================
435 public void configure (String filename) {
436 // ---------------------------------------
437 // Non customizable settings
438 menus = new HashMap<String, SimpleMenu>();
439 SimpleMenu menu = new NewMenu();
440 menus.put( menu.getName(), menu );
441 menu = new SearchMenu();
442 menus.put( menu.getName(), menu );
443 menu = new DatadminMenu();
444 menus.put( menu.getName(), menu );
445 menu = new SysadminMenu();
446 menus.put( menu.getName(), menu );
447 menu = new PropertiesMenu();
448 menus.put( menu.getName(), menu );
450 popups = new HashMap<String, PopupMenu>();
451 popups.put("steditable", new EditableStudyPopup());
452 popups.put("editable", new EditableDocumentPopup());
453 popups.put("notresult", new NotResultDocumentPopup());
454 popups.put("reviewable", new ReviewableDocumentPopup());
455 popups.put("approvable", new ApprovableDocumentPopup());
456 popups.put("approved", new ApprovedPopup());
457 popups.put("extern", new ExternPopup());
458 popups.put("scontext", new ScontextPopup());
459 popups.put("feedbex", new FeedbexPopup());
461 // Default customizable mandatory settings
462 Map<String, Object> fprop = new HashMap<String, Object>();
463 fprop.put("visibility", "PRIVATE");
464 fprop.put("matchamong", "all");
465 fprop.put("matcontext", "all");
466 fprop.put("state", "END");
467 fprop.put("author", "0");
468 fprop.put("reference", "");
469 fprop.put("title", "");
470 fprop.put("context", new Vector<SimulationContext>());
472 Map<String, Object> gprop = new HashMap<String, Object>();
473 gprop.put("visibility", "PUBLIC");
474 gprop.put("matchamong", "all");
475 gprop.put("matcontext", "all");
476 gprop.put("type", "2"); //TODO: Get the index from the type name
477 gprop.put("author", "0");
478 gprop.put("reference", "");
479 gprop.put("title", "");
480 gprop.put("context", new Vector<SimulationContext>());
482 defdoctype = new LinkedHashMap<String, DocumentType>();
483 tempfile = new HashMap<String, String>();
484 viewermap = new String[0];
485 convertmap = new HashMap<String, Converter>();
486 filter = new HashMap<String, Map<String, Object>>();
487 filter.put("study", fprop);
488 filter.put("knowledge", gprop);
490 // Customization (must be done after above default settings)
491 File config = new File(filename);
492 if (config.exists()) {
493 loadCustomization(config); // Sets default document types, installed modules and available templates
495 logger.info("Could not find the application configuration file \"" + config.getAbsolutePath() + "\", using default settings");
497 // Settings based on the customization
498 bars = new HashMap<Integer, ToolBar>(); // May be empty if no module installed
500 List<ProjectSettingsService.Step> steps = getProjectSettings().getAllSteps();
501 for (Iterator<ProjectSettingsService.Step> i=steps.iterator(); i.hasNext();) {
502 ProjectSettingsService.Step step = i.next();
503 List<String> formats = getDefaultFormats(step);
504 if (formats.size() == 0) continue;
506 ToolBar bar = new ToolBar(24); // Height of the module-bar
507 HashSet<String> module = new HashSet<String>(); // For not duplicating modules
508 for (Iterator<String> j=formats.iterator(); j.hasNext();) {
509 String format = j.next();
510 String command = getApplicationProperty("executable." + format);
511 if (command == null) continue; // Module not installed
512 if (module.contains(command)) continue;
514 String[] parsed = command.split("/");
515 String[] name = parsed[parsed.length-1].split("\\x2E");
516 String docname = my.defdoctype.get(step.getNumber() + "." + format).getName();
517 if (tempfile.get(docname) == null) { // No available template
518 String tool = parsed[parsed.length-1];
519 String icon = name[0];
520 if (icon.equals("index")) {
521 tool = parsed[parsed.length-2];
522 icon = "tool." + tool.toLowerCase() + ".png";
525 icon = "tool." + icon.toLowerCase() + ".png";
527 File image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
528 if (!image.exists()) icon = "tool.any.png";
529 bar.addTool(tool, icon, command);
531 docname = "/jsp/newDocument.jsp?type=" + docname;
532 String icon = "tool." + name[0].toLowerCase() + ".png";
533 File image = new File(ApplicationSettings.getApplicationSkinPath() + icon);
534 if (!image.exists()) icon = "tool.any.png";
535 bar.addTool(name[0], icon, command, docname);
538 if (!bar.isEmpty()) bars.put(step.getNumber(), bar);
542 public String getApplicationProperty (String name) {
543 // --------------------------------------------------
544 return wapprops.getProperty(name); // May be null
547 public String getApplicationRootPath () {
548 // ---------------------------------------
549 return getApplicationProperty("wapp.root"); // The property is supposed including the Web application name
552 public String getApplicationURL () {
553 // ----------------------------------
554 StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/").append(wappname);
555 return url.toString();
558 public Map<String, Object> getFilter (String name) {
559 // --------------------------------------------------
560 return filter.get(name);
563 public ToolBar getModuleBar (Step step) {
564 // -----------------------------------------
565 return bars.get(step.getNumber());
568 public Properties getNamingProperties () {
569 // ----------------------------------------
573 // ==============================================================================================================================
575 // ==============================================================================================================================
577 public static String getApplicationPluginPath () {
578 // ------------------------------------------------
579 return my.getApplicationRootPath() + "plugin/";
581 public static String getApplicationResourcePath () {
582 // --------------------------------------------------
583 return my.getApplicationRootPath() + "WEB-INF/classes/";
585 public static String getApplicationSkinPath () {
586 // ----------------------------------------------
587 return my.getApplicationRootPath() + "skin/";
589 public static Converter getConverter (DocumentType type, String format) {
590 // -----------------------------------------------------------------------
591 return my.convertmap.get(format + type.getName()); // May be null;
593 public static DocumentType getDefaultDocumentType (Step step, String format) {
594 // ----------------------------------------------------------------------------
595 String[] table = format.split("\\x2E");
596 return my.defdoctype.get(step.getNumber() + "." + table[table.length-1]); // May be null
598 public static String getDownloadURL (User user) {
599 // --------------------------------------------------
600 StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/download/").append(user.getUsername()).append("/");
601 return url.toString(); // The download Tomcat context is supposed being defined
603 public static Locale getCurrentLocale () {
604 // ----------------------------------------
607 public static SimpleMenu getMenu (String name) {
608 // ----------------------------------------------
609 return my.menus.get(name);
611 public static PopupMenu getPopupMenu (String name) {
612 // --------------------------------------------------
613 return my.popups.get(name);
615 public static String getRepositoryURL () {
616 // ----------------------------------------
617 StringBuffer url = new StringBuffer("http://").append(my.wappserver).append("/repository/");
618 return url.toString(); // The repository Tomcat context is supposed being defined
620 public static Locale[] getSupportedLocales () {
621 // ---------------------------------------------
622 String[] code = my.wapprops.getProperty("locale.supported").split(",");
623 Locale[] result = new Locale[code.length];
624 for (int i=0; i<code.length; i++) result[i] = new Locale(code[i]);
627 public static String[] getViewersMapping () {
628 // -------------------------------------------
631 public static String getWebSiteURL () {
632 // -------------------------------------
633 return my.getApplicationProperty("wapp.website");
635 public static String getHelpURL () {
636 // ----------------------------------
637 return my.getApplicationProperty("wapp.onlinehelp");
639 // ==============================================================================================================================
641 // ==============================================================================================================================
643 private List<String> getDefaultFormats (ProjectSettingsService.Step step) {
644 // ------------------------------------------------------------------
645 Set<String> keys = defdoctype.keySet();
646 int number = step.getNumber();
647 Vector<String> result = new Vector<String>();
649 for (Iterator<String> i=keys.iterator(); i.hasNext();) {
650 String[] key = i.next().split("\\x2E");
651 if (Integer.valueOf(key[0]) != number) continue;
652 if (key[1].equals("pdf")) continue; // PDF is not an authoring format
653 result.add(key[1]); // Formats are unique
658 private void loadCustomization (File config) {
659 // --------------------------------------------
661 DocumentBuilderFactory dfactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
662 DocumentBuilder dBuilder = dfactory.newDocumentBuilder();
664 org.w3c.dom.Document conf = dBuilder.parse(config.getPath());
665 HashMap<String, Node> children = XDOM.getNamedChildNodes(conf.getDocumentElement());
667 // Default document types tag
668 Node child = children.get("default-doctypes");
669 NodeList nlist = child.getChildNodes();
671 List<DocumentType> listype = Document.selectAllTypes();
672 HashMap<String,DocumentType> maptype = new HashMap<String,DocumentType>();
673 for (Iterator<DocumentType> i=listype.iterator(); i.hasNext();) {
674 DocumentType type = i.next();
675 maptype.put(type.getName(), type);
677 for (int i=0; i<nlist.getLength(); i++) {
678 child = nlist.item(i);
679 if (!child.getNodeName().equals("step")) continue;
681 String nstep = child.getAttributes().getNamedItem("number").getNodeValue();
682 NodeList map = child.getChildNodes();
683 for (int j=0; j<map.getLength(); j++) {
685 if (!child.getNodeName().equals("mapping")) continue;
686 NamedNodeMap natr = child.getAttributes();
687 String dext = natr.getNamedItem("extension").getNodeValue();
688 String type = natr.getNamedItem("type").getNodeValue();
689 defdoctype.put(nstep + "." + dext, maptype.get(type));
693 child = children.get("modules");
694 nlist = child.getChildNodes();
695 for (int i=0; i<nlist.getLength(); i++) {
696 child = nlist.item(i);
697 if (!child.getNodeName().equals("mapping")) continue;
699 NamedNodeMap natr = child.getAttributes();
700 String dext = natr.getNamedItem("extension").getNodeValue();
701 String exec = natr.getNamedItem("executable").getNodeValue();
702 wapprops.put("executable." + dext, exec);
704 // Viewer mappings tag
705 child = children.get("viewers");
706 viewermap = child.getAttributes().getNamedItem("extension").getNodeValue().split(",");
709 child = children.get("converters");
710 nlist = child.getChildNodes();
711 for (int i=0; i<nlist.getLength(); i++) {
712 child = nlist.item(i);
714 if (child.getNodeName().equals("geometry")) {
715 NamedNodeMap natr = child.getAttributes();
716 String from = natr.getNamedItem("from").getNodeValue();
717 String to = natr.getNamedItem("to").getNodeValue();
718 String exec = natr.getNamedItem("executable").getNodeValue();
719 convertmap.put(from + "geometry", new Converter("geometry", from, to, exec));
724 child = children.get("templates");
725 nlist = child.getChildNodes();
726 for (int i=0; i<nlist.getLength(); i++) {
727 child = nlist.item(i);
728 if (!child.getNodeName().equals("document")) continue;
730 NamedNodeMap natr = child.getAttributes();
731 String type = natr.getNamedItem("type").getNodeValue();
732 String file = natr.getNamedItem("file").getNodeValue();
733 tempfile.put(type, file);
736 catch (Exception error) {
737 logger.info("Error in customization", error);