1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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  /**
41   * <a href="DLServiceImpl.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   * @author Michael Young
45   *
46   */
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, long fileEntryId, String properties,
84              Date modifiedDate, String[] tagsCategories, String[] tagsEntries,
85              File file)
86          throws PortalException, SystemException {
87  
88          dlLocalService.validate(fileName, file);
89  
90          Hook hook = HookFactory.getInstance();
91  
92          hook.addFile(
93              companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
94              properties, modifiedDate, tagsCategories, tagsEntries, file);
95      }
96  
97      public void addFile(
98              long companyId, String portletId, long groupId, long repositoryId,
99              String fileName, long fileEntryId, String properties,
100             Date modifiedDate, String[] tagsCategories, String[] tagsEntries,
101             byte[] bytes)
102         throws PortalException, SystemException {
103 
104         dlLocalService.validate(fileName, bytes);
105 
106         Hook hook = HookFactory.getInstance();
107 
108         hook.addFile(
109             companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
110             properties, modifiedDate, tagsCategories, tagsEntries, bytes);
111     }
112 
113     public void deleteDirectory(
114             long companyId, String portletId, long repositoryId, String dirName)
115         throws PortalException, SystemException {
116 
117         Hook hook = HookFactory.getInstance();
118 
119         hook.deleteDirectory(companyId, portletId, repositoryId, dirName);
120     }
121 
122     public void deleteFile(
123             long companyId, String portletId, long repositoryId,
124             String fileName)
125         throws PortalException, SystemException {
126 
127         Hook hook = HookFactory.getInstance();
128 
129         hook.deleteFile(companyId, portletId, repositoryId, fileName);
130     }
131 
132     public void deleteFile(
133             long companyId, String portletId, long repositoryId,
134             String fileName, double versionNumber)
135         throws PortalException, SystemException {
136 
137         Hook hook = HookFactory.getInstance();
138 
139         hook.deleteFile(
140             companyId, portletId, repositoryId, fileName, versionNumber);
141     }
142 
143     public byte[] getFile(long companyId, long repositoryId, String fileName)
144         throws PortalException, SystemException {
145 
146         Hook hook = HookFactory.getInstance();
147 
148         return hook.getFile(companyId, repositoryId, fileName);
149     }
150 
151     public byte[] getFile(
152             long companyId, long repositoryId, String fileName,
153             double versionNumber)
154         throws PortalException, SystemException {
155 
156         Hook hook = HookFactory.getInstance();
157 
158         return hook.getFile(companyId, repositoryId, fileName, versionNumber);
159     }
160 
161     public String[] getFileNames(
162             long companyId, long repositoryId, String dirName)
163         throws PortalException, SystemException {
164 
165         Hook hook = HookFactory.getInstance();
166 
167         return hook.getFileNames(companyId, repositoryId, dirName);
168     }
169 
170     public long getFileSize(
171             long companyId, long repositoryId, String fileName)
172         throws PortalException, SystemException {
173 
174         Hook hook = HookFactory.getInstance();
175 
176         return hook.getFileSize(companyId, repositoryId, fileName);
177     }
178 
179     public void reIndex(String[] ids) throws SystemException {
180         try {
181             Indexer indexer = new Indexer();
182 
183             indexer.reIndex(ids);
184         }
185         catch (SearchException se) {
186             throw new SystemException(se);
187         }
188     }
189 
190     public void updateFile(
191             long companyId, String portletId, long groupId, long repositoryId,
192             String fileName, double versionNumber, String sourceFileName,
193             long fileEntryId, String properties, Date modifiedDate,
194             String[] tagsCategories, String[] tagsEntries, File file)
195         throws PortalException, SystemException {
196 
197         dlLocalService.validate(fileName, file);
198 
199         Hook hook = HookFactory.getInstance();
200 
201         hook.updateFile(
202             companyId, portletId, groupId, repositoryId, fileName,
203             versionNumber, sourceFileName, fileEntryId, properties,
204             modifiedDate, tagsCategories, tagsEntries, file);
205     }
206 
207     public void updateFile(
208             long companyId, String portletId, long groupId, long repositoryId,
209             String fileName, double versionNumber, String sourceFileName,
210             long fileEntryId, String properties, Date modifiedDate,
211             String[] tagsCategories, String[] tagsEntries, byte[] bytes)
212         throws PortalException, SystemException {
213 
214         dlLocalService.validate(fileName, bytes);
215 
216         Hook hook = HookFactory.getInstance();
217 
218         hook.updateFile(
219             companyId, portletId, groupId, repositoryId, fileName,
220             versionNumber, sourceFileName, fileEntryId, properties,
221             modifiedDate, tagsCategories, tagsEntries, bytes);
222     }
223 
224     public void updateFile(
225             long companyId, String portletId, long groupId, long repositoryId,
226             long newRepositoryId, String fileName, long fileEntryId)
227         throws PortalException, SystemException {
228 
229         Hook hook = HookFactory.getInstance();
230 
231         hook.updateFile(
232             companyId, portletId, groupId, repositoryId, newRepositoryId,
233             fileName, fileEntryId);
234     }
235 
236     @BeanReference(name = _DL_LOCAL_SERVICE)
237     protected DLLocalService dlLocalService;
238 
239     private static final String _DL_LOCAL_SERVICE =
240         "com.liferay.documentlibrary.service.DLLocalService.impl";
241 
242 }