Example usage for com.liferay.portal.kernel.model Portlet getTemplateHandlerInstance

List of usage examples for com.liferay.portal.kernel.model Portlet getTemplateHandlerInstance

Introduction

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

Prototype

public com.liferay.portal.kernel.template.TemplateHandler getTemplateHandlerInstance();

Source Link

Document

Returns the template handler instance of the portlet.

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;//w  w  w . jav a2  s  . c  om
    }

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

From source file:com.liferay.portlet.display.template.exportimport.portlet.preferences.processor.PortletDisplayTemplateExportCapability.java

License:Open Source License

protected long getClassNameId(PortletDataContext portletDataContext, String portletId) {

    Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletId);

    TemplateHandler templateHandler = portlet.getTemplateHandlerInstance();

    if (templateHandler == null) {
        return 0;
    }//from   w w w  .  j  av a  2 s.c om

    String className = templateHandler.getClassName();

    return portal.getClassNameId(className);
}