Search in sources :

Example 1 with WVideo

use of com.github.bordertech.wcomponents.WVideo in project wcomponents by BorderTech.

the class WVideoRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WVideo video = new WVideo();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(video) instanceof WVideoRenderer);
}
Also used : WVideo(com.github.bordertech.wcomponents.WVideo) Test(org.junit.Test)

Example 2 with WVideo

use of com.github.bordertech.wcomponents.WVideo in project wcomponents by BorderTech.

the class WVideoRenderer method doRender.

/**
 * Paints the given WVideo.
 *
 * @param component the WVideo to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WVideo videoComponent = (WVideo) component;
    XmlStringBuilder xml = renderContext.getWriter();
    Video[] video = videoComponent.getVideo();
    if (video == null || video.length == 0) {
        return;
    }
    Track[] tracks = videoComponent.getTracks();
    WVideo.Controls controls = videoComponent.getControls();
    int width = videoComponent.getWidth();
    int height = videoComponent.getHeight();
    int duration = video[0].getDuration();
    // Check for alternative text
    String alternativeText = videoComponent.getAltText();
    if (alternativeText == null) {
        LOG.warn("Video should have a description.");
        alternativeText = null;
    } else {
        alternativeText = I18nUtilities.format(null, alternativeText);
    }
    xml.appendTagOpen("ui:video");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalUrlAttribute("poster", videoComponent.getPosterUrl());
    xml.appendOptionalAttribute("alt", alternativeText);
    xml.appendOptionalAttribute("autoplay", videoComponent.isAutoplay(), "true");
    xml.appendOptionalAttribute("mediagroup", videoComponent.getMediaGroup());
    xml.appendOptionalAttribute("loop", videoComponent.isLoop(), "true");
    xml.appendOptionalAttribute("muted", videoComponent.isMuted(), "true");
    xml.appendOptionalAttribute("hidden", videoComponent.isHidden(), "true");
    xml.appendOptionalAttribute("disabled", videoComponent.isDisabled(), "true");
    xml.appendOptionalAttribute("toolTip", videoComponent.getToolTip());
    xml.appendOptionalAttribute("width", width > 0, width);
    xml.appendOptionalAttribute("height", height > 0, height);
    xml.appendOptionalAttribute("duration", duration > 0, duration);
    switch(videoComponent.getPreload()) {
        case NONE:
            xml.appendAttribute("preload", "none");
            break;
        case META_DATA:
            xml.appendAttribute("preload", "metadata");
            break;
        case AUTO:
        default:
            break;
    }
    if (controls != null && !WVideo.Controls.NATIVE.equals(controls)) {
        switch(controls) {
            case NONE:
                xml.appendAttribute("controls", "none");
                break;
            case ALL:
                xml.appendAttribute("controls", "all");
                break;
            case PLAY_PAUSE:
                xml.appendAttribute("controls", "play");
                break;
            case DEFAULT:
                xml.appendAttribute("controls", "default");
                break;
            default:
                LOG.error("Unknown control type: " + controls);
        }
    }
    xml.appendClose();
    String[] urls = videoComponent.getVideoUrls();
    for (int i = 0; i < urls.length; i++) {
        xml.appendTagOpen("ui:src");
        xml.appendUrlAttribute("uri", urls[i]);
        xml.appendOptionalAttribute("type", video[i].getMimeType());
        if (video[i].getSize() != null) {
            xml.appendOptionalAttribute("width", video[i].getSize().width > 0, video[i].getSize().width);
            xml.appendOptionalAttribute("height", video[i].getSize().height > 0, video[i].getSize().height);
        }
        xml.appendEnd();
    }
    if (tracks != null && tracks.length > 0) {
        String[] trackUrls = videoComponent.getTrackUrls();
        for (int i = 0; i < tracks.length; i++) {
            xml.appendTagOpen("ui:track");
            xml.appendUrlAttribute("src", trackUrls[i]);
            xml.appendOptionalAttribute("lang", tracks[i].getLanguage());
            xml.appendOptionalAttribute("desc", tracks[i].getDescription());
            xml.appendOptionalAttribute("kind", trackKindToString(tracks[i].getKind()));
            xml.appendEnd();
        }
    }
    xml.appendEndTag("ui:video");
}
Also used : WVideo(com.github.bordertech.wcomponents.WVideo) Video(com.github.bordertech.wcomponents.Video) WVideo(com.github.bordertech.wcomponents.WVideo) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) Track(com.github.bordertech.wcomponents.Track)

Example 3 with WVideo

use of com.github.bordertech.wcomponents.WVideo in project wcomponents by BorderTech.

the class StepCountUtil method isCachedContentRequest.

/**
 * Check if the request is for cached content.
 *
 * @param request the request being processed
 * @return true if content is cached, otherwise false
 */
