Example usage for com.liferay.portal.kernel.servlet.taglib.ui ImageSelector ImageSelector

List of usage examples for com.liferay.portal.kernel.servlet.taglib.ui ImageSelector ImageSelector

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet.taglib.ui ImageSelector ImageSelector.

Prototype

public ImageSelector(byte[] imageBytes, String imageTitle, String imageMimeType, String imageCropRegion) 

Source Link

Usage

From source file:com.liferay.adaptive.media.blogs.web.internal.counter.test.BlogsAMImageCounterTest.java

License:Open Source License

@Test
public void testBlogsAMImageCounterOnlyCountsBlogsImages() throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group1, _user1.getUserId());

    _dlAppLocalService.addFileEntry(_user1.getUserId(), _group1.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString() + ".jpg",
            ContentTypes.IMAGE_JPEG, _getImageBytes(), serviceContext);

    BlogsEntry blogsEntry = _blogsEntryLocalService.addEntry(_user1.getUserId(), RandomTestUtil.randomString(),
            RandomTestUtil.randomString(), new Date(), serviceContext);

    Assert.assertEquals(0, _amImageCounter.countExpectedAMImageEntries(_company1.getCompanyId()));

    ImageSelector imageSelector = new ImageSelector(_getImageBytes(), RandomTestUtil.randomString() + ".jpg",
            ContentTypes.IMAGE_JPEG, IMAGE_CROP_REGION);

    _blogsEntryLocalService.addCoverImage(blogsEntry.getEntryId(), imageSelector);

    Assert.assertEquals(1, _amImageCounter.countExpectedAMImageEntries(_company1.getCompanyId()));
}

From source file:com.liferay.adaptive.media.blogs.web.internal.counter.test.BlogsAMImageCounterTest.java

License:Open Source License

@Test
public void testBlogsAMImageCounterOnlyCountsBlogsImagesPerCompany() throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group1, _user1.getUserId());

    _dlAppLocalService.addFileEntry(_user1.getUserId(), _group1.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString() + ".jpg",
            ContentTypes.IMAGE_JPEG, _getImageBytes(), serviceContext);

    BlogsEntry blogsEntry = _blogsEntryLocalService.addEntry(_user1.getUserId(), RandomTestUtil.randomString(),
            RandomTestUtil.randomString(), new Date(), serviceContext);

    Assert.assertEquals(0, _amImageCounter.countExpectedAMImageEntries(_company1.getCompanyId()));
    Assert.assertEquals(0, _amImageCounter.countExpectedAMImageEntries(_company2.getCompanyId()));

    ImageSelector imageSelector = new ImageSelector(_getImageBytes(), RandomTestUtil.randomString() + ".jpg",
            ContentTypes.IMAGE_JPEG, IMAGE_CROP_REGION);

    _blogsEntryLocalService.addCoverImage(blogsEntry.getEntryId(), imageSelector);

    Assert.assertEquals(1, _amImageCounter.countExpectedAMImageEntries(_company1.getCompanyId()));
    Assert.assertEquals(0, _amImageCounter.countExpectedAMImageEntries(_company2.getCompanyId()));
}

From source file:com.liferay.adaptive.media.blogs.web.internal.optimizer.test.BlogsAMImageOptimizerTest.java

License:Open Source License

private BlogsEntry _addBlogEntryWithCoverImage(long userId, long groupId) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(groupId, userId);

    _dlAppLocalService.addFileEntry(userId, groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString() + ".jpg", ContentTypes.IMAGE_JPEG, _getImageBytes(), serviceContext);

    BlogsEntry blogsEntry = _blogsEntryLocalService.addEntry(userId, RandomTestUtil.randomString(),
            RandomTestUtil.randomString(), new Date(), serviceContext);

    ImageSelector imageSelector = new ImageSelector(_getImageBytes(), RandomTestUtil.randomString() + ".jpg",
            ContentTypes.IMAGE_JPEG, IMAGE_CROP_REGION);

    _blogsEntryLocalService.addCoverImage(blogsEntry.getEntryId(), imageSelector);

    return _blogsEntryLocalService.getEntry(blogsEntry.getEntryId());
}

From source file:com.liferay.blogs.attachments.test.BaseBlogsEntryImageTestCase.java

License:Open Source License

