Improve image test
[gpl/argeo-suite.git] / org.argeo.app.ui / src / org / argeo / app / ui / SuiteUiUtils.java
index cad9bdd1ed1715595da5c6dd7f023fab00362659..504fbd2e3ed72d54d979aa50b822f03e57a0ecd0 100644 (file)
@@ -2,11 +2,15 @@ package org.argeo.app.ui;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.commons.io.IOUtils;
 import org.argeo.api.cms.CmsEditable;
 import org.argeo.api.cms.CmsEvent;
 import org.argeo.api.cms.CmsStyle;
@@ -25,7 +29,6 @@ import org.argeo.cms.ui.util.CmsLink;
 import org.argeo.cms.ui.util.CmsUiUtils;
 import org.argeo.eclipse.ui.EclipseUiUtils;
 import org.argeo.jcr.Jcr;
-import org.argeo.jcr.JcrException;
 import org.argeo.jcr.JcrUtils;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.ScrolledComposite;
@@ -232,6 +235,25 @@ public class SuiteUiUtils {
        public static Label addPicture(Composite parent, Node fileNode, Integer maxWidth, Node link)
                        throws RepositoryException {
                Node content = fileNode.getNode(Node.JCR_CONTENT);
+
+               boolean test = false;
+               if (test) {
+                       try (InputStream in = JcrUtils.getFileAsStream(fileNode);
+                                       OutputStream out = Files.newOutputStream(Paths.get("/home/mbaudier/tmp/" + fileNode.getName()));) {
+//                             BufferedImage img = ImageIO.read(in);
+//                             System.out.println(fileNode.getName() + ": width=" + img.getWidth() + ", height=" + img.getHeight());
+                               IOUtils.copy(in, out);
+                       } catch (IOException e) {
+                               throw new RuntimeException(e);
+                       }
+
+//                     try (InputStream in = JcrUtils.getFileAsStream(fileNode);) {
+//                             ImageData imageData = new ImageData(in);
+//                             System.out.println(fileNode.getName() + ": width=" + imageData.width + ", height=" + imageData.height);
+//                     } catch (IOException e) {
+//                             throw new RuntimeException(e);
+//                     }
+               }
                // TODO move it deeper in the middleware.
                if (!content.isNodeType(EntityType.box.get())) {
                        if (content.getSession().hasPermission(content.getPath(), Session.ACTION_SET_PROPERTY)) {
@@ -337,7 +359,7 @@ public class SuiteUiUtils {
        }
 
        public static String toLink(Node node) {
-                       return node != null ? "#" + CmsUiUtils.cleanPathForUrl(SuiteApp.nodeToState(node)) : null;
+               return node != null ? "#" + CmsUiUtils.cleanPathForUrl(SuiteApp.nodeToState(node)) : null;
        }
 
        public static Control addLink(Composite parent, String label, Node node, CmsStyle style)