Example usage for com.liferay.portal.kernel.model Layout getRegularURL

List of usage examples for com.liferay.portal.kernel.model Layout getRegularURL

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Layout getRegularURL.

Prototype

public String getRegularURL(javax.servlet.http.HttpServletRequest httpServletRequest)
            throws com.liferay.portal.kernel.exception.PortalException;

Source Link

Usage

From source file:com.liferay.layout.admin.web.internal.portlet.action.ResetCustomizationViewMVCActionCommand.java

License:Open Source License

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

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    if (!LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), themeDisplay.getLayout(),
            ActionKeys.CUSTOMIZE)) {//from   ww  w.  ja v  a  2s.com

        throw new PrincipalException();
    }

    LayoutTypePortlet layoutTypePortlet = themeDisplay.getLayoutTypePortlet();

    if ((layoutTypePortlet != null) && layoutTypePortlet.isCustomizable()
            && layoutTypePortlet.isCustomizedView()) {

        layoutTypePortlet.resetUserPreferences();
    }

    MultiSessionMessages.add(actionRequest, _portal.getPortletId(actionRequest) + "requestProcessed");

    Layout layout = themeDisplay.getLayout();

    actionResponse.sendRedirect(layout.getRegularURL(_portal.getHttpServletRequest(actionRequest)));
}

From source file:com.liferay.layout.internal.util.LayoutsTreeImpl.java

License:Open Source License

private JSONObject _toJSONObject(HttpServletRequest request, long groupId, LayoutTreeNodes layoutTreeNodes,
        LayoutSetBranch layoutSetBranch) throws Exception {

    if (_log.isDebugEnabled()) {
        StringBundler sb = new StringBundler(5);

        sb.append("_toJSON(groupId=");
        sb.append(groupId);//from   w w w  .  ja  v a  2s .com
        sb.append(", layoutTreeNodes=");
        sb.append(layoutTreeNodes);
        sb.append(StringPool.CLOSE_PARENTHESIS);

        _log.debug(sb.toString());
    }

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    boolean hasManageLayoutsPermission = GroupPermissionUtil.contains(themeDisplay.getPermissionChecker(),
            groupId, ActionKeys.MANAGE_LAYOUTS);
    boolean mobile = BrowserSnifferUtil.isMobile(request);

    for (LayoutTreeNode layoutTreeNode : layoutTreeNodes) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        JSONObject childrenJSONObject = _toJSONObject(request, groupId,
                layoutTreeNode.getChildLayoutTreeNodes(), layoutSetBranch);

        jsonObject.put("children", childrenJSONObject);

        Layout layout = layoutTreeNode.getLayout();

        jsonObject.put("contentDisplayPage", layout.isContentDisplayPage());
        jsonObject.put("deleteable", _isDeleteable(layout, themeDisplay, layoutSetBranch));
        jsonObject.put("friendlyURL", layout.getFriendlyURL());

        if (layout instanceof VirtualLayout) {
            VirtualLayout virtualLayout = (VirtualLayout) layout;

            jsonObject.put("groupId", virtualLayout.getSourceGroupId());
        } else {
            jsonObject.put("groupId", layout.getGroupId());
        }

        jsonObject.put("hasChildren", layout.hasChildren());
        jsonObject.put("layoutId", layout.getLayoutId());
        jsonObject.put("name", layout.getName(themeDisplay.getLocale()));
        jsonObject.put("parentable", LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout,
                ActionKeys.ADD_LAYOUT));
        jsonObject.put("parentLayoutId", layout.getParentLayoutId());
        jsonObject.put("plid", layout.getPlid());
        jsonObject.put("priority", layout.getPriority());
        jsonObject.put("privateLayout", layout.isPrivateLayout());
        jsonObject.put("regularURL", layout.getRegularURL(request));
        jsonObject.put("sortable", hasManageLayoutsPermission && !mobile && SitesUtil.isLayoutSortable(layout));
        jsonObject.put("type", layout.getType());
        jsonObject.put("updateable",
                LayoutPermissionUtil.contains(themeDisplay.getPermissionChecker(), layout, ActionKeys.UPDATE));
        jsonObject.put("uuid", layout.getUuid());

        LayoutRevision layoutRevision = LayoutStagingUtil.getLayoutRevision(layout);

        if (layoutRevision != null) {
            long layoutSetBranchId = layoutRevision.getLayoutSetBranchId();

            if (_staging.isIncomplete(layout, layoutSetBranchId)) {
                jsonObject.put("incomplete", true);
            }

            LayoutSetBranch boundLayoutSetBranch = _layoutSetBranchLocalService
                    .getLayoutSetBranch(layoutSetBranchId);

            LayoutBranch layoutBranch = layoutRevision.getLayoutBranch();

            if (!layoutBranch.isMaster()) {
                jsonObject.put("layoutBranchId", layoutBranch.getLayoutBranchId());
                jsonObject.put("layoutBranchName", layoutBranch.getName());
            }

            if (layoutRevision.isHead()) {
                jsonObject.put("layoutRevisionHead", true);
            }

            jsonObject.put("layoutRevisionId", layoutRevision.getLayoutRevisionId());
            jsonObject.put("layoutSetBranchId", layoutSetBranchId);
            jsonObject.put("layoutSetBranchName", boundLayoutSetBranch.getName());
        }

        jsonArray.put(jsonObject);
    }

    JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject();

    responseJSONObject.put("layouts", jsonArray);
    responseJSONObject.put("total", layoutTreeNodes.getTotal());

    return responseJSONObject;
}

From source file:com.liferay.layout.type.controller.test.LayoutTypeURLTest.java

License:Open Source License

@Test
public void testGetRegularURLLayoutTypeURL() throws Exception {
    ThemeDisplay themeDisplay = _initThemeDisplay();

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext();

    Layout layoutURLType = LayoutLocalServiceUtil.addLayout(TestPropsValues.getUserId(),
            TestPropsValues.getGroupId(), false, _publicLayout.getLayoutId(), "Link", "Link",
            "Test invalid URL", LayoutConstants.TYPE_URL, false, null, serviceContext);

    MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();

    mockHttpServletRequest.setAttribute(WebKeys.THEME_DISPLAY, themeDisplay);

    UnicodeProperties properties = layoutURLType.getTypeSettingsProperties();

    properties.setProperty("url", "javascript:alert(1)");

    Assert.assertTrue(Validator.isUrl(layoutURLType.getRegularURL(mockHttpServletRequest), true));
}