Example usage for com.google.gwt.safehtml.shared UriUtils fromTrustedString

List of usage examples for com.google.gwt.safehtml.shared UriUtils fromTrustedString

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared UriUtils fromTrustedString.

Prototype

public static SafeUri fromTrustedString(String s) 

Source Link

Document

Returns a SafeUri constructed from a trusted string, i.e., without sanitizing the string.

Usage

From source file:com.retech.reader.web.client.home.MyDownLoadPanel.java

License:Apache License

private void displayResource(final ResourceProxy resource, final HTMLPanel imagePanel) {
    SafeHtml safe = template.img(UriUtils.fromTrustedString(
            "data:" + resource.getMimeType().getType() + ";base64," + resource.getDataString()));
    String asString = safe.asString();
    imagePanel.add(new HTML(asString));
}

From source file:eu.maxschuster.vaadin.signaturefield.client.signaturepad.SignaturePad.java

License:Apache License

public void fromDataURL(String dataURL, final Double width, final Double height) {
    SafeUri uri = UriUtils.fromTrustedString(dataURL);
    final Image image = new Image(uri);
    image.addLoadHandler(new LoadHandler() {
        @Override// w  ww  .j  a v  a 2  s .c o m
        public void onLoad(LoadEvent event) {
            ImageElement imageElement = ImageElement.as(image.getElement());
            if (width == null && height == null) {
                context.drawImage(imageElement, 0d, 0d);
            } else {
                context.drawImage(imageElement, 0d, 0d, width, height);
            }

            RootPanel.get().remove(image);
        }
    });
    RootPanel.get().add(image);
    empty = false;
}

From source file:fr.mncc.gwttoolbox.datagrid.client.cells.ClickableImageCell.java

License:Open Source License

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    if (value != null) {
        SafeUri uri = trustUri_ ? UriUtils.fromTrustedString(value) : UriUtils.fromString(value);
        if (width_ == null && height_ != null) // resize with constraint on height
            sb.append(template_.imgByHeight(uri, height_));
        else if (height_ == null && width_ != null) // resize with constraint on width
            sb.append(template_.imgByWidth(uri, width_));
        else if (height_ != null) // resize with constraint on width and height
            sb.append(template_.img(uri, width_, height_));
    }//from   w  ww .  j  a v a 2 s.  co  m
}

From source file:fr.mncc.sandbox.client.layouts.photogallery.PhotoGalleryLayout.java

License:Open Source License

private SafeHtml createImageWrapper(Image img) {
    return htmlTemplate_.input(UriUtils.fromTrustedString(img.authorWebsite),
            UriUtils.fromTrustedString(img.imageUrl), img.imageText, img.authorName, img.css);
}

From source file:nl.mpi.tg.eg.experiment.client.presenter.AbstractStimulusPresenter.java

License:Open Source License

protected void stimulusImageCapture(final StimuliProvider stimulusProvider, final Stimulus currentStimulusO,
        final String captureLabel, int percentOfPage, int maxHeight, int maxWidth, int postLoadMs,
        final TimedStimulusListener timedStimulusListener) {
    final SdCardStimulus currentStimulus = (SdCardStimulus) currentStimulusO;
    final SdCardImageCapture sdCardImageCapture = new SdCardImageCapture(new TimedStimulusListener() {
        @Override/* www  .ja v  a2s .  co m*/
        public void postLoadTimerFired() {
            clearPage();
            // cause the taken image to be shown
            hasMoreStimulusListener.postLoadTimerFired(stimulusProvider, currentStimulusO);
        }
    }, currentStimulus, userResults.getUserData().getUserId(), localStorage);
    if (sdCardImageCapture.hasBeenCaptured()) {
        final CancelableStimulusListener shownStimulusListener = new CancelableStimulusListener() {
            @Override
            protected void trigggerCancelableEvent() {
                timedStimulusListener.postLoadTimerFired();
            }
        };
        timedStimulusView.addTimedImage(timedEventMonitor,
                UriUtils.fromTrustedString(sdCardImageCapture.getCapturedPath()), percentOfPage, maxHeight,
                maxWidth, null, null, postLoadMs, shownStimulusListener, shownStimulusListener, null, null);
    }
    timedStimulusView.addOptionButton(new PresenterEventListner() {
        @Override
        public String getLabel() {
            return captureLabel;
        }

        @Override
        public String getStyleName() {
            return null;
        }

        @Override
        public void eventFired(ButtonBase button, SingleShotEventListner shotEventListner) {
            sdCardImageCapture.captureImage();
        }

        @Override
        public int getHotKey() {
            return -1;
        }
    });
}

