1 13 package info.magnolia.cms.beans.config; 14 15 import info.magnolia.cms.core.Content; 16 17 import java.util.Hashtable ; 18 import java.util.Map ; 19 20 import javax.jcr.RepositoryException; 21 22 import org.apache.commons.lang.StringUtils; 23 import org.apache.commons.lang.builder.ToStringBuilder; 24 import org.apache.log4j.Logger; 25 26 27 30 public final class Paragraph { 31 32 35 private static Logger log = Logger.getLogger(Paragraph.class); 36 37 private static final String DIALOGS_DIR = "/dialogs/"; 39 private static Map cachedContent = new Hashtable (); 40 41 private String name; 42 43 private String title; 44 45 private String templatePath; 46 47 private String dialogPath; 48 49 private String templateType; 50 51 private String description; 52 53 private Content dialogContent; 54 55 58 private Paragraph() { 59 } 60 61 71 public static Paragraph getInfo(String key) { 72 return (Paragraph) Paragraph.cachedContent.get(key); 73 } 74 75 79 public static Paragraph addParagraphToCache(Content c, String startPage) { 80 81 Paragraph pi = new Paragraph(); 82 pi.name = c.getNodeData("name").getString(); pi.templatePath = c.getNodeData("templatePath").getString(); pi.dialogPath = c.getNodeData("dialogPath").getString(); pi.templateType = c.getNodeData("type").getString(); pi.title = c.getNodeData("title").getString(); pi.description = c.getNodeData("description").getString(); try { 90 String dialog = pi.dialogPath; 91 dialog = StringUtils.substringBeforeLast(dialog, "."); 93 if (dialog.indexOf("/") != 0) { dialog = startPage + DIALOGS_DIR + dialog; } 96 Content dialogPage = ContentRepository.getHierarchyManager(ContentRepository.CONFIG).getContent(dialog); 97 pi.dialogContent = dialogPage; 98 99 103 } 104 catch (RepositoryException re) { 105 log.error(re.getMessage(), re); 106 } 107 108 if (log.isDebugEnabled()) { 109 log.debug("Registering paragraph [" + pi.name + "]"); } 111 cachedContent.put(pi.name, pi); 112 return pi; 113 } 114 115 118 public String getName() { 119 return this.name; 120 } 121 122 125 public String getTitle() { 126 return this.title; 127 } 128 129 132 public String getTemplatePath() { 133 return this.templatePath; 134 } 135 136 139 public String getDialogPath() { 140 return this.dialogPath; 141 } 142 143 146 public String getTemplateType() { 147 return this.templateType; 148 } 149 150 153 public String getDescription() { 154 return this.description; 155 } 156 157 160 public Content getDialogContent() { 161 return this.dialogContent; 162 } 163 164 167 public String toString() { 168 return new ToStringBuilder(this) 169 .append("name", this.name) .append("templateType", this.templateType) .append("description", this.description) .append("dialogPath", this.dialogPath) .append("title", this.title) .append("templatePath", this.templatePath) .append("dialogContent", this.dialogContent) .toString(); 178 } 179 } | Popular Tags |