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.bookmarks.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.security.permission.ActionKeys;
019    import com.liferay.portal.theme.ThemeDisplay;
020    import com.liferay.portal.util.PortalUtil;
021    import com.liferay.portal.util.WebKeys;
022    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
023    import com.liferay.portlet.bookmarks.model.BookmarksFolder;
024    import com.liferay.portlet.bookmarks.model.BookmarksFolderConstants;
025    import com.liferay.portlet.bookmarks.service.BookmarksEntryServiceUtil;
026    import com.liferay.portlet.bookmarks.service.BookmarksFolderServiceUtil;
027    import com.liferay.portlet.bookmarks.service.permission.BookmarksPermission;
028    
029    import javax.portlet.PortletRequest;
030    
031    import javax.servlet.http.HttpServletRequest;
032    
033    /**
034     * @author Brian Wing Shun Chan
035     */
036    public class ActionUtil {
037    
038            public static void getEntry(HttpServletRequest request) throws Exception {
039                    long entryId = ParamUtil.getLong(request, "entryId");
040    
041                    BookmarksEntry entry = null;
042    
043                    if (entryId > 0) {
044                            entry = BookmarksEntryServiceUtil.getEntry(entryId);
045                    }
046    
047                    request.setAttribute(WebKeys.BOOKMARKS_ENTRY, entry);
048            }
049    
050            public static void getEntry(PortletRequest portletRequest)
051                    throws Exception {
052    
053                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
054                            portletRequest);
055    
056                    getEntry(request);
057            }
058    
059            public static void getFolder(HttpServletRequest request) throws Exception {
060                    ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
061                            WebKeys.THEME_DISPLAY);
062    
063                    long folderId = ParamUtil.getLong(request, "folderId");
064    
065                    BookmarksFolder folder = null;
066    
067                    if ((folderId > 0) &&
068                            (folderId != BookmarksFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {
069    
070                            folder = BookmarksFolderServiceUtil.getFolder(folderId);
071                    }
072                    else {
073                            BookmarksPermission.check(
074                                    themeDisplay.getPermissionChecker(),
075                                    themeDisplay.getScopeGroupId(), ActionKeys.VIEW);
076                    }
077    
078                    request.setAttribute(WebKeys.BOOKMARKS_FOLDER, folder);
079            }
080    
081            public static void getFolder(PortletRequest portletRequest)
082                    throws Exception {
083    
084                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
085                            portletRequest);
086    
087                    getFolder(request);
088            }
089    
090    }