From source file:nl.mpi.tg.eg.experiment.client.presenter.AbstractStimulusPresenter.java

License:Open Source License

protected void backgroundImage(final String imageSrc, String styleName, int postLoadMs,
        final TimedStimulusListener timedStimulusListener) {
    timedStimulusView.addBackgroundImage(
            (imageSrc == null || imageSrc.isEmpty()) ? null
                    : UriUtils.fromTrustedString((imageSrc.startsWith("file")) ? imageSrc
                            : serviceLocations.staticFilesUrl() + imageSrc),
            styleName, postLoadMs, timedStimulusListener);
}

From source file:nl.mpi.tg.eg.experiment.client.presenter.AbstractStimulusPresenter.java

License:Open Source License

protected void stimulusPresent(final StimuliProvider stimulusProvider, final Stimulus currentStimulus,
        int percentOfPage, int maxHeight, int maxWidth, final AnimateTypes animateType,
        final boolean showControls, final Integer fixedPositionY, String regex, String replacement,
        final int dataChannel, final CancelableStimulusListener loadedStimulusListener,
        final CancelableStimulusListener failedStimulusListener,
        final CancelableStimulusListener playbackStartedStimulusListener,
        final CancelableStimulusListener playedStimulusListener,
        final CancelableStimulusListener clickedStimulusListener) {
    if (currentStimulus.hasImage()) {
        final String image;
        if (regex != null && replacement != null) {
            image = currentStimulus.getImage().replaceAll(regex, replacement);
        } else {/*ww w  .ja v a  2  s .c om*/
            image = currentStimulus.getImage();
        }
        final CancelableStimulusListener shownStimulusListener = new CancelableStimulusListener() {
            @Override
            protected void trigggerCancelableEvent() {
                // send image shown tag
                submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(),
                        dataChannel, "StimulusImageShown", currentStimulus.getUniqueId(), image,
                        duration.elapsedMillis());
            }
        };
        //            submissionService.submitTagValue(userResults.getUserData().getUserId(), "StimulusImage", image, duration.elapsedMillis());
        final String animateStyle;
        if (animateType == AnimateTypes.stimuliCode) {
            animateStyle = currentStimulus.getCode() + "Animation";
        } else if (animateType != AnimateTypes.none) {
            animateStyle = animateType.name() + "Animation";
        } else {
            animateStyle = null;
        }
        timedStimulusView.addTimedImage(timedEventMonitor, UriUtils.fromTrustedString(image), percentOfPage,
                maxHeight, maxWidth, animateStyle, fixedPositionY, 0, shownStimulusListener,
                new CancelableStimulusListener() {
                    @Override
                    protected void trigggerCancelableEvent() {
                        loadedStimulusListener.postLoadTimerFired();
                        playedStimulusListener.postLoadTimerFired();
                    }
                }, failedStimulusListener, clickedStimulusListener);
        //        timedStimulusView.addText("addStimulusImage: " + duration.elapsedMillis() + "ms");
    } else if (currentStimulus.hasAudio()) {
        String mp3 = currentStimulus.getAudio() + ".mp3";
        String ogg = currentStimulus.getAudio() + ".ogg";
        if (regex != null && replacement != null) {
            mp3 = mp3.replaceAll(regex, replacement);
            ogg = ogg.replaceAll(regex, replacement);
        }
        final SafeUri oggTrustedString = (ogg == null) ? null : UriUtils.fromTrustedString(ogg);
        final SafeUri mp3TrustedString = (mp3 == null) ? null : UriUtils.fromTrustedString(mp3);
        final CancelableStimulusListener shownStimulusListener = new CancelableStimulusListener() {
            @Override
            protected void trigggerCancelableEvent() {
                // send audio shown tag
                submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(),
                        dataChannel, "StimulusAudioShown", currentStimulus.getUniqueId(),
                        currentStimulus.getAudio(), duration.elapsedMillis());
                loadedStimulusListener.postLoadTimerFired();
            }
        };
        //            submissionService.submitTagValue(userResults.getUserData().getUserId(), "StimulusAudio", currentStimulus.getAudio(), duration.elapsedMillis());
        timedStimulusView.addTimedAudio(timedEventMonitor, oggTrustedString, mp3TrustedString, false,
                shownStimulusListener, failedStimulusListener, playbackStartedStimulusListener,
                playedStimulusListener, true, "autoStimulus");
    } else if (currentStimulus.hasVideo()) {
        String ogg = currentStimulus.getVideo() + ".ogg";
        String ogv = currentStimulus.getVideo() + ".ogv";
        String mp4 = currentStimulus.getVideo() + ".mp4";
        if (regex != null && replacement != null) {
            mp4 = mp4.replaceAll(regex, replacement);
            ogg = ogg.replaceAll(regex, replacement);
        }
        //            submissionService.submitTagValue(userResults.getUserData().getUserId(), "StimulusVideo", currentStimulus.getVideo(), duration.elapsedMillis());
        final SafeUri oggTrustedString = (ogg == null) ? null : UriUtils.fromTrustedString(ogg);
        final SafeUri ogvTrustedString = (ogv == null) ? null : UriUtils.fromTrustedString(ogv);
        final SafeUri mp4TrustedString = (mp4 == null) ? null : UriUtils.fromTrustedString(mp4);
        final CancelableStimulusListener shownStimulusListener = new CancelableStimulusListener() {
            @Override
            protected void trigggerCancelableEvent() {
                // send video shown tag
                submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(),
                        dataChannel, "StimulusVideoShown", currentStimulus.getUniqueId(),
                        currentStimulus.getVideo(), duration.elapsedMillis());
                loadedStimulusListener.postLoadTimerFired();
            }
        };
        timedStimulusView.addTimedVideo(timedEventMonitor, oggTrustedString, ogvTrustedString, mp4TrustedString,
                percentOfPage, maxHeight, maxWidth, null, false, false, showControls, shownStimulusListener,
                failedStimulusListener, playbackStartedStimulusListener, playedStimulusListener,
                "stimulusPresent");
    } else if (currentStimulus.getLabel() != null) {
        timedStimulusView.addHtmlText(currentStimulus.getLabel(), null);
        // send label shown tag
        submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(), dataChannel,
                "StimulusLabelShown", currentStimulus.getUniqueId(), currentStimulus.getLabel(),
                duration.elapsedMillis());
        loadedStimulusListener.postLoadTimerFired();
        playedStimulusListener.postLoadTimerFired();
    } else {
        final String incorrect_stimulus_format = "incorrect stimulus format";
        nextStimulusButton(stimulusProvider, currentStimulus, incorrect_stimulus_format,
                incorrect_stimulus_format + " " + currentStimulus.getLabel(), null, true, -1,
                "incorrectStimulusFormat");
    }
}

