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

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

Introduction

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

Prototype

public String getClassName();

Source Link

Document

Returns the template handler's class name.

Usage

From source file:com.liferay.content.targeting.service.test.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. j av a 2 s.  co  m
    }

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

        return;
    }

    TemplateHandler templateHandler = portlet.getTemplateHandlerInstance();

    if (templateHandler == null) {
        Assert.assertTrue("This test does not apply", true);

        return;
    }

    String className = templateHandler.getClassName();

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

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

    String displayStyle = PortletDisplayTemplate.DISPLAY_STYLE_PREFIX + ddmTemplate.getUuid();

    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.dynamic.data.mapping.internal.template.TemplateHandlerRegistryImpl.java

License:Open Source License

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY, unbind = "removeTemplateHandler")
protected synchronized void addTemplateHandler(TemplateHandler templateHandler) {

    String className = templateHandler.getClassName();

    _classNameTemplateHandlers.put(className, templateHandler);

    if (_bundleContext == null) {
        return;//from ww  w  .  j  ava  2  s .c  om
    }

    _classNameIdTemplateHandlers.put(_portal.getClassNameId(className), templateHandler);

    registerPortalInstanceLifecycleListener(templateHandler);
}

From source file:com.liferay.dynamic.data.mapping.internal.template.TemplateHandlerRegistryImpl.java

License:Open Source License

protected void registerPortalInstanceLifecycleListener(TemplateHandler templateHandler) {

    ServiceRegistration<?> serviceRegistration = _serviceRegistrations.get(templateHandler.getClassName());

    if (serviceRegistration != null) {
        serviceRegistration.unregister();
    }//from   w w w .  j a va2s . c  o  m

    PortalInstanceLifecycleListener portalInstanceLifecycleListener = new TemplateHandlerPortalInstanceLifecycleListener(
            templateHandler);

    serviceRegistration = _bundleContext.registerService(PortalInstanceLifecycleListener.class,
            portalInstanceLifecycleListener, new HashMapDictionary<String, Object>());

    _serviceRegistrations.put(templateHandler.getClassName(), serviceRegistration);
}

From source file:com.liferay.dynamic.data.mapping.internal.template.TemplateHandlerRegistryImpl.java

License:Open Source License

protected synchronized void removeTemplateHandler(TemplateHandler templateHandler) {

    String className = templateHandler.getClassName();

    _classNameTemplateHandlers.remove(className);

    if (_portal != null) {
        _classNameIdTemplateHandlers.remove(_portal.getClassNameId(className));
    }//ww  w.j a  v  a2  s  .  c  o m

    ServiceRegistration<?> serviceRegistration = _serviceRegistrations.remove(className);

    if (serviceRegistration != null) {
        serviceRegistration.unregister();
    }
}

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  w w  w  .j  a v  a 2 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  ww  w. j a  va 2  s  .  com*/

    String className = templateHandler.getClassName();

    return portal.getClassNameId(className);
}