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