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