001    /**
002     * Copyright (c) 2000-present 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.portlet.documentlibrary.store;
016    
017    import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.util.ReferenceRegistry;
020    
021    import java.io.File;
022    import java.io.InputStream;
023    
024    /**
025     * Provides methods for storing files in the portal. The file storage
026     * implementation can be selected in <code>portal.properties</code> under the
027     * property <code>dl.store.impl</code>. Virus checking can also be enabled under
028     * the property <code>dl.store.antivirus.impl</code>.
029     *
030     * <p>
031     * The main client for this class is the Document Library portlet. It is also
032     * used by other portlets like Wiki and Message Boards to store file
033     * attachments. For the Document Library portlet, the <code>repositoryId</code>
034     * can be obtained by calling {@link
035     * com.liferay.portlet.documentlibrary.model.DLFolderConstants#getDataRepositoryId(
036     * long,long)}. For all other portlets, the <code>repositoryId</code> should be
037     * set to {@link com.liferay.portal.model.CompanyConstants#SYSTEM}. These
038     * methods can be used in plugins and other portlets, as shown below.
039     * </p>
040     *
041     * <p>
042     * <pre>
043     * <code>
044     * long repositoryId = CompanyConstants.SYSTEM;
045     * String dirName = "portlet_name/1234";
046     *
047     * try {
048     * DLStoreUtil.addDirectory(companyId, repositoryId, dirName);
049     * }
050     * catch (DuplicateDirectoryException dde) {
051     * }
052     *
053     * DLStoreUtil.addFile(
054     * companyId, repositoryId, dirName + "/" + fileName, file);
055     * </code>
056     * </pre>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @author Alexander Chow
061     * @author Edward Han
062     * @see    DLStoreImpl
063     */
064    public class DLStoreUtil {
065    
066            /**
067             * Adds a directory.
068             *
069             * @param  companyId the primary key of the company
070             * @param  repositoryId the primary key of the data repository (optionally
071             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
072             * @param  dirName the directory's name
073             * @throws PortalException if the directory's information was invalid
074             */
075            public static void addDirectory(
076                            long companyId, long repositoryId, String dirName)
077                    throws PortalException {
078    
079                    getStore().addDirectory(companyId, repositoryId, dirName);
080            }
081    
082            /**
083             * Adds a file based on a byte array.
084             *
085             * @param  companyId the primary key of the company
086             * @param  repositoryId the primary key of the data repository (optionally
087             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
088             * @param  fileName the file name
089             * @param  validateFileExtension whether to validate the file's extension
090             * @param  bytes the files's data
091             * @throws PortalException if the file's information was invalid or is found
092             *         to contain a virus
093             */
094            public static void addFile(
095                            long companyId, long repositoryId, String fileName,
096                            boolean validateFileExtension, byte[] bytes)
097                    throws PortalException {
098    
099                    getStore().addFile(
100                            companyId, repositoryId, fileName, validateFileExtension, bytes);
101            }
102    
103            /**
104             * Adds a file based on a {@link File} object.
105             *
106             * @param  companyId the primary key of the company
107             * @param  repositoryId the primary key of the data repository (optionally
108             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
109             * @param  fileName the file name
110             * @param  validateFileExtension whether to validate the file's extension
111             * @param  file Name the file name
112             * @throws PortalException if the file's information was invalid or is found
113             *         to contain a virus
114             */
115            public static void addFile(
116                            long companyId, long repositoryId, String fileName,
117                            boolean validateFileExtension, File file)
118                    throws PortalException {
119    
120                    getStore().addFile(
121                            companyId, repositoryId, fileName, validateFileExtension, file);
122            }
123    
124            /**
125             * Adds a file based on a {@link InputStream} object.
126             *
127             * @param  companyId the primary key of the company
128             * @param  repositoryId the primary key of the data repository (optionally
129             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
130             * @param  fileName the file name
131             * @param  validateFileExtension whether to validate the file's extension
132             * @param  is the files's data
133             * @throws PortalException if the file's information was invalid or is found
134             *         to contain a virus
135             */
136            public static void addFile(
137                            long companyId, long repositoryId, String fileName,
138                            boolean validateFileExtension, InputStream is)
139                    throws PortalException {
140    
141                    getStore().addFile(
142                            companyId, repositoryId, fileName, validateFileExtension, is);
143            }
144    
145            /**
146             * Adds a file based on a byte array. Enforces validation of file's
147             * extension.
148             *
149             * @param  companyId the primary key of the company
150             * @param  repositoryId the primary key of the data repository (optionally
151             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
152             * @param  fileName the file name
153             * @param  bytes the files's data
154             * @throws PortalException if the file's information was invalid or is found
155             *         to contain a virus
156             */
157            public static void addFile(
158                            long companyId, long repositoryId, String fileName, byte[] bytes)
159                    throws PortalException {
160    
161                    getStore().addFile(companyId, repositoryId, fileName, bytes);
162            }
163    
164            /**
165             * Adds a file based on a {@link File} object. Enforces validation of file's
166             * extension.
167             *
168             * @param  companyId the primary key of the company
169             * @param  repositoryId the primary key of the data repository (optionally
170             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
171             * @param  fileName the file name
172             * @param  file Name the file name
173             * @throws PortalException if the file's information was invalid or is found
174             *         to contain a virus
175             */
176            public static void addFile(
177                            long companyId, long repositoryId, String fileName, File file)
178                    throws PortalException {
179    
180                    getStore().addFile(companyId, repositoryId, fileName, file);
181            }
182    
183            /**
184             * Adds a file based on an {@link InputStream} object. Enforces validation
185             * of file's extension.
186             *
187             * @param  companyId the primary key of the company
188             * @param  repositoryId the primary key of the data repository (optionally
189             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
190             * @param  fileName the file name
191             * @param  is the files's data
192             * @throws PortalException if the file's information was invalid or is found
193             *         to contain a virus
194             */
195            public static void addFile(
196                            long companyId, long repositoryId, String fileName, InputStream is)
197                    throws PortalException {
198    
199                    getStore().addFile(companyId, repositoryId, fileName, is);
200            }
201    
202            /**
203             * Ensures company's root directory exists. Only implemented by {@link
204             * JCRStore#checkRoot(long)}.
205             *
206             * @param companyId the primary key of the company
207             */
208            public static void checkRoot(long companyId) {
209                    getStore().checkRoot(companyId);
210            }
211    
212            /**
213             * Creates a new copy of the file version.
214             *
215             * @param  companyId the primary key of the company
216             * @param  repositoryId the primary key of the data repository (optionally
217             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
218             * @param  fileName the original's file name
219             * @param  fromVersionLabel the original file's version label
220             * @param  toVersionLabel the new version label
221             * @throws PortalException if the file's information was invalid
222             */
223            public static void copyFileVersion(
224                            long companyId, long repositoryId, String fileName,
225                            String fromVersionLabel, String toVersionLabel)
226                    throws PortalException {
227    
228                    getStore().copyFileVersion(
229                            companyId, repositoryId, fileName, fromVersionLabel,
230                            toVersionLabel);
231            }
232    
233            /**
234             * Deletes a directory.
235             *
236             * @param  companyId the primary key of the company
237             * @param  repositoryId the primary key of the data repository (optionally
238             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
239             * @param  dirName the directory's name
240             * @throws PortalException if the directory's information was invalid
241             */
242            public static void deleteDirectory(
243                            long companyId, long repositoryId, String dirName)
244                    throws PortalException {
245    
246                    getStore().deleteDirectory(companyId, repositoryId, dirName);
247            }
248    
249            /**
250             * Deletes a file. If a file has multiple versions, all versions will be
251             * deleted.
252             *
253             * @param  companyId the primary key of the company
254             * @param  repositoryId the primary key of the data repository (optionally
255             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
256             * @param  fileName the file's name
257             * @throws PortalException if the file's information was invalid
258             */
259            public static void deleteFile(
260                            long companyId, long repositoryId, String fileName)
261                    throws PortalException {
262    
263                    getStore().deleteFile(companyId, repositoryId, fileName);
264            }
265    
266            /**
267             * Deletes a file at a particular version.
268             *
269             * @param  companyId the primary key of the company
270             * @param  repositoryId the primary key of the data repository (optionally
271             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
272             * @param  fileName the file's name
273             * @param  versionLabel the file's version label
274             * @throws PortalException if the file's information was invalid
275             */
276            public static void deleteFile(
277                            long companyId, long repositoryId, String fileName,
278                            String versionLabel)
279                    throws PortalException {
280    
281                    getStore().deleteFile(companyId, repositoryId, fileName, versionLabel);
282            }
283    
284            /**
285             * Returns the file as a {@link File} object.
286             *
287             * <p>
288             * This method is useful when optimizing low-level file operations like
289             * copy. The client must not delete or change the returned {@link File}
290             * object in any way. This method is only supported in certain stores. If
291             * not supported, this method will throw an {@link
292             * UnsupportedOperationException}.
293             * </p>
294             *
295             * <p>
296             * If using an S3 store, it is preferable for performance reasons to use
297             * {@link #getFileAsStream(long, long, String)} instead of this method
298             * wherever possible.
299             * </p>
300             *
301             * @param  companyId the primary key of the company
302             * @param  repositoryId the primary key of the data repository (optionally
303             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
304             * @param  fileName the file's name
305             * @return Returns the {@link File} object with the file's name
306             * @throws PortalException if the file's information was invalid
307             */
308            public static File getFile(
309                            long companyId, long repositoryId, String fileName)
310                    throws PortalException {
311    
312                    return getStore().getFile(companyId, repositoryId, fileName);
313            }
314    
315            /**
316             * Returns the file as a {@link File} object.
317             *
318             * <p>
319             * This method is useful when optimizing low-level file operations like
320             * copy. The client must not delete or change the returned {@link File}
321             * object in any way. This method is only supported in certain stores. If
322             * not supported, this method will throw an {@link
323             * UnsupportedOperationException}.
324             * </p>
325             *
326             * <p>
327             * If using an S3 store, it is preferable for performance reasons to use
328             * {@link #getFileAsStream(long, long, String, String)} instead of this
329             * method wherever possible.
330             * </p>
331             *
332             * @param  companyId the primary key of the company
333             * @param  repositoryId the primary key of the data repository (optionally
334             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
335             * @param  fileName the file's name
336             * @param  versionLabel the file's version label
337             * @return Returns the {@link File} object with the file's name
338             * @throws PortalException if the file's information was invalid
339             */
340            public static File getFile(
341                            long companyId, long repositoryId, String fileName,
342                            String versionLabel)
343                    throws PortalException {
344    
345                    return getStore().getFile(
346                            companyId, repositoryId, fileName, versionLabel);
347            }
348    
349            /**
350             * Returns the file as a byte array.
351             *
352             * @param  companyId the primary key of the company
353             * @param  repositoryId the primary key of the data repository (optionally
354             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
355             * @param  fileName the file's name
356             * @return Returns the byte array with the file's name
357             * @throws PortalException if the file's information was invalid
358             */
359            public static byte[] getFileAsBytes(
360                            long companyId, long repositoryId, String fileName)
361                    throws PortalException {
362    
363                    return getStore().getFileAsBytes(companyId, repositoryId, fileName);
364            }
365    
366            /**
367             * Returns the file as a byte array.
368             *
369             * @param  companyId the primary key of the company
370             * @param  repositoryId the primary key of the data repository (optionally
371             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
372             * @param  fileName the file's name
373             * @param  versionLabel the file's version label
374             * @return Returns the byte array with the file's name
375             * @throws PortalException if the file's information was invalid
376             */
377            public static byte[] getFileAsBytes(
378                            long companyId, long repositoryId, String fileName,
379                            String versionLabel)
380                    throws PortalException {
381    
382                    return getStore().getFileAsBytes(
383                            companyId, repositoryId, fileName, versionLabel);
384            }
385    
386            /**
387             * Returns the file as an {@link java.io.InputStream} object.
388             *
389             * <p>
390             * If using an S3 store, it is preferable for performance reasons to use
391             * this method to get the file as an {@link java.io.InputStream} instead of
392             * using other methods to get the file as a {@link java.io.File}.
393             * </p>
394             *
395             * @param  companyId the primary key of the company
396             * @param  repositoryId the primary key of the data repository (optionally
397             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
398             * @param  fileName the file's name
399             * @return Returns the {@link java.io.InputStream} object with the file's
400             *         name
401             * @throws PortalException if the file's information was invalid
402             */
403            public static InputStream getFileAsStream(
404                            long companyId, long repositoryId, String fileName)
405                    throws PortalException {
406    
407                    return getStore().getFileAsStream(companyId, repositoryId, fileName);
408            }
409    
410            /**
411             * Returns the file as an {@link java.io.InputStream} object.
412             *
413             * <p>
414             * If using an S3 store, it is preferable for performance reasons to use
415             * this method to get the file as an {@link java.io.InputStream} instead of
416             * using other methods to get the file as a {@link java.io.File}.
417             * </p>
418             *
419             * @param  companyId the primary key of the company
420             * @param  repositoryId the primary key of the data repository (optionally
421             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
422             * @param  fileName the file's name
423             * @param  versionLabel the file's version label
424             * @return Returns the {@link java.io.InputStream} object with the file's
425             *         name
426             * @throws PortalException if the file's information was invalid
427             */
428            public static InputStream getFileAsStream(
429                            long companyId, long repositoryId, String fileName,
430                            String versionLabel)
431                    throws PortalException {
432    
433                    return getStore().getFileAsStream(
434                            companyId, repositoryId, fileName, versionLabel);
435            }
436    
437            /**
438             * Returns all files of the directory.
439             *
440             * @param  companyId the primary key of the company
441             * @param  repositoryId the primary key of the data repository (optionally
442             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
443             * @param  dirName the directory's name
444             * @return Returns all files of the directory
445             * @throws PortalException if the directory's information was invalid
446             */
447            public static String[] getFileNames(
448                            long companyId, long repositoryId, String dirName)
449                    throws PortalException {
450    
451                    return getStore().getFileNames(companyId, repositoryId, dirName);
452            }
453    
454            /**
455             * Returns the size of the file.
456             *
457             * @param  companyId the primary key of the company
458             * @param  repositoryId the primary key of the data repository (optionally
459             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
460             * @param  fileName the file's name
461             * @return Returns the size of the file
462             * @throws PortalException if the file's information was invalid
463             */
464            public static long getFileSize(
465                            long companyId, long repositoryId, String fileName)
466                    throws PortalException {
467    
468                    return getStore().getFileSize(companyId, repositoryId, fileName);
469            }
470    
471            /**
472             * Returns the {@link DLStore} object. Used primarily by Spring and should
473             * not be used by the client.
474             *
475             * @return Returns the {@link DLStore} object
476             */
477            public static DLStore getStore() {
478                    if (_store == null) {
479                            _store = (DLStore)PortalBeanLocatorUtil.locate(
480                                    DLStore.class.getName());
481    
482                            ReferenceRegistry.registerReference(DLStoreUtil.class, "_store");
483                    }
484    
485                    return _store;
486            }
487    
488            /**
489             * Returns <code>true</code> if the directory exists.
490             *
491             * @param  companyId the primary key of the company
492             * @param  repositoryId the primary key of the data repository (optionally
493             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
494             * @param  dirName the directory's name
495             * @return <code>true</code> if the directory exists; <code>false</code>
496             *         otherwise
497             * @throws PortalException if the directory's information was invalid
498             */
499            public static boolean hasDirectory(
500                            long companyId, long repositoryId, String dirName)
501                    throws PortalException {
502    
503                    return getStore().hasDirectory(companyId, repositoryId, dirName);
504            }
505    
506            /**
507             * Returns <code>true</code> if the file exists.
508             *
509             * @param  companyId the primary key of the company
510             * @param  repositoryId the primary key of the data repository (optionally
511             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
512             * @param  fileName the file's name
513             * @return <code>true</code> if the file exists; <code>false</code>
514             *         otherwise
515             * @throws PortalException if the file's information was invalid
516             */
517            public static boolean hasFile(
518                            long companyId, long repositoryId, String fileName)
519                    throws PortalException {
520    
521                    return getStore().hasFile(companyId, repositoryId, fileName);
522            }
523    
524            /**
525             * Returns <code>true</code> if the file exists.
526             *
527             * @param  companyId the primary key of the company
528             * @param  repositoryId the primary key of the data repository (optionally
529             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
530             * @param  fileName the file's name
531             * @param  versionLabel the file's version label
532             * @return <code>true</code> if the file exists; <code>false</code>
533             *         otherwise
534             * @throws PortalException if the file's information was invalid
535             */
536            public static boolean hasFile(
537                            long companyId, long repositoryId, String fileName,
538                            String versionLabel)
539                    throws PortalException {
540    
541                    return getStore().hasFile(
542                            companyId, repositoryId, fileName, versionLabel);
543            }
544    
545            public static boolean isValidName(String name) {
546                    return getStore().isValidName(name);
547            }
548    
549            /**
550             * Moves an existing directory. Only implemented by {@link
551             * JCRStore#move(String, String)}.
552             *
553             * @param srcDir the original directory's name
554             * @param destDir the new directory's name
555             */
556            public static void move(String srcDir, String destDir) {
557                    getStore().move(srcDir, destDir);
558            }
559    
560            /**
561             * Moves a file to a new data repository.
562             *
563             * @param  companyId the primary key of the company
564             * @param  repositoryId the primary key of the data repository
565             * @param  newRepositoryId the primary key of the new data repository
566             * @param  fileName the file's name
567             * @throws PortalException if the file's information was invalid
568             */
569            public static void updateFile(
570                            long companyId, long repositoryId, long newRepositoryId,
571                            String fileName)
572                    throws PortalException {
573    
574                    getStore().updateFile(
575                            companyId, repositoryId, newRepositoryId, fileName);
576            }
577    
578            /**
579             * Update's the file's name
580             *
581             * @param  companyId the primary key of the company
582             * @param  repositoryId the primary key of the data repository (optionally
583             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
584             * @param  fileName the file's name
585             * @param  newFileName the file's new name
586             * @throws PortalException if the file's information was invalid
587             */
588            public static void updateFile(
589                            long companyId, long repositoryId, String fileName,
590                            String newFileName)
591                    throws PortalException {
592    
593                    getStore().updateFile(companyId, repositoryId, fileName, newFileName);
594            }
595    
596            /**
597             * Updates a file based on a {@link File} object.
598             *
599             * @param  companyId the primary key of the company
600             * @param  repositoryId the primary key of the data repository (optionally
601             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
602             * @param  fileName the file name
603             * @param  fileExtension the file's extension
604             * @param  validateFileExtension whether to validate the file's extension
605             * @param  versionLabel the file's new version label
606             * @param  sourceFileName the new file's original name
607             * @param  file Name the file name
608             * @throws PortalException if the file's information was invalid or is found
609             *         to contain a virus
610             */
611            public static void updateFile(
612                            long companyId, long repositoryId, String fileName,
613                            String fileExtension, boolean validateFileExtension,
614                            String versionLabel, String sourceFileName, File file)
615                    throws PortalException {
616    
617                    getStore().updateFile(
618                            companyId, repositoryId, fileName, fileExtension,
619                            validateFileExtension, versionLabel, sourceFileName, file);
620            }
621    
622            /**
623             * Updates a file based on a {@link InputStream} object.
624             *
625             * @param  companyId the primary key of the company
626             * @param  repositoryId the primary key of the data repository (optionally
627             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
628             * @param  fileName the file name
629             * @param  fileExtension the file's extension
630             * @param  validateFileExtension whether to validate the file's extension
631             * @param  versionLabel the file's new version label
632             * @param  sourceFileName the new file's original name
633             * @param  is the new file's data
634             * @throws PortalException if the file's information was invalid or is found
635             *         to contain a virus
636             */
637            public static void updateFile(
638                            long companyId, long repositoryId, String fileName,
639                            String fileExtension, boolean validateFileExtension,
640                            String versionLabel, String sourceFileName, InputStream is)
641                    throws PortalException {
642    
643                    getStore().updateFile(
644                            companyId, repositoryId, fileName, fileExtension,
645                            validateFileExtension, versionLabel, sourceFileName, is);
646            }
647    
648            /**
649             * Update's a file version label. Similar to {@link #copyFileVersion(long,
650             * long, String, String, String)} except that the old file version is
651             * deleted.
652             *
653             * @param  companyId the primary key of the company
654             * @param  repositoryId the primary key of the data repository (optionally
655             *         {@link com.liferay.portal.model.CompanyConstants#SYSTEM})
656             * @param  fileName the file's name
657             * @param  fromVersionLabel the file's version label
658             * @param  toVersionLabel the file's new version label
659             * @throws PortalException if the file's information was invalid
660             */
661            public static void updateFileVersion(
662                            long companyId, long repositoryId, String fileName,
663                            String fromVersionLabel, String toVersionLabel)
664                    throws PortalException {
665    
666                    getStore().updateFileVersion(
667                            companyId, repositoryId, fileName, fromVersionLabel,
668                            toVersionLabel);
669            }
670    
671            /**
672             * Validates a file's name.
673             *
674             * @param  fileName the file's name
675             * @param  validateFileExtension whether to validate the file's extension
676             * @throws PortalException if the file's information was invalid
677             */
678            public static void validate(String fileName, boolean validateFileExtension)
679                    throws PortalException {
680    
681                    getStore().validate(fileName, validateFileExtension);
682            }
683    
684            /**
685             * Validates a file's name and data.
686             *
687             * @param  fileName the file's name
688             * @param  validateFileExtension whether to validate the file's extension
689             * @param  bytes the file's data (optionally <code>null</code>)
690             * @throws PortalException if the file's information was invalid
691             */
692            public static void validate(
693                            String fileName, boolean validateFileExtension, byte[] bytes)
694                    throws PortalException {
695    
696                    getStore().validate(fileName, validateFileExtension, bytes);
697            }
698    
699            /**
700             * Validates a file's name and data.
701             *
702             * @param  fileName the file's name
703             * @param  validateFileExtension whether to validate the file's extension
704             * @param  file Name the file's name
705             * @throws PortalException if the file's information was invalid
706             */
707            public static void validate(
708                            String fileName, boolean validateFileExtension, File file)
709                    throws PortalException {
710    
711                    getStore().validate(fileName, validateFileExtension, file);
712            }
713    
714            /**
715             * Validates a file's name and data.
716             *
717             * @param  fileName the file's name
718             * @param  validateFileExtension whether to validate the file's extension
719             * @param  is the file's data (optionally <code>null</code>)
720             * @throws PortalException if the file's information was invalid
721             */
722            public static void validate(
723                            String fileName, boolean validateFileExtension, InputStream is)
724                    throws PortalException {
725    
726                    getStore().validate(fileName, validateFileExtension, is);
727            }
728    
729            public static void validate(
730                            String fileName, String fileExtension, String sourceFileName,
731                            boolean validateFileExtension)
732                    throws PortalException {
733    
734                    getStore().validate(
735                            fileName, fileExtension, sourceFileName, validateFileExtension);
736            }
737    
738            /**
739             * Validates a file's name and data.
740             *
741             * @param  fileName the file's name
742             * @param  fileExtension the file's extension
743             * @param  sourceFileName the file's original name
744             * @param  validateFileExtension whether to validate the file's extension
745             * @param  file Name the file's name
746             * @throws PortalException if the file's information was invalid
747             */
748            public static void validate(
749                            String fileName, String fileExtension, String sourceFileName,
750                            boolean validateFileExtension, File file)
751                    throws PortalException {
752    
753                    getStore().validate(
754                            fileName, fileExtension, sourceFileName, validateFileExtension,
755                            file);
756            }
757    
758            /**
759             * Validates a file's name and data.
760             *
761             * @param  fileName the file's name
762             * @param  fileExtension the file's extension
763             * @param  sourceFileName the file's original name
764             * @param  validateFileExtension whether to validate the file's extension
765             * @param  is the file's data (optionally <code>null</code>)
766             * @throws PortalException if the file's information was invalid
767             */
768            public static void validate(
769                            String fileName, String fileExtension, String sourceFileName,
770                            boolean validateFileExtension, InputStream is)
771                    throws PortalException {
772    
773                    getStore().validate(
774                            fileName, fileExtension, sourceFileName, validateFileExtension, is);
775            }
776    
777            public static void validateDirectoryName(String directoryName)
778                    throws PortalException {
779    
780                    getStore().validateDirectoryName(directoryName);
781            }
782    
783            /**
784             * Set's the {@link DLStore} object. Used primarily by Spring and should not
785             * be used by the client.
786             *
787             * @param store the {@link DLStore} object
788             */
789            public void setStore(DLStore store) {
790                    _store = store;
791    
792                    ReferenceRegistry.registerReference(DLStoreUtil.class, "_store");
793            }
794    
795            private static DLStore _store;
796    
797    }