@Test
public void testAddImage() throws Exception {
    BlogsEntry blogsEntry = addBlogsEntry((ImageSelector) null);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            user.getUserId());/*from www .  j  ava  2 s.  c  o  m*/

    FileEntry fileEntry = getTempFileEntry(user.getUserId(), "image1.jpg", serviceContext);

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()),
            fileEntry.getTitle(), fileEntry.getMimeType(), IMAGE_CROP_REGION);

    addImage(blogsEntry.getEntryId(), imageSelector);

    blogsEntry = BlogsEntryLocalServiceUtil.getEntry(blogsEntry.getEntryId());

    FileEntry imageFileEntry = PortletFileRepositoryUtil.getPortletFileEntry(getImageFileEntryId(blogsEntry));

    Assert.assertEquals("image1.jpg", imageFileEntry.getTitle());
}

From source file:com.liferay.blogs.attachments.test.BaseBlogsEntryImageTestCase.java

License:Open Source License

@Test(expected = NoSuchFileEntryException.class)
public void testImageDeletedWhenUpdatingBlogsEntryWithEmptyImageSelector() throws Exception {

    BlogsEntry blogsEntry = addBlogsEntry("image1.jpg");

    FileEntry imageFileEntry = PortletFileRepositoryUtil.getPortletFileEntry(getImageFileEntryId(blogsEntry));

    ImageSelector imageSelector = new ImageSelector(null, StringPool.BLANK, StringPool.BLANK, StringPool.BLANK);

    blogsEntry = updateBlogsEntry(blogsEntry.getEntryId(), imageSelector);

    Assert.assertEquals(0, getImageFileEntryId(blogsEntry));

    PortletFileRepositoryUtil.getPortletFileEntry(imageFileEntry.getFileEntryId());
}

From source file:com.liferay.blogs.attachments.test.BlogsEntryCoverImageTest.java

License:Open Source License

@Override
protected BlogsEntry addBlogsEntry(String imageTitle) throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            user.getUserId());//ww  w.  ja v  a2  s.c  om

    FileEntry fileEntry = getTempFileEntry(user.getUserId(), imageTitle, serviceContext);

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()),
            fileEntry.getTitle(), fileEntry.getMimeType(), IMAGE_CROP_REGION);

    return addBlogsEntry(imageSelector);
}

From source file:com.liferay.blogs.attachments.test.BlogsEntryCoverImageTest.java

License:Open Source License

@Override
protected BlogsEntry updateBlogsEntry(long blogsEntryId, String imageTitle) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            user.getUserId());/*from  w w w.ja v a2s .co m*/

    FileEntry fileEntry = getTempFileEntry(user.getUserId(), imageTitle, serviceContext);

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()),
            fileEntry.getTitle(), fileEntry.getMimeType(), IMAGE_CROP_REGION);

    return updateBlogsEntry(blogsEntryId, imageSelector);
}

From source file:com.liferay.blogs.attachments.test.BlogsEntrySmallImageTest.java

License:Open Source License

@Override
protected BlogsEntry addBlogsEntry(String imageTitle) throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            user.getUserId());//from w ww.j  av a2 s .  co m

    FileEntry fileEntry = getTempFileEntry(user.getUserId(), imageTitle, serviceContext);

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()),
            fileEntry.getTitle(), fileEntry.getMimeType(), StringPool.BLANK);

    return addBlogsEntry(imageSelector);
}

From source file:com.liferay.blogs.attachments.test.BlogsEntrySmallImageTest.java

License:Open Source License

@Override
protected BlogsEntry updateBlogsEntry(long blogsEntryId, String coverImageTitle) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            user.getUserId());/*from w w w. j a v a2  s  .co  m*/

    FileEntry fileEntry = getTempFileEntry(user.getUserId(), coverImageTitle, serviceContext);

    ImageSelector imageSelector = new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()),
            fileEntry.getTitle(), fileEntry.getMimeType(), StringPool.BLANK);

    return updateBlogsEntry(blogsEntryId, imageSelector);
}

From source file:com.liferay.blogs.demo.data.creator.internal.BaseBlogsEntryDemoDataCreator.java

License:Open Source License

public BlogsEntry createBlogsEntry(long userId, long groupId, String title, String subtitle, String content)
        throws IOException, PortalException {

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setScopeGroupId(groupId);

    ImageSelector imageSelector = new ImageSelector(_getRandomImageBytes(userId, groupId),
            StringUtil.randomString() + ".jpeg", "image/jpeg", StringPool.BLANK);

    BlogsEntry blogsEntry = blogsEntryLocalService.addEntry(userId, title, subtitle, null, content,
            _getRandomDate(), false, false, null, null, imageSelector, null, serviceContext);

    entryIds.add(blogsEntry.getEntryId());

    return blogsEntry;
}