19
19
*/
20
20
package io .wcm .wcm .core .components .impl .models .helpers ;
21
21
22
- import static com .adobe .cq .wcm .core .components .models .List .PN_TEASER_DELEGATE ;
23
- import static com .day .cq .commons .jcr .JcrConstants .JCR_DESCRIPTION ;
24
- import static com .day .cq .commons .jcr .JcrConstants .JCR_TITLE ;
25
- import static io .wcm .handler .link .LinkNameConstants .PN_LINK_CONTENT_REF ;
26
- import static io .wcm .handler .link .LinkNameConstants .PN_LINK_TYPE ;
27
-
28
- import java .util .Calendar ;
29
- import java .util .HashMap ;
30
- import java .util .HashSet ;
31
- import java .util .Map ;
32
- import java .util .Set ;
33
-
34
- import org .apache .commons .lang3 .StringUtils ;
35
- import org .apache .sling .api .resource .Resource ;
36
22
import org .jetbrains .annotations .NotNull ;
37
23
import org .jetbrains .annotations .Nullable ;
38
- import org .slf4j .Logger ;
39
- import org .slf4j .LoggerFactory ;
40
24
41
25
import com .adobe .cq .wcm .core .components .models .ListItem ;
42
- import com .adobe .cq .wcm .core .components .models .datalayer .PageData ;
43
- import com .adobe .cq .wcm .core .components .models .datalayer .builder .DataLayerBuilder ;
44
- import com .adobe .cq .wcm .core .components .util .ComponentUtils ;
45
26
import com .day .cq .wcm .api .Page ;
46
27
import com .day .cq .wcm .api .components .Component ;
47
- import com .fasterxml .jackson .annotation .JsonIgnore ;
48
28
49
29
import io .wcm .handler .link .Link ;
50
- import io .wcm .handler .link .type .InternalLinkType ;
51
- import io .wcm .wcm .core .components .impl .link .LinkWrapper ;
52
- import io .wcm .wcm .core .components .impl .util .CoreResourceWrapper ;
53
30
54
31
/**
55
32
* {@link ListItem} implementation for page links.
56
33
*/
57
- public class PageListItemV2Impl extends AbstractListItemImpl implements ListItem {
58
-
59
- private final Page page ;
60
- protected final LinkWrapper link ;
61
- private final Component parentComponent ;
62
- private final boolean showDescription ;
63
- private final boolean linkItems ;
64
- private Resource teaserResource ;
65
-
66
- private static final Logger log = LoggerFactory .getLogger (PageListItemV2Impl .class );
34
+ public class PageListItemV2Impl extends PageListItemV4Impl implements ListItem {
67
35
68
36
/**
69
37
* @param page Page
@@ -76,12 +44,7 @@ public class PageListItemV2Impl extends AbstractListItemImpl implements ListItem
76
44
public PageListItemV2Impl (@ NotNull Page page , @ NotNull Link link ,
77
45
@ Nullable String parentId , @ Nullable Component parentComponent ,
78
46
boolean showDescription , boolean linkItems ) {
79
- super (page .getContentResource (), parentId , parentComponent );
80
- this .page = page ;
81
- this .link = new LinkWrapper (link );
82
- this .parentComponent = parentComponent ;
83
- this .showDescription = showDescription ;
84
- this .linkItems = linkItems ;
47
+ super (page , link , parentId , parentComponent , showDescription , linkItems , null );
85
48
}
86
49
87
50
/**
@@ -95,117 +58,4 @@ public PageListItemV2Impl(@NotNull Page page, @NotNull Link link,
95
58
this (page , link , parentId , parentComponent , false , false );
96
59
}
97
60
98
- @ Override
99
- public @ Nullable com .adobe .cq .wcm .core .components .commons .link .Link getLink () {
100
- return link .orNull ();
101
- }
102
-
103
- /**
104
- * @deprecated Deprecated in API
105
- */
106
- @ Override
107
- @ Deprecated
108
- @ JsonIgnore
109
- public String getURL () {
110
- return link .getURL ();
111
- }
112
-
113
- @ Override
114
- public String getTitle () {
115
- String title = page .getNavigationTitle ();
116
- if (title == null ) {
117
- title = page .getPageTitle ();
118
- }
119
- if (title == null ) {
120
- title = page .getTitle ();
121
- }
122
- if (title == null ) {
123
- title = page .getName ();
124
- }
125
- return title ;
126
- }
127
-
128
- @ Override
129
- public String getDescription () {
130
- return page .getDescription ();
131
- }
132
-
133
- @ Override
134
- public Calendar getLastModified () {
135
- return page .getLastModified ();
136
- }
137
-
138
- @ Override
139
- public String getPath () {
140
- return page .getPath ();
141
- }
142
-
143
- @ Override
144
- @ JsonIgnore
145
- public String getName () {
146
- return page .getName ();
147
- }
148
-
149
- @ Override
150
- @ JsonIgnore
151
- public @ Nullable Resource getTeaserResource () {
152
- if (teaserResource == null && parentComponent != null ) {
153
- String delegateResourceType = parentComponent .getProperties ().get (PN_TEASER_DELEGATE , String .class );
154
- if (delegateResourceType == null || StringUtils .isEmpty (delegateResourceType )) {
155
- log .error ("In order for list rendering delegation to work correctly you need to set up the teaserDelegate property on" +
156
- " the {} component; its value has to point to the resource type of a teaser component." , parentComponent .getPath ());
157
- }
158
- else {
159
- teaserResource = buildTeaserResource (delegateResourceType );
160
- }
161
- }
162
- return teaserResource ;
163
- }
164
-
165
- /**
166
- * Builds a wrapped teaser resource based on the target page with title and description from this link item,
167
- * linking to the target page.
168
- * @param delegateResourceType Delegate resource type
169
- * @return Wrapped teaser resource
170
- */
171
- private Resource buildTeaserResource (@ NotNull String delegateResourceType ) {
172
- Map <String , Object > overriddenProperties = new HashMap <>();
173
- Set <String > hiddenProperties = new HashSet <>();
174
-
175
- Resource resourceToBeWrapped = ComponentUtils .getFeaturedImage (page );
176
- if (resourceToBeWrapped != null ) {
177
- // use the page featured image and inherit properties from the page item
178
- overriddenProperties .put (JCR_TITLE , this .getTitle ());
179
- if (showDescription ) {
180
- overriddenProperties .put (JCR_DESCRIPTION , this .getDescription ());
181
- }
182
- }
183
- else {
184
- // use the page content node and inherit properties from the page item
185
- resourceToBeWrapped = page .getContentResource ();
186
- if (resourceToBeWrapped == null ) {
187
- return null ;
188
- }
189
- if (!showDescription ) {
190
- hiddenProperties .add (JCR_DESCRIPTION );
191
- }
192
- }
193
- if (linkItems ) {
194
- overriddenProperties .put (PN_LINK_TYPE , InternalLinkType .ID );
195
- overriddenProperties .put (PN_LINK_CONTENT_REF , this .getPath ());
196
- }
197
-
198
- return new CoreResourceWrapper (resourceToBeWrapped , delegateResourceType , overriddenProperties , hiddenProperties );
199
- }
200
-
201
- // --- data layer ---
202
-
203
- @ Override
204
- protected @ NotNull PageData getComponentData () {
205
- return DataLayerBuilder .extending (super .getComponentData ()).asPage ()
206
- .withTitle (this ::getTitle )
207
- .withLinkUrl (link ::getURL )
208
- .build ();
209
- }
210
-
211
61
}
0 commit comments