Example usage for com.liferay.portal.kernel.util PortalUtil getPortletNamespace

List of usage examples for com.liferay.portal.kernel.util PortalUtil getPortletNamespace

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PortalUtil getPortletNamespace.

Prototype

public static String getPortletNamespace(String portletId) 

Source Link

Usage

From source file:com.liferay.asset.taglib.servlet.taglib.AssetCategoriesSelectorTag.java

License:Open Source License

protected String getEventName() {
    String portletId = PortletProviderUtil.getPortletId(AssetCategory.class.getName(),
            PortletProvider.Action.BROWSE);

    return PortalUtil.getPortletNamespace(portletId) + "selectCategory";
}

From source file:com.liferay.asset.taglib.servlet.taglib.AssetTagsSelectorTag.java

License:Open Source License

protected String getEventName() {
    String portletId = PortletProviderUtil.getPortletId(AssetTag.class.getName(),
            PortletProvider.Action.BROWSE);

    return PortalUtil.getPortletNamespace(portletId) + "selectTag";
}

From source file:com.liferay.blogs.internal.util.PingbackMethodImpl.java

License:Open Source License

protected String getParam(Map<String, String[]> params, String name) {
    String[] paramArray = params.get(name);

    if (paramArray == null) {
        String portletId = PortletProviderUtil.getPortletId(BlogsEntry.class.getName(),
                PortletProvider.Action.VIEW);

        String namespace = PortalUtil.getPortletNamespace(portletId);

        paramArray = params.get(namespace + name);
    }//from  w w w  .  j ava2s  . c  om

    if (ArrayUtil.isNotEmpty(paramArray)) {
        return paramArray[0];
    } else {
        return null;
    }
}

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  ww  w  .  java 2  s  .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.bookmarks.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   www.  jav  a 2 s  .  c  om
        BookmarksEntry entry = null;

        if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
            entry = updateEntry(actionRequest);
        } else if (cmd.equals(Constants.DELETE)) {
            deleteEntry(actionRequest, false);
        } else if (cmd.equals(Constants.MOVE)) {
            moveEntries(actionRequest);
        } else if (cmd.equals(Constants.MOVE_TO_TRASH)) {
            deleteEntry(actionRequest, true);
        } else if (cmd.equals(Constants.RESTORE)) {
            restoreTrashEntries(actionRequest);
        } else if (cmd.equals(Constants.SUBSCRIBE)) {
            subscribeEntry(actionRequest);
        } else if (cmd.equals(Constants.UNSUBSCRIBE)) {
            unsubscribeEntry(actionRequest);
        }

        WindowState windowState = actionRequest.getWindowState();

        if (windowState.equals(LiferayWindowState.POP_UP)) {
            String redirect = PortalUtil.escapeRedirect(ParamUtil.getString(actionRequest, "redirect"));

            if (Validator.isNotNull(redirect)) {
                if (cmd.equals(Constants.ADD) && (entry != null)) {
                    String portletId = HttpUtil.getParameter(redirect, "p_p_id", false);

                    String namespace = PortalUtil.getPortletNamespace(portletId);

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

                actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
            }
        }
    } catch (Exception e) {
        if (e instanceof NoSuchEntryException || e instanceof PrincipalException) {

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

            actionResponse.setRenderParameter("mvcPath", "/bookmarks/error.jsp");
        } else if (e instanceof EntryURLException || e instanceof NoSuchFolderException) {

            SessionErrors.add(actionRequest, e.getClass());
        } else if (e instanceof AssetCategoryException || e instanceof AssetTagException) {

            SessionErrors.add(actionRequest, e.getClass(), e);
        } else {
            throw e;
        }
    }
}

From source file:com.liferay.calendar.notification.impl.NotificationTemplateContextFactory.java

License:Open Source License

