KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > core > ie > ContentExporter


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.core.ie;
14
15 import info.magnolia.cms.util.ClassUtil;
16
17 import java.util.Hashtable JavaDoc;
18 import java.util.Map JavaDoc;
19
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23
24 /**
25  * This class is a main export handler, which could be used to instanciate appropriate export handlers using ID
26  * @author Sameer Charles $Id :$
27  */

28 public final class ContentExporter {
29
30     /**
31      * Logger.
32      */

33     private static Logger log = LoggerFactory.getLogger(ContentExporter.class);
34
35     /**
36      * default export handler
37      */

38     public static final String JavaDoc DEFAULT_HANDLER_CLASS = "info.magnolia.cms.core.ie.XmlExport"; //$NON-NLS-1$
39

40     public static final String JavaDoc DEFAULT_HANDLER = "defaultHandler"; //$NON-NLS-1$
41

42     /**
43      * all initialized exporters
44      */

45     private Map JavaDoc handlers = new Hashtable JavaDoc();
46
47     private static ContentExporter contentExporter = new ContentExporter();
48
49     /**
50      * Initialize Content exporter with default handler
51      */

52     private ContentExporter() {
53         try {
54             ExportHandler defaultExporter = (ExportHandler) ClassUtil.newInstance(DEFAULT_HANDLER_CLASS);
55             this.addExportHandler(DEFAULT_HANDLER, defaultExporter);
56         }
57         catch (Exception JavaDoc e) {
58             log.error(e.getMessage(), e);
59         }
60     }
61
62     public static ContentExporter getInstance() {
63         return ContentExporter.contentExporter;
64     }
65
66     public void addExportHandler(String JavaDoc name, ExportHandler export) {
67         if (log.isDebugEnabled()) {
68             log.debug("Adding export handler " + export.getClass()); //$NON-NLS-1$
69
}
70         this.handlers.put(name, export);
71     }
72
73     public ExportHandler getExportHandler(String JavaDoc name) {
74         if (this.handlers.get(name) == null) {
75             log.error("No export handler found with name - " + name); //$NON-NLS-1$
76
log.error("Returning default export handler - " + DEFAULT_HANDLER); //$NON-NLS-1$
77
return (ExportHandler) this.handlers.get(DEFAULT_HANDLER);
78         }
79         return (ExportHandler) this.handlers.get(name);
80     }
81
82 }
83
Popular Tags