001    /**
002     * Copyright (c) 2000-2013 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.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();
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    }