summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-01-24 15:41:15 +0200
committerAleksi Hietanen <aleksi@vaadin.com>2017-01-24 15:41:15 +0200
commitc916782da19362dc210402bbe922873d6386b05d (patch)
tree5e184d80e68f5b65e13d51c5ccf36e84d2b3125a /server
parenta0b80c1d9b22aed986e885d8a32cf1446533d6da (diff)
downloadvaadin-framework-c916782da19362dc210402bbe922873d6386b05d.tar.gz
vaadin-framework-c916782da19362dc210402bbe922873d6386b05d.zip
Support using multiple @JavaScript and @StyleSheet annotations on a class (#8293)
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/annotations/InternalContainerAnnotationForJS.java45
-rw-r--r--server/src/main/java/com/vaadin/annotations/InternalContainerAnnotationForSS.java45
-rw-r--r--server/src/main/java/com/vaadin/annotations/JavaScript.java9
-rw-r--r--server/src/main/java/com/vaadin/annotations/StyleSheet.java7
-rw-r--r--server/src/main/java/com/vaadin/server/BootstrapHandler.java34
-rw-r--r--server/src/main/java/com/vaadin/server/communication/UidlWriter.java28
6 files changed, 141 insertions, 27 deletions
diff --git a/server/src/main/java/com/vaadin/annotations/InternalContainerAnnotationForJS.java b/server/src/main/java/com/vaadin/annotations/InternalContainerAnnotationForJS.java
new file mode 100644
index 0000000000..6b4152dfa0
--- /dev/null
+++ b/server/src/main/java/com/vaadin/annotations/InternalContainerAnnotationForJS.java
@@ -0,0 +1,45 @@
+/*
+ * 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.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation enabling using multiple {@link JavaScript @JavaScript}
+ * annotations.
+ * <p>
+ * <b>NOT meant to be used</b>, for multiple JavaScript dependencies,
+ * {@link JavaScript @JavaScript} should be used instead.
+ *
+ * @author Vaadin Ltd
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Documented
+public @interface InternalContainerAnnotationForJS {
+
+ /**
+ * Not to be used, instead multiple {@link JavaScript @JavaScript}
+ * annotations should be used.
+ *
+ * @return an array of the JavaScript annotations
+ */
+ JavaScript[] value();
+}
diff --git a/server/src/main/java/com/vaadin/annotations/InternalContainerAnnotationForSS.java b/server/src/main/java/com/vaadin/annotations/InternalContainerAnnotationForSS.java
new file mode 100644
index 0000000000..2c3d8b19c0
--- /dev/null
+++ b/server/src/main/java/com/vaadin/annotations/InternalContainerAnnotationForSS.java
@@ -0,0 +1,45 @@
+/*
+ * 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.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation enabling using multiple {@link StyleSheet @StyleSheet}
+ * annotations.
+ * <p>
+ * <b>NOT meant to be used</b>, for multiple style sheet dependencies,
+ * {@link StyleSheet @StyleSheet} should be used instead.
+ *
+ * @author Vaadin Ltd
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+@Documented
+public @interface InternalContainerAnnotationForSS {
+
+ /**
+ * Not to be used, instead multiple {@link StyleSheet @StyleSheet}
+ * annotations should be used.
+ *
+ * @return an array of the style sheet annotations
+ */
+ StyleSheet[] value();
+}
diff --git a/server/src/main/java/com/vaadin/annotations/JavaScript.java b/server/src/main/java/com/vaadin/annotations/JavaScript.java
index 60950603fe..6ea8904c79 100644
--- a/server/src/main/java/com/vaadin/annotations/JavaScript.java
+++ b/server/src/main/java/com/vaadin/annotations/JavaScript.java
@@ -16,7 +16,9 @@
package com.vaadin.annotations;
+import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@@ -49,17 +51,22 @@ import com.vaadin.server.ClientConnector;
* http://host.com/file1.js as is and file2.js from /com/example/file2.js on the
* server's classpath using the ClassLoader that was used to load
* com.example.MyConnector.
+ * <p>
+ * For adding multiple JavaScript files for a single component, you can use this
+ * annotation multiple times.
*
* @author Vaadin Ltd
* @since 7.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
+@Documented
+@Repeatable(InternalContainerAnnotationForJS.class)
public @interface JavaScript {
/**
* JavaScript files to load before initializing the client-side connector.
*
- * @return an array of JavaScript file urls
+ * @return an array of JavaScript file URLs
*/
public String[] value();
}
diff --git a/server/src/main/java/com/vaadin/annotations/StyleSheet.java b/server/src/main/java/com/vaadin/annotations/StyleSheet.java
index 59e61dd209..85d19f70cd 100644
--- a/server/src/main/java/com/vaadin/annotations/StyleSheet.java
+++ b/server/src/main/java/com/vaadin/annotations/StyleSheet.java
@@ -16,7 +16,9 @@
package com.vaadin.annotations;
+import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
+import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@@ -54,12 +56,17 @@ import com.vaadin.server.ClientConnector;
* http://host.com/file1.css as is and file2.css from /com/example/file2.css on
* the server's classpath using the ClassLoader that was used to load
* com.example.MyConnector.
+ * <p>
+ * For adding multiple style sheets for a single component, you can use this
+ * annotation multiple times.
*
* @author Vaadin Ltd
* @since 7.0.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
+@Documented
+@Repeatable(InternalContainerAnnotationForSS.class)
public @interface StyleSheet {
/**
* Style sheets to load before initializing the client-side connector.
diff --git a/server/src/main/java/com/vaadin/server/BootstrapHandler.java b/server/src/main/java/com/vaadin/server/BootstrapHandler.java
index 895598ae6f..be0e9e4593 100644
--- a/server/src/main/java/com/vaadin/server/BootstrapHandler.java
+++ b/server/src/main/java/com/vaadin/server/BootstrapHandler.java
@@ -437,23 +437,29 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
.attr("href", themeUri + "/favicon.ico");
}
- JavaScript javaScript = uiClass.getAnnotation(JavaScript.class);
- if (javaScript != null) {
- String[] resources = javaScript.value();
- for (String resource : resources) {
- String url = registerDependency(context, uiClass, resource);
- head.appendElement("script").attr("type", "text/javascript")
- .attr("src", url);
+ JavaScript[] javaScripts = uiClass
+ .getAnnotationsByType(JavaScript.class);
+ if (javaScripts != null) {
+ for (JavaScript javaScript : javaScripts) {
+ String[] resources = javaScript.value();
+ for (String resource : resources) {
+ String url = registerDependency(context, uiClass, resource);
+ head.appendElement("script").attr("type", "text/javascript")
+ .attr("src", url);
+ }
}
}
- StyleSheet styleSheet = uiClass.getAnnotation(StyleSheet.class);
- if (styleSheet != null) {
- String[] resources = styleSheet.value();
- for (String resource : resources) {
- String url = registerDependency(context, uiClass, resource);
- head.appendElement("link").attr("rel", "stylesheet")
- .attr("type", "text/css").attr("href", url);
+ StyleSheet[] styleSheets = uiClass
+ .getAnnotationsByType(StyleSheet.class);
+ if (styleSheets != null) {
+ for (StyleSheet styleSheet : styleSheets) {
+ String[] resources = styleSheet.value();
+ for (String resource : resources) {
+ String url = registerDependency(context, uiClass, resource);
+ head.appendElement("link").attr("rel", "stylesheet")
+ .attr("type", "text/css").attr("href", url);
+ }
}
}
diff --git a/server/src/main/java/com/vaadin/server/communication/UidlWriter.java b/server/src/main/java/com/vaadin/server/communication/UidlWriter.java
index 7132433963..f8f6c2fc5b 100644
--- a/server/src/main/java/com/vaadin/server/communication/UidlWriter.java
+++ b/server/src/main/java/com/vaadin/server/communication/UidlWriter.java
@@ -288,21 +288,25 @@ public class UidlWriter implements Serializable {
List<String> styleDependencies = new ArrayList<>();
for (Class<? extends ClientConnector> class1 : newConnectorTypes) {
- JavaScript jsAnnotation = class1
- .getAnnotation(JavaScript.class);
- if (jsAnnotation != null) {
- for (String uri : jsAnnotation.value()) {
- scriptDependencies
- .add(manager.registerDependency(uri, class1));
+ JavaScript[] jsAnnotations = class1
+ .getAnnotationsByType(JavaScript.class);
+ if (jsAnnotations != null) {
+ for (JavaScript jsAnnotation : jsAnnotations) {
+ for (String uri : jsAnnotation.value()) {
+ scriptDependencies.add(
+ manager.registerDependency(uri, class1));
+ }
}
}
- StyleSheet styleAnnotation = class1
- .getAnnotation(StyleSheet.class);
- if (styleAnnotation != null) {
- for (String uri : styleAnnotation.value()) {
- styleDependencies
- .add(manager.registerDependency(uri, class1));
+ StyleSheet[] styleAnnotations = class1
+ .getAnnotationsByType(StyleSheet.class);
+ if (styleAnnotations != null) {
+ for (StyleSheet styleAnnotation : styleAnnotations) {
+ for (String uri : styleAnnotation.value()) {
+ styleDependencies.add(
+ manager.registerDependency(uri, class1));
+ }
}
}
}