summaryrefslogtreecommitdiffstats
path: root/liferay-integration
diff options
context:
space:
mode:
authorMirjan Merruko <mirjan@vaadin.com>2017-04-10 10:43:35 +0300
committerHenri Sara <henri.sara@gmail.com>2017-04-25 15:01:06 +0300
commitda352179395269beb7e8976246be83e2546f17c2 (patch)
treead5f7c864d32d656f8692bf19d32dc8ae004e0fb /liferay-integration
parent24cfdc4ea0dc6260c044c6f2d53820a748f1d87e (diff)
downloadvaadin-framework-da352179395269beb7e8976246be83e2546f17c2.tar.gz
vaadin-framework-da352179395269beb7e8976246be83e2546f17c2.zip
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.
Diffstat (limited to 'liferay-integration')
-rw-r--r--liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletProperties.java67
-rw-r--r--liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletUIServiceTrackerCustomizer.java36
2 files changed, 96 insertions, 7 deletions
diff --git a/liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletProperties.java b/liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletProperties.java
new file mode 100644
index 0000000000..188c20cde4
--- /dev/null
+++ b/liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletProperties.java
@@ -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";
+}
diff --git a/liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletUIServiceTrackerCustomizer.java b/liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletUIServiceTrackerCustomizer.java
index 9a42b34588..d985f55352 100644
--- a/liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletUIServiceTrackerCustomizer.java
+++ b/liferay-integration/src/main/java/com/vaadin/osgi/liferay/PortletUIServiceTrackerCustomizer.java
@@ -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) {