1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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.portal.kernel.annotation.BeanReference;
22  import com.liferay.portal.kernel.exception.PortalException;
23  import com.liferay.portal.kernel.exception.SystemException;
24  import com.liferay.portal.service.ServiceContext;
25  
26  import java.io.File;
27  
28  import java.util.Date;
29  
30  /**
31   * <a href="DLServiceImpl.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   * @author Michael Young
35   */
36  public class DLServiceImpl implements DLService {
37  
38      public static final String GROUP_NAME = DLServiceImpl.class.getName();
39  
40      public static final String[] GROUP_NAME_ARRAY = new String[] {GROUP_NAME};
41  
42      public void addDirectory(long companyId, long repositoryId, String dirName)
43          throws PortalException, SystemException {
44  
45          if ((dirName == null || dirName.equals("/")) ||
46              (dirName.indexOf("\\\\") != -1) ||
47              (dirName.indexOf("//") != -1) ||
48              (dirName.indexOf(":") != -1) ||
49              (dirName.indexOf("*") != -1) ||
50              (dirName.indexOf("?") != -1) ||
51              (dirName.indexOf("\"") != -1) ||
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  
63              throw new DirectoryNameException(dirName);
64          }
65  
66          hook.addDirectory(companyId, repositoryId, dirName);
67      }
68  
69      public void addFile(
70              long companyId, String portletId, long groupId, long repositoryId,
71              String fileName, long fileEntryId, String properties,
72              Date modifiedDate, ServiceContext serviceContext, byte[] bytes)
73          throws PortalException, SystemException {
74  
75          dlLocalService.validate(fileName, true, bytes);
76  
77          hook.addFile(
78              companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
79              properties, modifiedDate, serviceContext, bytes);
80      }
81  
82      public void addFile(
83              long companyId, String portletId, long groupId, long repositoryId,
84              String fileName, long fileEntryId, String properties,
85              Date modifiedDate, ServiceContext serviceContext, File file)
86          throws PortalException, SystemException {
87  
88          dlLocalService.validate(fileName, true, file);
89  
90          hook.addFile(
91              companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
92              properties, modifiedDate, serviceContext, file);
93      }
94  
95      public void deleteDirectory(
96              long companyId, String portletId, long repositoryId, String dirName)
97          throws PortalException, SystemException {
98  
99          hook.deleteDirectory(companyId, portletId, repositoryId, dirName);
100     }
101 
102     public void deleteFile(
103             long companyId, String portletId, long repositoryId,
104             String fileName)
105         throws PortalException, SystemException {
106 
107         hook.deleteFile(companyId, portletId, repositoryId, fileName);
108     }
109 
110     public void deleteFile(
111             long companyId, String portletId, long repositoryId,
112             String fileName, String versionNumber)
113         throws PortalException, SystemException {
114 
115         hook.deleteFile(
116             companyId, portletId, repositoryId, fileName, versionNumber);
117     }
118 
119     public byte[] getFile(long companyId, long repositoryId, String fileName)
120         throws PortalException, SystemException {
121 
122         return hook.getFile(companyId, repositoryId, fileName);
123     }
124 
125     public byte[] getFile(
126             long companyId, long repositoryId, String fileName,
127             String versionNumber)
128         throws PortalException, SystemException {
129 
130         return hook.getFile(companyId, repositoryId, fileName, versionNumber);
131     }
132 
133     public String[] getFileNames(
134             long companyId, long repositoryId, String dirName)
135         throws PortalException, SystemException {
136 
137         return hook.getFileNames(companyId, repositoryId, dirName);
138     }
139 
140     public long getFileSize(
141             long companyId, long repositoryId, String fileName)
142         throws PortalException, SystemException {
143 
144         return hook.getFileSize(companyId, repositoryId, fileName);
145     }
146 
147     public void updateFile(
148             long companyId, String portletId, long groupId, long repositoryId,
149             long newRepositoryId, String fileName, long fileEntryId)
150         throws PortalException, SystemException {
151 
152         hook.updateFile(
153             companyId, portletId, groupId, repositoryId, newRepositoryId,
154             fileName, fileEntryId);
155     }
156 
157     public void updateFile(
158             long companyId, String portletId, long groupId, long repositoryId,
159             String fileName, String versionNumber, String sourceFileName,
160             long fileEntryId, String properties, Date modifiedDate,
161             ServiceContext serviceContext, byte[] bytes)
162         throws PortalException, SystemException {
163 
164         dlLocalService.validate(fileName, true, bytes);
165 
166         hook.updateFile(
167             companyId, portletId, groupId, repositoryId, fileName,
168             versionNumber, sourceFileName, fileEntryId, properties,
169             modifiedDate, serviceContext, bytes);
170     }
171 
172     public void updateFile(
173             long companyId, String portletId, long groupId, long repositoryId,
174             String fileName, String versionNumber, String sourceFileName,
175             long fileEntryId, String properties, Date modifiedDate,
176             ServiceContext serviceContext, File file)
177         throws PortalException, SystemException {
178 
179         dlLocalService.validate(fileName, true, file);
180 
181         hook.updateFile(
182             companyId, portletId, groupId, repositoryId, fileName,
183             versionNumber, sourceFileName, fileEntryId, properties,
184             modifiedDate, serviceContext, file);
185     }
186 
187     public void updateFile(
188             long companyId, String portletId, long groupId, long repositoryId,
189             String fileName, String newFileName, boolean reindex)
190         throws PortalException, SystemException {
191 
192         hook.updateFile(
193             companyId, portletId, groupId, repositoryId, fileName, newFileName,
194             reindex);
195     }
196 
197     @BeanReference(type = DLLocalService.class)
198     protected DLLocalService dlLocalService;
199 
200     @BeanReference(type = Hook.class)
201     protected Hook hook;
202 
203 }