import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.StringTokenizer;
import javax.jcr.Binary;
import javax.jcr.Node;
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;
} 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) {
/** @return null if not available */
@Override
public String getImageUrl(Node node) throws RepositoryException {
- return CmsUiUtils.getDataPath(node);
+ return getCleanDataPath(node);
+ }
+
+ /** Clean special character from the URL. */
+ protected String getCleanDataPath(Node node) throws RepositoryException {
+ String path = CmsUiUtils.getDataPath(node);
+ StringTokenizer st = new StringTokenizer(path, "/");
+ StringBuilder sb = new StringBuilder();
+ while (st.hasMoreElements()) {
+ sb.append('/');
+ String encoded = URLEncoder.encode(st.nextToken(), StandardCharsets.UTF_8);
+ encoded = encoded.replace("+", "%20");
+ sb.append(encoded);
+
+ }
+ return sb.toString();
}
protected String getResourceName(Node node) throws RepositoryException {
if (log.isDebugEnabled())
log.debug("Unregistered image " + previousResourceName);
}
- return getImageUrl(fileNode);
+ 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);
}