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.DLLocalServiceUtil;
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.search.SearchException;
31  
32  import java.io.File;
33  
34  import java.util.Date;
35  
36  /**
37   * <a href="DLServiceImpl.java.html"><b><i>View Source</i></b></a>
38   *
39   * @author Brian Wing Shun Chan
40   * @author Michael Young
41   *
42   */
43  public class DLServiceImpl implements DLService {
44  
45      public static final String GROUP_NAME = DLServiceImpl.class.getName();
46  
47      public static final String[] GROUP_NAME_ARRAY = new String[] { GROUP_NAME };
48  
49      public static final String VERSION = "_VERSION_";
50  
51      public void addDirectory(long companyId, long repositoryId, String dirName)
52          throws PortalException, SystemException {
53  
54          if ((dirName == null || dirName.equals("/")) ||
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 hook = HookFactory.getInstance();
73  
74          hook.addDirectory(companyId, repositoryId, dirName);
75      }
76  
77      public void addFile(
78              long companyId, String portletId, long groupId, long repositoryId,
79              String fileName, String properties, Date modifiedDate,
80              String[] tagsEntries, byte[] bytes)
81          throws PortalException, SystemException {
82  
83          DLLocalServiceUtil.validate(fileName, bytes);
84  
85          Hook hook = HookFactory.getInstance();
86  
87          hook.addFile(
88              companyId, portletId, groupId, repositoryId, fileName, properties,
89              modifiedDate, tagsEntries, bytes);
90      }
91  
92      public void addFile(
93              long companyId, String portletId, long groupId, long repositoryId,
94              String fileName, String properties, Date modifiedDate,
95              String[] tagsEntries, File file)
96          throws PortalException, SystemException {
97  
98          DLLocalServiceUtil.validate(fileName, file);
99  
100         Hook hook = HookFactory.getInstance();
101 
102         hook.addFile(
103             companyId, portletId, groupId, repositoryId, fileName, properties,
104             modifiedDate, tagsEntries, file);
105     }
106 
107     public void deleteDirectory(
108             long companyId, String portletId, long repositoryId, String dirName)
109         throws PortalException, SystemException {
110 
111         Hook hook = HookFactory.getInstance();
112 
113         hook.deleteDirectory(companyId, portletId, repositoryId, dirName);
114     }
115 
116     public void deleteFile(
117             long companyId, String portletId, long repositoryId,
118             String fileName)
119         throws PortalException, SystemException {
120 
121         Hook hook = HookFactory.getInstance();
122 
123         hook.deleteFile(companyId, portletId, repositoryId, fileName);
124     }
125 
126     public void deleteFile(
127             long companyId, String portletId, long repositoryId,
128             String fileName, double versionNumber)
129         throws PortalException, SystemException {
130 
131         Hook hook = HookFactory.getInstance();
132 
133         hook.deleteFile(
134             companyId, portletId, repositoryId, fileName, versionNumber);
135     }
136 
137     public byte[] getFile(long companyId, long repositoryId, String fileName)
138         throws PortalException, SystemException {
139 
140         Hook hook = HookFactory.getInstance();
141 
142         return hook.getFile(companyId, repositoryId, fileName);
143     }
144 
145     public byte[] getFile(
146             long companyId, long repositoryId, String fileName,
147             double versionNumber)
148         throws PortalException, SystemException {
149 
150         Hook hook = HookFactory.getInstance();
151 
152         return hook.getFile(companyId, repositoryId, fileName, versionNumber);
153     }
154 
155     public String[] getFileNames(
156             long companyId, long repositoryId, String dirName)
157         throws PortalException, SystemException {
158 
159         Hook hook = HookFactory.getInstance();
160 
161         return hook.getFileNames(companyId, repositoryId, dirName);
162     }
163 
164     public long getFileSize(
165             long companyId, long repositoryId, String fileName)
166         throws PortalException, SystemException {
167 
168         Hook hook = HookFactory.getInstance();
169 
170         return hook.getFileSize(companyId, repositoryId, fileName);
171     }
172 
173     public void reIndex(String[] ids) throws SystemException {
174         try {
175             Indexer indexer = new Indexer();
176 
177             indexer.reIndex(ids);
178         }
179         catch (SearchException se) {
180             throw new SystemException(se);
181         }
182     }
183 
184     public void updateFile(
185             long companyId, String portletId, long groupId, long repositoryId,
186             String fileName, double versionNumber, String sourceFileName,
187             String properties, Date modifiedDate, String[] tagsEntries,
188             byte[] bytes)
189         throws PortalException, SystemException {
190 
191         DLLocalServiceUtil.validate(fileName, bytes);
192 
193         Hook hook = HookFactory.getInstance();
194 
195         hook.updateFile(
196             companyId, portletId, groupId, repositoryId, fileName,
197             versionNumber, sourceFileName, properties, modifiedDate,
198                 tagsEntries, bytes);
199     }
200 
201     public void updateFile(
202             long companyId, String portletId, long groupId, long repositoryId,
203             String fileName, double versionNumber, String sourceFileName,
204             String properties, Date modifiedDate, String[] tagsEntries,
205             File file)
206         throws PortalException, SystemException {
207 
208         DLLocalServiceUtil.validate(fileName, file);
209 
210         Hook hook = HookFactory.getInstance();
211 
212         hook.updateFile(
213             companyId, portletId, groupId, repositoryId, fileName,
214             versionNumber, sourceFileName, properties, modifiedDate,
215             tagsEntries, file);
216     }
217 
218     public void updateFile(
219             long companyId, String portletId, long groupId, long repositoryId,
220             long newRepositoryId, String fileName)
221         throws PortalException, SystemException {
222 
223         Hook hook = HookFactory.getInstance();
224 
225         hook.updateFile(
226             companyId, portletId, groupId, repositoryId, newRepositoryId,
227             fileName);
228     }
229 
230 }