KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > beans > config > Paragraph


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-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.beans.config;
14
15 import info.magnolia.cms.core.Content;
16
17 import java.util.Hashtable JavaDoc;
18 import java.util.Map JavaDoc;
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 /**
28  * @author Sameer Charles
29  */

30 public final class Paragraph {
31
32     /**
33      * Logger.
34      */

35     private static Logger log = Logger.getLogger(Paragraph.class);
36
37     private static final String JavaDoc DIALOGS_DIR = "/dialogs/"; //$NON-NLS-1$
38

39     private static Map JavaDoc cachedContent = new Hashtable JavaDoc();
40
41     private String JavaDoc name;
42
43     private String JavaDoc title;
44
45     private String JavaDoc templatePath;
46
47     private String JavaDoc dialogPath;
48
49     private String JavaDoc templateType;
50
51     private String JavaDoc description;
52
53     private Content dialogContent;
54
55     /**
56      * constructor
57      */

58     private Paragraph() {
59     }
60
61     /**
62      * Returns the cached content of the requested template. TemplateInfo properties :
63      * <ol>
64      * <li>title - title describing template</li>
65      * <li>type - jsp / servlet</li>
66      * <li>path - jsp / servlet path</li>
67      * <li>description - description of a template</li>
68      * </ol>
69      * @return TemplateInfo
70      */

71     public static Paragraph getInfo(String JavaDoc key) {
72         return (Paragraph) Paragraph.cachedContent.get(key);
73     }
74
75     /**
76      * Adds paragraph definition to ParagraphInfo cache.
77      * @param paragraphs iterator as read from the repository
78      */

79     public static Paragraph addParagraphToCache(Content c, String JavaDoc startPage) {
80
81         Paragraph pi = new Paragraph();
82         pi.name = c.getNodeData("name").getString(); //$NON-NLS-1$
83
pi.templatePath = c.getNodeData("templatePath").getString(); //$NON-NLS-1$
84
pi.dialogPath = c.getNodeData("dialogPath").getString(); //$NON-NLS-1$
85
pi.templateType = c.getNodeData("type").getString(); //$NON-NLS-1$
86
pi.title = c.getNodeData("title").getString(); //$NON-NLS-1$
87
pi.description = c.getNodeData("description").getString(); //$NON-NLS-1$
88
// get remaining from dialog definition
89
try {
90             String JavaDoc dialog = pi.dialogPath;
91             dialog = StringUtils.substringBeforeLast(dialog, "."); //$NON-NLS-1$
92

93             if (dialog.indexOf("/") != 0) { //$NON-NLS-1$
94
dialog = startPage + DIALOGS_DIR + dialog; // dialog: pars/text.xml -> /info/dialogs/pars/text.xml
95
}
96             Content dialogPage = ContentRepository.getHierarchyManager(ContentRepository.CONFIG).getContent(dialog);
97             pi.dialogContent = dialogPage;
98
99             // this is registered in module
100
// classes in info.magnolia.cms.beans.config should NEVER depends from classes in info.magnolia.module!!
101
// Store.getInstance().registerParagraphDialogHandler(pi.name, pi.dialogContent);
102

103         }
104         catch (RepositoryException re) {
105             log.error(re.getMessage(), re);
106         }
107
108         if (log.isDebugEnabled()) {
109             log.debug("Registering paragraph [" + pi.name + "]"); //$NON-NLS-1$ //$NON-NLS-2$
110
}
111         cachedContent.put(pi.name, pi);
112         return pi;
113     }
114
115     /**
116      * @return String, name
117      */

118     public String JavaDoc getName() {
119         return this.name;
120     }
121
122     /**
123      * @return String, title
124      */

125     public String JavaDoc getTitle() {
126         return this.title;
127     }
128
129     /**
130      * @return String, templatePath
131      */

132     public String JavaDoc getTemplatePath() {
133         return this.templatePath;
134     }
135
136     /**
137      * @return String, dialogPath
138      */

139     public String JavaDoc getDialogPath() {
140         return this.dialogPath;
141     }
142
143     /**
144      * @return String, template type (jsp / servlet)
145      */

146     public String JavaDoc getTemplateType() {
147         return this.templateType;
148     }
149
150     /**
151      * @return String, description
152      */

153     public String JavaDoc getDescription() {
154         return this.description;
155     }
156
157     /**
158      * @return Content, Content holding information for the paragraph dialog
159      */

160     public Content getDialogContent() {
161         return this.dialogContent;
162     }
163
164     /**
165      * @see java.lang.Object#toString()
166      */

167     public String JavaDoc toString() {
168         return new ToStringBuilder(this)
169         //
170
.append("name", this.name) //$NON-NLS-1$
171
.append("templateType", this.templateType) //$NON-NLS-1$
172
.append("description", this.description) //$NON-NLS-1$
173
.append("dialogPath", this.dialogPath) //$NON-NLS-1$
174
.append("title", this.title) //$NON-NLS-1$
175
.append("templatePath", this.templatePath) //$NON-NLS-1$
176
.append("dialogContent", this.dialogContent) //$NON-NLS-1$
177
.toString();
178     }
179 }
Popular Tags