From source file:nl.mpi.tg.eg.experiment.client.presenter.AbstractStimulusPresenter.java

License:Open Source License

protected void stimulusCodeAudio(final Stimulus currentStimulus, final boolean autoPlay, final String mediaId,
        String codeFormat, boolean showPlaybackIndicator, final int dataChannel,
        final CancelableStimulusListener loadedStimulusListener,
        final CancelableStimulusListener failedStimulusListener,
        final CancelableStimulusListener playbackStartedStimulusListener,
        final CancelableStimulusListener playedStimulusListener) {
    final String formattedCode = new HtmlTokenFormatter(currentStimulus, localStorage, groupParticipantService,
            userResults.getUserData(), timerService, metadataFieldProvider.metadataFieldArray)
                    .formatString(codeFormat);
    final String formattedMediaId = new HtmlTokenFormatter(currentStimulus, localStorage,
            groupParticipantService, userResults.getUserData(), timerService,
            metadataFieldProvider.metadataFieldArray).formatString(mediaId);
    final String uniqueId = currentStimulus.getUniqueId();

    String mp3 = formattedCode + ".mp3";
    String ogg = formattedCode + ".ogg";
    final SafeUri oggTrustedString = (ogg == null) ? null
            : UriUtils
                    .fromTrustedString((ogg.startsWith("file") ? "" : serviceLocations.staticFilesUrl()) + ogg);
    final SafeUri mp3TrustedString = (mp3 == null) ? null
            : UriUtils//www.  j a va2 s .  c  o m
                    .fromTrustedString((mp3.startsWith("file") ? "" : serviceLocations.staticFilesUrl()) + mp3);
    //        submissionService.submitTagValue(userResults.getUserData().getUserId(), "StimulusCodeAudio", formattedCode, duration.elapsedMillis());
    //        submissionService.submitTagValue(userResults.getUserData().getUserId(), "StimulusAudio", formattedCode, duration.elapsedMillis());
    final CancelableStimulusListener shownStimulusListener = new CancelableStimulusListener() {
        @Override
        protected void trigggerCancelableEvent() {
            submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(),
                    dataChannel, "StimulusCodeAudioShown", uniqueId, formattedCode, duration.elapsedMillis());
            loadedStimulusListener.postLoadTimerFired();
        }
    };
    timedStimulusView.addTimedAudio(timedEventMonitor, oggTrustedString, mp3TrustedString,
            showPlaybackIndicator, shownStimulusListener, failedStimulusListener,
            playbackStartedStimulusListener, playedStimulusListener, autoPlay, formattedMediaId);
}

