Example usage for com.liferay.portal.kernel.editor EditorConstants ATTRIBUTE_DATA_IMAGE_ID

List of usage examples for com.liferay.portal.kernel.editor EditorConstants ATTRIBUTE_DATA_IMAGE_ID

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.editor EditorConstants ATTRIBUTE_DATA_IMAGE_ID.

Prototype

String ATTRIBUTE_DATA_IMAGE_ID

To view the source code for com.liferay.portal.kernel.editor EditorConstants ATTRIBUTE_DATA_IMAGE_ID.

Click Source Link

Usage

From source file:com.liferay.blogs.attachments.test.BlogsEntryAttachmentFileEntryHelperTest.java

License:Open Source License

protected String getModifiedTempFileEntryImgTag(FileEntry tempFileEntry) {
    StringBundler sb = new StringBundler(7);

    sb.append("<img ");
    sb.append(EditorConstants.ATTRIBUTE_DATA_IMAGE_ID);
    sb.append("=\"");
    sb.append(tempFileEntry.getFileEntryId());
    sb.append("\" class=\"test-class\" id=\"test-id\" src=\"");
    sb.append(PortletFileRepositoryUtil.getPortletFileEntryURL(null, tempFileEntry, StringPool.BLANK));
    sb.append("\" title=\"test-title\" />");

    return sb.toString();
}

From source file:com.liferay.blogs.test.util.BlogsTestUtil.java

License:Open Source License

public static String getTempBlogsEntryAttachmentFileEntryImgTag(long dataImageId, String url) {

    StringBundler sb = new StringBundler(7);

    sb.append("<img ");
    sb.append(EditorConstants.ATTRIBUTE_DATA_IMAGE_ID);
    sb.append("=\"");
    sb.append(dataImageId);/* w ww  . j  a v a2 s.  c  om*/
    sb.append("\" src=\"");
    sb.append(url);
    sb.append("\"/>");

    return sb.toString();
}

From source file:com.liferay.blogs.util.BlogsEntryAttachmentContentUpdater.java

License:Open Source License

public String updateContent(String content,
        List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences) {

    for (BlogsEntryAttachmentFileEntryReference blogsEntryAttachmentFileEntryReference : blogsEntryAttachmentFileEntryReferences) {

        StringBundler sb = new StringBundler(8);

        sb.append("<\\s*?img");
        sb.append(_ATTRIBUTE_LIST_REGEXP);
        sb.append(EditorConstants.ATTRIBUTE_DATA_IMAGE_ID);
        sb.append("\\s*?=\\s*?\"");
        sb.append(blogsEntryAttachmentFileEntryReference.getTempBlogsEntryAttachmentFileEntryId());
        sb.append("\"");
        sb.append(_ATTRIBUTE_LIST_REGEXP);
        sb.append("/>");

        content = content.replaceAll(sb.toString(), getBlogsEntryAttachmentFileEntryImgTag(
                blogsEntryAttachmentFileEntryReference.getBlogsEntryAttachmentFileEntry()));
    }//from  ww w .jav a 2 s  .c  o  m

    return content;
}

From source file:com.liferay.blogs.util.BlogsEntryAttachmentFileEntryUtil.java

License:Open Source License

public static List<FileEntry> getTempBlogsEntryAttachmentFileEntries(String content) throws PortalException {

    List<FileEntry> tempBlogsEntryAttachmentFileEntries = new ArrayList<>();

    Pattern pattern = Pattern.compile(EditorConstants.ATTRIBUTE_DATA_IMAGE_ID + "=.(\\d+)");

    Matcher matcher = pattern.matcher(content);

    while (matcher.find()) {
        long fileEntryId = GetterUtil.getLong(matcher.group(1));

        FileEntry tempFileEntry = PortletFileRepositoryUtil.getPortletFileEntry(fileEntryId);

        tempBlogsEntryAttachmentFileEntries.add(tempFileEntry);
    }/*from w w w. jav  a  2  s.  c  o  m*/

    return tempBlogsEntryAttachmentFileEntries;
}

