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.portlet.trash.model.impl;
016    
017    import com.liferay.portal.kernel.trash.TrashHandler;
018    import com.liferay.portal.kernel.util.UnicodeProperties;
019    import com.liferay.portal.model.ClassedModel;
020    import com.liferay.portal.model.TrashedModel;
021    import com.liferay.portlet.trash.model.TrashEntry;
022    
023    /**
024     * @author Zsolt Berentey
025     */
026    public class TrashEntryImpl extends TrashEntryBaseImpl {
027    
028            @Override
029            public TrashEntry getRootEntry() {
030                    return _rootEntry;
031            }
032    
033            @Override
034            public String getTypeSettings() {
035                    if (_typeSettingsProperties == null) {
036                            return super.getTypeSettings();
037                    }
038                    else {
039                            return _typeSettingsProperties.toString();
040                    }
041            }
042    
043            @Override
044            public UnicodeProperties getTypeSettingsProperties() {
045                    if (_typeSettingsProperties == null) {
046                            _typeSettingsProperties = new UnicodeProperties(true);
047    
048                            _typeSettingsProperties.fastLoad(super.getTypeSettings());
049                    }
050    
051                    return _typeSettingsProperties;
052            }
053    
054            @Override
055            public String getTypeSettingsProperty(String key) {
056                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
057    
058                    return typeSettingsProperties.getProperty(key);
059            }
060    
061            @Override
062            public String getTypeSettingsProperty(String key, String defaultValue) {
063                    UnicodeProperties typeSettingsProperties = getTypeSettingsProperties();
064    
065                    return typeSettingsProperties.getProperty(key, defaultValue);
066            }
067    
068            @Override
069            public boolean isTrashEntry(Class<?> clazz, long classPK) {
070                    if (clazz == null) {
071                            return false;
072                    }
073    
074                    return isTrashEntry(clazz.getName(), classPK);
075            }
076    
077            @Override
078            public boolean isTrashEntry(String className, long classPK) {
079                    if (className.equals(getClassName()) && (classPK == getClassPK())) {
080                            return true;
081                    }
082    
083                    return false;
084            }
085    
086            @Override
087            public boolean isTrashEntry(TrashedModel trashedModel) {
088                    TrashHandler trashHandler = trashedModel.getTrashHandler();
089    
090                    if (trashHandler == null) {
091                            return false;
092                    }
093    
094                    if (!(trashedModel instanceof ClassedModel)) {
095                            return false;
096                    }
097    
098                    return trashHandler.isTrashEntry(this, (ClassedModel)trashedModel);
099            }
100    
101            @Override
102            public void setRootEntry(TrashEntry rootEntry) {
103                    _rootEntry = rootEntry;
104            }
105    
106            @Override
107            public void setTypeSettings(String typeSettings) {
108                    _typeSettingsProperties = null;
109    
110                    super.setTypeSettings(typeSettings);
111            }
112    
113            @Override
114            public void setTypeSettingsProperties(
115                    UnicodeProperties typeSettingsProperties) {
116    
117                    _typeSettingsProperties = typeSettingsProperties;
118    
119                    super.setTypeSettings(_typeSettingsProperties.toString());
120            }
121    
122            private TrashEntry _rootEntry;
123            private UnicodeProperties _typeSettingsProperties;
124    
125    }