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.security.AccessControlException;
20
21 import javax.jcr.Node;
22 import javax.xml.parsers.DocumentBuilder;
23 import javax.xml.parsers.DocumentBuilderFactory;
24
25 import org.exoplatform.container.PortalContainer;
26 import org.exoplatform.container.xml.PortalContainerInfo;
27 import org.exoplatform.services.jcr.access.PermissionType;
28 import org.exoplatform.services.jcr.core.ExtendedNode;
29 import org.exoplatform.services.jcr.core.ManageableRepository;
30 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
31 import org.w3c.dom.Document;
32 import org.w3c.dom.Element;
33
34
35
36
37
38
39
40 public class FCKUtils {
41
42
43 public static final String LAST_MODIFIED_PROPERTY = "Last-Modified";
44
45
46 public static final String IF_MODIFIED_SINCE_DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss z";
47
48 public static String GET_FOLDERS_AND_FILES="getFoldersAndFiles";
49 public static String CREATE_FOLDER = "createFolder";
50 public static String UPLOAD_FILE = "upload";
51
52 public static final String EXO_HIDDENABLE = "exo:hiddenable";
53 public static final String NT_FILE = "nt:file";
54 public static final String NT_FOLDER = "nt:folder";
55 public static final String NT_UNSTRUCTURED = "nt:unstructured";
56
57 public final static String DOCUMENT_TYPE = "file";
58
59
60 public final static String IMAGE_TYPE = "image";
61 public final static String FLASH_TYPE = "flash";
62 public final static String LINK_TYPE = "link";
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 public static Element createRootElement(String command, Node node, String folderType) throws Exception {
81 Document doc = null;
82 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
83 DocumentBuilder builder = factory.newDocumentBuilder();
84 doc = builder.newDocument();
85 StringBuffer currentPath = new StringBuffer(node.getPath());
86 if (!currentPath.toString().endsWith("/")) {
87 currentPath.append("/");
88 }
89 Element rootElement = doc.createElement("Connector");
90 doc.appendChild(rootElement);
91 rootElement.setAttribute("command", command);
92 rootElement.setAttribute("resourceType", "Node");
93 Element currentFolderElement = doc.createElement("CurrentFolder");
94 currentFolderElement.setAttribute("name", node.getName());
95 currentFolderElement.setAttribute("folderType", folderType);
96 currentFolderElement.setAttribute("path", currentPath.toString());
97 currentFolderElement.setAttribute("url", createWebdavURL(node));
98 rootElement.appendChild(currentFolderElement);
99 return rootElement;
100 }
101
102 public static boolean hasAddNodePermission(Node node) throws Exception {
103 try {
104 ((ExtendedNode)node).checkPermission(PermissionType.ADD_NODE) ;
105 return true ;
106 } catch (AccessControlException e) {
107 return false ;
108 }
109 }
110
111 public static String getPortalName() {
112 PortalContainerInfo containerInfo = WCMCoreUtils.getService(PortalContainerInfo.class) ;
113 return containerInfo.getContainerName() ;
114 }
115
116 public static String createWebdavURL(final Node node) throws Exception {
117 String repository = ((ManageableRepository) node.getSession().getRepository()).getConfiguration().getName();
118 String workspace = node.getSession().getWorkspace().getName();
119 String currentPath = node.getPath();
120 String url = "/" + getPortalName() + "/" + PortalContainer.getCurrentRestContextName()
121 + "/jcr/" + repository + "/" + workspace + currentPath;
122 return url;
123 }
124 }