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, String properties, Date modifiedDate,
81              String[] tagsEntries, byte[] bytes)
82          throws PortalException, SystemException {
83  
84          dlLocalService.validate(fileName, bytes);
85  
86          Hook hook = HookFactory.getInstance();
87  
88          hook.addFile(
89              companyId, portletId, groupId, repositoryId, fileName, properties,
90              modifiedDate, tagsEntries, bytes);
91      }
92  
93      public void addFile(
94              long companyId, String portletId, long groupId, long repositoryId,
95              String fileName, String properties, Date modifiedDate,
96              String[] tagsEntries, File file)
97          throws PortalException, SystemException {
98  
99          dlLocalService.validate(fileName, file);
100 
101         Hook hook = HookFactory.getInstance();
102 
103         hook.addFile(
104             companyId, portletId, groupId, repositoryId, fileName, properties,
105             modifiedDate, tagsEntries, file);
106     }
107 
108     public void deleteDirectory(
109             long companyId, String portletId, long repositoryId, String dirName)
110         throws PortalException, SystemException {
111 
112         Hook hook = HookFactory.getInstance();
113 
114         hook.deleteDirectory(companyId, portletId, repositoryId, dirName);
115     }
116 
117     public void deleteFile(
118             long companyId, String portletId, long repositoryId,
119             String fileName)
120         throws PortalException, SystemException {
121 
122         Hook hook = HookFactory.getInstance();
123 
124         hook.deleteFile(companyId, portletId, repositoryId, fileName);
125     }
126 
127     public void deleteFile(
128             long companyId, String portletId, long repositoryId,
129             String fileName, double versionNumber)
130         throws PortalException, SystemException {
131 
132         Hook hook = HookFactory.getInstance();
133 
134         hook.deleteFile(
135             companyId, portletId, repositoryId, fileName, versionNumber);
136     }
137 
138     public byte[] getFile(long companyId, long repositoryId, String fileName)
139         throws PortalException, SystemException {
140 
141         Hook hook = HookFactory.getInstance();
142 
143         return hook.getFile(companyId, repositoryId, fileName);
144     }
145 
146     public byte[] getFile(
147             long companyId, long repositoryId, String fileName,
148             double versionNumber)
149         throws PortalException, SystemException {
150 
151         Hook hook = HookFactory.getInstance();
152 
153         return hook.getFile(companyId, repositoryId, fileName, versionNumber);
154     }
155 
156     public String[] getFileNames(
157             long companyId, long repositoryId, String dirName)
158         throws PortalException, SystemException {
159 
160         Hook hook = HookFactory.getInstance();
161 
162         return hook.getFileNames(companyId, repositoryId, dirName);
163     }
164 
165     public long getFileSize(
166             long companyId, long repositoryId, String fileName)
167         throws PortalException, SystemException {
168 
169         Hook hook = HookFactory.getInstance();
170 
171         return hook.getFileSize(companyId, repositoryId, fileName);
172     }
173 
174     public void reIndex(String[] ids) throws SystemException {
175         try {
176             Indexer indexer = new Indexer();
177 
178             indexer.reIndex(ids);
179         }
180         catch (SearchException se) {
181             throw new SystemException(se);
182         }
183     }
184 
185     public void updateFile(
186             long companyId, String portletId, long groupId, long repositoryId,
187             String fileName, double versionNumber, String sourceFileName,
188             String properties, Date modifiedDate, String[] tagsEntries,
189             byte[] bytes)
190         throws PortalException, SystemException {
191 
192         dlLocalService.validate(fileName, bytes);
193 
194         Hook hook = HookFactory.getInstance();
195 
196         hook.updateFile(
197             companyId, portletId, groupId, repositoryId, fileName,
198             versionNumber, sourceFileName, properties, modifiedDate,
199                 tagsEntries, bytes);
200     }
201 
202     public void updateFile(
203             long companyId, String portletId, long groupId, long repositoryId,
204             String fileName, double versionNumber, String sourceFileName,
205             String properties, Date modifiedDate, String[] tagsEntries,
206             File file)
207         throws PortalException, SystemException {
208 
209         dlLocalService.validate(fileName, file);
210 
211         Hook hook = HookFactory.getInstance();
212 
213         hook.updateFile(
214             companyId, portletId, groupId, repositoryId, fileName,
215             versionNumber, sourceFileName, properties, modifiedDate,
216             tagsEntries, file);
217     }
218 
219     public void updateFile(
220             long companyId, String portletId, long groupId, long repositoryId,
221             long newRepositoryId, String fileName)
222         throws PortalException, SystemException {
223 
224         Hook hook = HookFactory.getInstance();
225 
226         hook.updateFile(
227             companyId, portletId, groupId, repositoryId, newRepositoryId,
228             fileName);
229     }
230 
231     @BeanReference(name = _DL_LOCAL_SERVICE)
232     protected DLLocalService dlLocalService;
233 
234     private static final String _DL_LOCAL_SERVICE =
235         "com.liferay.documentlibrary.service.DLLocalService.impl";
236 
237 }