public static boolean isCachedContentRequest(final Request request) {
    // Get target id on request
    String targetId = request.getParameter(Environment.TARGET_ID);
    if (targetId == null) {
        return false;
    }
    // Get target
    ComponentWithContext targetWithContext = WebUtilities.getComponentById(targetId, true);
    if (targetWithContext == null) {
        return false;
    }
    // Check for caching key
    WComponent target = targetWithContext.getComponent();
    UIContextHolder.pushContext(targetWithContext.getContext());
    try {
        // TODO Look at implementing CacheableTarget interface
        String key = null;
        if (target instanceof WContent) {
            key = ((WContent) target).getCacheKey();
        } else if (target instanceof WImage) {
            key = ((WImage) target).getCacheKey();
        } else if (target instanceof WVideo) {
            key = ((WVideo) target).getCacheKey();
        } else if (target instanceof WAudio) {
            key = ((WAudio) target).getCacheKey();
        }
        return !Util.empty(key);
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WContent(com.github.bordertech.wcomponents.WContent) WVideo(com.github.bordertech.wcomponents.WVideo) WImage(com.github.bordertech.wcomponents.WImage) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext) WAudio(com.github.bordertech.wcomponents.WAudio)

Example 4 with WVideo

use of com.github.bordertech.wcomponents.WVideo in project wcomponents by BorderTech.

the class WVideoRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    MockVideo mockVideo = new MockVideo();
    mockVideo.setMimeType("video/mpeg");
    mockVideo.setSize(new Dimension(111, 222));
    // Test with no video tracks - should not render
    WVideo video = new WVideo();
    assertSchemaMatch(video);
    assertXpathNotExists("//ui:video", video);
    // Test with minimal options
    video = new WVideo(mockVideo);
    // so that the URIs are consistent
    video.setCacheKey("x");
    setActiveContext(createUIContext());
    assertSchemaMatch(video);
    assertXpathExists("//ui:video", video);
    assertXpathEvaluatesTo(video.getId(), "//ui:video/@id", video);
    assertXpathEvaluatesTo("none", "//ui:video/@preload", video);
    assertXpathNotExists("//ui:video/@alt", video);
    assertXpathNotExists("//ui:video/@autoplay", video);
    assertXpathNotExists("//ui:video/@loop", video);
    assertXpathNotExists("//ui:video/@muted", video);
    assertXpathNotExists("//ui:video/@controls", video);
    assertXpathNotExists("//ui:video/@hidden", video);
    assertXpathNotExists("//ui:video/@disabled", video);
    assertXpathNotExists("//ui:video/@tooltip", video);
    assertXpathNotExists("//ui:video/@width", video);
    assertXpathNotExists("//ui:video/@height", video);
    assertXpathNotExists("//ui:video/@duration", video);
    assertXpathNotExists("//ui:video/@poster", video);
    assertXpathEvaluatesTo("0", "count(//ui:video/ui:track)", video);
    assertXpathEvaluatesTo("1", "count(//ui:video/ui:src)", video);
    assertXpathUrlEvaluatesTo(video.getVideoUrls()[0], "//ui:video/ui:src/@uri", video);
    assertXpathEvaluatesTo(video.getVideo()[0].getMimeType(), "//ui:video/ui:src/@type", video);
    assertXpathEvaluatesTo(String.valueOf(mockVideo.getSize().width), "//ui:video/ui:src/@width", video);
    assertXpathEvaluatesTo(String.valueOf(mockVideo.getSize().height), "//ui:video/ui:src/@height", video);
    // Test other options, resetting them after each test
    video.setAltText("altText");
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("altText", "//ui:video/@alt", video);
    video.reset();
    video.setPreload(WVideo.Preload.META_DATA);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("metadata", "//ui:video/@preload", video);
    video.reset();
    video.setAutoplay(true);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("true", "//ui:video/@autoplay", video);
    video.reset();
    video.setLoop(true);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("true", "//ui:video/@loop", video);
    video.reset();
    video.setMuted(true);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("true", "//ui:video/@muted", video);
    video.reset();
    video.setControls(WVideo.Controls.NONE);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("none", "//ui:video/@controls", video);
    video.reset();
    video.setControls(WVideo.Controls.ALL);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("all", "//ui:video/@controls", video);
    video.reset();
    video.setControls(WVideo.Controls.PLAY_PAUSE);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("play", "//ui:video/@controls", video);
    video.reset();
    video.setControls(WVideo.Controls.DEFAULT);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("default", "//ui:video/@controls", video);
    video.reset();
    setFlag(video, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("true", "//ui:video/@hidden", video);
    video.reset();
    video.setDisabled(true);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("true", "//ui:video/@disabled", video);
    video.reset();
    video.setToolTip("toolTip");
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("toolTip", "//ui:video/@toolTip", video);
    video.reset();
    video.setWidth(123);
    video.setHeight(456);
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("123", "//ui:video/@width", video);
    assertXpathEvaluatesTo("456", "//ui:video/@height", video);
    video.reset();
    video.setPoster(new MockImage());
    assertXpathUrlEvaluatesTo(video.getPosterUrl(), "//ui:video/@poster", video);
    video.reset();
    MockTrack track = new MockTrack();
    track.setLanguage("en");
    track.setDescription("trackDesc");
    track.setKind(Track.Kind.SUBTITLES);
    video.setTracks(new Track[] { track });
    assertSchemaMatch(video);
    assertXpathEvaluatesTo("1", "count(//ui:video/ui:track)", video);
    assertXpathEvaluatesTo("en", "//ui:video/ui:track/@lang", video);
    assertXpathEvaluatesTo("subtitles", "//ui:video/ui:track/@kind", video);
    assertXpathEvaluatesTo("trackDesc", "//ui:video/ui:track/@desc", video);
    assertXpathUrlEvaluatesTo(video.getTrackUrls()[0], "//ui:video/ui:track/@src", video);
    track.setKind(Track.Kind.CAPTIONS);
    assertXpathEvaluatesTo("captions", "//ui:video/ui:track/@kind", video);
    track.setKind(Track.Kind.DESCRIPTIONS);
    assertXpathEvaluatesTo("descriptions", "//ui:video/ui:track/@kind", video);
    track.setKind(Track.Kind.CHAPTERS);
    assertXpathEvaluatesTo("chapters", "//ui:video/ui:track/@kind", video);
    track.setKind(Track.Kind.METADATA);
    assertXpathEvaluatesTo("metadata", "//ui:video/ui:track/@kind", video);
    video.reset();
    mockVideo.setDuration(123);
    assertXpathEvaluatesTo("123", "//ui:video/@duration", video);
}
Also used : MockVideo(com.github.bordertech.wcomponents.MockVideo) WVideo(com.github.bordertech.wcomponents.WVideo) Dimension(java.awt.Dimension) MockTrack(com.github.bordertech.wcomponents.MockTrack) MockImage(com.github.bordertech.wcomponents.MockImage) Test(org.junit.Test)

Aggregations

WVideo (com.github.bordertech.wcomponents.WVideo)4 Test (org.junit.Test)2 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)1 MockImage (com.github.bordertech.wcomponents.MockImage)1 MockTrack (com.github.bordertech.wcomponents.MockTrack)1 MockVideo (com.github.bordertech.wcomponents.MockVideo)1 Track (com.github.bordertech.wcomponents.Track)1 Video (com.github.bordertech.wcomponents.Video)1 WAudio (com.github.bordertech.wcomponents.WAudio)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WContent (com.github.bordertech.wcomponents.WContent)1 WImage (com.github.bordertech.wcomponents.WImage)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1 Dimension (java.awt.Dimension)1