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.taglib.ui;
016    
017    import com.liferay.portal.kernel.util.ArrayUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.kernel.util.WebKeys;
021    import com.liferay.portal.model.Group;
022    import com.liferay.portal.theme.ThemeDisplay;
023    import com.liferay.portal.util.PortalUtil;
024    import com.liferay.taglib.util.IncludeTag;
025    
026    import javax.servlet.http.HttpServletRequest;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     * @author Jorge Ferrer
031     */
032    public class AssetTagsSelectorTag extends IncludeTag {
033    
034            public void setAddCallback(String addCallback) {
035                    _addCallback = addCallback;
036            }
037    
038            public void setAllowAddEntry(boolean allowAddEntry) {
039                    _allowAddEntry = allowAddEntry;
040            }
041    
042            public void setAutoFocus(boolean autoFocus) {
043                    _autoFocus = autoFocus;
044            }
045    
046            public void setClassName(String className) {
047                    _className = className;
048            }
049    
050            public void setClassPK(long classPK) {
051                    _classPK = classPK;
052            }
053    
054            public void setCurTags(String curTags) {
055                    _curTags = curTags;
056            }
057    
058            public void setGroupIds(long[] groupIds) {
059                    _groupIds = groupIds;
060            }
061    
062            public void setHiddenInput(String hiddenInput) {
063                    _hiddenInput = hiddenInput;
064            }
065    
066            public void setId(String id) {
067                    _id = id;
068            }
069    
070            public void setIgnoreRequestValue(boolean ignoreRequestValue) {
071                    _ignoreRequestValue = ignoreRequestValue;
072            }
073    
074            public void setRemoveCallback(String removeCallback) {
075                    _removeCallback = removeCallback;
076            }
077    
078            @Override
079            protected void cleanUp() {
080                    _addCallback = null;
081                    _allowAddEntry = true;
082                    _autoFocus = false;
083                    _className = null;
084                    _classPK = 0;
085                    _curTags = null;
086                    _groupIds = null;
087                    _hiddenInput = "assetTagNames";
088                    _id = null;
089                    _ignoreRequestValue = false;
090                    _removeCallback = null;
091            }
092    
093            @Override
094            protected String getPage() {
095                    return _PAGE;
096            }
097    
098            @Override
099            protected void setAttributes(HttpServletRequest request) {
100                    String id = _id;
101    
102                    if (Validator.isNull(id)) {
103                            id = PortalUtil.generateRandomKey(
104                                    request,
105                                    "taglib_ui_asset_tags_selector_page") + StringPool.UNDERLINE;
106                    }
107    
108                    request.setAttribute(
109                            "liferay-ui:asset-tags-selector:addCallback",
110                            String.valueOf(_addCallback));
111                    request.setAttribute(
112                            "liferay-ui:asset-tags-selector:allowAddEntry",
113                            String.valueOf(_allowAddEntry));
114                    request.setAttribute(
115                            "liferay-ui:asset-tags-selector:autoFocus",
116                            String.valueOf(_autoFocus));
117                    request.setAttribute(
118                            "liferay-ui:asset-tags-selector:className", _className);
119                    request.setAttribute(
120                            "liferay-ui:asset-tags-selector:classPK", String.valueOf(_classPK));
121                    request.setAttribute(
122                            "liferay-ui:asset-tags-selector:curTags", _curTags);
123                    request.setAttribute(
124                            "liferay-ui:asset-tags-selector:removeCallback",
125                            String.valueOf(_removeCallback));
126    
127                    if (_groupIds == null) {
128                            ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
129                                    WebKeys.THEME_DISPLAY);
130    
131                            long[] groupIds = null;
132    
133                            Group group = themeDisplay.getScopeGroup();
134    
135                            if (group.isLayout()) {
136                                    groupIds = new long[] {group.getParentGroupId()};
137                            }
138                            else {
139                                    groupIds = new long[] {group.getGroupId()};
140                            }
141    
142                            if (group.getParentGroupId() != themeDisplay.getCompanyGroupId()) {
143                                    groupIds = ArrayUtil.append(
144                                            groupIds, themeDisplay.getCompanyGroupId());
145                            }
146    
147                            _groupIds = groupIds;
148                    }
149    
150                    request.setAttribute(
151                            "liferay-ui:asset-tags-selector:groupIds", _groupIds);
152    
153                    request.setAttribute(
154                            "liferay-ui:asset-tags-selector:hiddenInput", _hiddenInput);
155                    request.setAttribute("liferay-ui:asset-tags-selector:id", id);
156                    request.setAttribute(
157                            "liferay-ui:asset-tags-selector:ignoreRequestValue",
158                            _ignoreRequestValue);
159            }
160    
161            private static final String _PAGE =
162                    "/html/taglib/ui/asset_tags_selector/page.jsp";
163    
164            private String _addCallback;
165            private boolean _allowAddEntry = true;
166            private boolean _autoFocus;
167            private String _className;
168            private long _classPK;
169            private String _curTags;
170            private long[] _groupIds;
171            private String _hiddenInput = "assetTagNames";
172            private String _id;
173            private boolean _ignoreRequestValue;
174            private String _removeCallback;
175    
176    }