From source file:nl.mpi.tg.eg.experiment.client.presenter.AbstractStimulusPresenter.java

License:Open Source License

protected void stimulusVideo(final Stimulus currentStimulus, final String styleName, final boolean autoPlay,
        final String mediaId, final boolean loop, final boolean showControls, final int dataChannel,
        final CancelableStimulusListener loadedStimulusListener,
        final CancelableStimulusListener failedStimulusListener,
        final CancelableStimulusListener playbackStartedStimulusListener,
        final CancelableStimulusListener playedStimulusListener) {
    final String videoName = currentStimulus.getVideo();
    final String uniqueId = currentStimulus.getUniqueId();
    final String formattedMediaId = new HtmlTokenFormatter(currentStimulus, localStorage,
            groupParticipantService, userResults.getUserData(), timerService,
            metadataFieldProvider.metadataFieldArray).formatString(mediaId);
    String mp4 = videoName + ".mp4";
    String ogg = videoName + ".ogg";
    String ogv = videoName + ".ogv";
    final SafeUri oggTrustedString = (ogg == null) ? null : UriUtils.fromTrustedString(ogg);
    final SafeUri ogvTrustedString = (ogv == null) ? null : UriUtils.fromTrustedString(ogv);
    final SafeUri mp4TrustedString = (mp4 == null) ? null : UriUtils.fromTrustedString(mp4);
    //        submissionService.submitTagValue(userResults.getUserData().getUserId(), "StimulusCodeVideo", formattedCode, duration.elapsedMillis());
    final CancelableStimulusListener shownStimulusListener = new CancelableStimulusListener() {
        @Override// w w  w.j  a  v  a2  s . co m
        protected void trigggerCancelableEvent() {
            submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(),
                    dataChannel, "StimulusVideoShown", uniqueId, videoName, duration.elapsedMillis());
            loadedStimulusListener.postLoadTimerFired();
        }
    };
    //        submissionService.submitTagValue(userResults.getUserData().getUserId(), "StimulusAudio", formattedCode, duration.elapsedMillis());
    Element videoElement = timedStimulusView.addTimedVideo(timedEventMonitor, oggTrustedString,
            ogvTrustedString, mp4TrustedString, 0, 0, 0, styleName, autoPlay, loop, showControls,
            shownStimulusListener, failedStimulusListener, playbackStartedStimulusListener,
            playedStimulusListener, formattedMediaId);
    if (videoElement != null) {
        timedEventMonitor.addVisibilityListener(widgetTag.getElement(), videoElement, "stimulusVideo");
    }
}

