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.portlet.assetcategoryadmin.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.theme.ThemeDisplay;
019    import com.liferay.portal.util.PortalUtil;
020    import com.liferay.portal.util.WebKeys;
021    import com.liferay.portlet.asset.model.AssetCategory;
022    import com.liferay.portlet.asset.model.AssetVocabulary;
023    import com.liferay.portlet.asset.service.AssetCategoryServiceUtil;
024    import com.liferay.portlet.asset.service.AssetVocabularyServiceUtil;
025    
026    import java.util.List;
027    
028    import javax.portlet.PortletRequest;
029    
030    import javax.servlet.http.HttpServletRequest;
031    
032    /**
033     * @author Iliyan Peychev
034     * @author Julio Camarero
035     */
036    public class ActionUtil {
037    
038            public static void getCategory(HttpServletRequest request)
039                    throws Exception {
040    
041                    long categoryId = ParamUtil.getLong(request, "categoryId");
042    
043                    AssetCategory category = null;
044    
045                    if (categoryId > 0) {
046                            category = AssetCategoryServiceUtil.getCategory(categoryId);
047                    }
048    
049                    request.setAttribute(WebKeys.ASSET_CATEGORY, category);
050            }
051    
052            public static void getCategory(PortletRequest portletRequest)
053                    throws Exception {
054    
055                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
056                            portletRequest);
057    
058                    getCategory(request);
059            }
060    
061            public static void getVocabularies(HttpServletRequest request)
062                    throws Exception {
063    
064                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
065                            WebKeys.THEME_DISPLAY);
066    
067                    List<AssetVocabulary> vocabularies =
068                            AssetVocabularyServiceUtil.getGroupVocabularies(
069                                    themeDisplay.getScopeGroupId());
070    
071                    request.setAttribute(WebKeys.ASSET_VOCABULARIES, vocabularies);
072            }
073    
074            public static void getVocabularies(PortletRequest portletRequest)
075                    throws Exception {
076    
077                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
078                            portletRequest);
079    
080                    getVocabularies(request);
081            }
082    
083            public static void getVocabulary(HttpServletRequest request)
084                    throws Exception {
085    
086                    long vocabularyId = ParamUtil.getLong(request, "vocabularyId");
087    
088                    AssetVocabulary vocabulary = null;
089    
090                    if (vocabularyId > 0) {
091                            vocabulary = AssetVocabularyServiceUtil.getVocabulary(vocabularyId);
092                    }
093    
094                    request.setAttribute(WebKeys.ASSET_VOCABULARY, vocabulary);
095            }
096    
097            public static void getVocabulary(PortletRequest portletRequest)
098                    throws Exception {
099    
100                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
101                            portletRequest);
102    
103                    getVocabulary(request);
104            }
105    
106    }