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