1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.connector.fckeditor;
18
19 import java.text.SimpleDateFormat;
20
21 import javax.jcr.Node;
22
23 import org.exoplatform.commons.utils.ISO8601;
24 import org.exoplatform.container.ExoContainer;
25 import org.exoplatform.services.cms.templates.TemplateService;
26 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
27 import org.w3c.dom.Document;
28 import org.w3c.dom.Element;
29
30
31
32
33
34
35 public class FCKFileHandler {
36
37 private TemplateService templateService;
38
39 private static final String[] IMAGE_MIMETYPE = {"image/gif", "image/jpeg", "image/bmp", "image/png", "image/tiff"};
40
41
42
43
44
45
46 public FCKFileHandler(ExoContainer container) {
47 templateService = WCMCoreUtils.getService(TemplateService.class);
48 }
49
50
51
52
53
54
55
56
57
58 public String getFileType(final Node node, final String resourceType) throws Exception {
59 if(FCKUtils.DOCUMENT_TYPE.equalsIgnoreCase(resourceType)) {
60 return getDocumentType(node);
61 }else if(FCKUtils.IMAGE_TYPE.equalsIgnoreCase(resourceType)) {
62 return getImageType(node);
63 }else if(FCKUtils.FLASH_TYPE.equalsIgnoreCase(resourceType)) {
64 return getFlashType(node);
65 }else if(FCKUtils.LINK_TYPE.equalsIgnoreCase(resourceType)) {
66 return getLinkType(node);
67 }
68 return null;
69 }
70
71
72
73
74
75
76
77
78 protected String getFileURL(final Node file) throws Exception {
79 return FCKUtils.createWebdavURL(file);
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93 public Element createFileElement(Document document, Node child, String fileType) throws Exception {
94 Element file = document.createElement("File");
95 file.setAttribute("name", child.getName());
96 SimpleDateFormat formatter = new SimpleDateFormat(ISO8601.SIMPLE_DATETIME_FORMAT);
97 file.setAttribute("dateCreated", formatter.format(child.getProperty("exo:dateCreated").getDate().getTime()));
98 file.setAttribute("dateModified", formatter.format(child.getProperty("exo:dateModified").getDate().getTime()));
99 file.setAttribute("creator", child.getProperty("exo:owner").getString());
100 file.setAttribute("fileType", fileType);
101 file.setAttribute("url",getFileURL(child));
102 if(child.isNodeType(FCKUtils.NT_FILE)) {
103 long size = child.getNode("jcr:content").getProperty("jcr:data").getLength();
104 file.setAttribute("size", "" + size / 1000);
105 }else {
106 file.setAttribute("size", "");
107 }
108 return file;
109 }
110
111
112
113
114
115
116
117
118 protected String getDocumentType(final Node node) throws Exception {
119 if (node.isNodeType("exo:presentationable"))
120 return node.getProperty("exo:presentationType").getString();
121 String primaryType = node.getPrimaryNodeType().getName();
122 if (templateService.getDocumentTemplates().contains(primaryType))
123 return primaryType;
124 return null;
125 }
126
127
128
129
130
131
132
133
134 protected String getImageType(final Node node) throws Exception {
135 if(node.isNodeType("nt:file")) {
136 String mimeType = node.getNode("jcr:content").getProperty("jcr:mimeType").getString();
137 for(String s:IMAGE_MIMETYPE) {
138 if(s.equals(mimeType)) {
139 return node.getPrimaryNodeType().getName();
140 }
141 }
142 }
143 return null;
144 }
145
146
147
148
149
150
151
152
153 protected String getFlashType(final Node node) throws Exception {
154 return null;
155 }
156
157
158
159
160
161
162
163
164 protected String getLinkType(final Node node) throws Exception {
165 return "exo:link";
166 }
167
168 }