Example usage for com.liferay.portal.kernel.util Validator isUrl

List of usage examples for com.liferay.portal.kernel.util Validator isUrl

Introduction

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

Prototype

public static boolean isUrl(String url, boolean acceptRootRelative) 

Source Link

Document

Returns true if the string is a valid URL based on the rules in URL .

Usage

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