1
22
23 package com.liferay.portal.webdav;
24
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portal.kernel.util.StringUtil;
28 import com.liferay.util.FileUtil;
29
30 import java.io.IOException;
31
32 import javax.servlet.http.HttpServletRequest;
33
34 import org.apache.commons.logging.Log;
35 import org.apache.commons.logging.LogFactory;
36
37
43 public class WebDAVUtil {
44
45 public static final int SC_MULTI_STATUS = 207;
46
47 public static String fixPath(String path) {
48 if (path.endsWith(StringPool.SLASH)) {
49 path = path.substring(0, path.length() - 1);
50 }
51
52 return path;
53 }
54
55 public static long getCompanyId(String path) {
56 String[] pathArray = getPathArray(path);
57
58 if (pathArray.length <= 0) {
59 return 0;
60 }
61 else {
62 return GetterUtil.getLong(pathArray[0]);
63 }
64 }
65
66 public static String getDestination(HttpServletRequest req) {
67 String destination = req.getHeader("Destination");
68
69 if (_log.isDebugEnabled()) {
70 _log.debug("Destination " + destination);
71 }
72
73 return destination;
74 }
75
76 public static long getGroupId(String path) {
77 String[] pathArray = getPathArray(path);
78
79 if (pathArray.length <= 1) {
80 return 0;
81 }
82 else {
83 return GetterUtil.getLong(pathArray[1]);
84 }
85 }
86
87 public static String[] getPathArray(String path) {
88 if (path.startsWith(StringPool.SLASH)) {
89 path = path.substring(1, path.length());
90 }
91
92 return StringUtil.split(path, StringPool.SLASH);
93 }
94
95 public static String getRequestXML(HttpServletRequest req)
96 throws IOException {
97
98 String xml = new String(FileUtil.getBytes(req.getInputStream()));
99
100 if (_log.isDebugEnabled()) {
101 _log.debug("Request XML\n" + xml);
102 }
103
104 return xml;
105 }
106
107 public static boolean isGroupPath(String path) {
108 String[] pathArray = getPathArray(path);
109
110 if (pathArray.length == 2) {
111 return true;
112 }
113 else {
114 return false;
115 }
116 }
117
118 private static Log _log = LogFactory.getLog(WebDAVUtil.class);
119
120 }