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.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 setClassName(String className) {
034                    _className = className;
035            }
036    
037            public void setClassPK(long classPK) {
038                    _classPK = classPK;
039            }
040    
041            public void setContentCallback(String contentCallback) {
042                    _contentCallback = contentCallback;
043            }
044    
045            public void setCurTags(String curTags) {
046                    _curTags = curTags;
047            }
048    
049            public void setFocus(boolean focus) {
050                    _focus = focus;
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            @Override
066            protected void cleanUp() {
067                    _className = null;
068                    _classPK = 0;
069                    _contentCallback = null;
070                    _curTags = null;
071                    _focus = false;
072                    _groupIds = null;
073                    _hiddenInput = "assetTagNames";
074                    _id = null;
075            }
076    
077            @Override
078            protected String getPage() {
079                    return _PAGE;
080            }
081    
082            @Override
083            protected void setAttributes(HttpServletRequest request) {
084                    String id = _id;
085    
086                    if (Validator.isNull(id)) {
087                            id = PortalUtil.generateRandomKey(
088                                    request,
089                                    "taglib_ui_asset_tags_selector_page") + StringPool.UNDERLINE;
090                    }
091    
092                    request.setAttribute(
093                            "liferay-ui:asset-tags-selector:className", _className);
094                    request.setAttribute(
095                            "liferay-ui:asset-tags-selector:classPK", String.valueOf(_classPK));
096                    request.setAttribute(
097                            "liferay-ui:asset-tags-selector:contentCallback",
098                            String.valueOf(_contentCallback));
099                    request.setAttribute(
100                            "liferay-ui:asset-tags-selector:curTags", _curTags);
101                    request.setAttribute(
102                            "liferay-ui:asset-tags-selector:focus", String.valueOf(_focus));
103    
104                    if (_groupIds == null) {
105                            ThemeDisplay themeDisplay = (ThemeDisplay)pageContext.getAttribute(
106                                    "themeDisplay");
107    
108                            long[] groupIds = null;
109    
110                            Group group = themeDisplay.getScopeGroup();
111    
112                            if (group.isLayout()) {
113                                    groupIds = new long[] {group.getParentGroupId()};
114                            }
115                            else {
116                                    groupIds = new long[] {group.getGroupId()};
117                            }
118    
119                            if (group.getParentGroupId() != themeDisplay.getCompanyGroupId()) {
120                                    groupIds = ArrayUtil.append(
121                                            groupIds, themeDisplay.getCompanyGroupId());
122                            }
123    
124                            _groupIds = groupIds;
125                    }
126    
127                    request.setAttribute(
128                            "liferay-ui:asset-tags-selector:groupIds", _groupIds);
129    
130                    request.setAttribute(
131                            "liferay-ui:asset-tags-selector:hiddenInput", _hiddenInput);
132                    request.setAttribute("liferay-ui:asset-tags-selector:id", id);
133            }
134    
135            private static final String _PAGE =
136                    "/html/taglib/ui/asset_tags_selector/page.jsp";
137    
138            private String _className;
139            private long _classPK;
140            private String _contentCallback;
141            private String _curTags;
142            private boolean _focus;
143            private long[] _groupIds;
144            private String _hiddenInput = "assetTagNames";
145            private String _id;
146    
147    }