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.kernel.workflow.WorkflowConstants;
019    import com.liferay.portal.struts.ActionConstants;
020    import com.liferay.portal.util.PortalUtil;
021    import com.liferay.portal.util.WebKeys;
022    import com.liferay.portlet.bookmarks.NoSuchEntryException;
023    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
024    import com.liferay.portlet.bookmarks.service.BookmarksEntryServiceUtil;
025    
026    import javax.servlet.http.HttpServletRequest;
027    import javax.servlet.http.HttpServletResponse;
028    
029    import org.apache.struts.action.Action;
030    import org.apache.struts.action.ActionForm;
031    import org.apache.struts.action.ActionForward;
032    import org.apache.struts.action.ActionMapping;
033    
034    /**
035     * @author Brian Wing Shun Chan
036     */
037    public class OpenEntryAction extends Action {
038    
039            @Override
040            public ActionForward execute(
041                            ActionMapping actionMapping, ActionForm actionForm,
042                            HttpServletRequest request, HttpServletResponse response)
043                    throws Exception {
044    
045                    try {
046                            long entryId = ParamUtil.getLong(request, "entryId");
047    
048                            BookmarksEntry entry = BookmarksEntryServiceUtil.getEntry(entryId);
049    
050                            if (entry.isInTrash()) {
051                                    int status = ParamUtil.getInteger(
052                                            request, "status", WorkflowConstants.STATUS_APPROVED);
053    
054                                    if (status != WorkflowConstants.STATUS_IN_TRASH) {
055                                            throw new NoSuchEntryException("{entryId=" + entryId + "}");
056                                    }
057                            }
058    
059                            entry = BookmarksEntryServiceUtil.openEntry(entry);
060    
061                            request.setAttribute(WebKeys.FORWARD_URL, entry.getUrl());
062    
063                            return actionMapping.findForward(ActionConstants.COMMON_FORWARD);
064                    }
065                    catch (Exception e) {
066                            PortalUtil.sendError(e, request, response);
067    
068                            return null;
069                    }
070            }
071    
072    }