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.portal.model.impl;
016    
017    import com.liferay.portal.kernel.util.CharPool;
018    import com.liferay.portal.kernel.util.StringUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.model.PortletDecorator;
021    
022    /**
023     * @author Eduardo Garcia
024     */
025    public class PortletDecoratorImpl implements PortletDecorator {
026    
027            public PortletDecoratorImpl() {
028                    this(null, null, null);
029            }
030    
031            public PortletDecoratorImpl(String portletDecoratorId) {
032                    this(portletDecoratorId, null, null);
033            }
034    
035            public PortletDecoratorImpl(
036                    String portletDecoratorId, String name, String cssClass) {
037    
038                    _portletDecoratorId = portletDecoratorId;
039                    _name = name;
040                    _cssClass = cssClass;
041            }
042    
043            @Override
044            public int compareTo(PortletDecorator portletDecorator) {
045                    return getName().compareTo(portletDecorator.getName());
046            }
047    
048            @Override
049            public boolean equals(Object obj) {
050                    if (this == obj) {
051                            return true;
052                    }
053    
054                    if (!(obj instanceof PortletDecorator)) {
055                            return false;
056                    }
057    
058                    PortletDecorator portletDecorator = (PortletDecorator)obj;
059    
060                    String portletDecoratorId = portletDecorator.getPortletDecoratorId();
061    
062                    if (getPortletDecoratorId().equals(portletDecoratorId)) {
063                            return true;
064                    }
065                    else {
066                            return false;
067                    }
068            }
069    
070            @Override
071            public String getCssClass() {
072                    return _cssClass;
073            }
074    
075            @Override
076            public String getName() {
077                    if (Validator.isNull(_name)) {
078                            return _portletDecoratorId;
079                    }
080                    else {
081                            return _name;
082                    }
083            }
084    
085            @Override
086            public String getPortletDecoratorId() {
087                    return _portletDecoratorId;
088            }
089    
090            @Override
091            public String getPortletDecoratorThumbnailPath() {
092                    if (Validator.isNotNull(_cssClass) &&
093                            Validator.isNotNull(_portletDecoratorThumbnailPath)) {
094    
095                            int pos = _cssClass.indexOf(CharPool.SPACE);
096    
097                            if (pos > 0) {
098                                    if (_portletDecoratorThumbnailPath.endsWith(
099                                                    _cssClass.substring(0, pos))) {
100    
101                                            String subclassPath = StringUtil.replace(
102                                                    _cssClass, CharPool.SPACE, CharPool.SLASH);
103    
104                                            return _portletDecoratorThumbnailPath +
105                                                    subclassPath.substring(pos);
106                                    }
107                            }
108                    }
109    
110                    return _portletDecoratorThumbnailPath;
111            }
112    
113            @Override
114            public int hashCode() {
115                    return _portletDecoratorId.hashCode();
116            }
117    
118            @Override
119            public boolean isDefaultPortletDecorator() {
120                    return _defaultPortletDecorator;
121            }
122    
123            @Override
124            public void setCssClass(String cssClass) {
125                    _cssClass = cssClass;
126            }
127    
128            @Override
129            public void setDefaultPortletDecorator(boolean defaultPortletDecorator) {
130                    _defaultPortletDecorator = defaultPortletDecorator;
131            }
132    
133            @Override
134            public void setName(String name) {
135                    _name = name;
136            }
137    
138            @Override
139            public void setPortletDecoratorThumbnailPath(
140                    String portletDecoratorThumbnailPath) {
141    
142                    _portletDecoratorThumbnailPath = portletDecoratorThumbnailPath;
143            }
144    
145            private String _cssClass;
146            private boolean _defaultPortletDecorator;
147            private String _name;
148            private final String _portletDecoratorId;
149            private String _portletDecoratorThumbnailPath =
150                    "${images-path}/portlet_decorators/${portlet-decorator-css-class}";
151    
152    }