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.blogs.action;
016    
017    import com.liferay.portal.kernel.editor.EditorConstants;
018    import com.liferay.portal.kernel.exception.PortalException;
019    import com.liferay.portal.kernel.json.JSONArray;
020    import com.liferay.portal.kernel.json.JSONFactoryUtil;
021    import com.liferay.portal.kernel.json.JSONObject;
022    import com.liferay.portal.kernel.log.Log;
023    import com.liferay.portal.kernel.log.LogFactoryUtil;
024    import com.liferay.portal.kernel.portlet.LiferayWindowState;
025    import com.liferay.portal.kernel.repository.model.FileEntry;
026    import com.liferay.portal.kernel.sanitizer.SanitizerException;
027    import com.liferay.portal.kernel.servlet.SessionErrors;
028    import com.liferay.portal.kernel.servlet.taglib.ui.ImageSelector;
029    import com.liferay.portal.kernel.transaction.Propagation;
030    import com.liferay.portal.kernel.upload.LiferayFileItemException;
031    import com.liferay.portal.kernel.upload.UploadException;
032    import com.liferay.portal.kernel.util.Constants;
033    import com.liferay.portal.kernel.util.HttpUtil;
034    import com.liferay.portal.kernel.util.ParamUtil;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.workflow.WorkflowConstants;
039    import com.liferay.portal.model.TrashedModel;
040    import com.liferay.portal.portletfilerepository.PortletFileRepositoryUtil;
041    import com.liferay.portal.security.auth.PrincipalException;
042    import com.liferay.portal.service.ServiceContext;
043    import com.liferay.portal.service.ServiceContextFactory;
044    import com.liferay.portal.spring.transaction.TransactionAttributeBuilder;
045    import com.liferay.portal.spring.transaction.TransactionHandlerUtil;
046    import com.liferay.portal.struts.PortletAction;
047    import com.liferay.portal.theme.ThemeDisplay;
048    import com.liferay.portal.util.PortalUtil;
049    import com.liferay.portal.util.PortletKeys;
050    import com.liferay.portal.util.PropsValues;
051    import com.liferay.portal.util.WebKeys;
052    import com.liferay.portlet.PortletURLImpl;
053    import com.liferay.portlet.asset.AssetCategoryException;
054    import com.liferay.portlet.asset.AssetTagException;
055    import com.liferay.portlet.blogs.BlogsEntryAttachmentFileEntryHelper;
056    import com.liferay.portlet.blogs.BlogsEntryAttachmentFileEntryReference;
057    import com.liferay.portlet.blogs.EntryContentException;
058    import com.liferay.portlet.blogs.EntryDescriptionException;
059    import com.liferay.portlet.blogs.EntryDisplayDateException;
060    import com.liferay.portlet.blogs.EntrySmallImageNameException;
061    import com.liferay.portlet.blogs.EntrySmallImageSizeException;
062    import com.liferay.portlet.blogs.EntryTitleException;
063    import com.liferay.portlet.blogs.NoSuchEntryException;
064    import com.liferay.portlet.blogs.model.BlogsEntry;
065    import com.liferay.portlet.blogs.service.BlogsEntryLocalServiceUtil;
066    import com.liferay.portlet.blogs.service.BlogsEntryServiceUtil;
067    import com.liferay.portlet.documentlibrary.FileSizeException;
068    import com.liferay.portlet.trash.service.TrashEntryServiceUtil;
069    import com.liferay.portlet.trash.util.TrashUtil;
070    
071    import java.util.ArrayList;
072    import java.util.Calendar;
073    import java.util.List;
074    import java.util.concurrent.Callable;
075    
076    import javax.portlet.ActionRequest;
077    import javax.portlet.ActionResponse;
078    import javax.portlet.PortletConfig;
079    import javax.portlet.PortletRequest;
080    import javax.portlet.RenderRequest;
081    import javax.portlet.RenderResponse;
082    import javax.portlet.WindowState;
083    
084    import javax.servlet.http.HttpServletResponse;
085    
086    import org.apache.struts.action.ActionForm;
087    import org.apache.struts.action.ActionForward;
088    import org.apache.struts.action.ActionMapping;
089    
090    import org.springframework.transaction.interceptor.TransactionAttribute;
091    
092    /**
093     * @author Brian Wing Shun Chan
094     * @author Wilson S. Man
095     * @author Thiago Moreira
096     * @author Juan Fern??ndez
097     * @author Zsolt Berentey
098     * @author Levente Hud??k
099     */
100    public class EditEntryAction extends PortletAction {
101    
102            @Override
103            public void processAction(
104                            ActionMapping actionMapping, ActionForm actionForm,
105                            PortletConfig portletConfig, ActionRequest actionRequest,
106                            ActionResponse actionResponse)
107                    throws Exception {
108    
109                    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
110    
111                    try {
112                            BlogsEntry entry = null;
113                            String oldUrlTitle = StringPool.BLANK;
114                            List<BlogsEntryAttachmentFileEntryReference>
115                                    blogsEntryAttachmentFileEntryReferences = null;
116    
117                            UploadException uploadException =
118                                    (UploadException)actionRequest.getAttribute(
119                                            WebKeys.UPLOAD_EXCEPTION);
120    
121                            if (uploadException != null) {
122                                    if (uploadException.isExceededLiferayFileItemSizeLimit()) {
123                                            throw new LiferayFileItemException();
124                                    }
125                                    else if (uploadException.isExceededSizeLimit()) {
126                                            throw new FileSizeException(uploadException.getCause());
127                                    }
128    
129                                    throw new PortalException(uploadException.getCause());
130                            }
131                            else if (cmd.equals(Constants.ADD) ||
132                                             cmd.equals(Constants.UPDATE)) {
133    
134                                    Callable<Object[]> updateEntryCallable =
135                                            new UpdateEntryCallable(actionRequest);
136    
137                                    Object[] returnValue = TransactionHandlerUtil.invoke(
138                                            _transactionAttribute, updateEntryCallable);
139    
140                                    entry = (BlogsEntry)returnValue[0];
141                                    oldUrlTitle = ((String)returnValue[1]);
142                                    blogsEntryAttachmentFileEntryReferences =
143                                            ((List<BlogsEntryAttachmentFileEntryReference>)
144                                                    returnValue[2]);
145                            }
146                            else if (cmd.equals(Constants.DELETE)) {
147                                    deleteEntries(actionRequest, false);
148                            }
149                            else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
150                                    deleteEntries(actionRequest, true);
151                            }
152                            else if (cmd.equals(Constants.RESTORE)) {
153                                    restoreTrashEntries(actionRequest);
154                            }
155                            else if (cmd.equals(Constants.SUBSCRIBE)) {
156                                    subscribe(actionRequest);
157                            }
158                            else if (cmd.equals(Constants.UNSUBSCRIBE)) {
159                                    unsubscribe(actionRequest);
160                            }
161    
162                            String redirect = ParamUtil.getString(actionRequest, "redirect");
163                            boolean updateRedirect = false;
164    
165                            String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);
166    
167                            if (Validator.isNotNull(oldUrlTitle)) {
168                                    String oldRedirectParam =
169                                            PortalUtil.getPortletNamespace(portletId) + "redirect";
170    
171                                    String oldRedirect = HttpUtil.getParameter(
172                                            redirect, oldRedirectParam, false);
173    
174                                    if (Validator.isNotNull(oldRedirect)) {
175                                            String newRedirect = HttpUtil.decodeURL(oldRedirect);
176    
177                                            newRedirect = StringUtil.replace(
178                                                    newRedirect, oldUrlTitle, entry.getUrlTitle());
179                                            newRedirect = StringUtil.replace(
180                                                    newRedirect, oldRedirectParam, "redirect");
181    
182                                            redirect = StringUtil.replace(
183                                                    redirect, oldRedirect, newRedirect);
184                                    }
185                                    else if (redirect.endsWith("/blogs/" + oldUrlTitle) ||
186                                                     redirect.contains("/blogs/" + oldUrlTitle + "?") ||
187                                                     redirect.contains("/blog/" + oldUrlTitle + "?")) {
188    
189                                            redirect = StringUtil.replace(
190                                                    redirect, oldUrlTitle, entry.getUrlTitle());
191                                    }
192    
193                                    updateRedirect = true;
194                            }
195    
196                            int workflowAction = ParamUtil.getInteger(
197                                    actionRequest, "workflowAction",
198                                    WorkflowConstants.ACTION_SAVE_DRAFT);
199    
200                            boolean ajax = ParamUtil.getBoolean(actionRequest, "ajax");
201    
202                            if (ajax) {
203                                    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
204    
205                                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
206    
207                                    for (BlogsEntryAttachmentFileEntryReference
208                                                    blogsEntryAttachmentFileEntryReference :
209                                                            blogsEntryAttachmentFileEntryReferences) {
210    
211                                            JSONObject blogsEntryFileEntryReferencesJSONObject =
212                                                    JSONFactoryUtil.createJSONObject();
213    
214                                            blogsEntryFileEntryReferencesJSONObject.put(
215                                                    "attributeDataImageId",
216                                                    EditorConstants.ATTRIBUTE_DATA_IMAGE_ID);
217                                            blogsEntryFileEntryReferencesJSONObject.put(
218                                                    "fileEntryId",
219                                                    String.valueOf(
220                                                            blogsEntryAttachmentFileEntryReference.
221                                                                    getTempBlogsEntryAttachmentFileEntryId()));
222                                            blogsEntryFileEntryReferencesJSONObject.put(
223                                                    "fileEntryUrl",
224                                                    PortletFileRepositoryUtil.getPortletFileEntryURL(
225                                                            null,
226                                                            blogsEntryAttachmentFileEntryReference.
227                                                                    getBlogsEntryAttachmentFileEntry(),
228                                                            StringPool.BLANK));
229    
230                                            jsonArray.put(blogsEntryFileEntryReferencesJSONObject);
231                                    }
232    
233                                    jsonObject.put("blogsEntryAttachmentReferences", jsonArray);
234    
235                                    jsonObject.put("entryId", entry.getEntryId());
236                                    jsonObject.put("redirect", redirect);
237                                    jsonObject.put("updateRedirect", updateRedirect);
238    
239                                    writeJSON(actionRequest, actionResponse, jsonObject);
240    
241                                    return;
242                            }
243    
244                            if ((entry != null) &&
245                                    (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {
246    
247                                    redirect = getSaveAndContinueRedirect(
248                                            portletConfig, actionRequest, entry, redirect);
249    
250                                    sendRedirect(actionRequest, actionResponse, redirect);
251                            }
252                            else {
253                                    WindowState windowState = actionRequest.getWindowState();
254    
255                                    if (!windowState.equals(LiferayWindowState.POP_UP)) {
256                                            sendRedirect(actionRequest, actionResponse, redirect);
257                                    }
258                                    else {
259                                            redirect = PortalUtil.escapeRedirect(redirect);
260    
261                                            if (Validator.isNotNull(redirect)) {
262                                                    if (cmd.equals(Constants.ADD) && (entry != null)) {
263                                                            String namespace = PortalUtil.getPortletNamespace(
264                                                                    portletId);
265    
266                                                            redirect = HttpUtil.addParameter(
267                                                                    redirect, namespace + "className",
268                                                                    BlogsEntry.class.getName());
269                                                            redirect = HttpUtil.addParameter(
270                                                                    redirect, namespace + "classPK",
271                                                                    entry.getEntryId());
272                                                    }
273    
274                                                    actionResponse.sendRedirect(redirect);
275                                            }
276                                    }
277                            }
278                    }
279                    catch (Exception e) {
280                            if (e instanceof NoSuchEntryException ||
281                                    e instanceof PrincipalException) {
282    
283                                    SessionErrors.add(actionRequest, e.getClass());
284    
285                                    setForward(actionRequest, "portlet.blogs.error");
286                            }
287                            else if (e instanceof EntryContentException ||
288                                             e instanceof EntryDescriptionException ||
289                                             e instanceof EntryDisplayDateException ||
290                                             e instanceof EntrySmallImageNameException ||
291                                             e instanceof EntrySmallImageSizeException ||
292                                             e instanceof EntryTitleException ||
293                                             e instanceof FileSizeException ||
294                                             e instanceof LiferayFileItemException ||
295                                             e instanceof SanitizerException) {
296    
297                                    SessionErrors.add(actionRequest, e.getClass());
298                            }
299                            else if (e instanceof AssetCategoryException ||
300                                             e instanceof AssetTagException) {
301    
302                                    SessionErrors.add(actionRequest, e.getClass(), e);
303                            }
304                            else {
305                                    Throwable cause = e.getCause();
306    
307                                    if (cause instanceof SanitizerException) {
308                                            SessionErrors.add(actionRequest, SanitizerException.class);
309                                    }
310                                    else {
311                                            throw e;
312                                    }
313                            }
314                    }
315                    catch (Throwable t) {
316                            _log.error(t, t);
317    
318                            setForward(actionRequest, "portlet.blogs.error");
319                    }
320            }
321    
322            @Override
323            public ActionForward render(
324                            ActionMapping actionMapping, ActionForm actionForm,
325                            PortletConfig portletConfig, RenderRequest renderRequest,
326                            RenderResponse renderResponse)
327                    throws Exception {
328    
329                    try {
330                            ActionUtil.getEntry(renderRequest);
331    
332                            if (PropsValues.BLOGS_PINGBACK_ENABLED) {
333                                    BlogsEntry entry = (BlogsEntry)renderRequest.getAttribute(
334                                            WebKeys.BLOGS_ENTRY);
335    
336                                    if ((entry != null) && entry.isAllowPingbacks()) {
337                                            HttpServletResponse response =
338                                                    PortalUtil.getHttpServletResponse(renderResponse);
339    
340                                            response.addHeader(
341                                                    "X-Pingback",
342                                                    PortalUtil.getPortalURL(renderRequest) +
343                                                            "/xmlrpc/pingback");
344                                    }
345                            }
346                    }
347                    catch (Exception e) {
348                            if (e instanceof NoSuchEntryException ||
349                                    e instanceof PrincipalException) {
350    
351                                    SessionErrors.add(renderRequest, e.getClass());
352    
353                                    return actionMapping.findForward("portlet.blogs.error");
354                            }
355                            else {
356                                    throw e;
357                            }
358                    }
359    
360                    long assetCategoryId = ParamUtil.getLong(renderRequest, "categoryId");
361                    String assetCategoryName = ParamUtil.getString(renderRequest, "tag");
362    
363                    if ((assetCategoryId > 0) || Validator.isNotNull(assetCategoryName)) {
364                            return actionMapping.findForward("portlet.blogs.view");
365                    }
366    
367                    return actionMapping.findForward(
368                            getForward(renderRequest, "portlet.blogs.edit_entry"));
369            }
370    
371            protected void deleteEntries(
372                            ActionRequest actionRequest, boolean moveToTrash)
373                    throws Exception {
374    
375                    long[] deleteEntryIds = null;
376    
377                    long entryId = ParamUtil.getLong(actionRequest, "entryId");
378    
379                    if (entryId > 0) {
380                            deleteEntryIds = new long[] {entryId};
381                    }
382                    else {
383                            deleteEntryIds = StringUtil.split(
384                                    ParamUtil.getString(actionRequest, "deleteEntryIds"), 0L);
385                    }
386    
387                    List<TrashedModel> trashedModels = new ArrayList<>();
388    
389                    for (long deleteEntryId : deleteEntryIds) {
390                            if (moveToTrash) {
391                                    BlogsEntry entry = BlogsEntryServiceUtil.moveEntryToTrash(
392                                            deleteEntryId);
393    
394                                    trashedModels.add(entry);
395                            }
396                            else {
397                                    BlogsEntryServiceUtil.deleteEntry(deleteEntryId);
398                            }
399                    }
400    
401                    if (moveToTrash && !trashedModels.isEmpty()) {
402                            TrashUtil.addTrashSessionMessages(actionRequest, trashedModels);
403    
404                            hideDefaultSuccessMessage(actionRequest);
405                    }
406            }
407    
408            protected String getSaveAndContinueRedirect(
409                            PortletConfig portletConfig, ActionRequest actionRequest,
410                            BlogsEntry entry, String redirect)
411                    throws Exception {
412    
413                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
414                            WebKeys.THEME_DISPLAY);
415    
416                    String backURL = ParamUtil.getString(actionRequest, "backURL");
417    
418                    PortletURLImpl portletURL = new PortletURLImpl(
419                            actionRequest, portletConfig.getPortletName(),
420                            themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);
421    
422                    String portletName = portletConfig.getPortletName();
423    
424                    if (portletName.equals(PortletKeys.BLOGS_ADMIN)) {
425                            portletURL.setParameter("struts_action", "/blogs_admin/edit_entry");
426                    }
427                    else {
428                            portletURL.setParameter("struts_action", "/blogs/edit_entry");
429                    }
430    
431                    portletURL.setParameter(Constants.CMD, Constants.UPDATE, false);
432                    portletURL.setParameter("redirect", redirect, false);
433                    portletURL.setParameter("backURL", backURL, false);
434                    portletURL.setParameter(
435                            "groupId", String.valueOf(entry.getGroupId()), false);
436                    portletURL.setParameter(
437                            "entryId", String.valueOf(entry.getEntryId()), false);
438                    portletURL.setWindowState(actionRequest.getWindowState());
439    
440                    return portletURL.toString();
441            }
442    
443            protected void restoreTrashEntries(ActionRequest actionRequest)
444                    throws Exception {
445    
446                    long[] restoreTrashEntryIds = StringUtil.split(
447                            ParamUtil.getString(actionRequest, "restoreTrashEntryIds"), 0L);
448    
449                    for (long restoreTrashEntryId : restoreTrashEntryIds) {
450                            TrashEntryServiceUtil.restoreEntry(restoreTrashEntryId);
451                    }
452            }
453    
454            protected void subscribe(ActionRequest actionRequest) throws Exception {
455                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
456                            WebKeys.THEME_DISPLAY);
457    
458                    BlogsEntryServiceUtil.subscribe(themeDisplay.getScopeGroupId());
459            }
460    
461            protected void unsubscribe(ActionRequest actionRequest) throws Exception {
462                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
463                            WebKeys.THEME_DISPLAY);
464    
465                    BlogsEntryServiceUtil.unsubscribe(themeDisplay.getScopeGroupId());
466            }
467    
468            protected Object[] updateEntry(ActionRequest actionRequest)
469                    throws Exception {
470    
471                    ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
472                            WebKeys.THEME_DISPLAY);
473    
474                    long entryId = ParamUtil.getLong(actionRequest, "entryId");
475    
476                    String title = ParamUtil.getString(actionRequest, "title");
477                    String subtitle = ParamUtil.getString(actionRequest, "subtitle");
478    
479                    String description = StringPool.BLANK;
480    
481                    boolean customAbstract = ParamUtil.getBoolean(
482                            actionRequest, "customAbstract");
483    
484                    if (customAbstract) {
485                            description = ParamUtil.getString(actionRequest, "description");
486    
487                            if (Validator.isNull(description)) {
488                                    throw new EntryDescriptionException();
489                            }
490                    }
491    
492                    String content = ParamUtil.getString(actionRequest, "content");
493    
494                    int displayDateMonth = ParamUtil.getInteger(
495                            actionRequest, "displayDateMonth");
496                    int displayDateDay = ParamUtil.getInteger(
497                            actionRequest, "displayDateDay");
498                    int displayDateYear = ParamUtil.getInteger(
499                            actionRequest, "displayDateYear");
500                    int displayDateHour = ParamUtil.getInteger(
501                            actionRequest, "displayDateHour");
502                    int displayDateMinute = ParamUtil.getInteger(
503                            actionRequest, "displayDateMinute");
504                    int displayDateAmPm = ParamUtil.getInteger(
505                            actionRequest, "displayDateAmPm");
506    
507                    if (displayDateAmPm == Calendar.PM) {
508                            displayDateHour += 12;
509                    }
510    
511                    boolean allowPingbacks = ParamUtil.getBoolean(
512                            actionRequest, "allowPingbacks");
513                    boolean allowTrackbacks = ParamUtil.getBoolean(
514                            actionRequest, "allowTrackbacks");
515                    String[] trackbacks = StringUtil.split(
516                            ParamUtil.getString(actionRequest, "trackbacks"));
517    
518                    long coverImageFileEntryId = ParamUtil.getLong(
519                            actionRequest, "coverImageFileEntryId");
520                    String coverImageURL = ParamUtil.getString(
521                            actionRequest, "coverImageURL");
522                    String coverImageFileEntryCropRegion = ParamUtil.getString(
523                            actionRequest, "coverImageFileEntryCropRegion");
524    
525                    String coverImageCaption = ParamUtil.getString(
526                            actionRequest, "coverImageCaption");
527    
528                    ImageSelector coverImageImageSelector = new ImageSelector(
529                            coverImageFileEntryId, coverImageURL,
530                            coverImageFileEntryCropRegion);
531    
532                    long smallImageFileEntryId = ParamUtil.getLong(
533                            actionRequest, "smallImageFileEntryId");
534                    String smallImageURL = ParamUtil.getString(
535                            actionRequest, "smallImageURL");
536    
537                    ImageSelector smallImageImageSelector = new ImageSelector(
538                            smallImageFileEntryId, smallImageURL, null);
539    
540                    ServiceContext serviceContext = ServiceContextFactory.getInstance(
541                            BlogsEntry.class.getName(), actionRequest);
542    
543                    BlogsEntry entry = null;
544                    String oldUrlTitle = StringPool.BLANK;
545                    List<BlogsEntryAttachmentFileEntryReference>
546                            blogsEntryAttachmentFileEntryReferences = new ArrayList<>();
547    
548                    if (entryId <= 0) {
549    
550                            // Add entry
551    
552                            entry = BlogsEntryServiceUtil.addEntry(
553                                    title, subtitle, description, content, displayDateMonth,
554                                    displayDateDay, displayDateYear, displayDateHour,
555                                    displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks,
556                                    coverImageCaption, coverImageImageSelector,
557                                    smallImageImageSelector, serviceContext);
558    
559                            BlogsEntryAttachmentFileEntryHelper
560                                    blogsEntryAttachmentFileEntryHelper =
561                                            new BlogsEntryAttachmentFileEntryHelper();
562    
563                            List<FileEntry> tempBlogsEntryAttachments =
564                                    blogsEntryAttachmentFileEntryHelper.
565                                            getTempBlogsEntryAttachmentFileEntries(content);
566    
567                            if (!tempBlogsEntryAttachments.isEmpty()) {
568                                    blogsEntryAttachmentFileEntryReferences =
569                                            blogsEntryAttachmentFileEntryHelper.
570                                                    addBlogsEntryAttachmentFileEntries(
571                                                            entry.getGroupId(), themeDisplay.getUserId(),
572                                                            entry.getEntryId(), tempBlogsEntryAttachments);
573    
574                                    content = blogsEntryAttachmentFileEntryHelper.updateContent(
575                                            content, blogsEntryAttachmentFileEntryReferences);
576    
577                                    entry.setContent(content);
578    
579                                    BlogsEntryLocalServiceUtil.updateBlogsEntry(entry);
580                            }
581    
582                            for (FileEntry tempBlogsEntryAttachment :
583                                            tempBlogsEntryAttachments) {
584    
585                                    PortletFileRepositoryUtil.deletePortletFileEntry(
586                                            tempBlogsEntryAttachment.getFileEntryId());
587                            }
588                    }
589                    else {
590    
591                            // Update entry
592    
593                            boolean sendEmailEntryUpdated = ParamUtil.getBoolean(
594                                    actionRequest, "sendEmailEntryUpdated");
595    
596                            serviceContext.setAttribute(
597                                    "sendEmailEntryUpdated", sendEmailEntryUpdated);
598    
599                            String emailEntryUpdatedComment = ParamUtil.getString(
600                                    actionRequest, "emailEntryUpdatedComment");
601    
602                            serviceContext.setAttribute(
603                                    "emailEntryUpdatedComment", emailEntryUpdatedComment);
604    
605                            entry = BlogsEntryLocalServiceUtil.getEntry(entryId);
606    
607                            String tempOldUrlTitle = entry.getUrlTitle();
608    
609                            BlogsEntryAttachmentFileEntryHelper blogsEntryAttachmentHelper =
610                                    new BlogsEntryAttachmentFileEntryHelper();
611    
612                            List<FileEntry> tempBlogsEntryAttachmentFileEntries =
613                                    blogsEntryAttachmentHelper.
614                                            getTempBlogsEntryAttachmentFileEntries(content);
615    
616                            if (!tempBlogsEntryAttachmentFileEntries.isEmpty()) {
617                                    blogsEntryAttachmentFileEntryReferences =
618                                            blogsEntryAttachmentHelper.
619                                                    addBlogsEntryAttachmentFileEntries(
620                                                            entry.getGroupId(), themeDisplay.getUserId(),
621                                                            entry.getEntryId(),
622                                                            tempBlogsEntryAttachmentFileEntries);
623    
624                                    content = blogsEntryAttachmentHelper.updateContent(
625                                            content, blogsEntryAttachmentFileEntryReferences);
626                            }
627    
628                            entry = BlogsEntryServiceUtil.updateEntry(
629                                    entryId, title, subtitle, description, content,
630                                    displayDateMonth, displayDateDay, displayDateYear,
631                                    displayDateHour, displayDateMinute, allowPingbacks,
632                                    allowTrackbacks, trackbacks, coverImageCaption,
633                                    coverImageImageSelector, smallImageImageSelector,
634                                    serviceContext);
635    
636                            for (FileEntry tempBlogsEntryAttachmentFileEntry :
637                                            tempBlogsEntryAttachmentFileEntries) {
638    
639                                    PortletFileRepositoryUtil.deletePortletFileEntry(
640                                            tempBlogsEntryAttachmentFileEntry.getFileEntryId());
641                            }
642    
643                            if (!tempOldUrlTitle.equals(entry.getUrlTitle())) {
644                                    oldUrlTitle = tempOldUrlTitle;
645                            }
646                    }
647    
648                    return new Object[] {
649                            entry, oldUrlTitle, blogsEntryAttachmentFileEntryReferences
650                    };
651            }
652    
653            private static final Log _log = LogFactoryUtil.getLog(
654                    EditEntryAction.class);
655    
656            private final TransactionAttribute _transactionAttribute =
657                    TransactionAttributeBuilder.build(
658                            Propagation.REQUIRED, new Class<?>[] {Exception.class});
659    
660            private class UpdateEntryCallable implements Callable<Object[]> {
661    
662                    @Override
663                    public Object[] call() throws Exception {
664                            return updateEntry(_actionRequest);
665                    }
666    
667                    private UpdateEntryCallable(ActionRequest actionRequest) {
668                            _actionRequest = actionRequest;
669                    }
670    
671                    private final ActionRequest _actionRequest;
672    
673            }
674    
675    }