1   /**
2    * Copyright (c) 2000-2008 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  /**
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, String[] tagsEntries, File file)
81          throws PortalException, SystemException {
82  
83          DLLocalServiceUtil.validate(fileName, file);
84  
85          Hook hook = HookFactory.getInstance();
86  
87          hook.addFile(
88              companyId, portletId, groupId, repositoryId, fileName, properties,
89              tagsEntries, file);
90      }
91  
92      public void addFile(
93              long companyId, String portletId, long groupId, long repositoryId,
94              String fileName, String properties, String[] tagsEntries,
95              byte[] bytes)
96          throws PortalException, SystemException {
97  
98          DLLocalServiceUtil.validate(fileName, bytes);
99  
100         Hook hook = HookFactory.getInstance();
101 
102         hook.addFile(
103             companyId, portletId, groupId, repositoryId, fileName, properties,
104             tagsEntries, bytes);
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, String[] tagsEntries, File file)
188         throws PortalException, SystemException {
189 
190         DLLocalServiceUtil.validate(fileName, file);
191 
192         Hook hook = HookFactory.getInstance();
193 
194         hook.updateFile(
195             companyId, portletId, groupId, repositoryId, fileName,
196             versionNumber, sourceFileName, properties, tagsEntries, file);
197     }
198 
199     public void updateFile(
200             long companyId, String portletId, long groupId, long repositoryId,
201             String fileName, double versionNumber, String sourceFileName,
202             String properties, String[] tagsEntries, byte[] bytes)
203         throws PortalException, SystemException {
204 
205         DLLocalServiceUtil.validate(fileName, bytes);
206 
207         Hook hook = HookFactory.getInstance();
208 
209         hook.updateFile(
210             companyId, portletId, groupId, repositoryId, fileName,
211             versionNumber, sourceFileName, properties, tagsEntries, bytes);
212     }
213 
214     public void updateFile(
215             long companyId, String portletId, long groupId, long repositoryId,
216             long newRepositoryId, String fileName)
217         throws PortalException, SystemException {
218 
219         Hook hook = HookFactory.getInstance();
220 
221         hook.updateFile(
222             companyId, portletId, groupId, repositoryId, newRepositoryId,
223             fileName);
224     }
225 
226 }