KickJava   Java API By Example, From Geeks To Geeks.

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


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-2006 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 import info.magnolia.cms.core.ItemType;
17 import info.magnolia.cms.util.FactoryUtil;
18
19 import java.util.Collection JavaDoc;
20 import java.util.Hashtable JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.commons.lang.StringUtils;
25
26
27 /**
28  * Manages the paragraph ot the system. The modules register the nodes where the paragraph are defined.
29  * @author philipp
30  */

31 public class ParagraphManager extends ObservedManager {
32
33     private static final String JavaDoc ND_I18N_BASENAME = "i18nBasename";
34
35     private static final String JavaDoc ND_DESCRIPTION = "description";
36
37     private static final String JavaDoc ND_TITLE = "title";
38
39     private static final String JavaDoc ND_TYPE = "type";
40
41     private static final String JavaDoc ND_DIALOG_PATH = "dialogPath";
42
43     private static final String JavaDoc ND_TEMPLATE_PATH = "templatePath";
44
45     private static final String JavaDoc ND_DIALOG = "dialog";
46
47     private static final String JavaDoc ND_NAME = "name";
48
49     /**
50      * Cached paragraphs
51      */

52     protected Map JavaDoc paragraphs = new Hashtable JavaDoc();
53
54     /**
55      * Returns the cached content of the requested template. TemplateInfo properties :
56      * <ol>
57      * <li>title - title describing template</li>
58      * <li>type - jsp / servlet</li>
59      * <li>path - jsp / servlet path</li>
60      * <li>description - description of a template</li>
61      * </ol>
62      * @return TemplateInfo
63      */

64     public Paragraph getInfo(String JavaDoc key) {
65         return (Paragraph) paragraphs.get(key);
66     }
67
68     /**
69      * Get a map of all registered paragraphs.
70      * @return
71      */

72     public Map JavaDoc getParagraphs() {
73         return paragraphs;
74     }
75
76     /**
77      * Register all the paragraphs under this and subnodes.
78      * @param node
79      * @param observate true if an eventlistener should get registered
80      */

81     protected void onRegister(Content node) {
82         // register a listener
83

84         Collection JavaDoc paragraphNodes = node.getChildren(ItemType.CONTENTNODE);
85         for (Iterator JavaDoc iter = paragraphNodes.iterator(); iter.hasNext();) {
86             Content paragraphNode = (Content) iter.next();
87             addParagraphToCache(paragraphNode);
88         }
89
90         Collection JavaDoc subDefinitions = node.getChildren(ItemType.CONTENT);
91         Iterator JavaDoc it = subDefinitions.iterator();
92         while (it.hasNext()) {
93             Content subNode = (Content) it.next();
94             // do not register other observations
95
onRegister(subNode);
96         }
97
98     }
99
100     /**
101      * Adds paragraph definition to ParagraphInfo cache.
102      */

103     protected Paragraph addParagraphToCache(Content c) {
104         Paragraph pi = new Paragraph();
105
106         String JavaDoc name = c.getNodeData(ND_NAME).getString();
107         if (StringUtils.isEmpty(name)) {
108             name = c.getName();
109         }
110
111         pi.setName(name);
112
113         // by default just use the dialog with the same name of the paragraph
114
String JavaDoc 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()); //$NON-NLS-1$
128
}
129
130         paragraphs.put(pi.getName(), pi);
131         return pi;
132     }
133
134     /**
135      * Get the current singleton object
136      * @return
137      */

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