Example usage for com.liferay.portal.kernel.model ModelHintsUtil getMaxLength

List of usage examples for com.liferay.portal.kernel.model ModelHintsUtil getMaxLength

Introduction

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

Prototype

public static int getMaxLength(String model, String field) 

Source Link

Usage

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

protected void validate(String title, String urlTitle, String content) throws PortalException {

    if (Validator.isNull(title)) {
        throw new EntryTitleException("Title is null");
    }/*  w ww  .j  a va  2  s. c om*/

    int titleMaxLength = ModelHintsUtil.getMaxLength(BlogsEntry.class.getName(), "title");

    if (title.length() > titleMaxLength) {
        throw new EntryTitleException("Title has more than " + titleMaxLength + " characters");
    }

    if (Validator.isNotNull(urlTitle)) {
        int urlTitleMaxLength = ModelHintsUtil.getMaxLength(BlogsEntry.class.getName(), "urlTitle");

        if (urlTitle.length() > urlTitleMaxLength) {
            throw new EntryUrlTitleException("URL title has more than " + urlTitleMaxLength + " characters");
        }
    }

    if (Validator.isNull(content)) {
        throw new EntryContentException("Content is null");
    }

    int contentMaxLength = ModelHintsUtil.getMaxLength(BlogsEntry.class.getName(), "content");

    if (content.length() > contentMaxLength) {
        throw new EntryContentException("Content has more than " + contentMaxLength + " characters");
    }
}

From source file:com.liferay.blogs.service.test.BlogsEntryLocalServiceTest.java

License:Open Source License

@Test(expected = EntryContentException.class)
public void testAddEntryWithVeryLongContent() throws Exception {
    int maxLength = ModelHintsUtil.getMaxLength(BlogsEntry.class.getName(), "content");

    String content = _repeat("0", maxLength + 1);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group, _user.getUserId());

    BlogsEntryLocalServiceUtil.addEntry(_user.getUserId(), RandomTestUtil.randomString(), content,
            serviceContext);/*from   ww w  . j  a  v  a 2s  . com*/
}

From source file:com.liferay.blogs.service.test.BlogsEntryLocalServiceTest.java

License:Open Source License

@Test(expected = EntryTitleException.class)
public void testAddEntryWithVeryLongTitle() throws Exception {
    int maxLength = ModelHintsUtil.getMaxLength(BlogsEntry.class.getName(), "title");

    String title = _repeat("0", maxLength + 1);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group, _user.getUserId());

    BlogsEntryLocalServiceUtil.addEntry(_user.getUserId(), title, RandomTestUtil.randomString(),
            serviceContext);/*from www  . jav a 2 s . co m*/
}

From source file:com.liferay.grow.wiki.GrowWikiPageTitleValidator.java

License:Open Source License

@Override
public void validate(String title) throws PageTitleException {
    int titleMaxLength = ModelHintsUtil.getMaxLength(WikiPage.class.getName(), "title");

    if (title.length() > titleMaxLength) {
        throw new PageTitleException("Title has more than " + titleMaxLength + " characters");
    }//from w w  w.  ja  v a2  s. c o m

    if (title.equals("all_pages") || title.equals("orphan_pages") || title.equals("recent_changes")) {

        throw new PageTitleException(title + " is reserved");
    }

    Matcher matcher = _pageTitlePattern.matcher(title);

    if (!matcher.matches()) {
        throw new PageTitleException();
    }
}