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              (dirName.indexOf("..\\") != -1) ||
65              (dirName.indexOf("../") != -1) ||
66              (dirName.indexOf("\\..") != -1) ||
67              (dirName.indexOf("/..") != -1)) {
68  
69              throw new DirectoryNameException(dirName);
70          }
71  
72          hook.addDirectory(companyId, repositoryId, dirName);
73      }
74  
75      public void addFile(
76              long companyId, String portletId, long groupId, long repositoryId,
77              String fileName, long fileEntryId, String properties,
78              Date modifiedDate, String[] tagsCategories, String[] tagsEntries,
79              File file)
80          throws PortalException, SystemException {
81  
82          dlLocalService.validate(fileName, file);
83  
84          hook.addFile(
85              companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
86              properties, modifiedDate, tagsCategories, tagsEntries, file);
87      }
88  
89      public void addFile(
90              long companyId, String portletId, long groupId, long repositoryId,
91              String fileName, long fileEntryId, String properties,
92              Date modifiedDate, String[] tagsCategories, String[] tagsEntries,
93              byte[] bytes)
94          throws PortalException, SystemException {
95  
96          dlLocalService.validate(fileName, bytes);
97  
98          hook.addFile(
99              companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
100             properties, modifiedDate, tagsCategories, tagsEntries, bytes);
101     }
102 
103     public void deleteDirectory(
104             long companyId, String portletId, long repositoryId, String dirName)
105         throws PortalException, SystemException {
106 
107         hook.deleteDirectory(companyId, portletId, repositoryId, dirName);
108     }
109 
110     public void deleteFile(
111             long companyId, String portletId, long repositoryId,
112             String fileName)
113         throws PortalException, SystemException {
114 
115         hook.deleteFile(companyId, portletId, repositoryId, fileName);
116     }
117 
118     public void deleteFile(
119             long companyId, String portletId, long repositoryId,
120             String fileName, double versionNumber)
121         throws PortalException, SystemException {
122 
123         hook.deleteFile(
124             companyId, portletId, repositoryId, fileName, versionNumber);
125     }
126 
127     public byte[] getFile(long companyId, long repositoryId, String fileName)
128         throws PortalException, SystemException {
129 
130         return hook.getFile(companyId, repositoryId, fileName);
131     }
132 
133     public byte[] getFile(
134             long companyId, long repositoryId, String fileName,
135             double versionNumber)
136         throws PortalException, SystemException {
137 
138         return hook.getFile(companyId, repositoryId, fileName, versionNumber);
139     }
140 
141     public String[] getFileNames(
142             long companyId, long repositoryId, String dirName)
143         throws PortalException, SystemException {
144 
145         return hook.getFileNames(companyId, repositoryId, dirName);
146     }
147 
148     public long getFileSize(
149             long companyId, long repositoryId, String fileName)
150         throws PortalException, SystemException {
151 
152         return hook.getFileSize(companyId, repositoryId, fileName);
153     }
154 
155     public void reIndex(String[] ids) throws SystemException {
156         try {
157             Indexer indexer = new Indexer();
158 
159             indexer.reIndex(ids);
160         }
161         catch (SearchException se) {
162             throw new SystemException(se);
163         }
164     }
165 
166     public void updateFile(
167             long companyId, String portletId, long groupId, long repositoryId,
168             String fileName, double versionNumber, String sourceFileName,
169             long fileEntryId, String properties, Date modifiedDate,
170             String[] tagsCategories, String[] tagsEntries, File file)
171         throws PortalException, SystemException {
172 
173         dlLocalService.validate(fileName, file);
174 
175         hook.updateFile(
176             companyId, portletId, groupId, repositoryId, fileName,
177             versionNumber, sourceFileName, fileEntryId, properties,
178             modifiedDate, tagsCategories, tagsEntries, file);
179     }
180 
181     public void updateFile(
182             long companyId, String portletId, long groupId, long repositoryId,
183             String fileName, double versionNumber, String sourceFileName,
184             long fileEntryId, String properties, Date modifiedDate,
185             String[] tagsCategories, String[] tagsEntries, byte[] bytes)
186         throws PortalException, SystemException {
187 
188         dlLocalService.validate(fileName, bytes);
189 
190         hook.updateFile(
191             companyId, portletId, groupId, repositoryId, fileName,
192             versionNumber, sourceFileName, fileEntryId, properties,
193             modifiedDate, tagsCategories, tagsEntries, bytes);
194     }
195 
196     public void updateFile(
197             long companyId, String portletId, long groupId, long repositoryId,
198             long newRepositoryId, String fileName, long fileEntryId)
199         throws PortalException, SystemException {
200 
201         hook.updateFile(
202             companyId, portletId, groupId, repositoryId, newRepositoryId,
203             fileName, fileEntryId);
204     }
205 
206     @BeanReference(type = DLLocalService.class)
207     protected DLLocalService dlLocalService;
208 
209     @BeanReference(type = Hook.class)
210     protected Hook hook;
211 
212 }