001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.softwarecatalog.action;
016    
017    import com.liferay.portal.kernel.servlet.SessionErrors;
018    import com.liferay.portal.security.auth.PrincipalException;
019    import com.liferay.portal.struts.PortletAction;
020    import com.liferay.portal.util.WebKeys;
021    import com.liferay.portlet.softwarecatalog.NoSuchProductEntryException;
022    import com.liferay.portlet.softwarecatalog.model.SCProductEntry;
023    
024    import javax.portlet.PortletConfig;
025    import javax.portlet.RenderRequest;
026    import javax.portlet.RenderResponse;
027    
028    import org.apache.struts.action.ActionForm;
029    import org.apache.struts.action.ActionForward;
030    import org.apache.struts.action.ActionMapping;
031    
032    /**
033     * @author Jorge Ferrer
034     */
035    public class ViewProductEntryAction extends PortletAction {
036    
037            public ActionForward render(
038                            ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
039                            RenderRequest renderRequest, RenderResponse renderResponse)
040                    throws Exception {
041    
042                    try {
043                            ActionUtil.getProductEntry(renderRequest);
044    
045                            SCProductEntry productEntry =
046                                    (SCProductEntry)renderRequest.getAttribute(
047                                            WebKeys.SOFTWARE_CATALOG_PRODUCT_ENTRY);
048    
049                            if (productEntry == null) {
050                                    throw new NoSuchProductEntryException();
051                            }
052                    }
053                    catch (Exception e) {
054                            if (e instanceof NoSuchProductEntryException ||
055                                    e instanceof PrincipalException) {
056    
057                                    SessionErrors.add(renderRequest, e.getClass().getName());
058    
059                                    return mapping.findForward("portlet.software_catalog.error");
060                            }
061                            else {
062                                    throw e;
063                            }
064                    }
065    
066                    return mapping.findForward(
067                            "portlet.software_catalog.view_product_entry");
068            }
069    
070    }