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;
35
36 import info.magnolia.ui.api.i18n.I18NAuthoringSupport;
37
38 import java.util.Locale;
39 import java.util.stream.IntStream;
40
41 import javax.inject.Inject;
42 import javax.jcr.Node;
43
44 import com.machinezoo.noexception.Exceptions;
45
46 import lombok.EqualsAndHashCode;
47 import lombok.Getter;
48 import lombok.Setter;
49
50
51
52
53
54
55
56
57 @Deprecated
58 public class LexicographicallyIndexedChildNodeProvider extends JcrChildNodeProvider<LexicographicallyIndexedChildNodeProvider.Definition> {
59
60 @Inject
61 public LexicographicallyIndexedChildNodeProvider(
62 LexicographicallyIndexedChildNodeProvider.Definition definition,
63 ComplexPropertyDefinition<Node> associatedPropertyDefinition,
64 I18NAuthoringSupport<Node> i18NAuthoringSupport) {
65 super(definition, associatedPropertyDefinition, i18NAuthoringSupport);
66 }
67
68 @Override
69 protected String constructTargetSubNodeName(Node referenceNode, Locale locale) {
70 String subNodeName = getSubNodeNameBase();
71 if (this.definition.getIndex() >= 0) {
72 return constructLocalisedSubNodeName(referenceNode, String.format("%s%02d", subNodeName, definition.getIndex()), locale);
73 }
74
75 return IntStream.iterate(0, i -> i + 1)
76 .mapToObj(idx -> constructLocalisedSubNodeName(referenceNode, String.format("%s%02d", subNodeName, idx), locale))
77 .filter(Exceptions.sneak().predicate(referenceNode::hasNode).negate())
78 .findFirst()
79 .orElseThrow(RuntimeException::new);
80 }
81
82
83
84
85
86
87 @Deprecated
88 @EqualsAndHashCode(callSuper = true)
89 public static class Definition extends JcrChildNodeProviderDefinition {
90
91 @Getter
92 @Setter
93 private int index = -1;
94
95 public Definition() {
96 setImplementationClass(LexicographicallyIndexedChildNodeProvider.class);
97 }
98 }
99 }