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.link;
35
36 import info.magnolia.cms.beans.config.ServerConfiguration;
37 import info.magnolia.cms.beans.runtime.File;
38 import info.magnolia.cms.core.Content;
39 import info.magnolia.cms.core.ItemType;
40 import info.magnolia.cms.core.NodeData;
41
42 import javax.jcr.PropertyType;
43
44 import org.apache.commons.lang.StringUtils;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48
49
50
51
52
53 public class Link {
54
55 private static final Logger log = LoggerFactory.getLogger(Link.class);
56
57 private String repository;
58 private String handle;
59 private String uuid;
60 private String nodeDataName;
61 private String extension;
62 private Content node;
63 private NodeData nodeData;
64 private String fileName;
65 private String fallbackHandle;
66 private String anchor;
67 private String parameters;
68
69
70
71
72 public Link() {
73 }
74
75
76
77
78 public Link(Content content) {
79 setNode(content);
80 setRepository(content.getHierarchyManager().getName());
81
82 if (content.isNodeType(ItemType.MIX_REFERENCEABLE)) {
83 setUUID(content.getUUID());
84 }
85 }
86
87 public Link(String repoName, Content parent, NodeData nodedata) {
88 setNode(parent);
89 setRepository(repoName);
90 setNodeData(nodedata);
91 setNodeDataName(nodedata.getName());
92 }
93
94 public String getExtension() {
95 if(StringUtils.isEmpty(this.extension) && this.getNodeData() != null && this.getNodeData().getType() == PropertyType.BINARY){
96 File binary = new File(nodeData);
97 extension = binary.getExtension();
98 }
99 return StringUtils.defaultIfEmpty(this.extension, ServerConfiguration.getInstance().getDefaultExtension());
100 }
101
102
103 public void setExtension(String extension) {
104 this.extension = extension;
105 }
106
107
108 public String getFileName() {
109 if(StringUtils.isEmpty(this.fileName) && this.getNodeData() != null && this.getNodeData().getType() == PropertyType.BINARY){
110 File binary = new File(nodeData);
111 fileName = binary.getFileName();
112 }
113 return fileName;
114 }
115
116
117 public void setFileName(String fileName) {
118 this.fileName = fileName;
119 }
120
121 public Content getNode() {
122 return this.node;
123 }
124
125
126 public void setNode(Content node) {
127 this.node = node;
128 }
129
130 public NodeData getNodeData() {
131 if(this.nodeData == null && StringUtils.isNotEmpty(this.nodeDataName) && this.getNode() != null){
132 this.nodeData = this.getNode().getNodeData(this.nodeDataName);
133 }
134 return this.nodeData;
135 }
136
137 public void setNodeData(NodeData nodeData) {
138 this.nodeData = nodeData;
139 }
140
141 public String getNodeDataName() {
142 return this.nodeDataName;
143 }
144
145 public void setNodeDataName(String nodeDataName) {
146 this.nodeDataName = nodeDataName;
147 }
148
149 public String getHandle() {
150 if(StringUtils.isEmpty(this.handle)){
151 if(getNode() != null){
152 handle = getNode().getHandle();
153 } else {
154 handle = this.getFallbackHandle();
155 }
156 }
157 return this.handle;
158 }
159
160 public void setHandle(String path) {
161 this.handle = path;
162 }
163
164 public String getRepository() {
165 return this.repository;
166 }
167
168 public void setRepository(String repository) {
169 this.repository = repository;
170 }
171
172 public String getUUID() {
173 if(StringUtils.isEmpty(this.uuid) && this.getNode() != null){
174 this.uuid = this.getNode().getUUID();
175 }
176 return this.uuid;
177 }
178
179 public void setUUID(String uuid) {
180 this.uuid = uuid;
181 }
182
183 public String getFallbackHandle() {
184 return this.fallbackHandle;
185 }
186
187 public void setFallbackHandle(String fallbackPath) {
188 this.fallbackHandle = fallbackPath;
189 }
190
191 public String getAnchor() {
192 return this.anchor;
193 }
194
195 public void setAnchor(String anchor) {
196 this.anchor = anchor;
197 }
198
199 public String getParameters() {
200 return this.parameters;
201 }
202
203 public void setParameters(String parameters) {
204 this.parameters = parameters;
205 }
206 }