001    /**
002     * Copyright (c) 2000-present 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.softwarecatalog.action;
016    
017    import com.liferay.portal.kernel.portlet.bridges.mvc.MVCRenderCommand;
018    import com.liferay.portal.kernel.servlet.SessionErrors;
019    import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
020    import com.liferay.portal.kernel.util.WebKeys;
021    import com.liferay.portal.util.PortletKeys;
022    import com.liferay.portlet.softwarecatalog.NoSuchProductEntryException;
023    import com.liferay.portlet.softwarecatalog.model.SCProductEntry;
024    
025    import javax.portlet.RenderRequest;
026    import javax.portlet.RenderResponse;
027    
028    /**
029     * @author Philip Jones
030     */
031    @OSGiBeanProperties(
032            property = {
033                    "javax.portlet.name=" + PortletKeys.SOFTWARE_CATALOG,
034                    "mvc.command.name=/software_catalog/view_product_entry"
035            }
036    )
037    public class ViewProductEntryMVCRenderCommand implements MVCRenderCommand {
038    
039            @Override
040            public String render(
041                    RenderRequest renderRequest, RenderResponse renderResponse) {
042    
043                    try {
044                            ActionUtil.getProductEntry(renderRequest);
045    
046                            SCProductEntry productEntry =
047                                    (SCProductEntry)renderRequest.getAttribute(
048                                            WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY);
049    
050                            if (productEntry == null) {
051                                    throw new NoSuchProductEntryException();
052                            }
053                    }
054                    catch (Exception e) {
055                            SessionErrors.add(renderRequest, e.getClass());
056    
057                            return "/html/portlet/software_catalog/error.jsp";
058                    }
059    
060                    return "/html/portlet/software_catalog/view_product_entry.jsp";
061            }
062    
063    }