1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.documentlibrary.service.impl;
16  
17  import com.liferay.documentlibrary.DirectoryNameException;
18  import com.liferay.documentlibrary.service.DLLocalService;
19  import com.liferay.documentlibrary.service.DLService;
20  import com.liferay.documentlibrary.util.Hook;
21  import com.liferay.documentlibrary.util.Indexer;
22  import com.liferay.portal.PortalException;
23  import com.liferay.portal.SystemException;
24  import com.liferay.portal.kernel.annotation.BeanReference;
25  import com.liferay.portal.kernel.search.SearchException;
26  
27  import java.io.File;
28  
29  import java.util.Date;
30  
31  /**
32   * <a href="DLServiceImpl.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   * @author Michael Young
36   */
37  public class DLServiceImpl implements DLService {
38  
39      public static final String GROUP_NAME = DLServiceImpl.class.getName();
40  
41      public static final String[] GROUP_NAME_ARRAY = new String[] { GROUP_NAME };
42  
43      /**
44       * @deprecated
45       */
46      public static final String VERSION = "_VERSION_";
47  
48      public void addDirectory(long companyId, long repositoryId, String dirName)
49          throws PortalException, SystemException {
50  
51          if ((dirName == null || dirName.equals("/")) ||
52              (dirName.indexOf("\\\\") != -1) ||
53              (dirName.indexOf("//") != -1) ||
54              (dirName.indexOf(":") != -1) ||
55              (dirName.indexOf("*") != -1) ||
56              (dirName.indexOf("?") != -1) ||
57              (dirName.indexOf("\"") != -1) ||
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  
65              throw new DirectoryNameException(dirName);
66          }
67  
68          hook.addDirectory(companyId, repositoryId, dirName);
69      }
70  
71      public void addFile(
72              long companyId, String portletId, long groupId, long repositoryId,
73              String fileName, long fileEntryId, String properties,
74              Date modifiedDate, String[] tagsCategories, String[] tagsEntries,
75              File file)
76          throws PortalException, SystemException {
77  
78          dlLocalService.validate(fileName, file);
79  
80          hook.addFile(
81              companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
82              properties, modifiedDate, tagsCategories, tagsEntries, file);
83      }
84  
85      public void addFile(
86              long companyId, String portletId, long groupId, long repositoryId,
87              String fileName, long fileEntryId, String properties,
88              Date modifiedDate, String[] tagsCategories, String[] tagsEntries,
89              byte[] bytes)
90          throws PortalException, SystemException {
91  
92          dlLocalService.validate(fileName, bytes);
93  
94          hook.addFile(
95              companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
96              properties, modifiedDate, tagsCategories, tagsEntries, bytes);
97      }
98  
99      public void deleteDirectory(
100             long companyId, String portletId, long repositoryId, String dirName)
101         throws PortalException, SystemException {
102 
103         hook.deleteDirectory(companyId, portletId, repositoryId, dirName);
104     }
105 
106     public void deleteFile(
107             long companyId, String portletId, long repositoryId,
108             String fileName)
109         throws PortalException, SystemException {
110 
111         hook.deleteFile(companyId, portletId, repositoryId, fileName);
112     }
113 
114     public void deleteFile(
115             long companyId, String portletId, long repositoryId,
116             String fileName, double versionNumber)
117         throws PortalException, SystemException {
118 
119         hook.deleteFile(
120             companyId, portletId, repositoryId, fileName, versionNumber);
121     }
122 
123     public byte[] getFile(long companyId, long repositoryId, String fileName)
124         throws PortalException, SystemException {
125 
126         return hook.getFile(companyId, repositoryId, fileName);
127     }
128 
129     public byte[] getFile(
130             long companyId, long repositoryId, String fileName,
131             double versionNumber)
132         throws PortalException, SystemException {
133 
134         return hook.getFile(companyId, repositoryId, fileName, versionNumber);
135     }
136 
137     public String[] getFileNames(
138             long companyId, long repositoryId, String dirName)
139         throws PortalException, SystemException {
140 
141         return hook.getFileNames(companyId, repositoryId, dirName);
142     }
143 
144     public long getFileSize(
145             long companyId, long repositoryId, String fileName)
146         throws PortalException, SystemException {
147 
148         return hook.getFileSize(companyId, repositoryId, fileName);
149     }
150 
151     public void reIndex(String[] ids) throws SystemException {
152         try {
153             Indexer indexer = new Indexer();
154 
155             indexer.reIndex(ids);
156         }
157         catch (SearchException se) {
158             throw new SystemException(se);
159         }
160     }
161 
162     public void updateFile(
163             long companyId, String portletId, long groupId, long repositoryId,
164             String fileName, double versionNumber, String sourceFileName,
165             long fileEntryId, String properties, Date modifiedDate,
166             String[] tagsCategories, String[] tagsEntries, File file)
167         throws PortalException, SystemException {
168 
169         dlLocalService.validate(fileName, file);
170 
171         hook.updateFile(
172             companyId, portletId, groupId, repositoryId, fileName,
173             versionNumber, sourceFileName, fileEntryId, properties,
174             modifiedDate, tagsCategories, tagsEntries, file);
175     }
176 
177     public void updateFile(
178             long companyId, String portletId, long groupId, long repositoryId,
179             String fileName, double versionNumber, String sourceFileName,
180             long fileEntryId, String properties, Date modifiedDate,
181             String[] tagsCategories, String[] tagsEntries, byte[] bytes)
182         throws PortalException, SystemException {
183 
184         dlLocalService.validate(fileName, bytes);
185 
186         hook.updateFile(
187             companyId, portletId, groupId, repositoryId, fileName,
188             versionNumber, sourceFileName, fileEntryId, properties,
189             modifiedDate, tagsCategories, tagsEntries, bytes);
190     }
191 
192     public void updateFile(
193             long companyId, String portletId, long groupId, long repositoryId,
194             long newRepositoryId, String fileName, long fileEntryId)
195         throws PortalException, SystemException {
196 
197         hook.updateFile(
198             companyId, portletId, groupId, repositoryId, newRepositoryId,
199             fileName, fileEntryId);
200     }
201 
202     @BeanReference(type = DLLocalService.class)
203     protected DLLocalService dlLocalService;
204 
205     @BeanReference(type = Hook.class)
206     protected Hook hook;
207 
208 }