1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.DLLocalServiceUtil;
27  import com.liferay.documentlibrary.service.DLService;
28  import com.liferay.documentlibrary.util.Hook;
29  import com.liferay.documentlibrary.util.HookFactory;
30  import com.liferay.documentlibrary.util.Indexer;
31  import com.liferay.portal.PortalException;
32  import com.liferay.portal.SystemException;
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   */
46  public class DLServiceImpl implements DLService {
47  
48      public static final String GROUP_NAME = DLServiceImpl.class.getName();
49  
50      public static final String[] GROUP_NAME_ARRAY = new String[] { GROUP_NAME };
51  
52      public static final String VERSION = "_VERSION_";
53  
54      public void addDirectory(long companyId, long repositoryId, String dirName)
55          throws PortalException, SystemException {
56  
57          if ((dirName == null || dirName.equals("/")) ||
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              (dirName.indexOf("'") != -1)) {
71  
72              throw new DirectoryNameException(dirName);
73          }
74  
75          Hook hook = HookFactory.getInstance();
76  
77          hook.addDirectory(companyId, repositoryId, dirName);
78      }
79  
80      public void addFile(
81              long companyId, String portletId, long groupId, long repositoryId,
82              String fileName, long fileEntryId, String properties,
83              Date modifiedDate, String[] tagsEntries, File file)
84          throws PortalException, SystemException {
85  
86          DLLocalServiceUtil.validate(fileName, file);
87  
88          Hook hook = HookFactory.getInstance();
89  
90          hook.addFile(
91              companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
92              properties, modifiedDate, tagsEntries, file);
93      }
94  
95      public void addFile(
96              long companyId, String portletId, long groupId, long repositoryId,
97              String fileName, long fileEntryId, String properties,
98              Date modifiedDate, String[] tagsEntries, byte[] bytes)
99          throws PortalException, SystemException {
100 
101         DLLocalServiceUtil.validate(fileName, bytes);
102 
103         Hook hook = HookFactory.getInstance();
104 
105         hook.addFile(
106             companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
107             properties, modifiedDate, 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[] tagsEntries, File file)
192         throws PortalException, SystemException {
193 
194         DLLocalServiceUtil.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, 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[] tagsEntries, byte[] bytes)
209         throws PortalException, SystemException {
210 
211         DLLocalServiceUtil.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, 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 }