From source file:nl.mpi.tg.eg.experiment.client.presenter.AbstractStimulusPresenter.java

License:Open Source License

protected void stimulusCodeVideo(final Stimulus currentStimulus, int percentOfPage, int maxHeight, int maxWidth,
        final String codeStyleName, final boolean autoPlay, final String mediaId, final boolean loop,
        final boolean showControls, String codeFormat, final int dataChannel,
        final CancelableStimulusListener loadedStimulusListener,
        final CancelableStimulusListener failedStimulusListener,
        final CancelableStimulusListener playbackStartedStimulusListener,
        final CancelableStimulusListener playedStimulusListener) {
    final String formattedCode = new HtmlTokenFormatter(currentStimulus, localStorage, groupParticipantService,
            userResults.getUserData(), timerService, metadataFieldProvider.metadataFieldArray)
                    .formatString(codeFormat);
    final String styleName = new HtmlTokenFormatter(currentStimulus, localStorage, groupParticipantService,
            userResults.getUserData(), timerService, metadataFieldProvider.metadataFieldArray)
                    .formatString(codeStyleName);
    final String formattedMediaId = new HtmlTokenFormatter(currentStimulus, localStorage,
            groupParticipantService, userResults.getUserData(), timerService,
            metadataFieldProvider.metadataFieldArray).formatString(mediaId);
    final String uniqueId = currentStimulus.getUniqueId();
    String mp4 = formattedCode + ".mp4";
    String ogg = formattedCode + ".ogg";
    String ogv = formattedCode + ".ogv";
    final SafeUri oggTrustedString = (ogg == null) ? null
            : UriUtils.fromTrustedString(serviceLocations.staticFilesUrl() + ogg);
    final SafeUri ogvTrustedString = (ogv == null) ? null
            : UriUtils.fromTrustedString(serviceLocations.staticFilesUrl() + ogv);
    final SafeUri mp4TrustedString = (mp4 == null) ? null
            : UriUtils.fromTrustedString(serviceLocations.staticFilesUrl() + mp4);
    //        submissionService.submitTagValue(userResults.getUserData().getUserId(), "StimulusCodeVideo", formattedCode, duration.elapsedMillis());
    final CancelableStimulusListener shownStimulusListener = new CancelableStimulusListener() {
        @Override//ww  w  .  j  a  v a2 s .  c  o m
        protected void trigggerCancelableEvent() {
            submissionService.submitTagPairValue(userResults.getUserData().getUserId(), getSelfTag(),
                    dataChannel, "StimulusCodeVideoShown", uniqueId, formattedCode, duration.elapsedMillis());
            loadedStimulusListener.postLoadTimerFired();
        }
    };
    //        submissionService.submitTagValue(userResults.getUserData().getUserId(), "StimulusAudio", formattedCode, duration.elapsedMillis());
    timedStimulusView.addTimedVideo(timedEventMonitor, oggTrustedString, ogvTrustedString, mp4TrustedString,
            percentOfPage, maxHeight, maxWidth, styleName, autoPlay, loop, showControls, shownStimulusListener,
            failedStimulusListener, playbackStartedStimulusListener, playedStimulusListener, formattedMediaId);
}