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.templatingkit.templates.components;
35
36
37 import info.magnolia.jcr.util.PropertyUtil;
38 import info.magnolia.module.templatingkit.functions.STKTemplatingFunctions;
39 import info.magnolia.module.templatingkit.templates.AbstractSTKTemplateModel;
40 import info.magnolia.rendering.model.RenderingModel;
41 import info.magnolia.rendering.template.TemplateDefinition;
42 import info.magnolia.repository.RepositoryConstants;
43 import info.magnolia.templating.functions.TemplatingFunctions;
44
45 import javax.inject.Inject;
46 import javax.jcr.Node;
47 import javax.jcr.RepositoryException;
48
49 import org.apache.commons.lang3.StringUtils;
50
51
52
53
54
55
56 public class InternalLinkModel<RD extends TemplateDefinition> extends AbstractSTKTemplateModel<TemplateDefinition> {
57
58 @Inject
59 public InternalLinkModel(Node content, RD definition, RenderingModel<?> parent, STKTemplatingFunctions stkFunctions, TemplatingFunctions templatingFunctions) {
60 super(content, definition, parent, stkFunctions, templatingFunctions);
61 }
62
63 public String getLink() {
64 return templatingFunctions.link(RepositoryConstants.WEBSITE, PropertyUtil.getString(content, "link"));
65 }
66
67 public String getLinkTitle() {
68 String linkTitle = PropertyUtil.getString(content, "linkTitle", StringUtils.EMPTY);
69 if (!linkTitle.equals(StringUtils.EMPTY)) {
70 return linkTitle;
71 }
72 Node linkNode = getLinkNode();
73 String pageTitle = PropertyUtil.getString(linkNode, "title", StringUtils.EMPTY);
74 if (!pageTitle.equals(StringUtils.EMPTY)) {
75 return pageTitle;
76 } else {
77 String pageName = StringUtils.EMPTY;
78 try {
79 pageName = getLinkNode().getName();
80 } catch (RepositoryException e) {
81 }
82 return pageName;
83 }
84 }
85
86 protected Node getLinkNode() {
87 try {
88 return stkFunctions.getReferencedContent(content, "link", RepositoryConstants.WEBSITE);
89 } catch (RepositoryException e) {
90 return null;
91 }
92 }
93 }