1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.wcm.connector.fckeditor;
18
19 import javax.jcr.Node;
20
21 import org.exoplatform.container.ExoContainerContext;
22 import org.exoplatform.ecm.connector.fckeditor.FCKFileHandler;
23 import org.exoplatform.services.jcr.access.AccessControlEntry;
24 import org.exoplatform.services.jcr.access.AccessControlList;
25 import org.exoplatform.services.jcr.access.PermissionType;
26 import org.exoplatform.services.jcr.core.ExtendedNode;
27 import org.exoplatform.services.jcr.core.ManageableRepository;
28 import org.exoplatform.services.security.IdentityConstants;
29 import org.exoplatform.services.wcm.core.NodetypeConstant;
30 import org.exoplatform.services.wcm.core.WCMConfigurationService;
31 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
32
33
34
35
36
37
38
39
40 public class DocumentLinkHandler extends FCKFileHandler {
41
42
43 private String baseURI;
44
45
46 private String currentPortal;
47
48
49
50
51 public DocumentLinkHandler() {
52 super(ExoContainerContext.getCurrentContainer());
53 }
54
55
56
57
58
59
60 public void setBaseURI(String baseURI) {
61 this.baseURI = baseURI;
62 }
63
64
65
66
67 public String getFileURL(final Node node) throws Exception {
68 String accessMode = "private";
69 AccessControlList acl = ((ExtendedNode) node).getACL();
70 for (AccessControlEntry entry : acl.getPermissionEntries()) {
71 if (entry.getIdentity().equalsIgnoreCase(IdentityConstants.ANY)
72 && entry.getPermission().equalsIgnoreCase(PermissionType.READ)) {
73 accessMode = "public";
74 break;
75 }
76 }
77 String repository = ((ManageableRepository) node.getSession().getRepository()).getConfiguration()
78 .getName();
79 String workspace = node.getSession().getWorkspace().getName();
80 String nodePath = node.getPath();
81 StringBuilder builder = new StringBuilder();
82 if (node.isNodeType(NodetypeConstant.NT_FILE)) {
83 if ("public".equals(accessMode)) {
84 return builder.append(baseURI)
85 .append("/jcr/")
86 .append(repository)
87 .append("/")
88 .append(workspace)
89 .append(nodePath)
90 .toString();
91 }
92 return builder.append(baseURI)
93 .append("/private/jcr/")
94 .append(repository)
95 .append("/")
96 .append(workspace)
97 .append(nodePath)
98 .toString();
99 }
100 WCMConfigurationService configurationService = WCMCoreUtils.getService(WCMConfigurationService.class);
101 String parameterizedPageViewerURI = configurationService.
102 getRuntimeContextParam(WCMConfigurationService.PARAMETERIZED_PAGE_URI);
103 return baseURI.replace("/rest", "") + "/" + accessMode + "/" + currentPortal
104 + parameterizedPageViewerURI + "/" + repository + "/" + workspace + nodePath;
105 }
106
107
108
109
110
111
112 public void setCurrentPortal(String currentPortal) {
113 this.currentPortal = currentPortal;
114 }
115
116
117
118
119
120
121 public String getCurrentPortal() {
122 return this.currentPortal;
123 }
124 }