You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by ad...@apache.org on 2015/03/12 22:18:30 UTC
[23/34] wicket git commit: WICKET-5819 Media tags - examples / minor
changes
WICKET-5819 Media tags - examples / minor changes
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/5e5c6e0c
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/5e5c6e0c
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/5e5c6e0c
Branch: refs/heads/master
Commit: 5e5c6e0cbe11710da6799a1f28a0b5b78da49dec
Parents: 4f25b1b
Author: klopfdreh <kl...@192.168.2.110>
Authored: Mon Feb 16 10:33:39 2015 +0100
Committer: Andrea Del Bene <ad...@apache.org>
Committed: Thu Mar 12 22:13:05 2015 +0100
----------------------------------------------------------------------
.../markup/html/media/MediaComponent.java | 39 ++++---
.../media/MediaStreamingResourceReference.java | 40 ++++---
.../wicket/markup/html/media/audio/Audio.java | 10 ++
.../wicket/markup/html/media/video/Video.java | 10 ++
.../org/apache/wicket/examples/media/Home.html | 15 +++
.../org/apache/wicket/examples/media/Home.java | 103 +++++++++++++++++++
.../examples/media/VideosApplication.java | 63 ++++++++++++
.../apache/wicket/examples/media/novideo.gif | Bin 0 -> 25903 bytes
.../org/apache/wicket/examples/media/video.mp4 | Bin 0 -> 2757913 bytes
wicket-examples/src/main/webapp/WEB-INF/web.xml | 22 +++-
10 files changed, 270 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/5e5c6e0c/wicket-core/src/main/java/org/apache/wicket/markup/html/media/MediaComponent.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/MediaComponent.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/MediaComponent.java
index 20f39ec..d8f6d49 100755
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/MediaComponent.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/MediaComponent.java
@@ -19,8 +19,10 @@ package org.apache.wicket.markup.html.media;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.Url;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.request.mapper.parameter.PageParametersEncoder;
/**
* The media component is used to provide basic functionality to the video and audio component. The
@@ -106,7 +108,7 @@ public abstract class MediaComponent extends WebMarkupContainer
* Constructor.
*
* @param id
- * The component id
+ * The component id
*/
public MediaComponent(String id)
{
@@ -117,9 +119,9 @@ public abstract class MediaComponent extends WebMarkupContainer
* Constructor.
*
* @param id
- * The component id
+ * The component id
* @param model
- * The component model
+ * The component model
*/
public MediaComponent(String id, IModel<?> model)
{
@@ -130,12 +132,12 @@ public abstract class MediaComponent extends WebMarkupContainer
* Constructor.
*
* @param id
- * The component id
+ * The component id
* @param mediaStreamingResourceReference
*/
public MediaComponent(String id, MediaStreamingResourceReference mediaStreamingResourceReference)
{
- this(id, null, null, null,mediaStreamingResourceReference);
+ this(id, null, null, null, mediaStreamingResourceReference);
}
public MediaComponent(String id, IModel<?> model,
@@ -168,8 +170,13 @@ public abstract class MediaComponent extends WebMarkupContainer
this(id, model, url, null, null);
}
+ public MediaComponent(String id, IModel<?> model, String url, PageParameters pageParameters)
+ {
+ this(id, model, url, pageParameters, null);
+ }
+
private MediaComponent(String id, IModel<?> model, String url, PageParameters pageParameters,
- MediaStreamingResourceReference mediaStreamingResourceReference)
+ MediaStreamingResourceReference mediaStreamingResourceReference)
{
super(id, model);
this.url = url;
@@ -187,18 +194,20 @@ public abstract class MediaComponent extends WebMarkupContainer
String timeManagement = "";
if (startTime != null)
{
- timeManagement += "#t=" + startTime +
- (endTime != null ? "," + endTime : "");
+ timeManagement += "#t=" + startTime + (endTime != null ? "," + endTime : "");
}
if (mediaStreamingResourceReference != null)
{
- CharSequence urlToMediaReference = RequestCycle.get().urlFor(mediaStreamingResourceReference, pageParameters);
+ CharSequence urlToMediaReference = RequestCycle.get().urlFor(
+ mediaStreamingResourceReference, pageParameters);
tag.put("src", urlToMediaReference + timeManagement);
}
else if (url != null)
{
- tag.put("src", url + timeManagement);
+ Url encoded = new PageParametersEncoder().encodePageParameters(pageParameters);
+ String queryString = encoded.getQueryString();
+ tag.put("src", url + (queryString != null ? "?" + queryString : "") + timeManagement);
}
String mg = getMediaGroup();
@@ -339,12 +348,12 @@ public abstract class MediaComponent extends WebMarkupContainer
/**
* Sets the type of preload.
* <ul>
- * <li><b>none</b>: Hints to the user agent that either the author does not expect the user to need
- * the media resource, or that the server wants to minimise unnecessary traffic.</li>
+ * <li><b>none</b>: Hints to the user agent that either the author does not expect the user to
+ * need the media resource, or that the server wants to minimise unnecessary traffic.</li>
*
- * <li><b>metadata</b>: Hints to the user agent that the author does not expect the user to need the
- * media resource, but that fetching the resource metadata (dimensions, first frame, track list,
- * duration, etc) is reasonable.</li>
+ * <li><b>metadata</b>: Hints to the user agent that the author does not expect the user to need
+ * the media resource, but that fetching the resource metadata (dimensions, first frame, track
+ * list, duration, etc) is reasonable.</li>
*
* <li><b>auto</b>: Hints to the user agent that the user agent can put the user's needs first
* without risk to the server, up to and including optimistically downloading the entire
http://git-wip-us.apache.org/repos/asf/wicket/blob/5e5c6e0c/wicket-core/src/main/java/org/apache/wicket/markup/html/media/MediaStreamingResourceReference.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/MediaStreamingResourceReference.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/MediaStreamingResourceReference.java
index 6231eed..ed6932b 100755
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/MediaStreamingResourceReference.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/MediaStreamingResourceReference.java
@@ -72,7 +72,11 @@ public class MediaStreamingResourceReference extends PackageResourceReference
@Override
protected ResourceResponse newResourceResponse(Attributes attributes)
{
- IResourceStream packageResourceStream = getResourceStream();
+ IResourceStream resourceStream = getResourceStream();
+ if (resourceStream == null)
+ {
+ throw new WicketRuntimeException("Cannot find resource: " + toString());
+ }
Long startbyte = null;
Long endbyte = null;
try
@@ -83,19 +87,20 @@ public class MediaStreamingResourceReference extends PackageResourceReference
if (!(request instanceof WebRequest) || !(response instanceof WebResponse))
{
throw new IllegalStateException(
- "Web request/response are required! Request: " + request + ", response: " + response);
+ "Web request/response are required! Request: " + request +
+ ", response: " + response);
}
WebRequest webRequest = (WebRequest)request;
WebResponse webResponse = (WebResponse)response;
- long length = packageResourceStream.length().bytes();
+ long length = resourceStream.length().bytes();
ResourceResponse resourceResponse = new ResourceResponse();
- resourceResponse.setContentType(packageResourceStream.getContentType());
+ resourceResponse.setContentType(resourceStream.getContentType());
resourceResponse.setFileName(MediaStreamingResourceReference.this.getName());
resourceResponse.setContentDisposition(ContentDisposition.ATTACHMENT);
- resourceResponse.setLastModified(packageResourceStream.lastModifiedTime());
+ resourceResponse.setLastModified(resourceStream.lastModifiedTime());
// accept ranges, so that the player can
// load and play content from a specific byte position
@@ -123,8 +128,8 @@ public class MediaStreamingResourceReference extends PackageResourceReference
String[] rangeParts = Strings.split(range, '-');
if ("0".equals(rangeParts[0]))
{
- webResponse.setHeader("Content-Range",
- "bytes 0-" + (length - 1) + "/" + length);
+ webResponse.setHeader("Content-Range", "bytes 0-" + (length - 1) + "/" +
+ length);
resourceResponse.setContentLength(length);
}
else
@@ -132,21 +137,28 @@ public class MediaStreamingResourceReference extends PackageResourceReference
startbyte = Long.parseLong(rangeParts[0]);
if (rangeParts.length == 2)
{
- endbyte = Long.parseLong(rangeParts[1]);
+ if (!"".equals(rangeParts[1].trim()))
+ {
+ endbyte = Long.parseLong(rangeParts[1]);
+ }
+ else
+ {
+ endbyte = length - 1;
+ }
}
else
{
endbyte = length - 1;
}
- webResponse.setHeader("Content-Range",
- "bytes " + startbyte + '-' + endbyte + '/' + length);
+ webResponse.setHeader("Content-Range", "bytes " + startbyte + '-' +
+ endbyte + '/' + length);
resourceResponse.setContentLength((endbyte - startbyte) + 1);
}
}
// Apply the writer callback to send the requested part to the client
- resourceResponse.setWriteCallback(new PartWriterCallback(
- packageResourceStream, startbyte, endbyte));
+ resourceResponse.setWriteCallback(new PartWriterCallback(resourceStream,
+ startbyte, endbyte));
return resourceResponse;
}
@@ -157,11 +169,11 @@ public class MediaStreamingResourceReference extends PackageResourceReference
}
finally
{
- if (packageResourceStream != null)
+ if (resourceStream != null)
{
try
{
- packageResourceStream.close();
+ resourceStream.close();
}
catch (IOException e)
{
http://git-wip-us.apache.org/repos/asf/wicket/blob/5e5c6e0c/wicket-core/src/main/java/org/apache/wicket/markup/html/media/audio/Audio.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/audio/Audio.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/audio/Audio.java
index 3ab9615..c29d98c 100755
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/audio/Audio.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/audio/Audio.java
@@ -76,6 +76,16 @@ public class Audio extends MediaComponent
super(id, model, url);
}
+ public Audio(String id, String url, PageParameters pageParameters)
+ {
+ super(id, null, url, pageParameters);
+ }
+
+ public Audio(String id, IModel<?> model, String url, PageParameters pageParameters)
+ {
+ super(id, model, url, pageParameters);
+ }
+
@Override
protected void onComponentTag(ComponentTag tag)
{
http://git-wip-us.apache.org/repos/asf/wicket/blob/5e5c6e0c/wicket-core/src/main/java/org/apache/wicket/markup/html/media/video/Video.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/video/Video.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/video/Video.java
index 5a8b167..a608a4b 100755
--- a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/video/Video.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/video/Video.java
@@ -86,6 +86,16 @@ public class Video extends MediaComponent
super(id, model, url);
}
+ public Video(String id, String url, PageParameters pageParameters)
+ {
+ super(id, null, url, pageParameters);
+ }
+
+ public Video(String id, IModel<?> model, String url, PageParameters pageParameters)
+ {
+ super(id, model, url, pageParameters);
+ }
+
@Override
protected void onComponentTag(ComponentTag tag)
{
http://git-wip-us.apache.org/repos/asf/wicket/blob/5e5c6e0c/wicket-examples/src/main/java/org/apache/wicket/examples/media/Home.html
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/media/Home.html b/wicket-examples/src/main/java/org/apache/wicket/examples/media/Home.html
new file mode 100644
index 0000000..efceee8
--- /dev/null
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/media/Home.html
@@ -0,0 +1,15 @@
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+ <title>Wicket Examples - videos</title>
+ <link rel="stylesheet" type="text/css" href="style.css"/>
+</head>
+<body>
+ <span wicket:id="mainNavigation"/>
+ <video wicket:id="video1" />
+ <video wicket:id="video2" />
+ <video wicket:id="video3">
+ <source wicket:id="source3" />
+ </video><br><br>
+ For more video examples see comments in the java sources<br><br>The second movie is not displayed because of CORS settings - please read <a href="http://en.wikipedia.org/wiki/Cross-origin_resource_sharing">Cross-origin_resource_sharing - Wikipedia</a> for more information.
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/wicket/blob/5e5c6e0c/wicket-examples/src/main/java/org/apache/wicket/examples/media/Home.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/media/Home.java b/wicket-examples/src/main/java/org/apache/wicket/examples/media/Home.java
new file mode 100644
index 0000000..558b126
--- /dev/null
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/media/Home.java
@@ -0,0 +1,103 @@
+/*
+ * 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.examples.media;
+
+import java.util.UUID;
+
+import org.apache.wicket.examples.WicketExamplePage;
+import org.apache.wicket.markup.html.media.MediaComponent.Cors;
+import org.apache.wicket.markup.html.media.MediaStreamingResourceReference;
+import org.apache.wicket.markup.html.media.Source;
+import org.apache.wicket.markup.html.media.video.Video;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.request.resource.PackageResourceReference;
+
+
+/**
+ * Demonstrates different flavors of org.apache.wicket.examples.videos.<br>
+ * <br>
+ *
+ * Videos are from: http://media.w3.org/2010/05/video/<br>
+ * <br>
+ * Images are from: http://search.creativecommons.org/ with check on commercial use and modify...
+ *
+ * @author Tobias Soloschenko
+ */
+public final class Home extends WicketExamplePage
+{
+
+ /**
+ * Constructor
+ */
+ public Home()
+ {
+ // Internal video with several options
+
+ Video video1 = new Video("video1", new MediaStreamingResourceReference(Home.class,
+ "video.mp4"));
+ video1.setAutoplay(false);
+ video1.setControls(true);
+ video1.setLooping(false);
+ video1.setWidth(320);
+ video1.setHeight(240);
+ video1.setPoster(new PackageResourceReference(Home.class, "novideo.gif"));
+ add(video1);
+
+ // External video
+ PageParameters pageParameters = new PageParameters();
+ pageParameters.add("random", UUID.randomUUID().toString());
+ pageParameters.add("test", "test");
+ Video video2 = new Video("video2", "http://media.w3.org/2010/05/video/movie_300.mp4",
+ pageParameters);
+ video2.setCrossOrigin(Cors.ANONYMOUS);
+ add(video2);
+
+ // video with source
+
+ Video video3 = new Video("video3");
+ video3.setPoster(new PackageResourceReference(Home.class, "novideo.gif"));
+
+ Source source3 = new Source("source3", new MediaStreamingResourceReference(Home.class,
+ "video.mp4"));
+ // Need to be set to true to show the type
+ source3.setDisplayType(true);
+ // the default type is the mime type of the image with no codec information
+ source3.setType("video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"");
+ video3.add(source3);
+
+ add(video3);
+
+ // video with track
+
+ /*
+ * Video video4 = new Video("video4", new MediaStreamingResourceReference(Home.class,
+ * "dummyVideo.m4a"));
+ *
+ * // source tag Source source4 = new Source("source4",
+ * "http://www.mytestpage.xc/video.m4a");
+ * source4.setMedia("screen and (device-width:500px)"); source4.setType("video/mp4");
+ * source4.setDisplayType(true); video4.add(source4);
+ *
+ * // tack tag Track track4 = new Track("track4", new PackageResourceReference(Home.class,
+ * "dummySubtitles.vtt")); track4.setKind(Kind.subtitles);
+ * track4.setLabel("Subtitles of video"); track4.setSrclang(Locale.GERMANY);
+ * track4.setDefaultTrack(true); video4.add(track4);
+ *
+ * add(video4);
+ */
+ }
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/5e5c6e0c/wicket-examples/src/main/java/org/apache/wicket/examples/media/VideosApplication.java
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/media/VideosApplication.java b/wicket-examples/src/main/java/org/apache/wicket/examples/media/VideosApplication.java
new file mode 100644
index 0000000..c17a393
--- /dev/null
+++ b/wicket-examples/src/main/java/org/apache/wicket/examples/media/VideosApplication.java
@@ -0,0 +1,63 @@
+/*
+ * 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.examples.media;
+
+import org.apache.wicket.Page;
+import org.apache.wicket.examples.WicketExampleApplication;
+import org.apache.wicket.markup.html.IPackageResourceGuard;
+import org.apache.wicket.markup.html.SecurePackageResourceGuard;
+
+
+/**
+ * Application class for the videos examples.
+ *
+ * @author Tobias Soloschenko
+ */
+public class VideosApplication extends WicketExampleApplication
+{
+ /**
+ * Constructor
+ */
+ public VideosApplication()
+ {
+
+ }
+
+ /**
+ * @see org.apache.wicket.Application#getHomePage()
+ */
+ @Override
+ public Class<? extends Page> getHomePage()
+ {
+ return Home.class;
+ }
+
+ /**
+ * @see org.apache.wicket.examples.WicketExampleApplication#init()
+ */
+ @Override
+ protected void init()
+ {
+ IPackageResourceGuard packageResourceGuard = getResourceSettings().getPackageResourceGuard();
+ if (packageResourceGuard instanceof SecurePackageResourceGuard)
+ {
+ SecurePackageResourceGuard guard = (SecurePackageResourceGuard)packageResourceGuard;
+ guard.addPattern("+*.mp4");
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/wicket/blob/5e5c6e0c/wicket-examples/src/main/java/org/apache/wicket/examples/media/novideo.gif
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/media/novideo.gif b/wicket-examples/src/main/java/org/apache/wicket/examples/media/novideo.gif
new file mode 100644
index 0000000..98cc51a
Binary files /dev/null and b/wicket-examples/src/main/java/org/apache/wicket/examples/media/novideo.gif differ
http://git-wip-us.apache.org/repos/asf/wicket/blob/5e5c6e0c/wicket-examples/src/main/java/org/apache/wicket/examples/media/video.mp4
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/java/org/apache/wicket/examples/media/video.mp4 b/wicket-examples/src/main/java/org/apache/wicket/examples/media/video.mp4
new file mode 100644
index 0000000..cf59777
Binary files /dev/null and b/wicket-examples/src/main/java/org/apache/wicket/examples/media/video.mp4 differ
http://git-wip-us.apache.org/repos/asf/wicket/blob/5e5c6e0c/wicket-examples/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/wicket-examples/src/main/webapp/WEB-INF/web.xml b/wicket-examples/src/main/webapp/WEB-INF/web.xml
index 92f956a..6b91161 100644
--- a/wicket-examples/src/main/webapp/WEB-INF/web.xml
+++ b/wicket-examples/src/main/webapp/WEB-INF/web.xml
@@ -16,9 +16,9 @@
limitations under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- version="2.5">
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
<display-name>Wicket Examples</display-name>
@@ -160,6 +160,15 @@
<param-value>org.apache.wicket.examples.images.ImagesApplication</param-value>
</init-param>
</filter>
+
+ <filter>
+ <filter-name>VideosApplication</filter-name>
+ <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
+ <init-param>
+ <param-name>applicationClassName</param-name>
+ <param-value>org.apache.wicket.examples.media.VideosApplication</param-value>
+ </init-param>
+ </filter>
<filter>
<filter-name>LibraryApplication</filter-name>
@@ -542,6 +551,13 @@
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
+
+ <filter-mapping>
+ <filter-name>VideosApplication</filter-name>
+ <url-pattern>/videos/*</url-pattern>
+ <dispatcher>REQUEST</dispatcher>
+ <dispatcher>INCLUDE</dispatcher>
+ </filter-mapping>
<filter-mapping>
<filter-name>HelloWorldApplication</filter-name>