You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2015/01/28 17:53:46 UTC

[2/4] wicket git commit: Wicket-5801 Responsive Images - CORS settings

Wicket-5801 Responsive Images - CORS settings

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/6b31d4c6
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/6b31d4c6
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/6b31d4c6

Branch: refs/heads/master
Commit: 6b31d4c64b8ee0dd3b513025eebec9ae75ff2893
Parents: 0880713
Author: klopfdreh <no...@googlemail.com>
Authored: Thu Jan 22 12:28:52 2015 +0100
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Wed Jan 28 18:53:33 2015 +0200

----------------------------------------------------------------------
 .../apache/wicket/markup/html/image/Image.java  | 60 ++++++++++++++++++++
 .../apache/wicket/markup/html/image/Source.java | 16 ++++++
 2 files changed, 76 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/6b31d4c6/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java
index 74b6512..644e491 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Image.java
@@ -67,6 +67,11 @@ public class Image extends WebComponent implements IResourceListener
 	private List<String> sizes = null;
 
 	/**
+	 * Cross origin settings
+	 */
+	private Cors crossorigin = null;
+
+	/**
 	 * This constructor can be used if you override {@link #getImageResourceReference()} or
 	 * {@link #getImageResource()}
 	 * 
@@ -347,8 +352,13 @@ public class Image extends WebComponent implements IResourceListener
 			String srcAttribute = this.buildSrcAttribute(tag);
 			this.buildSrcSetAttribute(tag);
 			tag.put("src", srcAttribute);
+
 		}
 		this.buildSizesAttribute(tag);
+
+		if (this.crossorigin != null) {
+			tag.put("crossorigin", this.crossorigin.getRealName());
+		}
 	}
 
 	/**
@@ -514,4 +524,54 @@ public class Image extends WebComponent implements IResourceListener
 			return super.canCallListenerInterface(method);
 		}
 	}
+
+	/**
+	 * Gets the cross origin settings
+	 *
+	 * @see {@link #setCrossorigin(Cors)}
+	 *
+	 * @return the cross origins settings
+	 */
+	public Cors getCrossorigin() {
+		return this.crossorigin;
+	}
+
+	/**
+	 * Sets the cross origin settings<br>
+	 * <br>
+	 *
+	 * <b>anonymous</b>: Cross-origin CORS requests for the element will not have the credentials flag set.<br>
+	 * <br>
+	 * <b>use_credentials</b>: Cross-origin CORS requests for the element will have the credentials flag set.<br>
+	 * <br>
+	 * <b>no_cores</b>: The empty string is also a valid keyword, and maps to the Anonymous state. The attribute's invalid value default is the
+	 * Anonymous state. The missing value default, used when the attribute is omitted, is the No CORS state
+	 *
+	 * @param crossorigin
+	 *            the cross origins settings to set
+	 */
+	public void setCrossorigin(Cors crossorigin) {
+		this.crossorigin = crossorigin;
+	}
+
+	/**
+	 * To be used for the crossorigin attribute
+	 *
+	 * @see {@link #setCrossorigin(Cors)}
+	 */
+	public enum Cors {
+		anonymous("anonymous"),
+		use_credentials("user-credentials"),
+		no_cors("");
+
+		private String realName;
+
+		private Cors(String realName) {
+			this.realName = realName;
+		}
+
+		public String getRealName() {
+			return this.realName;
+		}
+	}
 }

http://git-wip-us.apache.org/repos/asf/wicket/blob/6b31d4c6/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Source.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Source.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Source.java
index cb074e9..b38f5fc 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Source.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/image/Source.java
@@ -120,4 +120,20 @@ public class Source extends Image
 	{
 		return media;
 	}
+
+	/**
+	 * Unsupported for source tag
+	 */
+	@Override
+	public void setCrossorigin(Cors crossorigin) {
+		throw new UnsupportedOperationException("It is not allowed to set the crossorigin attribute for source tag");
+	}
+
+	/**
+	 * Unsupported for source tag
+	 */
+	@Override
+	public Cors getCrossorigin() {
+		throw new UnsupportedOperationException("It is not allowed to get the crossorigin attribute for source tag");
+	}
 }