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.kernel.template;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    import com.liferay.portal.kernel.util.Validator;
019    
020    /**
021     * @author Jorge Ferrer
022     */
023    public class TemplateVariableDefinition {
024    
025            public TemplateVariableDefinition(
026                    String label, Class<?> clazz, String variableName) {
027    
028                    this(
029                            label, clazz, StringPool.BLANK, variableName, label.concat("-help"),
030                            false);
031            }
032    
033            public TemplateVariableDefinition(
034                    String label, Class<?> clazz, String dataType, String variableName,
035                    String help, boolean repeatable) {
036    
037                    _label = label;
038                    _clazz = clazz;
039                    _dataType = dataType;
040                    _name = variableName;
041                    _help = help;
042                    _repeatable = repeatable;
043            }
044    
045            public TemplateVariableDefinition(
046                    String label, Class<?> clazz, String variableName,
047                    TemplateVariableDefinition itemTemplateVariableDefinition) {
048    
049                    this(label, clazz, variableName);
050    
051                    _itemTemplateVariableDefinition = itemTemplateVariableDefinition;
052            }
053    
054            @Override
055            public boolean equals(Object obj) {
056                    if (this == obj) {
057                            return true;
058                    }
059    
060                    if (!(obj instanceof TemplateVariableDefinition)) {
061                            return false;
062                    }
063    
064                    TemplateVariableDefinition templateVariableDefinition =
065                            (TemplateVariableDefinition)obj;
066    
067                    if (Validator.equals(_name, templateVariableDefinition._name)) {
068                            return true;
069                    }
070    
071                    return false;
072            }
073    
074            public Class<?> getClazz() {
075                    return _clazz;
076            }
077    
078            public String getDataType() {
079                    return _dataType;
080            }
081    
082            public String getHelp() {
083                    return _help;
084            }
085    
086            public TemplateVariableDefinition getItemTemplateVariableDefinition() {
087                    return _itemTemplateVariableDefinition;
088            }
089    
090            public String getLabel() {
091                    return _label;
092            }
093    
094            public String getName() {
095                    return _name;
096            }
097    
098            public boolean isCollection() {
099                    if (_itemTemplateVariableDefinition != null) {
100                            return true;
101                    }
102    
103                    return false;
104            }
105    
106            public boolean isRepeatable() {
107                    return _repeatable;
108            }
109    
110            private Class<?> _clazz;
111            private String _dataType;
112            private String _help;
113            private TemplateVariableDefinition _itemTemplateVariableDefinition;
114            private String _label;
115            private String _name;
116            private boolean _repeatable;
117    
118    }