Fix video display.
authorMathieu Baudier <mbaudier@argeo.org>
Mon, 19 Jul 2021 13:01:39 +0000 (15:01 +0200)
committerMathieu Baudier <mbaudier@argeo.org>
Mon, 19 Jul 2021 13:01:39 +0000 (15:01 +0200)
publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/AbstractDbkViewer.java
publishing/org.argeo.publishing.ui/src/org/argeo/docbook/ui/DbkVideo.java

index 7c2b59b32905ea272622a7baba831bc2071f9729..e9000936128b2f94f850475471b28161399911dc 100644 (file)
@@ -221,13 +221,13 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
 
        protected DbkVideo newVideo(TextSection parent, Node node) {
                try {
-                       DbkVideo video = new DbkVideo(parent,getCmsEditable().canEdit()?SWT.NONE : SWT.READ_ONLY, node);
+                       DbkVideo video = new DbkVideo(parent, getCmsEditable().canEdit() ? SWT.NONE : SWT.READ_ONLY, node);
                        GridData gd;
                        if (maxMediaWidth != null) {
                                gd = new GridData(SWT.CENTER, SWT.FILL, false, false);
                                // TODO, manage size
-                               gd.widthHint = maxMediaWidth;
-                               gd.heightHint = (int) (gd.heightHint * 0.5625);
+//                             gd.widthHint = maxMediaWidth;
+//                             gd.heightHint = (int) (gd.heightHint * 0.5625);
                        } else {
                                gd = new GridData(SWT.CENTER, SWT.FILL, false, false);
 //                             gd.widthHint = video.getWidth();
@@ -235,7 +235,7 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                        }
                        video.setLayoutData(gd);
                        updateContent(video);
-                       return null;
+                       return video;
                } catch (RepositoryException e) {
                        throw new JcrException("Cannot add new image " + node, e);
                }
@@ -807,8 +807,7 @@ public abstract class AbstractDbkViewer extends AbstractPageViewer implements Ke
                return newParagraph;
        }
 
-       protected Paragraph sectionTitleSplitted(DbkSectionTitle sectionTitle, Node newNode)
-                       throws RepositoryException {
+       protected Paragraph sectionTitleSplitted(DbkSectionTitle sectionTitle, Node newNode) throws RepositoryException {
                updateContent(sectionTitle);
                Paragraph newParagraph = newParagraph(sectionTitle.getSection(), newNode);
                // we assume beforeFirst is not null since there was a sectionTitle
index af2ee8487b9dba92c642b6cc7c14628cff1ece0b..acb266b94746be475536edd404b7d24aead7489a 100644 (file)
@@ -58,15 +58,15 @@ public class DbkVideo extends StyledControl implements SectionPart, NodePart {
 
                Composite browserC = new Composite(wrapper, SWT.NONE);
                browserC.setLayout(CmsUiUtils.noSpaceGridLayout());
-//             wrapper.setLayoutData(CmsUiUtils.fillAll());
-               Browser browser = new Browser(browserC, SWT.NONE);
-               GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
+               GridData gd = new GridData(SWT.CENTER, SWT.FILL, true, true);
                gd.widthHint = getWidth();
                gd.heightHint = getHeight();
                browserC.setLayoutData(gd);
+//             wrapper.setLayoutData(CmsUiUtils.fillAll());
+               Browser browser = new Browser(browserC, SWT.NONE);
 
                if (editable) {
-                       Composite editor = new Composite(wrapper, SWT.NONE);
+                       Composite editor = new Composite(wrapper, SWT.BORDER);
                        editor.setLayout(new GridLayout(3, false));
                        editor.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
                        String fileref = DbkUtils.getMediaFileref(mediaobject);
@@ -74,7 +74,7 @@ public class DbkVideo extends StyledControl implements SectionPart, NodePart {
                        if (fileref != null)
                                text.setText(fileref);
                        else
-                               text.setMessage("Embed URL of the video.");
+                               text.setMessage("Embed URL of the video");
                        text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
                        Button updateB = new Button(editor, SWT.FLAT);
                        updateB.setText("Update");
@@ -95,22 +95,39 @@ public class DbkVideo extends StyledControl implements SectionPart, NodePart {
                                                        return;
                                                }
 
-                                               // transform YouTube watch URL in embed
-                                               String youTubeVideoId = null;
-                                               if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost())) {
-                                                       if ("/watch".equals(uri.getPath())) {
-                                                               Map<String, List<String>> map = NamingUtils.queryToMap(uri);
-                                                               youTubeVideoId = map.get("v").get(0);
+                                               // Transform watch URL in embed
+                                               // YouTube
+                                               String videoId = null;
+                                               if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost())
+                                                               || "youtu.be".equals(uri.getHost())) {
+                                                       if ("www.youtube.com".equals(uri.getHost()) || "youtube.com".equals(uri.getHost())) {
+                                                               if ("/watch".equals(uri.getPath())) {
+                                                                       Map<String, List<String>> map = NamingUtils.queryToMap(uri);
+                                                                       videoId = map.get("v").get(0);
+                                                               }
+                                                       } else if ("youtu.be".equals(uri.getHost())) {
+                                                               videoId = uri.getPath().substring(1);
+                                                       }
+                                                       if (videoId != null) {
+                                                               try {
+                                                                       uri = new URI("https://www.youtube.com/embed/" + videoId);
+                                                                       text.setText(uri.toString());
+                                                               } catch (URISyntaxException e1) {
+                                                                       throw new IllegalStateException(e1);
+                                                               }
                                                        }
-                                               } else if ("youtu.be".equals(uri.getHost())) {
-                                                       youTubeVideoId = uri.getPath().substring(1);
                                                }
-                                               if (youTubeVideoId != null) {
-                                                       try {
-                                                               uri = new URI("https://www.youtube.com/embed/" + youTubeVideoId);
-                                                               text.setText(uri.toString());
-                                                       } catch (URISyntaxException e1) {
-                                                               throw new IllegalStateException(e1);
+
+                                               // Vimeo
+                                               if ("vimeo.com".equals(uri.getHost())) {
+                                                       videoId = uri.getPath().substring(1);
+                                                       if (videoId != null) {
+                                                               try {
+                                                                       uri = new URI("https://player.vimeo.com/video/" + videoId);
+                                                                       text.setText(uri.toString());
+                                                               } catch (URISyntaxException e1) {
+                                                                       throw new IllegalStateException(e1);
+                                                               }
                                                        }
                                                }
 
@@ -175,7 +192,7 @@ public class DbkVideo extends StyledControl implements SectionPart, NodePart {
 
        @Override
        protected void setContainerLayoutData(Composite composite) {
-               composite.setLayoutData(CmsUiUtils.fillAll());
+               composite.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true));
        }
 
        @Override