001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.documentlibrary.service.impl;
016    
017    import com.liferay.documentlibrary.DirectoryNameException;
018    import com.liferay.documentlibrary.service.DLLocalService;
019    import com.liferay.documentlibrary.service.DLService;
020    import com.liferay.documentlibrary.util.Hook;
021    import com.liferay.portal.kernel.annotation.BeanReference;
022    import com.liferay.portal.kernel.exception.PortalException;
023    import com.liferay.portal.kernel.exception.SystemException;
024    import com.liferay.portal.service.ServiceContext;
025    
026    import java.io.File;
027    
028    import java.util.Date;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     * @author Michael Young
033     */
034    public class DLServiceImpl implements DLService {
035    
036            public static final String GROUP_NAME = DLServiceImpl.class.getName();
037    
038            public static final String[] GROUP_NAME_ARRAY = new String[] {GROUP_NAME};
039    
040            public void addDirectory(long companyId, long repositoryId, String dirName)
041                    throws PortalException, SystemException {
042    
043                    if ((dirName == null || dirName.equals("/")) ||
044                            (dirName.indexOf("\\\\") != -1) ||
045                            (dirName.indexOf("//") != -1) ||
046                            (dirName.indexOf(":") != -1) ||
047                            (dirName.indexOf("*") != -1) ||
048                            (dirName.indexOf("?") != -1) ||
049                            (dirName.indexOf("\"") != -1) ||
050                            (dirName.indexOf("<") != -1) ||
051                            (dirName.indexOf(">") != -1) ||
052                            (dirName.indexOf("|") != -1) ||
053                            (dirName.indexOf("[") != -1) ||
054                            (dirName.indexOf("]") != -1) ||
055                            (dirName.indexOf("'") != -1) ||
056                            (dirName.indexOf("..\\") != -1) ||
057                            (dirName.indexOf("../") != -1) ||
058                            (dirName.indexOf("\\..") != -1) ||
059                            (dirName.indexOf("/..") != -1)) {
060    
061                            throw new DirectoryNameException(dirName);
062                    }
063    
064                    hook.addDirectory(companyId, repositoryId, dirName);
065            }
066    
067            public void addFile(
068                            long companyId, String portletId, long groupId, long repositoryId,
069                            String fileName, long fileEntryId, String properties,
070                            Date modifiedDate, ServiceContext serviceContext, byte[] bytes)
071                    throws PortalException, SystemException {
072    
073                    dlLocalService.validate(fileName, true, bytes);
074    
075                    hook.addFile(
076                            companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
077                            properties, modifiedDate, serviceContext, bytes);
078            }
079    
080            public void addFile(
081                            long companyId, String portletId, long groupId, long repositoryId,
082                            String fileName, long fileEntryId, String properties,
083                            Date modifiedDate, ServiceContext serviceContext, File file)
084                    throws PortalException, SystemException {
085    
086                    dlLocalService.validate(fileName, true, file);
087    
088                    hook.addFile(
089                            companyId, portletId, groupId, repositoryId, fileName, fileEntryId,
090                            properties, modifiedDate, serviceContext, file);
091            }
092    
093            public void deleteDirectory(
094                            long companyId, String portletId, long repositoryId, String dirName)
095                    throws PortalException, SystemException {
096    
097                    hook.deleteDirectory(companyId, portletId, repositoryId, dirName);
098            }
099    
100            public void deleteFile(
101                            long companyId, String portletId, long repositoryId,
102                            String fileName)
103                    throws PortalException, SystemException {
104    
105                    hook.deleteFile(companyId, portletId, repositoryId, fileName);
106            }
107    
108            public void deleteFile(
109                            long companyId, String portletId, long repositoryId,
110                            String fileName, String versionNumber)
111                    throws PortalException, SystemException {
112    
113                    hook.deleteFile(
114                            companyId, portletId, repositoryId, fileName, versionNumber);
115            }
116    
117            public byte[] getFile(long companyId, long repositoryId, String fileName)
118                    throws PortalException, SystemException {
119    
120                    return hook.getFile(companyId, repositoryId, fileName);
121            }
122    
123            public byte[] getFile(
124                            long companyId, long repositoryId, String fileName,
125                            String versionNumber)
126                    throws PortalException, SystemException {
127    
128                    return hook.getFile(companyId, repositoryId, fileName, versionNumber);
129            }
130    
131            public String[] getFileNames(
132                            long companyId, long repositoryId, String dirName)
133                    throws PortalException, SystemException {
134    
135                    return hook.getFileNames(companyId, repositoryId, dirName);
136            }
137    
138            public long getFileSize(
139                            long companyId, long repositoryId, String fileName)
140                    throws PortalException, SystemException {
141    
142                    return hook.getFileSize(companyId, repositoryId, fileName);
143            }
144    
145            public void updateFile(
146                            long companyId, String portletId, long groupId, long repositoryId,
147                            long newRepositoryId, String fileName, long fileEntryId)
148                    throws PortalException, SystemException {
149    
150                    hook.updateFile(
151                            companyId, portletId, groupId, repositoryId, newRepositoryId,
152                            fileName, fileEntryId);
153            }
154    
155            public void updateFile(
156                            long companyId, String portletId, long groupId, long repositoryId,
157                            String fileName, String versionNumber, String sourceFileName,
158                            long fileEntryId, String properties, Date modifiedDate,
159                            ServiceContext serviceContext, byte[] bytes)
160                    throws PortalException, SystemException {
161    
162                    dlLocalService.validate(fileName, true, bytes);
163    
164                    hook.updateFile(
165                            companyId, portletId, groupId, repositoryId, fileName,
166                            versionNumber, sourceFileName, fileEntryId, properties,
167                            modifiedDate, serviceContext, bytes);
168            }
169    
170            public void updateFile(
171                            long companyId, String portletId, long groupId, long repositoryId,
172                            String fileName, String versionNumber, String sourceFileName,
173                            long fileEntryId, String properties, Date modifiedDate,
174                            ServiceContext serviceContext, File file)
175                    throws PortalException, SystemException {
176    
177                    dlLocalService.validate(fileName, true, file);
178    
179                    hook.updateFile(
180                            companyId, portletId, groupId, repositoryId, fileName,
181                            versionNumber, sourceFileName, fileEntryId, properties,
182                            modifiedDate, serviceContext, file);
183            }
184    
185            public void updateFile(
186                            long companyId, String portletId, long groupId, long repositoryId,
187                            String fileName, String newFileName, boolean reindex)
188                    throws PortalException, SystemException {
189    
190                    hook.updateFile(
191                            companyId, portletId, groupId, repositoryId, fileName, newFileName,
192                            reindex);
193            }
194    
195            @BeanReference(type = DLLocalService.class)
196            protected DLLocalService dlLocalService;
197    
198            @BeanReference(type = Hook.class)
199            protected Hook hook;
200    
201    }