From source file:com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    String cmd = ParamUtil.getString(actionRequest, Constants.CMD);

    try {//from   w  w w .  j  a va2s .c o  m
        BlogsEntry entry = null;
        List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences = null;

        UploadException uploadException = (UploadException) actionRequest
                .getAttribute(WebKeys.UPLOAD_EXCEPTION);

        if (uploadException != null) {
            Throwable cause = uploadException.getCause();

            if (uploadException.isExceededFileSizeLimit()) {
                throw new FileSizeException(cause);
            }

            if (uploadException.isExceededLiferayFileItemSizeLimit()) {
                throw new LiferayFileItemException(cause);
            }

            if (uploadException.isExceededUploadRequestSizeLimit()) {
                throw new UploadRequestSizeException(cause);
            }

            throw new PortalException(cause);
        } else if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {

            Callable<Object[]> updateEntryCallable = new UpdateEntryCallable(actionRequest);

            Object[] returnValue = TransactionInvokerUtil.invoke(_transactionConfig, updateEntryCallable);

            entry = (BlogsEntry) returnValue[0];
            blogsEntryAttachmentFileEntryReferences = (List<BlogsEntryAttachmentFileEntryReference>) returnValue[1];
        } else if (cmd.equals(Constants.DELETE)) {
            deleteEntries(actionRequest, false);
        } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
            deleteEntries(actionRequest, true);
        } else if (cmd.equals(Constants.RESTORE)) {
            restoreTrashEntries(actionRequest);
        } else if (cmd.equals(Constants.SUBSCRIBE)) {
            subscribe(actionRequest);
        } else if (cmd.equals(Constants.UNSUBSCRIBE)) {
            unsubscribe(actionRequest);
        }

        String redirect = ParamUtil.getString(actionRequest, "redirect");
        String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

        int workflowAction = ParamUtil.getInteger(actionRequest, "workflowAction",
                WorkflowConstants.ACTION_SAVE_DRAFT);

        boolean ajax = ParamUtil.getBoolean(actionRequest, "ajax");

        if (ajax) {
            JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

            JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

            for (BlogsEntryAttachmentFileEntryReference blogsEntryAttachmentFileEntryReference : blogsEntryAttachmentFileEntryReferences) {

                JSONObject blogsEntryFileEntryReferencesJSONObject = JSONFactoryUtil.createJSONObject();

                blogsEntryFileEntryReferencesJSONObject.put("attributeDataImageId",
                        EditorConstants.ATTRIBUTE_DATA_IMAGE_ID);
                blogsEntryFileEntryReferencesJSONObject.put("fileEntryId", String.valueOf(
                        blogsEntryAttachmentFileEntryReference.getTempBlogsEntryAttachmentFileEntryId()));
                blogsEntryFileEntryReferencesJSONObject.put("fileEntryUrl",
                        PortletFileRepositoryUtil.getPortletFileEntryURL(null,
                                blogsEntryAttachmentFileEntryReference.getBlogsEntryAttachmentFileEntry(),
                                StringPool.BLANK));

                jsonArray.put(blogsEntryFileEntryReferencesJSONObject);
            }

            jsonObject.put("blogsEntryAttachmentReferences", jsonArray);
            jsonObject.put("coverImageFileEntryId", entry.getCoverImageFileEntryId());
            jsonObject.put("entryId", entry.getEntryId());
            jsonObject.put("redirect", redirect);

            JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);

            return;
        }

        if ((entry != null) && (workflowAction == WorkflowConstants.ACTION_SAVE_DRAFT)) {

            redirect = getSaveAndContinueRedirect(actionRequest, entry, redirect);

            sendRedirect(actionRequest, actionResponse, redirect);
        } else {
            WindowState windowState = actionRequest.getWindowState();

            if (!windowState.equals(LiferayWindowState.POP_UP)) {
                sendRedirect(actionRequest, actionResponse, redirect);
            } else {
                redirect = PortalUtil.escapeRedirect(redirect);

                if (Validator.isNotNull(redirect)) {
                    if (cmd.equals(Constants.ADD) && (entry != null)) {
                        String namespace = PortalUtil.getPortletNamespace(portletId);

                        redirect = HttpUtil.addParameter(redirect, namespace + "className",
                                BlogsEntry.class.getName());
                        redirect = HttpUtil.addParameter(redirect, namespace + "classPK", entry.getEntryId());
                    }

                    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
                }
            }
        }
    } catch (AssetCategoryException | AssetTagException e) {
        SessionErrors.add(actionRequest, e.getClass(), e);

        actionResponse.setRenderParameter("mvcRenderCommandName", "/blogs/edit_entry");

        hideDefaultSuccessMessage(actionRequest);
    } catch (EntryContentException | EntryCoverImageCropException | EntryDescriptionException
            | EntryDisplayDateException | EntrySmallImageNameException | EntrySmallImageScaleException
            | EntryTitleException | EntryUrlTitleException | FileSizeException | LiferayFileItemException
            | SanitizerException | UploadRequestSizeException e) {

        SessionErrors.add(actionRequest, e.getClass());

        actionResponse.setRenderParameter("mvcRenderCommandName", "/blogs/edit_entry");

        hideDefaultSuccessMessage(actionRequest);
    } catch (NoSuchEntryException | PrincipalException e) {
        SessionErrors.add(actionRequest, e.getClass());

        actionResponse.setRenderParameter("mvcPath", "/blogs/error.jsp");

        hideDefaultSuccessMessage(actionRequest);
    } catch (Throwable t) {
        _log.error(t, t);

        actionResponse.setRenderParameter("mvcPath", "/blogs/error.jsp");

        hideDefaultSuccessMessage(actionRequest);
    }
}

