001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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.model.Group;
021    import com.liferay.portal.theme.ThemeDisplay;
022    import com.liferay.portal.util.PortalUtil;
023    import com.liferay.taglib.util.IncludeTag;
024    
025    import javax.servlet.http.HttpServletRequest;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     * @author Jorge Ferrer
030     */
031    public class AssetTagsSelectorTag extends IncludeTag {
032    
033            public void setAutoFocus(boolean autoFocus) {
034                    _autoFocus = autoFocus;
035            }
036    
037            public void setClassName(String className) {
038                    _className = className;
039            }
040    
041            public void setClassPK(long classPK) {
042                    _classPK = classPK;
043            }
044    
045            public void setContentCallback(String contentCallback) {
046                    _contentCallback = contentCallback;
047            }
048    
049            public void setCurTags(String curTags) {
050                    _curTags = curTags;
051            }
052    
053            public void setGroupIds(long[] groupIds) {
054                    _groupIds = groupIds;
055            }
056    
057            public void setHiddenInput(String hiddenInput) {
058                    _hiddenInput = hiddenInput;
059            }
060    
061            public void setId(String id) {
062                    _id = id;
063            }
064    
065            public void setIgnoreRequestValue(boolean ignoreRequestValue) {
066                    _ignoreRequestValue = ignoreRequestValue;
067            }
068    
069            @Override
070            protected void cleanUp() {
071                    _autoFocus = false;
072                    _className = null;
073                    _classPK = 0;
074                    _contentCallback = null;
075                    _curTags = null;
076                    _groupIds = null;
077                    _hiddenInput = "assetTagNames";
078                    _id = null;
079                    _ignoreRequestValue = false;
080            }
081    
082            @Override
083            protected String getPage() {
084                    return _PAGE;
085            }
086    
087            @Override
088            protected void setAttributes(HttpServletRequest request) {
089                    String id = _id;
090    
091                    if (Validator.isNull(id)) {
092                            id = PortalUtil.generateRandomKey(
093                                    request,
094                                    "taglib_ui_asset_tags_selector_page") + StringPool.UNDERLINE;
095                    }
096    
097                    request.setAttribute(
098                            "liferay-ui:asset-tags-selector:autoFocus",
099                            String.valueOf(_autoFocus));
100                    request.setAttribute(
101                            "liferay-ui:asset-tags-selector:className", _className);
102                    request.setAttribute(
103                            "liferay-ui:asset-tags-selector:classPK", String.valueOf(_classPK));
104                    request.setAttribute(
105                            "liferay-ui:asset-tags-selector:contentCallback",
106                            String.valueOf(_contentCallback));
107                    request.setAttribute(
108                            "liferay-ui:asset-tags-selector:curTags", _curTags);
109    
110                    if (_groupIds == null) {
111                            ThemeDisplay themeDisplay = (ThemeDisplay)pageContext.getAttribute(
112                                    "themeDisplay");
113    
114                            long[] groupIds = null;
115    
116                            Group group = themeDisplay.getScopeGroup();
117    
118                            if (group.isLayout()) {
119                                    groupIds = new long[] {group.getParentGroupId()};
120                            }
121                            else {
122                                    groupIds = new long[] {group.getGroupId()};
123                            }
124    
125                            if (group.getParentGroupId() != themeDisplay.getCompanyGroupId()) {
126                                    groupIds = ArrayUtil.append(
127                                            groupIds, themeDisplay.getCompanyGroupId());
128                            }
129    
130                            _groupIds = groupIds;
131                    }
132    
133                    request.setAttribute(
134                            "liferay-ui:asset-tags-selector:groupIds", _groupIds);
135    
136                    request.setAttribute(
137                            "liferay-ui:asset-tags-selector:hiddenInput", _hiddenInput);
138                    request.setAttribute("liferay-ui:asset-tags-selector:id", id);
139                    request.setAttribute(
140                            "liferay-ui:asset-tags-selector:ignoreRequestValue",
141                            _ignoreRequestValue);
142            }
143    
144            private static final String _PAGE =
145                    "/html/taglib/ui/asset_tags_selector/page.jsp";
146    
147            private boolean _autoFocus;
148            private String _className;
149            private long _classPK;
150            private String _contentCallback;
151            private String _curTags;
152            private long[] _groupIds;
153            private String _hiddenInput = "assetTagNames";
154            private String _id;
155            private boolean _ignoreRequestValue;
156    
157    }