1   /**
2    * Copyright (c) 2000-2007 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, 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              file);
90      }
91  
92      public void addFile(
93              long companyId, String portletId, long groupId, long repositoryId,
94              String fileName, String properties, byte[] byteArray)
95          throws PortalException, SystemException {
96  
97          DLLocalServiceUtil.validate(fileName, byteArray);
98  
99          Hook hook = HookFactory.getInstance();
100 
101         hook.addFile(
102             companyId, portletId, groupId, repositoryId, fileName, properties,
103             byteArray);
104     }
105 
106     public void deleteDirectory(
107             long companyId, String portletId, long repositoryId, String dirName)
108         throws PortalException, SystemException {
109 
110         Hook hook = HookFactory.getInstance();
111 
112         hook.deleteDirectory(companyId, portletId, repositoryId, dirName);
113     }
114 
115     public void deleteFile(
116             long companyId, String portletId, long repositoryId,
117             String fileName)
118         throws PortalException, SystemException {
119 
120         Hook hook = HookFactory.getInstance();
121 
122         hook.deleteFile(companyId, portletId, repositoryId, fileName);
123     }
124 
125     public void deleteFile(
126             long companyId, String portletId, long repositoryId,
127             String fileName, double versionNumber)
128         throws PortalException, SystemException {
129 
130         Hook hook = HookFactory.getInstance();
131 
132         hook.deleteFile(
133             companyId, portletId, repositoryId, fileName, versionNumber);
134     }
135 
136     public byte[] getFile(long companyId, long repositoryId, String fileName)
137         throws PortalException, SystemException {
138 
139         Hook hook = HookFactory.getInstance();
140 
141         return hook.getFile(companyId, repositoryId, fileName);
142     }
143 
144     public byte[] getFile(
145             long companyId, long repositoryId, String fileName,
146             double versionNumber)
147         throws PortalException, SystemException {
148 
149         Hook hook = HookFactory.getInstance();
150 
151         return hook.getFile(companyId, repositoryId, fileName, versionNumber);
152     }
153 
154     public String[] getFileNames(
155             long companyId, long repositoryId, String dirName)
156         throws PortalException, SystemException {
157 
158         Hook hook = HookFactory.getInstance();
159 
160         return hook.getFileNames(companyId, repositoryId, dirName);
161     }
162 
163     public long getFileSize(
164             long companyId, long repositoryId, String fileName)
165         throws PortalException, SystemException {
166 
167         Hook hook = HookFactory.getInstance();
168 
169         return hook.getFileSize(companyId, repositoryId, fileName);
170     }
171 
172     public void reIndex(String[] ids) throws SystemException {
173         try {
174             Indexer indexer = new Indexer();
175 
176             indexer.reIndex(ids);
177         }
178         catch (SearchException se) {
179             throw new SystemException(se);
180         }
181     }
182 
183     public void updateFile(
184             long companyId, String portletId, long groupId, long repositoryId,
185             String fileName, double versionNumber, String sourceFileName,
186             String properties, File file)
187         throws PortalException, SystemException {
188 
189         DLLocalServiceUtil.validate(fileName, file);
190 
191         Hook hook = HookFactory.getInstance();
192 
193         hook.updateFile(
194             companyId, portletId, groupId, repositoryId, fileName,
195             versionNumber, sourceFileName, properties, file);
196     }
197 
198     public void updateFile(
199             long companyId, String portletId, long groupId, long repositoryId,
200             String fileName, double versionNumber, String sourceFileName,
201             String properties, byte[] byteArray)
202         throws PortalException, SystemException {
203 
204         DLLocalServiceUtil.validate(fileName, byteArray);
205 
206         Hook hook = HookFactory.getInstance();
207 
208         hook.updateFile(
209             companyId, portletId, groupId, repositoryId, fileName,
210             versionNumber, sourceFileName, properties, byteArray);
211     }
212 
213     public void updateFile(
214             long companyId, String portletId, long groupId, long repositoryId,
215             long newRepositoryId, String fileName)
216         throws PortalException, SystemException {
217 
218         Hook hook = HookFactory.getInstance();
219 
220         hook.updateFile(
221             companyId, portletId, groupId, repositoryId, newRepositoryId,
222             fileName);
223     }
224 
225 }