private static String _getCalendarBookingURL(User user, long calendarBookingId) throws PortalException {

    Group group = GroupLocalServiceUtil.getGroup(user.getCompanyId(), GroupConstants.GUEST);

    Layout layout = LayoutLocalServiceUtil.fetchLayout(group.getDefaultPublicPlid());

    String portalURL = _getPortalURL(group.getCompanyId(), group.getGroupId());

    String layoutActualURL = PortalUtil.getLayoutActualURL(layout);

    String url = portalURL + layoutActualURL;

    String namespace = PortalUtil.getPortletNamespace(CalendarPortletKeys.CALENDAR);

    url = HttpUtil.addParameter(url, namespace + "mvcPath", "/view_calendar_booking.jsp");

    url = HttpUtil.addParameter(url, "p_p_id", CalendarPortletKeys.CALENDAR);
    url = HttpUtil.addParameter(url, "p_p_lifecycle", "0");
    url = HttpUtil.addParameter(url, "p_p_state", WindowState.MAXIMIZED.toString());
    url = HttpUtil.addParameter(url, namespace + "calendarBookingId", calendarBookingId);

    return url;/*from w w  w  . ja v a 2 s .c o m*/
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.display.context.DDLFormViewRecordDisplayContext.java

License:Open Source License

protected DDMFormRenderingContext createDDMFormRenderingContext() {
    DDMFormRenderingContext ddmFormRenderingContext = new DDMFormRenderingContext();

    ddmFormRenderingContext.setHttpServletRequest(_ddlFormAdminRequestHelper.getRequest());
    ddmFormRenderingContext.setHttpServletResponse(_httpServletResponse);
    ddmFormRenderingContext.setLocale(_ddlFormAdminRequestHelper.getLocale());
    ddmFormRenderingContext.setPortletNamespace(
            PortalUtil.getPortletNamespace(DDLFormPortletKeys.DYNAMIC_DATA_LISTS_FORM_ADMIN));
    ddmFormRenderingContext.setReadOnly(true);

    return ddmFormRenderingContext;
}

From source file:com.liferay.dynamic.data.mapping.form.web.internal.display.context.DDMFormViewFormInstanceRecordDisplayContext.java

License:Open Source License

protected DDMFormRenderingContext createDDMFormRenderingContext() {
    DDMFormRenderingContext formRenderingContext = new DDMFormRenderingContext();

    formRenderingContext.setHttpServletRequest(_ddmFormAdminRequestHelper.getRequest());
    formRenderingContext.setHttpServletResponse(_httpServletResponse);
    formRenderingContext.setLocale(_ddmFormAdminRequestHelper.getLocale());
    formRenderingContext.setPortletNamespace(
            PortalUtil.getPortletNamespace(DDMFormPortletKeys.DYNAMIC_DATA_MAPPING_FORM_ADMIN));
    formRenderingContext.setReadOnly(true);

    return formRenderingContext;
}

From source file:com.liferay.flags.taglib.servlet.taglib.soy.FlagsTag.java

License:Open Source License

@Override
public int doStartTag() {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    String randomNamespace = StringUtil.randomId() + StringPool.UNDERLINE;

    try {/* w  w w . java 2 s .  c  o  m*/
        Map<String, Object> context = getContext();

        boolean enabled = GetterUtil.getBoolean(context.get("enabled"), true);

        Company company = themeDisplay.getCompany();

        putValue("companyName", company.getName());

        putValue("flagsEnabled", _isFlagsEnabled(themeDisplay));

        putValue("formData", _getDataJSONObject(context));

        putValue("id", randomNamespace + "id");

        putValue("enabled", enabled);

        boolean label = GetterUtil.getBoolean(context.get("label"), true);

        putValue("label", label);

        String message = GetterUtil.getString(context.get("message"), LanguageUtil.get(request, "flag"));

        putValue("message", message);

        putValue("pathTermsOfUse", themeDisplay.getPathMain() + "/portal/terms_of_use");

        putValue("pathThemeImages", themeDisplay.getPathThemeImages());

        putValue("portletNamespace", PortalUtil.getPortletNamespace(PortletKeys.FLAGS));

        boolean signedIn = themeDisplay.isSignedIn();

        putValue("signedIn", signedIn);

        if (signedIn) {
            User user = themeDisplay.getUser();

            putValue("reporterEmailAddress", user.getEmailAddress());
        }

        String title = message;

        if (!enabled) {
            title = LanguageUtil.get(request,
                    "flags-are-disabled-because-this-entry-is-in-the-recycle-" + "bin");
        }

        putValue("title", title);

        putValue("uri", _getURI());

        putValue("reasons", _getReasons(themeDisplay.getCompanyId()));
    } catch (Exception e) {
        _log.error(e, e);
    }

    setTemplateNamespace("Flags.render");

    return super.doStartTag();
}

From source file:com.liferay.flags.taglib.servlet.taglib.soy.FlagsTag.java

License:Open Source License

private JSONObject _getDataJSONObject(Map<String, Object> context) {
    String namespace = PortalUtil.getPortletNamespace(PortletKeys.FLAGS);

    JSONObject dataJSONObject = JSONFactoryUtil.createJSONObject();

    dataJSONObject.put(namespace + "className", context.get("className"));
    dataJSONObject.put(namespace + "classPK", context.get("classPK"));
    dataJSONObject.put(namespace + "contentTitle", context.get("contentTitle"));
    dataJSONObject.put(namespace + "contentURL", _getCurrentURL());
    dataJSONObject.put(namespace + "reportedUserId", context.get("reportedUserId"));

    return dataJSONObject;
}