1 12 package info.magnolia.cms.gui.dialog; 13 14 import info.magnolia.cms.beans.config.ObservedManager; 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.core.ItemType; 17 import info.magnolia.cms.util.ClassUtil; 18 import info.magnolia.cms.util.FactoryUtil; 19 20 import java.util.Iterator ; 21 22 import org.apache.commons.lang.StringUtils; 23 import org.slf4j.Logger; 24 import org.slf4j.LoggerFactory; 25 26 27 31 public final class ControlsManager extends ObservedManager { 32 33 36 private static Logger log = LoggerFactory.getLogger(ControlsManager.class); 37 38 41 private static final String DATA_CONTROL_CLASS = "class"; 43 46 private static final String DATA_CONTROL_NAME = "name"; 48 51 protected void onRegister(Content configNode) { 52 log.info("Config : loading dialog controls configuration"); 54 Iterator iterator = configNode.getChildren(ItemType.CONTENTNODE).iterator(); 55 56 while (iterator.hasNext()) { 57 Content controlNode = (Content) iterator.next(); 58 59 if (log.isDebugEnabled()) { 60 log.debug("Initializing control [{}]", controlNode); } 62 63 String classNodeData = controlNode.getNodeData(DATA_CONTROL_CLASS).getString(); 64 String nameNodeData = controlNode.getNodeData(DATA_CONTROL_NAME).getString(); 65 66 if (StringUtils.isEmpty(nameNodeData)) { 67 nameNodeData = controlNode.getName(); 68 } 69 70 if (StringUtils.isEmpty(classNodeData) || StringUtils.isEmpty(nameNodeData)) { 71 log.warn("Config : Can't add custom control with name [{}] and class [{}] specified in node [{}]", new Object []{nameNodeData, classNodeData, controlNode.getName()}); 73 continue; 74 } 75 Class controlClass = null; 76 77 try { 78 controlClass = ClassUtil.classForName(classNodeData); 79 } 80 catch (ClassNotFoundException e) { 81 log.error("Config : Failed to load dialog control with class [" + classNodeData + "]", e); continue; 83 } 84 85 if (!DialogControl.class.isAssignableFrom(controlClass)) { 86 log.error("Config : Invalid class specified for control [{}]: does not implement DialogControl", nameNodeData); 88 continue; 89 } 90 91 DialogFactory.registerDialog(nameNodeData, controlClass); 92 93 } 94 } 95 96 99 public static ControlsManager getInstance() { 100 return (ControlsManager) FactoryUtil.getSingleton(ControlsManager.class); 101 } 102 103 protected void onClear() { 104 } 105 106 } 107 | Popular Tags |