1 13 package info.magnolia.cms.beans.config; 14 15 import info.magnolia.cms.core.Content; 16 import info.magnolia.cms.core.ItemType; 17 import info.magnolia.cms.util.FactoryUtil; 18 19 import java.util.Collection ; 20 import java.util.Hashtable ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 24 import org.apache.commons.lang.StringUtils; 25 26 27 31 public class ParagraphManager extends ObservedManager { 32 33 private static final String ND_I18N_BASENAME = "i18nBasename"; 34 35 private static final String ND_DESCRIPTION = "description"; 36 37 private static final String ND_TITLE = "title"; 38 39 private static final String ND_TYPE = "type"; 40 41 private static final String ND_DIALOG_PATH = "dialogPath"; 42 43 private static final String ND_TEMPLATE_PATH = "templatePath"; 44 45 private static final String ND_DIALOG = "dialog"; 46 47 private static final String ND_NAME = "name"; 48 49 52 protected Map paragraphs = new Hashtable (); 53 54 64 public Paragraph getInfo(String key) { 65 return (Paragraph) paragraphs.get(key); 66 } 67 68 72 public Map getParagraphs() { 73 return paragraphs; 74 } 75 76 81 protected void onRegister(Content node) { 82 84 Collection paragraphNodes = node.getChildren(ItemType.CONTENTNODE); 85 for (Iterator iter = paragraphNodes.iterator(); iter.hasNext();) { 86 Content paragraphNode = (Content) iter.next(); 87 addParagraphToCache(paragraphNode); 88 } 89 90 Collection subDefinitions = node.getChildren(ItemType.CONTENT); 91 Iterator it = subDefinitions.iterator(); 92 while (it.hasNext()) { 93 Content subNode = (Content) it.next(); 94 onRegister(subNode); 96 } 97 98 } 99 100 103 protected Paragraph addParagraphToCache(Content c) { 104 Paragraph pi = new Paragraph(); 105 106 String name = c.getNodeData(ND_NAME).getString(); 107 if (StringUtils.isEmpty(name)) { 108 name = c.getName(); 109 } 110 111 pi.setName(name); 112 113 String dialog = c.getNodeData(ND_DIALOG).getString(); 115 if (StringUtils.isEmpty(dialog)) { 116 dialog = c.getName(); 117 } 118 pi.setDialog(dialog); 119 120 pi.setTemplatePath(c.getNodeData(ND_TEMPLATE_PATH).getString()); 121 pi.setDialogPath(c.getNodeData(ND_DIALOG_PATH).getString()); 122 pi.setTemplateType(c.getNodeData(ND_TYPE).getString()); 123 pi.setTitle(c.getNodeData(ND_TITLE).getString()); 124 pi.setDescription(c.getNodeData(ND_DESCRIPTION).getString()); 125 pi.setI18nBasename(c.getNodeData(ND_I18N_BASENAME).getString()); 126 if (Paragraph.log.isDebugEnabled()) { 127 Paragraph.log.debug("Registering paragraph [{}]", pi.getName()); } 129 130 paragraphs.put(pi.getName(), pi); 131 return pi; 132 } 133 134 138 public static ParagraphManager getInstance() { 139 return (ParagraphManager) FactoryUtil.getSingleton(ParagraphManager.class); 140 } 141 142 public void onClear() { 143 this.paragraphs.clear(); 144 } 145 146 } 147 | Popular Tags |