001    /**
002     * Copyright (c) 2000-2013 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.portal.repository.liferayrepository.util;
016    
017    import com.liferay.portal.kernel.repository.model.FileEntry;
018    import com.liferay.portal.kernel.repository.model.FileVersion;
019    import com.liferay.portal.kernel.repository.model.Folder;
020    import com.liferay.portal.kernel.util.UnmodifiableList;
021    import com.liferay.portal.repository.liferayrepository.model.LiferayFileEntry;
022    import com.liferay.portal.repository.liferayrepository.model.LiferayFileVersion;
023    import com.liferay.portal.repository.liferayrepository.model.LiferayFolder;
024    import com.liferay.portlet.documentlibrary.model.DLFileEntry;
025    import com.liferay.portlet.documentlibrary.model.DLFileVersion;
026    import com.liferay.portlet.documentlibrary.model.DLFolder;
027    
028    import java.util.ArrayList;
029    import java.util.List;
030    
031    /**
032     * @author Alexander Chow
033     */
034    public abstract class LiferayBase {
035    
036            public List<FileEntry> toFileEntries(List<DLFileEntry> dlFileEntries) {
037                    List<FileEntry> fileEntries = new ArrayList<FileEntry>(
038                            dlFileEntries.size());
039    
040                    for (DLFileEntry dlFileEntry : dlFileEntries) {
041                            FileEntry fileEntry = new LiferayFileEntry(dlFileEntry);
042    
043                            fileEntries.add(fileEntry);
044                    }
045    
046                    if (dlFileEntries instanceof UnmodifiableList) {
047                            return new UnmodifiableList<FileEntry>(fileEntries);
048                    }
049                    else {
050                            return fileEntries;
051                    }
052            }
053    
054            public List<Object> toFileEntriesAndFolders(
055                    List<Object> dlFileEntriesAndDLFolders) {
056    
057                    List<Object> fileEntriesAndFolders = new ArrayList<Object>(
058                            dlFileEntriesAndDLFolders.size());
059    
060                    for (Object object : dlFileEntriesAndDLFolders) {
061                            if (object instanceof DLFileEntry) {
062                                    DLFileEntry dlFileEntry = (DLFileEntry)object;
063    
064                                    FileEntry fileEntry = new LiferayFileEntry(dlFileEntry);
065    
066                                    fileEntriesAndFolders.add(fileEntry);
067                            }
068                            else if (object instanceof DLFolder) {
069                                    DLFolder dlFolder = (DLFolder)object;
070    
071                                    Folder folder = new LiferayFolder(dlFolder);
072    
073                                    fileEntriesAndFolders.add(folder);
074                            }
075                            else {
076                                    fileEntriesAndFolders.add(object);
077                            }
078                    }
079    
080                    if (dlFileEntriesAndDLFolders instanceof UnmodifiableList) {
081                            return new UnmodifiableList<Object>(fileEntriesAndFolders);
082                    }
083                    else {
084                            return fileEntriesAndFolders;
085                    }
086            }
087    
088            public List<FileVersion> toFileVersions(
089                    List<DLFileVersion> dlFileVersions) {
090    
091                    List<FileVersion> fileVersions = new ArrayList<FileVersion>(
092                            dlFileVersions.size());
093    
094                    for (DLFileVersion dlFileVersion : dlFileVersions) {
095                            FileVersion fileVersion = new LiferayFileVersion(dlFileVersion);
096    
097                            fileVersions.add(fileVersion);
098                    }
099    
100                    if (dlFileVersions instanceof UnmodifiableList) {
101                            return new UnmodifiableList<FileVersion>(fileVersions);
102                    }
103                    else {
104                            return fileVersions;
105                    }
106            }
107    
108            public List<Folder> toFolders(List<DLFolder> dlFolders) {
109                    List<Folder> folders = new ArrayList<Folder>(dlFolders.size());
110    
111                    for (DLFolder dlFolder : dlFolders) {
112                            Folder folder = new LiferayFolder(dlFolder);
113    
114                            folders.add(folder);
115                    }
116    
117                    if (dlFolders instanceof UnmodifiableList) {
118                            return new UnmodifiableList<Folder>(folders);
119                    }
120                    else {
121                            return folders;
122                    }
123            }
124    
125    }