Example usage for com.liferay.portal.kernel.template TemplateHandler isDisplayTemplateHandler

List of usage examples for com.liferay.portal.kernel.template TemplateHandler isDisplayTemplateHandler

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.template TemplateHandler isDisplayTemplateHandler.

Prototype

public boolean isDisplayTemplateHandler();

Source Link

Document

Returns true if the entity is a display template handler.

Usage

From source file:com.liferay.exportimport.test.util.lar.BasePortletExportImportTestCase.java

License:Open Source License

protected void testExportImportDisplayStyle(long displayStyleGroupId, String scopeType) throws Exception {

    Portlet portlet = PortletLocalServiceUtil.getPortletById(group.getCompanyId(), getPortletId());

    if (portlet == null) {
        return;//from www  .j  a va2s.  co  m
    }

    if (scopeType.equals("layout") && !portlet.isScopeable()) {
        Assert.assertTrue("This test does not apply", true);

        return;
    }

    TemplateHandler templateHandler = portlet.getTemplateHandlerInstance();

    if ((templateHandler == null) || !templateHandler.isDisplayTemplateHandler()) {

        Assert.assertTrue("This test does not apply", true);

        return;
    }

    String className = templateHandler.getClassName();
    long resourceClassNameId = PortalUtil
            .getClassNameId("com.liferay.portlet.display.template.PortletDisplayTemplate");

    DDMTemplate ddmTemplate = DDMTemplateTestUtil.addTemplate(displayStyleGroupId,
            PortalUtil.getClassNameId(className), 0, resourceClassNameId);

    Map<String, String[]> preferenceMap = new HashMap<>();

    String displayStyle = PortletDisplayTemplateManager.DISPLAY_STYLE_PREFIX + ddmTemplate.getTemplateKey();

    preferenceMap.put("displayStyle", new String[] { displayStyle });

    preferenceMap.put("displayStyleGroupId", new String[] { String.valueOf(ddmTemplate.getGroupId()) });

    if (scopeType.equals("layout")) {
        preferenceMap.put("lfrScopeLayoutUuid", new String[] { this.layout.getUuid() });
    }

    preferenceMap.put("lfrScopeType", new String[] { scopeType });

    PortletPreferences portletPreferences = getImportedPortletPreferences(preferenceMap);

    String importedDisplayStyle = portletPreferences.getValue("displayStyle", StringPool.BLANK);

    Assert.assertEquals(displayStyle, importedDisplayStyle);

    long importedDisplayStyleGroupId = GetterUtil
            .getLong(portletPreferences.getValue("displayStyleGroupId", null));

    long expectedDisplayStyleGroupId = importedGroup.getGroupId();

    if (scopeType.equals("company")) {
        Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(importedGroup.getCompanyId());

        expectedDisplayStyleGroupId = companyGroup.getGroupId();
    } else if (displayStyleGroupId != group.getGroupId()) {
        expectedDisplayStyleGroupId = displayStyleGroupId;
    }

    Assert.assertEquals(expectedDisplayStyleGroupId, importedDisplayStyleGroupId);
}