From source file:com.liferay.message.boards.web.internal.upload.format.handlers.MBMessageBBCodeFormatUploadHandler.java

License:Open Source License

private Pattern _getTempImagePattern(long tempFileId) {
    return Pattern.compile(StringBundler.concat("\\[img[^\\]]*?", EditorConstants.ATTRIBUTE_DATA_IMAGE_ID,
            "=\"", String.valueOf(tempFileId), "\"[^\\]]*\\][^\\[]+\\[/img\\]"));
}

From source file:com.liferay.message.boards.web.internal.upload.format.handlers.MBMessageHTMLFormatUploadHandler.java

License:Open Source License

@Override
public String replaceImageReferences(String content,
        List<MBAttachmentFileEntryReference> mbAttachmentFileEntryReferences) {

    for (MBAttachmentFileEntryReference mbAttachmentFileEntryReference : mbAttachmentFileEntryReferences) {

        StringBundler sb = new StringBundler(8);

        sb.append("<\\s*?img");
        sb.append(_ATTRIBUTE_LIST_REGEXP);
        sb.append(EditorConstants.ATTRIBUTE_DATA_IMAGE_ID);
        sb.append("\\s*?=\\s*?\"");
        sb.append(mbAttachmentFileEntryReference.getTempMBAttachmentFileEntryId());
        sb.append("\"");
        sb.append(_ATTRIBUTE_LIST_REGEXP);
        sb.append("/>");

        content = content.replaceAll(sb.toString(),
                _getMBAttachmentFileEntryHTMLImgTag(mbAttachmentFileEntryReference.getMBAttachmentFileEntry()));
    }//from   w  w  w .  j  a  va2s. co  m

    return content;
}

From source file:com.liferay.message.boards.web.internal.util.MBAttachmentFileEntryUtil.java

License:Open Source License

public static List<FileEntry> getTempMBAttachmentFileEntries(String content) throws PortalException {

    List<FileEntry> tempMBAttachmentFileEntries = new ArrayList<>();

    Pattern pattern = Pattern.compile(EditorConstants.ATTRIBUTE_DATA_IMAGE_ID + "=.(\\d+)");

    Matcher matcher = pattern.matcher(content);

    while (matcher.find()) {
        long fileEntryId = GetterUtil.getLong(matcher.group(1));

        FileEntry tempFileEntry = PortletFileRepositoryUtil.getPortletFileEntry(fileEntryId);

        tempMBAttachmentFileEntries.add(tempFileEntry);
    }/*from   w w w . jav  a  2 s . com*/

    return tempMBAttachmentFileEntries;
}