Example usage for com.liferay.portal.kernel.model LayoutConstants TYPE_URL

List of usage examples for com.liferay.portal.kernel.model LayoutConstants TYPE_URL

Introduction

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

Prototype

String TYPE_URL

To view the source code for com.liferay.portal.kernel.model LayoutConstants TYPE_URL.

Click Source Link

Usage

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

protected Object[] extractFriendlyURLInfo(Layout layout) {
    if (!Objects.equals(layout.getType(), LayoutConstants.TYPE_URL)) {
        return null;
    }//from  w  w  w . j av a 2 s  .c  o m

    UnicodeProperties typeSettings = layout.getTypeSettingsProperties();

    String url = GetterUtil.getString(typeSettings.getProperty("url"));

    String friendlyURLPrivateGroupPath = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING;
    String friendlyURLPrivateUserPath = PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING;
    String friendlyURLPublicPath = PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING;

    if (!url.startsWith(friendlyURLPrivateGroupPath) && !url.startsWith(friendlyURLPrivateUserPath)
            && !url.startsWith(friendlyURLPublicPath)) {

        return null;
    }

    int x = url.indexOf(CharPool.SLASH, 1);

    if (x == -1) {
        return null;
    }

    int y = url.indexOf(CharPool.SLASH, x + 1);

    if (y == -1) {
        return null;
    }

    return new Object[] { url.substring(x, y), url, x, y };
}

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));
}