1
22
23 package com.liferay.documentlibrary.service.impl;
24
25 import com.liferay.documentlibrary.DirectoryNameException;
26 import com.liferay.documentlibrary.service.DLLocalService;
27 import com.liferay.documentlibrary.service.DLService;
28 import com.liferay.documentlibrary.util.Hook;
29 import com.liferay.documentlibrary.util.HookFactory;
30 import com.liferay.documentlibrary.util.Indexer;
31 import com.liferay.portal.PortalException;
32 import com.liferay.portal.SystemException;
33 import com.liferay.portal.kernel.annotation.BeanReference;
34 import com.liferay.portal.kernel.search.SearchException;
35
36 import java.io.File;
37
38 import java.util.Date;
39
40
47 public class DLServiceImpl implements DLService {
48
49 public static final String GROUP_NAME = DLServiceImpl.class.getName();
50
51 public static final String[] GROUP_NAME_ARRAY = new String[] { GROUP_NAME };
52
53 public static final String VERSION = "_VERSION_";
54
55 public void addDirectory(long companyId, long repositoryId, String dirName)
56 throws PortalException, SystemException {
57
58 if ((dirName == null || dirName.equals("/")) ||
59 (dirName.indexOf("\\\\") != -1) ||
60 (dirName.indexOf("//") != -1) ||
61 (dirName.indexOf(":") != -1) ||
62 (dirName.indexOf("*") != -1) ||
63 (dirName.indexOf("?") != -1) ||
64 (dirName.indexOf("\"") != -1) ||
65 (dirName.indexOf("<") != -1) ||
66 (dirName.indexOf(">") != -1) ||
67 (dirName.indexOf("|") != -1) ||
68 (dirName.indexOf("&") != -1) ||
69 (dirName.indexOf("[") != -1) ||
70 (dirName.indexOf("]") != -1) ||
71 (dirName.indexOf("'") != -1)) {
72
73 throw new DirectoryNameException(dirName);
74 }
75
76 Hook hook = HookFactory.getInstance();
77
78 hook.addDirectory(companyId, repositoryId, dirName);
79 }
80
81 public void addFile(
82 long companyId, String portletId, long groupId, long repositoryId,
83 String fileName, String properties, Date modifiedDate,
84 String[] tagsEntries, byte[] bytes)
85 throws PortalException, SystemException {
86
87 dlLocalService.validate(fileName, bytes);
88
89 Hook hook = HookFactory.getInstance();
90
91 hook.addFile(
92 companyId, portletId, groupId, repositoryId, fileName, properties,
93 modifiedDate, tagsEntries, bytes);
94 }
95
96 public void addFile(
97 long companyId, String portletId, long groupId, long repositoryId,
98 String fileName, String properties, Date modifiedDate,
99 String[] tagsEntries, File file)
100 throws PortalException, SystemException {
101
102 dlLocalService.validate(fileName, file);
103
104 Hook hook = HookFactory.getInstance();
105
106 hook.addFile(
107 companyId, portletId, groupId, repositoryId, fileName, properties,
108 modifiedDate, tagsEntries, file);
109 }
110
111 public void deleteDirectory(
112 long companyId, String portletId, long repositoryId, String dirName)
113 throws PortalException, SystemException {
114
115 Hook hook = HookFactory.getInstance();
116
117 hook.deleteDirectory(companyId, portletId, repositoryId, dirName);
118 }
119
120 public void deleteFile(
121 long companyId, String portletId, long repositoryId,
122 String fileName)
123 throws PortalException, SystemException {
124
125 Hook hook = HookFactory.getInstance();
126
127 hook.deleteFile(companyId, portletId, repositoryId, fileName);
128 }
129
130 public void deleteFile(
131 long companyId, String portletId, long repositoryId,
132 String fileName, double versionNumber)
133 throws PortalException, SystemException {
134
135 Hook hook = HookFactory.getInstance();
136
137 hook.deleteFile(
138 companyId, portletId, repositoryId, fileName, versionNumber);
139 }
140
141 public byte[] getFile(long companyId, long repositoryId, String fileName)
142 throws PortalException, SystemException {
143
144 Hook hook = HookFactory.getInstance();
145
146 return hook.getFile(companyId, repositoryId, fileName);
147 }
148
149 public byte[] getFile(
150 long companyId, long repositoryId, String fileName,
151 double versionNumber)
152 throws PortalException, SystemException {
153
154 Hook hook = HookFactory.getInstance();
155
156 return hook.getFile(companyId, repositoryId, fileName, versionNumber);
157 }
158
159 public String[] getFileNames(
160 long companyId, long repositoryId, String dirName)
161 throws PortalException, SystemException {
162
163 Hook hook = HookFactory.getInstance();
164
165 return hook.getFileNames(companyId, repositoryId, dirName);
166 }
167
168 public long getFileSize(
169 long companyId, long repositoryId, String fileName)
170 throws PortalException, SystemException {
171
172 Hook hook = HookFactory.getInstance();
173
174 return hook.getFileSize(companyId, repositoryId, fileName);
175 }
176
177 public void reIndex(String[] ids) throws SystemException {
178 try {
179 Indexer indexer = new Indexer();
180
181 indexer.reIndex(ids);
182 }
183 catch (SearchException se) {
184 throw new SystemException(se);
185 }
186 }
187
188 public void updateFile(
189 long companyId, String portletId, long groupId, long repositoryId,
190 String fileName, double versionNumber, String sourceFileName,
191 String properties, Date modifiedDate, String[] tagsEntries,
192 byte[] bytes)
193 throws PortalException, SystemException {
194
195 dlLocalService.validate(fileName, bytes);
196
197 Hook hook = HookFactory.getInstance();
198
199 hook.updateFile(
200 companyId, portletId, groupId, repositoryId, fileName,
201 versionNumber, sourceFileName, properties, modifiedDate,
202 tagsEntries, bytes);
203 }
204
205 public void updateFile(
206 long companyId, String portletId, long groupId, long repositoryId,
207 String fileName, double versionNumber, String sourceFileName,
208 String properties, Date modifiedDate, String[] tagsEntries,
209 File file)
210 throws PortalException, SystemException {
211
212 dlLocalService.validate(fileName, file);
213
214 Hook hook = HookFactory.getInstance();
215
216 hook.updateFile(
217 companyId, portletId, groupId, repositoryId, fileName,
218 versionNumber, sourceFileName, properties, modifiedDate,
219 tagsEntries, file);
220 }
221
222 public void updateFile(
223 long companyId, String portletId, long groupId, long repositoryId,
224 long newRepositoryId, String fileName)
225 throws PortalException, SystemException {
226
227 Hook hook = HookFactory.getInstance();
228
229 hook.updateFile(
230 companyId, portletId, groupId, repositoryId, newRepositoryId,
231 fileName);
232 }
233
234 @BeanReference(name = _DL_LOCAL_SERVICE)
235 protected DLLocalService dlLocalService;
236
237 private static final String _DL_LOCAL_SERVICE =
238 "com.liferay.documentlibrary.service.DLLocalService.impl";
239
240 }