1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.documentlibrary.service.impl;
21  
22  import com.liferay.documentlibrary.DirectoryNameException;
23  import com.liferay.documentlibrary.service.DLLocalService;
24  import com.liferay.documentlibrary.service.DLService;
25  import com.liferay.documentlibrary.util.Hook;
26  import com.liferay.documentlibrary.util.HookFactory;
27  import com.liferay.documentlibrary.util.Indexer;
28  import com.liferay.portal.PortalException;
29  import com.liferay.portal.SystemException;
30  import com.liferay.portal.kernel.annotation.BeanReference;
31  import com.liferay.portal.kernel.search.SearchException;
32  
33  import java.io.File;
34  
35  import java.util.Date;
36  
37  /**
38   * <a href="DLServiceImpl.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author Brian Wing Shun Chan
41   * @author Michael Young
42   *
43   */
44  public class DLServiceImpl implements DLService {
45  
46      public static final String GROUP_NAME = DLServiceImpl.class.getName();
47  
48      public static final String[] GROUP_NAME_ARRAY = new String[] { GROUP_NAME };
49  
50      public static final String VERSION = "_VERSION_";
51  
52      public void addDirectory(long companyId, long repositoryId, String dirName)
53          throws PortalException, SystemException {
54  
55          if ((dirName == null || dirName.equals("/")) ||
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              (dirName.indexOf("'") != -1)) {
69  
70              throw new DirectoryNameException(dirName);
71          }
72  
73          Hook hook = HookFactory.getInstance();
74  
75          hook.addDirectory(companyId, repositoryId, dirName);
76      }
77  
78      public void addFile(
79              long companyId, String portletId, long groupId, long repositoryId,
80              String fileName, long fileEntryId, String properties,
81              Date modifiedDate, String[] tagsCategories, String[] tagsEntries,
82              File file)
83          throws PortalException, SystemException {
84  
85          dlLocalService.validate(fileName, file);
86  
87          Hook hook = HookFactory.getInstance();
88  
89          hook.addFile(
90              companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
91              properties, modifiedDate, tagsCategories, tagsEntries, file);
92      }
93  
94      public void addFile(
95              long companyId, String portletId, long groupId, long repositoryId,
96              String fileName, long fileEntryId, String properties,
97              Date modifiedDate, String[] tagsCategories, String[] tagsEntries,
98              byte[] bytes)
99          throws PortalException, SystemException {
100 
101         dlLocalService.validate(fileName, bytes);
102 
103         Hook hook = HookFactory.getInstance();
104 
105         hook.addFile(
106             companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
107             properties, modifiedDate, tagsCategories, tagsEntries, bytes);
108     }
109 
110     public void deleteDirectory(
111             long companyId, String portletId, long repositoryId, String dirName)
112         throws PortalException, SystemException {
113 
114         Hook hook = HookFactory.getInstance();
115 
116         hook.deleteDirectory(companyId, portletId, repositoryId, dirName);
117     }
118 
119     public void deleteFile(
120             long companyId, String portletId, long repositoryId,
121             String fileName)
122         throws PortalException, SystemException {
123 
124         Hook hook = HookFactory.getInstance();
125 
126         hook.deleteFile(companyId, portletId, repositoryId, fileName);
127     }
128 
129     public void deleteFile(
130             long companyId, String portletId, long repositoryId,
131             String fileName, double versionNumber)
132         throws PortalException, SystemException {
133 
134         Hook hook = HookFactory.getInstance();
135 
136         hook.deleteFile(
137             companyId, portletId, repositoryId, fileName, versionNumber);
138     }
139 
140     public byte[] getFile(long companyId, long repositoryId, String fileName)
141         throws PortalException, SystemException {
142 
143         Hook hook = HookFactory.getInstance();
144 
145         return hook.getFile(companyId, repositoryId, fileName);
146     }
147 
148     public byte[] getFile(
149             long companyId, long repositoryId, String fileName,
150             double versionNumber)
151         throws PortalException, SystemException {
152 
153         Hook hook = HookFactory.getInstance();
154 
155         return hook.getFile(companyId, repositoryId, fileName, versionNumber);
156     }
157 
158     public String[] getFileNames(
159             long companyId, long repositoryId, String dirName)
160         throws PortalException, SystemException {
161 
162         Hook hook = HookFactory.getInstance();
163 
164         return hook.getFileNames(companyId, repositoryId, dirName);
165     }
166 
167     public long getFileSize(
168             long companyId, long repositoryId, String fileName)
169         throws PortalException, SystemException {
170 
171         Hook hook = HookFactory.getInstance();
172 
173         return hook.getFileSize(companyId, repositoryId, fileName);
174     }
175 
176     public void reIndex(String[] ids) throws SystemException {
177         try {
178             Indexer indexer = new Indexer();
179 
180             indexer.reIndex(ids);
181         }
182         catch (SearchException se) {
183             throw new SystemException(se);
184         }
185     }
186 
187     public void updateFile(
188             long companyId, String portletId, long groupId, long repositoryId,
189             String fileName, double versionNumber, String sourceFileName,
190             long fileEntryId, String properties, Date modifiedDate,
191             String[] tagsCategories, String[] tagsEntries, File file)
192         throws PortalException, SystemException {
193 
194         dlLocalService.validate(fileName, file);
195 
196         Hook hook = HookFactory.getInstance();
197 
198         hook.updateFile(
199             companyId, portletId, groupId, repositoryId, fileName,
200             versionNumber, sourceFileName, fileEntryId, properties,
201             modifiedDate, tagsCategories, tagsEntries, file);
202     }
203 
204     public void updateFile(
205             long companyId, String portletId, long groupId, long repositoryId,
206             String fileName, double versionNumber, String sourceFileName,
207             long fileEntryId, String properties, Date modifiedDate,
208             String[] tagsCategories, String[] tagsEntries, byte[] bytes)
209         throws PortalException, SystemException {
210 
211         dlLocalService.validate(fileName, bytes);
212 
213         Hook hook = HookFactory.getInstance();
214 
215         hook.updateFile(
216             companyId, portletId, groupId, repositoryId, fileName,
217             versionNumber, sourceFileName, fileEntryId, properties,
218             modifiedDate, tagsCategories, tagsEntries, bytes);
219     }
220 
221     public void updateFile(
222             long companyId, String portletId, long groupId, long repositoryId,
223             long newRepositoryId, String fileName, long fileEntryId)
224         throws PortalException, SystemException {
225 
226         Hook hook = HookFactory.getInstance();
227 
228         hook.updateFile(
229             companyId, portletId, groupId, repositoryId, newRepositoryId,
230             fileName, fileEntryId);
231     }
232 
233     @BeanReference(name = _DL_LOCAL_SERVICE)
234     protected DLLocalService dlLocalService;
235 
236     private static final String _DL_LOCAL_SERVICE =
237         "com.liferay.documentlibrary.service.DLLocalService.impl";
238 
239 }