Improve CMS UI utilities.
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / ui / util / DefaultImageManager.java
index d99be6b02c3a9482ded01faf2254ed96a98158b3..6c4a870c49752f26731be354a492e49d7260d7da 100644 (file)
@@ -9,6 +9,8 @@ import static org.argeo.cms.ui.CmsConstants.NO_IMAGE_SIZE;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 
@@ -20,7 +22,6 @@ import javax.jcr.RepositoryException;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.argeo.cms.CmsException;
 import org.argeo.cms.ui.CmsImageManager;
 import org.argeo.jcr.JcrUtils;
 import org.eclipse.rap.rwt.RWT;
@@ -104,7 +105,7 @@ public class DefaultImageManager implements CmsImageManager {
                } else if (constraints.x == 0) {// force height
                        return new Point(scale(orig.x, orig.y, constraints.y), constraints.y);
                }
-               throw new CmsException("Cannot resize " + orig + " to " + constraints);
+               throw new IllegalArgumentException("Cannot resize " + orig + " to " + constraints);
        }
 
        private int scale(int origDimension, int otherDimension, int otherConstraint) {
@@ -151,7 +152,7 @@ public class DefaultImageManager implements CmsImageManager {
        /** @return null if not available */
        @Override
        public String getImageUrl(Node node) throws RepositoryException {
-               return CmsUiUtils.getDataPath(node);
+               return CmsUiUtils.getDataPathForUrl(node);
        }
 
        protected String getResourceName(Node node) throws RepositoryException {
@@ -220,7 +221,7 @@ public class DefaultImageManager implements CmsImageManager {
                        }
                        return CmsUiUtils.getDataPath(fileNode);
                } catch (IOException e) {
-                       throw new CmsException("Cannot upload image " + fileName + " in " + parentNode, e);
+                       throw new RuntimeException("Cannot upload image " + fileName + " in " + parentNode, e);
                } finally {
                        IOUtils.closeQuietly(inputStream);
                }