< to \u005Cu003C.
+ *
+ * @param response
+ * The HTTP: response
+ * @param text
+ * The text to added in between the script tags
+ * @param attributes
+ * Extra tag attributes. See constants prefixed with ATTR_ in {@link JavaScriptUtils}
+ */
+ public static void writeInlineScript(final Response response, final CharSequence text, AttributeMap attributes)
+ {
+ response.write("\n");
+ }
+}
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/head/JavaScriptContentHeaderItem.java b/wicket-core/src/main/java/org/apache/wicket/markup/head/JavaScriptContentHeaderItem.java
index 0c8839d6f47..85ce9a1a255 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/head/JavaScriptContentHeaderItem.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/head/JavaScriptContentHeaderItem.java
@@ -34,6 +34,8 @@ public class JavaScriptContentHeaderItem extends JavaScriptHeaderItem
{
private final CharSequence javaScript;
+ private JavaScriptReferenceType type = JavaScriptReferenceType.TEXT_JAVASCRIPT;
+
/**
* Creates a new {@code JavaScriptContentHeaderItem}.
*
@@ -57,11 +59,28 @@ public CharSequence getJavaScript()
return javaScript;
}
+ public JavaScriptReferenceType getType() {
+ return type;
+ }
+
+ /**
+ * Set the type of
+ * the script. If no type is set, it defaults to {@link JavaScriptReferenceType#TEXT_JAVASCRIPT}.
+ *
+ * @param type the new type.
+ */
+ public JavaScriptContentHeaderItem setType(final JavaScriptReferenceType type) {
+ this.type = type;
+ return this;
+ }
+
@Override
public void render(Response response)
{
AttributeMap attributes = new AttributeMap();
- attributes.putAttribute(JavaScriptUtils.ATTR_TYPE, "text/javascript");
+ // An empty string works the same as `text/javascript`, but use the latter for backward compatibility.
+ JavaScriptReferenceType actualType = type == null ? JavaScriptReferenceType.TEXT_JAVASCRIPT : type;
+ attributes.putAttribute(JavaScriptUtils.ATTR_TYPE, actualType.getType());
attributes.putAttribute(JavaScriptUtils.ATTR_ID, getId());
attributes.putAttribute(JavaScriptUtils.ATTR_CSP_NONCE, getNonce());
JavaScriptUtils.writeInlineScript(response, getJavaScript(), attributes);
@@ -88,7 +107,8 @@ public boolean equals(Object o)
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
JavaScriptContentHeaderItem that = (JavaScriptContentHeaderItem) o;
- return Objects.equals(javaScript, that.javaScript);
+ return Objects.equals(javaScript, that.javaScript) &&
+ Objects.equals(type, that.type);
}
@Override
@@ -97,6 +117,7 @@ public int hashCode()
// Not using `Objects.hash` for performance reasons
int result = super.hashCode();
result = 31 * result + ((javaScript != null) ? javaScript.hashCode() : 0);
+ result = 31 * result + ((type != null) ? type.hashCode() : 0);
return result;
}
}
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/head/JavaScriptImportMapHeaderItem.java b/wicket-core/src/main/java/org/apache/wicket/markup/head/JavaScriptImportMapHeaderItem.java
new file mode 100644
index 00000000000..a61f7c5c2fe
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/head/JavaScriptImportMapHeaderItem.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.wicket.markup.head;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+import com.github.openjson.JSONObject;
+import com.github.openjson.JSONStringer;
+import org.apache.wicket.core.util.string.JavaScriptUtils;
+import org.apache.wicket.core.util.string.JsonUtils;
+import org.apache.wicket.request.Response;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.apache.wicket.request.resource.JavaScriptResourceReference;
+import org.apache.wicket.util.LazyInitializer;
+import org.apache.wicket.util.string.Strings;
+import org.apache.wicket.util.value.AttributeMap;
+
+/**
+ * {@link HeaderItem} for
+ * import
+ * maps.
+ */
+public class JavaScriptImportMapHeaderItem extends JavaScriptHeaderItem
+{
+ private final Map
+ * This class should be called JavaScriptType, but
+ * renaming breaks backward compatibility.
*/
public class JavaScriptReferenceType implements IClusterable {