Browse Source

Remove dependency of portlets to liferay-integration bundle

A property can be used instead of the convenience annotation to mark a UI
as a Portlet UI registration that should be picked up by the liferay
integration. This removes the unnecessary dependency on the liferay-integration
bundle.
tags/8.1.0.alpha7
Mirjan Merruko 7 years ago
parent
commit
da35217939

+ 67
- 0
liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletProperties.java View File

@@ -0,0 +1,67 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.osgi.liferay;

import javax.portlet.Portlet;

import com.vaadin.ui.UI;

/**
* Constants for Liferay {@link Portlet portlets}. This doesn't have to be used
* by the application developer.
*
* @author Vaadin Ltd.
* @since 8.1
*/
public final class PortletProperties {
private PortletProperties() {

}

/**
* Property key for the Liferay category property. By default this is
* "category.vaadin"
*/
public static final String DISPLAY_CATEGORY = "com.liferay.portlet.display-category";

/**
* Property key for the name of the {@link Portlet}. It is recommended to
* use something like the bundle symbolic name and a version string appended
* for the value of this property as this is used as a {@link Portlet} id.
*/
public static final String PORTLET_NAME = "javax.portlet.name";

/**
* Property key for the {@link UI} visible name of the {@link Portlet}.
*/
public static final String DISPLAY_NAME = "javax.portlet.display-name";

/**
* Property key for the security roles mapped to the {@link Portlet}.
*/
public static final String PORTLET_SECURITY_ROLE = "javax.portlet.security-role-ref";

/**
* This property is used to mark the UI service as a {@link Portlet}
* {@link UI}. The value of this property must be non-null and will be
* ignored but must be present to use the {@link UI} as a {@link Portlet}.
*
* <p>
* The alternative is to simply annotate the {@link UI} with
* {@link VaadinLiferayPortletConfiguration}.
*/
public static final String PORTLET_UI_PROPERTY = "com.vaadin.osgi.liferay.portlet-ui";
}

+ 29
- 7
liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletUIServiceTrackerCustomizer.java View File

@@ -48,12 +48,12 @@ class PortletUIServiceTrackerCustomizer
implements ServiceTrackerCustomizer<UI, ServiceObjects<UI>> {

private static final String RESOURCE_PATH_PREFIX = "/o/%s";
private static final String DISPLAY_CATEGORY = "com.liferay.portlet.display-category";
private static final String DISPLAY_CATEGORY = PortletProperties.DISPLAY_CATEGORY;
private static final String VAADIN_CATEGORY = "category.vaadin";

private static final String PORTLET_NAME = "javax.portlet.name";
private static final String DISPLAY_NAME = "javax.portlet.display-name";
private static final String PORTLET_SECURITY_ROLE = "javax.portlet.security-role-ref";
private static final String PORTLET_NAME = PortletProperties.PORTLET_NAME;
private static final String DISPLAY_NAME = PortletProperties.DISPLAY_NAME;
private static final String PORTLET_SECURITY_ROLE = PortletProperties.PORTLET_SECURITY_ROLE;
private static final String VAADIN_RESOURCE_PATH = "javax.portlet.init-param.vaadin.resources.path";

private Map<ServiceReference<UI>, ServiceRegistration<Portlet>> portletRegistrations = new HashMap<ServiceReference<UI>, ServiceRegistration<Portlet>>();
@@ -75,7 +75,11 @@ class PortletUIServiceTrackerCustomizer
Class<? extends UI> uiClass = contributedUI.getClass();
VaadinLiferayPortletConfiguration portletConfiguration = uiClass
.getAnnotation(VaadinLiferayPortletConfiguration.class);
if (portletConfiguration != null) {

boolean isPortletUi = uiServiceReference
.getProperty(PortletProperties.PORTLET_UI_PROPERTY) != null
|| portletConfiguration != null;
if (isPortletUi) {
return registerPortlet(uiServiceReference,
portletConfiguration);
} else {
@@ -98,8 +102,13 @@ class PortletUIServiceTrackerCustomizer

OSGiUIProvider uiProvider = new OSGiUIProvider(serviceObjects);

Dictionary<String, Object> properties = createPortletProperties(
uiProvider, reference, configuration);
Dictionary<String, Object> properties = null;
if (configuration != null) {
properties = createPortletProperties(uiProvider, reference,
configuration);
} else {
properties = createPortletProperties(reference);
}

VaadinOSGiPortlet portlet = new VaadinOSGiPortlet(uiProvider);

@@ -157,6 +166,19 @@ class PortletUIServiceTrackerCustomizer
}
}

private Dictionary<String, Object> createPortletProperties(
ServiceReference<UI> reference) {
Hashtable<String, Object> properties = new Hashtable<>();
for (String key : reference.getPropertyKeys()) {
properties.put(key, reference.getProperty(key));
}
String resourcesPath = String.format(RESOURCE_PATH_PREFIX,
service.getResourcePathPrefix());
properties.put(VAADIN_RESOURCE_PATH, resourcesPath);

return properties;
}

@Override
public void modifiedService(ServiceReference<UI> serviceReference,
ServiceObjects<UI> ui) {

Loading…
Cancel
Save