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.ui.editor.i18n;
35
36 import info.magnolia.i18nsystem.AbstractI18nKeyGenerator;
37 import info.magnolia.ui.editor.ComplexPropertyDefinition;
38 import info.magnolia.ui.field.EditorPropertyDefinition;
39 import info.magnolia.ui.field.FieldDefinition;
40 import info.magnolia.ui.editor.FormDefinition;
41
42 import java.lang.reflect.AnnotatedElement;
43 import java.util.Deque;
44 import java.util.LinkedList;
45 import java.util.List;
46 import java.util.Optional;
47 import java.util.stream.Collectors;
48
49
50
51
52
53 public class EditorPropertyDefinitionKeyGenerator extends AbstractI18nKeyGenerator<EditorPropertyDefinition> {
54
55 @Override
56 protected void keysFor(List<String> list, EditorPropertyDefinition editorPropertyDefinition, AnnotatedElement el) {
57 Object parent = getParentViaCast(editorPropertyDefinition);
58 final Deque<String> parentNames = new LinkedList<>();
59
60 while (parent != null) {
61 Optional.ofNullable(getIdOrNameForUnknownRoot(parent)).ifPresent(parentNames::addFirst);
62 parent = getParentViaCast(parent);
63 }
64 final String parentKeyPart = parentNames
65 .stream()
66 .map(this::replaceColons)
67 .distinct()
68 .collect(Collectors.joining("."));
69
70 final String fieldOrGetterName = fieldOrGetterName(el);
71 addKey(list, parentKeyPart, replaceColons(editorPropertyDefinition.getName()), fieldOrGetterName);
72 addKey(list, "fields", replaceColons(editorPropertyDefinition.getName()), fieldOrGetterName);
73 }
74
75 @Override
76 protected String getIdOrNameForUnknownRoot(Object obj) {
77 if (obj instanceof ComplexPropertyDefinition) {
78 return ((ComplexPropertyDefinition) obj).getName();
79 }
80 return super.getIdOrNameForUnknownRoot(obj);
81 }
82 }