001    /**
002     * Copyright (c) 2000-2010 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.imagegallery.action;
016    
017    import com.liferay.portal.kernel.util.ParamUtil;
018    import com.liferay.portal.util.PortalUtil;
019    import com.liferay.portal.util.WebKeys;
020    import com.liferay.portlet.imagegallery.model.IGFolder;
021    import com.liferay.portlet.imagegallery.model.IGFolderConstants;
022    import com.liferay.portlet.imagegallery.model.IGImage;
023    import com.liferay.portlet.imagegallery.service.IGFolderServiceUtil;
024    import com.liferay.portlet.imagegallery.service.IGImageServiceUtil;
025    
026    import javax.portlet.PortletRequest;
027    
028    import javax.servlet.http.HttpServletRequest;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     */
033    public class ActionUtil {
034    
035            public static void getFolder(HttpServletRequest request) throws Exception {
036                    long folderId = ParamUtil.getLong(request, "folderId");
037    
038                    IGFolder folder = null;
039    
040                    if ((folderId > 0) &&
041                            (folderId != IGFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {
042    
043                            folder = IGFolderServiceUtil.getFolder(folderId);
044                    }
045    
046                    request.setAttribute(WebKeys.IMAGE_GALLERY_FOLDER, folder);
047            }
048    
049            public static void getFolder(PortletRequest portletRequest)
050                    throws Exception {
051    
052                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
053                            portletRequest);
054    
055                    getFolder(request);
056            }
057    
058            public static void getImage(HttpServletRequest request) throws Exception {
059                    long imageId = ParamUtil.getLong(request, "imageId");
060    
061                    IGImage image = null;
062    
063                    if (imageId > 0) {
064                            image = IGImageServiceUtil.getImage(imageId);
065                    }
066    
067                    request.setAttribute(WebKeys.IMAGE_GALLERY_IMAGE, image);
068            }
069    
070            public static void getImage(PortletRequest portletRequest)
071                    throws Exception {
072    
073                    HttpServletRequest request = PortalUtil.getHttpServletRequest(
074                            portletRequest);
075    
076                    getImage(request);
077            }
078    
079    }