1   /**
2    * Copyright (c) 2000-2010 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   *
12   * 
13   */
14  
15  package com.liferay.documentlibrary.util;
16  
17  import com.liferay.portal.PortalException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.search.SearchException;
20  import com.liferay.portal.kernel.util.FileUtil;
21  
22  import java.io.File;
23  import java.io.InputStream;
24  
25  import java.util.Date;
26  
27  /**
28   * <a href="SafeFileNameHookWrapper.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class SafeFileNameHookWrapper implements Hook {
33  
34      public SafeFileNameHookWrapper(Hook hook) {
35          _hook = hook;
36      }
37  
38      public void addDirectory(long companyId, long repositoryId, String dirName)
39          throws PortalException, SystemException {
40  
41          _hook.addDirectory(
42              companyId, repositoryId, FileUtil.encodeSafeFileName(dirName));
43      }
44  
45      public void addFile(
46              long companyId, String portletId, long groupId, long repositoryId,
47              String fileName, String properties, Date modifiedDate,
48              String[] tagsEntries, byte[] bytes)
49          throws PortalException, SystemException {
50  
51          _hook.addFile(
52              companyId, portletId, groupId, repositoryId,
53              FileUtil.encodeSafeFileName(fileName), properties, modifiedDate,
54              tagsEntries, bytes);
55      }
56  
57      public void addFile(
58              long companyId, String portletId, long groupId, long repositoryId,
59              String fileName, String properties, Date modifiedDate,
60              String[] tagsEntries, File file)
61          throws PortalException, SystemException {
62  
63          _hook.addFile(
64              companyId, portletId, groupId, repositoryId,
65              FileUtil.encodeSafeFileName(fileName), properties, modifiedDate,
66              tagsEntries, file);
67      }
68  
69      public void addFile(
70              long companyId, String portletId, long groupId, long repositoryId,
71              String fileName, String properties, Date modifiedDate,
72              String[] tagsEntries, InputStream is)
73          throws PortalException, SystemException {
74  
75          _hook.addFile(
76              companyId, portletId, groupId, repositoryId,
77              FileUtil.encodeSafeFileName(fileName), properties, modifiedDate,
78              tagsEntries, is);
79      }
80  
81      public void checkRoot(long companyId) throws SystemException {
82          _hook.checkRoot(companyId);
83      }
84  
85      public void deleteDirectory(
86              long companyId, String portletId, long repositoryId, String dirName)
87          throws PortalException, SystemException {
88  
89          _hook.deleteDirectory(
90              companyId, portletId, repositoryId,
91              FileUtil.encodeSafeFileName(dirName));
92      }
93  
94      public void deleteFile(
95              long companyId, String portletId, long repositoryId,
96              String fileName)
97          throws PortalException, SystemException {
98  
99          _hook.deleteFile(
100             companyId, portletId, repositoryId,
101             FileUtil.encodeSafeFileName(fileName));
102     }
103 
104     public void deleteFile(
105             long companyId, String portletId, long repositoryId,
106             String fileName, double versionNumber)
107         throws PortalException, SystemException {
108 
109         _hook.deleteFile(
110             companyId, portletId, repositoryId,
111             FileUtil.encodeSafeFileName(fileName), versionNumber);
112     }
113 
114     public byte[] getFile(long companyId, long repositoryId, String fileName)
115         throws PortalException, SystemException {
116 
117         return _hook.getFile(
118             companyId, repositoryId, FileUtil.encodeSafeFileName(fileName));
119     }
120 
121     public byte[] getFile(
122             long companyId, long repositoryId, String fileName,
123             double versionNumber)
124         throws PortalException, SystemException {
125 
126         return _hook.getFile(
127             companyId, repositoryId, FileUtil.encodeSafeFileName(fileName),
128             versionNumber);
129     }
130 
131     public InputStream getFileAsStream(
132             long companyId, long repositoryId, String fileName)
133         throws PortalException, SystemException {
134 
135         return _hook.getFileAsStream(
136             companyId, repositoryId, FileUtil.encodeSafeFileName(fileName));
137     }
138 
139     public InputStream getFileAsStream(
140             long companyId, long repositoryId, String fileName,
141             double versionNumber)
142         throws PortalException, SystemException {
143 
144         return _hook.getFileAsStream(
145             companyId, repositoryId, FileUtil.encodeSafeFileName(fileName),
146             versionNumber);
147     }
148 
149     public String[] getFileNames(
150             long companyId, long repositoryId, String dirName)
151         throws PortalException, SystemException {
152 
153         String[] fileNames = _hook.getFileNames(
154             companyId, repositoryId, FileUtil.encodeSafeFileName(dirName));
155 
156         String[] decodedFileNames = new String[fileNames.length];
157 
158         for (int i = 0; i < fileNames.length; i++) {
159             decodedFileNames[i] = FileUtil.decodeSafeFileName(fileNames[i]);
160         }
161 
162         return decodedFileNames;
163     }
164 
165     public long getFileSize(
166             long companyId, long repositoryId, String fileName)
167         throws PortalException, SystemException {
168 
169         return _hook.getFileSize(
170             companyId, repositoryId, FileUtil.encodeSafeFileName(fileName));
171     }
172 
173     public boolean hasFile(
174             long companyId, long repositoryId, String fileName,
175             double versionNumber)
176         throws PortalException, SystemException {
177 
178         return _hook.hasFile(
179             companyId, repositoryId, FileUtil.encodeSafeFileName(fileName),
180             versionNumber);
181     }
182 
183     public void move(String srcDir, String destDir) throws SystemException {
184         _hook.move(srcDir, destDir);
185     }
186 
187     public void reIndex(String[] ids) throws SearchException {
188         _hook.reIndex(ids);
189     }
190 
191     public void updateFile(
192             long companyId, String portletId, long groupId, long repositoryId,
193             long newRepositoryId, String fileName)
194         throws PortalException, SystemException {
195 
196         _hook.updateFile(
197             companyId, portletId, groupId, repositoryId, newRepositoryId,
198             FileUtil.encodeSafeFileName(fileName));
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             byte[] bytes)
206         throws PortalException, SystemException {
207 
208         _hook.updateFile(
209             companyId, portletId, groupId, repositoryId,
210             FileUtil.encodeSafeFileName(fileName), versionNumber,
211             FileUtil.encodeSafeFileName(sourceFileName), properties,
212             modifiedDate, tagsEntries, bytes);
213     }
214 
215     public void updateFile(
216             long companyId, String portletId, long groupId, long repositoryId,
217             String fileName, double versionNumber, String sourceFileName,
218             String properties, Date modifiedDate, String[] tagsEntries,
219             File file)
220         throws PortalException, SystemException {
221 
222         _hook.updateFile(
223             companyId, portletId, groupId, repositoryId,
224             FileUtil.encodeSafeFileName(fileName), versionNumber,
225             FileUtil.encodeSafeFileName(sourceFileName), properties,
226             modifiedDate, tagsEntries, file);
227     }
228 
229     public void updateFile(
230             long companyId, String portletId, long groupId, long repositoryId,
231             String fileName, double versionNumber, String sourceFileName,
232             String properties, Date modifiedDate, String[] tagsEntries,
233             InputStream is)
234         throws PortalException, SystemException {
235 
236         _hook.updateFile(
237             companyId, portletId, groupId, repositoryId,
238             FileUtil.encodeSafeFileName(fileName), versionNumber,
239             FileUtil.encodeSafeFileName(sourceFileName), properties,
240             modifiedDate, tagsEntries, is);
241     }
242 
243     private Hook _hook;
244 
245 }