1 13 package info.magnolia.cms.core.ie; 14 15 import info.magnolia.cms.util.ClassUtil; 16 17 import java.util.Hashtable ; 18 import java.util.Map ; 19 20 import org.slf4j.Logger; 21 import org.slf4j.LoggerFactory; 22 23 24 27 public final class ContentImporter { 28 29 32 private static Logger log = LoggerFactory.getLogger(ContentImporter.class); 33 34 37 public static final String DEFAULT_HANDLER_CLASS = "info.magnolia.cms.core.ie.XmlImport"; 39 public static final String DEFAULT_HANDLER = "defaultHandler"; 41 44 private Map handlers = new Hashtable (); 45 46 private static ContentImporter contentImporter = new ContentImporter(); 47 48 51 private ContentImporter() { 52 try { 53 ImportHandler defaultImporter = (ImportHandler) ClassUtil.newInstance(DEFAULT_HANDLER_CLASS); 54 this.addImportHandler(DEFAULT_HANDLER, defaultImporter); 55 } 56 catch (Exception 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 name, ImportHandler importhandler) { 66 if (log.isDebugEnabled()) { 67 log.debug("Adding import handler " + importhandler.getClass()); } 69 this.handlers.put(name, importhandler); 70 } 71 72 public ImportHandler getImportHandler(String name) { 73 if (this.handlers.get(name) == null) { 74 log.error("No import handler found with name - " + name); log.error("Returning default import handler - " + DEFAULT_HANDLER); return (ImportHandler) this.handlers.get(DEFAULT_HANDLER); 77 } 78 return (ImportHandler) this.handlers.get(name); 79 } 80 81 } 82 | Popular Tags |