1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.blossom.paragraph;
35
36 import info.magnolia.module.blossom.annotation.I18nBasename;
37 import info.magnolia.module.blossom.annotation.Paragraph;
38 import info.magnolia.module.blossom.annotation.ParagraphDescription;
39 import info.magnolia.module.blossom.annotation.TabOrder;
40 import info.magnolia.module.blossom.dialog.DialogFactoryMetaData;
41 import info.magnolia.module.blossom.dispatcher.BlossomDispatcher;
42 import org.apache.commons.lang.StringUtils;
43
44
45
46
47 public class ParagraphDescriptionBuilder {
48
49 public BlossomParagraphDescription buildDescription(BlossomDispatcher dispatcher, Object handler, String handlerPath) {
50
51 Paragraph annotation = handler.getClass().getAnnotation(Paragraph.class);
52 I18nBasename i18nBasename = handler.getClass().getAnnotation(I18nBasename.class);
53
54 BlossomParagraphDescription description = new BlossomParagraphDescription();
55 description.setName(resolveName(handlerPath, handler, annotation));
56 description.setTitle(resolveTitle(handlerPath, handler, annotation));
57 description.setDescription(resolveDescription(handlerPath, handler, annotation));
58 description.setHandlerPath(handlerPath);
59 description.setI18nBasename(i18nBasename != null ? i18nBasename.value() : null);
60 description.setHandler(handler);
61 description.setDispatcher(dispatcher);
62 description.setDialogName(StringUtils.trimToNull(annotation.dialog()));
63
64 if (description.getDialogName() == null) {
65 TabOrder tabOrder = handler.getClass().getAnnotation(TabOrder.class);
66 DialogFactoryMetaData factoryMetaData = new DialogFactoryMetaData();
67 factoryMetaData.setLabel(description.getTitle());
68 factoryMetaData.setI18nBasename(description.getI18nBasename());
69 factoryMetaData.setFactoryObject(handler);
70 factoryMetaData.setTabOrder(tabOrder != null ? tabOrder.value() : null);
71 description.setDialogFactoryMetaData(factoryMetaData);
72 }
73
74 return description;
75 }
76
77 protected String resolveName(String handlerPath, Object handler, Paragraph annotation) {
78 if (StringUtils.isNotEmpty(annotation.name()))
79 return annotation.name();
80 return StringUtils.replaceChars(StringUtils.strip(handlerPath, "/"), '/', '_');
81 }
82
83 protected String resolveTitle(String handlerPath, Object handler, Paragraph annotation) {
84 if (StringUtils.isNotEmpty(annotation.value()))
85 return annotation.value();
86 return handlerPath;
87 }
88
89 protected String resolveDescription(String handlerPath, Object handler, Paragraph annotation) {
90 ParagraphDescription paragraphDescription = handler.getClass().getAnnotation(ParagraphDescription.class);
91 if (paragraphDescription != null && StringUtils.isNotEmpty(paragraphDescription.value()))
92 return paragraphDescription.value();
93 return "";
94 }
95 }