1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package io.wcm.handler.url.impl.modes;
21
22 import org.apache.sling.api.adapter.Adaptable;
23 import org.apache.sling.api.resource.Resource;
24
25 import com.day.cq.wcm.api.Page;
26
27 import io.wcm.handler.url.UrlMode;
28
29 abstract class AbstractUrlMode implements UrlMode {
30
31 @Override
32 public int hashCode() {
33 return getId().hashCode();
34 }
35
36 @Override
37 public boolean equals(Object obj) {
38 if (obj == null || obj.getClass() != getClass()) {
39 return false;
40 }
41 return getId().equals(((UrlMode)obj).getId());
42 }
43
44 @Override
45 public String toString() {
46 return getId();
47 }
48
49
50
51
52
53
54
55 protected UrlConfig getUrlConfigForTarget(Adaptable adaptable, Page targetPage) {
56 Resource targetResource = null;
57 if (targetPage != null) {
58 targetResource = targetPage.adaptTo(Resource.class);
59 }
60 return getUrlConfigForTarget(adaptable, targetResource);
61 }
62
63
64
65
66
67
68
69 protected UrlConfig getUrlConfigForTarget(Adaptable adaptable, Resource targetResource) {
70 UrlConfig config = null;
71 if (targetResource != null) {
72 config = new UrlConfig(targetResource);
73 }
74 if (config == null || !config.isValid()) {
75 config = new UrlConfig(adaptable);
76 }
77 return config;
78 }
79
80 }