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 setContentCallback(String contentCallback) {
055                    _contentCallback = contentCallback;
056            }
057    
058            public void setCurTags(String curTags) {
059                    _curTags = curTags;
060            }
061    
062            public void setGroupIds(long[] groupIds) {
063                    _groupIds = groupIds;
064            }
065    
066            public void setHiddenInput(String hiddenInput) {
067                    _hiddenInput = hiddenInput;
068            }
069    
070            public void setId(String id) {
071                    _id = id;
072            }
073    
074            public void setIgnoreRequestValue(boolean ignoreRequestValue) {
075                    _ignoreRequestValue = ignoreRequestValue;
076            }
077    
078            public void setRemoveCallback(String removeCallback) {
079                    _removeCallback = removeCallback;
080            }
081    
082            @Override
083            protected void cleanUp() {
084                    _addCallback = null;
085                    _allowAddEntry = true;
086                    _autoFocus = false;
087                    _className = null;
088                    _classPK = 0;
089                    _contentCallback = null;
090                    _curTags = null;
091                    _groupIds = null;
092                    _hiddenInput = "assetTagNames";
093                    _id = null;
094                    _ignoreRequestValue = false;
095                    _removeCallback = null;
096            }
097    
098            @Override
099            protected String getPage() {
100                    return _PAGE;
101            }
102    
103            @Override
104            protected void setAttributes(HttpServletRequest request) {
105                    String id = _id;
106    
107                    if (Validator.isNull(id)) {
108                            id = PortalUtil.generateRandomKey(
109                                    request,
110                                    "taglib_ui_asset_tags_selector_page") + StringPool.UNDERLINE;
111                    }
112    
113                    request.setAttribute(
114                            "liferay-ui:asset-tags-selector:addCallback",
115                            String.valueOf(_addCallback));
116                    request.setAttribute(
117                            "liferay-ui:asset-tags-selector:allowAddEntry",
118                            String.valueOf(_allowAddEntry));
119                    request.setAttribute(
120                            "liferay-ui:asset-tags-selector:autoFocus",
121                            String.valueOf(_autoFocus));
122                    request.setAttribute(
123                            "liferay-ui:asset-tags-selector:className", _className);
124                    request.setAttribute(
125                            "liferay-ui:asset-tags-selector:classPK", String.valueOf(_classPK));
126                    request.setAttribute(
127                            "liferay-ui:asset-tags-selector:contentCallback",
128                            String.valueOf(_contentCallback));
129                    request.setAttribute(
130                            "liferay-ui:asset-tags-selector:curTags", _curTags);
131                    request.setAttribute(
132                            "liferay-ui:asset-tags-selector:removeCallback",
133                            String.valueOf(_removeCallback));
134    
135                    if (_groupIds == null) {
136                            ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
137                                    WebKeys.THEME_DISPLAY);
138    
139                            long[] groupIds = null;
140    
141                            Group group = themeDisplay.getScopeGroup();
142    
143                            if (group.isLayout()) {
144                                    groupIds = new long[] {group.getParentGroupId()};
145                            }
146                            else {
147                                    groupIds = new long[] {group.getGroupId()};
148                            }
149    
150                            if (group.getParentGroupId() != themeDisplay.getCompanyGroupId()) {
151                                    groupIds = ArrayUtil.append(
152                                            groupIds, themeDisplay.getCompanyGroupId());
153                            }
154    
155                            _groupIds = groupIds;
156                    }
157    
158                    request.setAttribute(
159                            "liferay-ui:asset-tags-selector:groupIds", _groupIds);
160    
161                    request.setAttribute(
162                            "liferay-ui:asset-tags-selector:hiddenInput", _hiddenInput);
163                    request.setAttribute("liferay-ui:asset-tags-selector:id", id);
164                    request.setAttribute(
165                            "liferay-ui:asset-tags-selector:ignoreRequestValue",
166                            _ignoreRequestValue);
167            }
168    
169            private static final String _PAGE =
170                    "/html/taglib/ui/asset_tags_selector/page.jsp";
171    
172            private String _addCallback;
173            private boolean _allowAddEntry = true;
174            private boolean _autoFocus;
175            private String _className;
176            private long _classPK;
177            private String _contentCallback;
178            private String _curTags;
179            private long[] _groupIds;
180            private String _hiddenInput = "assetTagNames";
181            private String _id;
182            private boolean _ignoreRequestValue;
183            private String _removeCallback;
184    
185    }