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