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.lar;
016    
017    import com.liferay.portal.kernel.language.LanguageUtil;
018    import com.liferay.portal.kernel.util.StringBundler;
019    import com.liferay.portal.kernel.util.StringPool;
020    import com.liferay.portal.kernel.util.Validator;
021    
022    import java.util.Locale;
023    
024    /**
025     * @author Raymond Aug??
026     */
027    public class PortletDataHandlerControl {
028    
029            public static String getNamespacedControlName(
030                    String namespace, String controlName) {
031    
032                    StringBundler sb = new StringBundler(4);
033    
034                    sb.append(StringPool.UNDERLINE);
035                    sb.append(namespace);
036                    sb.append(StringPool.UNDERLINE);
037                    sb.append(controlName);
038    
039                    return sb.toString();
040            }
041    
042            public PortletDataHandlerControl(String namespace, String controlName) {
043                    this(namespace, controlName, false);
044            }
045    
046            public PortletDataHandlerControl(
047                    String namespace, String controlName, boolean disabled) {
048    
049                    this(namespace, controlName, disabled, null);
050            }
051    
052            public PortletDataHandlerControl(
053                    String namespace, String controlName, boolean disabled,
054                    String className) {
055    
056                    this(namespace, controlName, disabled, className, null);
057            }
058    
059            public PortletDataHandlerControl(
060                    String namespace, String controlName, boolean disabled,
061                    String className, String referrerClassName) {
062    
063                    this(
064                            namespace, controlName, controlName, disabled, className,
065                            referrerClassName);
066            }
067    
068            public PortletDataHandlerControl(
069                    String namespace, String controlName, String controlLabel,
070                    boolean disabled, String className, String referrerClassName) {
071    
072                    _namespace = namespace;
073                    _controlLabel = controlLabel;
074                    _controlName = controlName;
075                    _disabled = disabled;
076                    _className = className;
077                    _referrerClassName = referrerClassName;
078            }
079    
080            public String getClassName() {
081                    return _className;
082            }
083    
084            public String getControlLabel() {
085                    return _controlLabel;
086            }
087    
088            public String getControlName() {
089                    return _controlName;
090            }
091    
092            public String getHelpMessage(Locale locale, String action) {
093                    String helpMessage = LanguageUtil.get(
094                            locale, action + "-" + _controlLabel + "-help", StringPool.BLANK);
095    
096                    if (Validator.isNull(helpMessage)) {
097                            helpMessage = LanguageUtil.get(
098                                    locale, "export-import-publish-" + _controlLabel + "-help",
099                                    StringPool.BLANK);
100                    }
101    
102                    return helpMessage;
103            }
104    
105            public String getNamespace() {
106                    return _namespace;
107            }
108    
109            public String getNamespacedControlName() {
110                    return getNamespacedControlName(_namespace, getControlName());
111            }
112    
113            public String getReferrerClassName() {
114                    return _referrerClassName;
115            }
116    
117            public boolean isDisabled() {
118                    return _disabled;
119            }
120    
121            public void setNamespace(String namespace) {
122                    _namespace = namespace;
123            }
124    
125            private String _className;
126            private String _controlLabel;
127            private String _controlName;
128            private boolean _disabled;
129            private String _namespace;
130            private String _referrerClassName;
131    
132    }