code style changes Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/ff1bf27f Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/ff1bf27f Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/ff1bf27f
Branch: refs/heads/pr-86-media_tags Commit: ff1bf27f6e768eb70256b38c0d99a09a85fab9c9 Parents: c396d76 Author: klopfdreh <klopfdreh@tobiass-mbp> Authored: Thu Feb 5 10:42:13 2015 +0100 Committer: klopfdreh <klopfdreh@tobiass-mbp> Committed: Thu Feb 5 10:42:13 2015 +0100 ---------------------------------------------------------------------- .../markup/html/media/MediaComponent.java | 148 ++++++++++--------- .../media/MediaStreamingResourceReference.java | 56 +++---- .../apache/wicket/markup/html/media/Source.java | 31 ++-- .../apache/wicket/markup/html/media/Track.java | 36 ++--- .../wicket/markup/html/media/audio/Audio.java | 2 +- .../wicket/markup/html/media/video/Video.java | 22 +-- .../markup/html/media/MediaTagsTestPage.java | 2 +- 7 files changed, 145 insertions(+), 152 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/ff1bf27f/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 02c2b8d..4131439 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 @@ -35,6 +35,50 @@ public abstract class MediaComponent extends WebMarkupContainer private static final long serialVersionUID = 1L; + /** + * To be used for the crossorigin attribute + * + * @see {@link #setCrossOrigin(Cors)} + */ + public enum Cors + { + ANONYMOUS("anonymous"), USER_CREDENTIALS("user-credentials"), NO_CORS(""); + + private String realName; + + private Cors(String realName) + { + this.realName = realName; + } + + public String getRealName() + { + return realName; + } + } + + /** + * To be used for the preload attribute + * + * @see {@link #setPreload(Preload)} + */ + public enum Preload + { + NONE("none"), METADATA("metadata"), AUTO("auto"); + + public String realName; + + private Preload(String realname) + { + realName = realname; + } + + public String getRealName() + { + return realName; + } + } + // use Boolean instead of elementary data types to get a lightweight component private Boolean autoplay; @@ -52,7 +96,7 @@ public abstract class MediaComponent extends WebMarkupContainer private String mediaGroup; - private Cors crossorigin; + private Cors crossOrigin; private PageParameters pageParameters; @@ -134,59 +178,58 @@ public abstract class MediaComponent extends WebMarkupContainer // The time management is used to set the start / stop // time in seconds of the movie to be played back String timeManagement = ""; - if (this.startTime != null) + if (startTime != null) { - timeManagement = timeManagement += "#t=" + this.startTime + - (this.endTime != null ? "," + this.endTime : ""); + timeManagement = timeManagement += "#t=" + startTime + + (endTime != null ? "," + endTime : ""); } - if (this.mediaStreamingResourceReference != null) + if (mediaStreamingResourceReference != null) { tag.put("src", - RequestCycle.get() - .urlFor(this.mediaStreamingResourceReference, this.pageParameters) + + RequestCycle.get().urlFor(mediaStreamingResourceReference, pageParameters) + timeManagement); } - if (this.url != null) + if (url != null) { - tag.put("src", this.url + timeManagement); + tag.put("src", url + timeManagement); } - if (this.mediaGroup != null) + if (mediaGroup != null) { - tag.put("mediagroup", this.mediaGroup); + tag.put("mediagroup", mediaGroup); } - if (this.autoplay != null && this.autoplay) + if (autoplay != null && autoplay) { tag.put("autoplay", "autoplay"); } - if (this.loop != null && this.loop) + if (loop != null && loop) { tag.put("loop", "loop"); } - if (this.muted != null && this.muted) + if (muted != null && muted) { tag.put("muted", "muted"); } // Use getter here because controls should be visible by default - if (this.getControls()) + if (getControls()) { tag.put("controls", "controls"); } - if (this.preload != null) + if (preload != null) { - tag.put("preload", this.preload.name()); + tag.put("preload", preload.getRealName()); } - if (this.crossorigin != null) + if (crossOrigin != null) { - tag.put("crossorigin", this.crossorigin.getRealName()); + tag.put("crossorigin", crossOrigin.getRealName()); } } @@ -197,7 +240,7 @@ public abstract class MediaComponent extends WebMarkupContainer */ public Boolean getAutoplay() { - return this.autoplay != null ? this.autoplay : false; + return autoplay != null ? autoplay : false; } /** @@ -218,7 +261,7 @@ public abstract class MediaComponent extends WebMarkupContainer */ public Boolean getLoop() { - return this.loop != null ? this.loop : false; + return loop != null ? loop : false; } /** @@ -239,7 +282,7 @@ public abstract class MediaComponent extends WebMarkupContainer */ public Boolean getMuted() { - return this.muted != null ? this.muted : false; + return muted != null ? muted : false; } /** @@ -260,7 +303,7 @@ public abstract class MediaComponent extends WebMarkupContainer */ public Boolean getControls() { - return this.controls != null ? this.controls : true; + return controls != null ? controls : true; } /** @@ -283,7 +326,7 @@ public abstract class MediaComponent extends WebMarkupContainer */ public Preload getPreload() { - return this.preload; + return preload; } /** @@ -317,7 +360,7 @@ public abstract class MediaComponent extends WebMarkupContainer */ public String getStartTime() { - return this.startTime; + return startTime; } /** @@ -354,7 +397,7 @@ public abstract class MediaComponent extends WebMarkupContainer */ public String getEndTime() { - return this.endTime; + return endTime; } /** @@ -389,7 +432,7 @@ public abstract class MediaComponent extends WebMarkupContainer */ public String getMediaGroup() { - return this.mediaGroup; + return mediaGroup; } /** @@ -406,67 +449,34 @@ public abstract class MediaComponent extends WebMarkupContainer /** * Gets the cross origin settings * - * @see {@link #setCrossorigin(Cors)} + * @see {@link #setCrossOrigin(Cors)} * * @return the cross origins settings */ - public Cors getCrossorigin() + public Cors getCrossOrigin() { - return this.crossorigin; + return crossOrigin; } /** * Sets the cross origin settings<br> * <br> * - * <b>anonymous</b>: Cross-origin CORS requests for the element will not have the credentials + * <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 + * <b>USER_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. + * <b>NO_CORS</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 + * @param crossOrigin * the cross origins settings to set */ - public void setCrossorigin(Cors crossorigin) - { - this.crossorigin = crossorigin; - } - - /** - * To be used for the preload attribute - * - * @see {@link #setPreload(Preload)} - */ - public enum Preload - { - none, metadata, auto - } - - /** - * To be used for the crossorigin attribute - * - * @see {@link #setCrossorigin(Cors)} - */ - public enum Cors + public void setCrossOrigin(Cors crossOrigin) { - anonymous("anonymous"), use_credentials("user-credentials"), no_cors(""); - - private String realName; - - private Cors(String realName) - { - this.realName = realName; - } - - public String getRealName() - { - return this.realName; - } + this.crossOrigin = crossOrigin; } - } http://git-wip-us.apache.org/repos/asf/wicket/blob/ff1bf27f/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 d538644..0f7568f 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 @@ -19,8 +19,6 @@ package org.apache.wicket.markup.html.media; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.StringWriter; import java.util.Locale; import org.apache.wicket.Application; @@ -93,19 +91,19 @@ public class MediaStreamingResourceReference extends ResourceReference WebRequest webRequest = (WebRequest)request; WebResponse webResponse = (WebResponse)response; - this.packageResourceStream = new PackageResourceStream( + packageResourceStream = new PackageResourceStream( MediaStreamingResourceReference.this.getScope(), MediaStreamingResourceReference.this.getName(), MediaStreamingResourceReference.this.getLocale(), MediaStreamingResourceReference.this.getStyle(), MediaStreamingResourceReference.this.getVariation()); - long length = this.packageResourceStream.length().bytes(); + long length = packageResourceStream.length().bytes(); ResourceResponse resourceResponse = new ResourceResponse(); - resourceResponse.setContentType(this.packageResourceStream.getContentType()); + resourceResponse.setContentType(packageResourceStream.getContentType()); resourceResponse.setFileName(MediaStreamingResourceReference.this.getName()); resourceResponse.setContentDisposition(ContentDisposition.ATTACHMENT); - resourceResponse.setLastModified(this.packageResourceStream.lastModifiedTime()); + resourceResponse.setLastModified(packageResourceStream.lastModifiedTime()); // We accept ranges, so that the player can // load and play content from a specific byte position @@ -138,18 +136,18 @@ public class MediaStreamingResourceReference extends ResourceReference } else { - this.startbyte = Long.parseLong(rangeParts[0]); + startbyte = Long.parseLong(rangeParts[0]); if (rangeParts.length == 2) { - this.endbyte = Long.parseLong(rangeParts[1]); + endbyte = Long.parseLong(rangeParts[1]); } else { - this.endbyte = length - 1; + endbyte = length - 1; } - webResponse.setHeader("Content-Range", "bytes " + this.startbyte + - "-" + this.endbyte + "/" + length); - resourceResponse.setContentLength((this.endbyte - this.startbyte) + 1); + webResponse.setHeader("Content-Range", "bytes " + startbyte + "-" + + endbyte + "/" + length); + resourceResponse.setContentLength((endbyte - startbyte) + 1); } } @@ -209,8 +207,9 @@ public class MediaStreamingResourceReference extends ResourceReference } catch (Exception e) { - StringWriter stringWriter = printStack(e); - throw new WicketRuntimeException(stringWriter.toString()); + throw new WicketRuntimeException( + "A problem occurred while writing the buffer to the output stream.", + e); } } }); @@ -225,40 +224,25 @@ public class MediaStreamingResourceReference extends ResourceReference } catch (Exception e) { - StringWriter stringWriter = this.printStack(e); - throw new WicketRuntimeException(stringWriter.toString()); + throw new WicketRuntimeException( + "A problem occurred while creating the video response.", e); } finally { - if (this.packageResourceStream != null) + if (packageResourceStream != null) { try { - this.packageResourceStream.close(); + packageResourceStream.close(); } catch (IOException e) { - StringWriter stringWriter = this.printStack(e); - throw new WicketRuntimeException(stringWriter.toString()); + throw new WicketRuntimeException( + "A problem occurred while closing the video response stream.", e); } } } } - - /** - * Prints the stack trace to a print writer - * - * @param exception - * the exception - * @return the string writer containing the stack trace - */ - private StringWriter printStack(Exception exception) - { - StringWriter stringWriter = new StringWriter(); - PrintWriter printWriter = new PrintWriter(stringWriter); - exception.printStackTrace(printWriter); - return stringWriter; - } }; return mediaStreamingResource; @@ -271,7 +255,7 @@ public class MediaStreamingResourceReference extends ResourceReference */ public Integer getBuffer() { - return this.buffer != null ? this.buffer : 4048; + return buffer != null ? buffer : 4048; } /** http://git-wip-us.apache.org/repos/asf/wicket/blob/ff1bf27f/wicket-core/src/main/java/org/apache/wicket/markup/html/media/Source.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/Source.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/Source.java index 0963f06..8926609 100755 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/Source.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/Source.java @@ -115,36 +115,35 @@ public class Source extends WebMarkupContainer @Override protected void onComponentTag(ComponentTag tag) { - this.checkComponentTag(tag, "source"); + checkComponentTag(tag, "source"); super.onComponentTag(tag); - if (this.mediaStreamingResourceReference != null) + if (mediaStreamingResourceReference != null) { tag.put("src", - RequestCycle.get() - .urlFor(this.mediaStreamingResourceReference, this.pageParameters)); + RequestCycle.get().urlFor(mediaStreamingResourceReference, pageParameters)); } - if (this.url != null) + if (url != null) { - tag.put("src", this.url); + tag.put("src", url); } - if (this.getDisplayType()) + if (getDisplayType()) { - if (this.type != null) + if (type != null) { - tag.put("type", this.type); + tag.put("type", type); } - else if (this.mediaStreamingResourceReference != null) + else if (mediaStreamingResourceReference != null) { - tag.put("type", this.mediaStreamingResourceReference.getType()); + tag.put("type", mediaStreamingResourceReference.getType()); } } - if (this.media != null) + if (media != null) { - tag.put("media", this.media); + tag.put("media", media); } } @@ -156,7 +155,7 @@ public class Source extends WebMarkupContainer */ public Boolean getDisplayType() { - return this.displayType != null ? this.displayType : false; + return displayType != null ? displayType : false; } /** @@ -179,7 +178,7 @@ public class Source extends WebMarkupContainer */ public String getType() { - return this.type; + return type; } /** @@ -238,7 +237,7 @@ public class Source extends WebMarkupContainer */ public String getMedia() { - return this.media; + return media; } /** http://git-wip-us.apache.org/repos/asf/wicket/blob/ff1bf27f/wicket-core/src/main/java/org/apache/wicket/markup/html/media/Track.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/Track.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/Track.java index 587ffcd..8871b23 100755 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/media/Track.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/media/Track.java @@ -117,30 +117,30 @@ public class Track extends WebMarkupContainer @Override protected void onComponentTag(ComponentTag tag) { - this.checkComponentTag(tag, "track"); + checkComponentTag(tag, "track"); super.onComponentTag(tag); - if (this.resourceReference != null) + if (resourceReference != null) { - tag.put("src", RequestCycle.get().urlFor(this.resourceReference, this.pageParameters)); + tag.put("src", RequestCycle.get().urlFor(resourceReference, pageParameters)); } - if (this.url != null) + if (url != null) { - tag.put("src", this.url); + tag.put("src", url); } - if (this.kind != null) + if (kind != null) { - tag.put("kind", this.kind.name()); + tag.put("kind", kind.name()); } - if (this.label != null) + if (label != null) { - tag.put("label", this.label); + tag.put("label", label); } - if (this.defaultTrack != null && this.defaultTrack) + if (defaultTrack != null && defaultTrack) { tag.put("default", "default"); } @@ -148,13 +148,13 @@ public class Track extends WebMarkupContainer // if the srclang field is set use this, else if the // resource reference provides a locale use the language // of the resource reference - if (this.srclang != null) + if (srclang != null) { - tag.put("srclang", this.srclang.getLanguage()); + tag.put("srclang", srclang.getLanguage()); } - else if (this.resourceReference != null && this.resourceReference.getLocale() != null) + else if (resourceReference != null && resourceReference.getLocale() != null) { - tag.put("srclang", this.resourceReference.getLocale().getLanguage()); + tag.put("srclang", resourceReference.getLocale().getLanguage()); } } @@ -167,7 +167,7 @@ public class Track extends WebMarkupContainer */ public Kind getKind() { - return this.kind; + return kind; } /** @@ -208,7 +208,7 @@ public class Track extends WebMarkupContainer */ public String getLabel() { - return this.label; + return label; } /** @@ -229,7 +229,7 @@ public class Track extends WebMarkupContainer */ public Boolean getDefaultTrack() { - return this.defaultTrack != null ? this.defaultTrack : false; + return defaultTrack != null ? defaultTrack : false; } /** @@ -250,7 +250,7 @@ public class Track extends WebMarkupContainer */ public Locale getSrclang() { - return this.srclang; + return srclang; } /** http://git-wip-us.apache.org/repos/asf/wicket/blob/ff1bf27f/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 d1f0fe2..0bcef1c 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 @@ -91,7 +91,7 @@ public class Audio extends MediaComponent @Override protected void onComponentTag(ComponentTag tag) { - this.checkComponentTag(tag, "audio"); + checkComponentTag(tag, "audio"); super.onComponentTag(tag); } } http://git-wip-us.apache.org/repos/asf/wicket/blob/ff1bf27f/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 c463a07..79a8d7e 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 @@ -100,22 +100,22 @@ public class Video extends MediaComponent @Override protected void onComponentTag(ComponentTag tag) { - this.checkComponentTag(tag, "video"); + checkComponentTag(tag, "video"); super.onComponentTag(tag); - if (this.width != null) + if (width != null) { - tag.put("width", this.width); + tag.put("width", width); } - if (this.height != null) + if (height != null) { - tag.put("height", this.height); + tag.put("height", height); } - if (this.poster != null) + if (poster != null) { - tag.put("poster", RequestCycle.get().urlFor(this.poster, this.posterPageParameters)); + tag.put("poster", RequestCycle.get().urlFor(poster, posterPageParameters)); } } @@ -126,7 +126,7 @@ public class Video extends MediaComponent */ public ResourceReference getPoster() { - return this.poster; + return poster; } /** @@ -136,7 +136,7 @@ public class Video extends MediaComponent */ public PageParameters getPosterPageParameters() { - return this.posterPageParameters; + return posterPageParameters; } /** @@ -171,7 +171,7 @@ public class Video extends MediaComponent */ public Integer getWidth() { - return this.width; + return width; } /** @@ -192,7 +192,7 @@ public class Video extends MediaComponent */ public Integer getHeight() { - return this.height; + return height; } /** http://git-wip-us.apache.org/repos/asf/wicket/blob/ff1bf27f/wicket-core/src/test/java/org/apache/wicket/markup/html/media/MediaTagsTestPage.java ---------------------------------------------------------------------- diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/media/MediaTagsTestPage.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/media/MediaTagsTestPage.java index 8393f42..6bb6619 100644 --- a/wicket-core/src/test/java/org/apache/wicket/markup/html/media/MediaTagsTestPage.java +++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/media/MediaTagsTestPage.java @@ -36,7 +36,7 @@ public class MediaTagsTestPage extends WebPage MediaTagsTestPage.class, "dummyAudio.mp3"), pageParameters); audio.setAutoplay(true); audio.setControls(true); - audio.setCrossorigin(Cors.use_credentials); + audio.setCrossOrigin(Cors.USER_CREDENTIALS); audio.setLoop(true); audio.setMuted(true); audio.setStartTime("5");