KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @author Sameer Charles $Id :$
26  */

27 public final class ContentImporter {
28
29     /**
30      * Logger.
31      */

32     private static Logger log = LoggerFactory.getLogger(ContentImporter.class);
33
34     /**
35      * default import handler
36      */

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

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

41     /**
42      * all initialized importers
43      */

44     private Map JavaDoc handlers = new Hashtable JavaDoc();
45
46     private static ContentImporter contentImporter = new ContentImporter();
47
48     /**
49      * Initialize Content importer with default handler
50      */

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