}
public Point getImageSize(Node node) throws RepositoryException {
- // TODO load the SWT image ?
- return new Point(0, 0);
+ // TODO optimise
+ Image image = getSwtImage(node);
+ return new Point(image.getBounds().width, image.getBounds().height);
}
/** @return null if not available */
@Override
public String getImageUrl(Node node) throws RepositoryException {
return CmsUiUtils.getDataPath(node);
- // String name = getResourceName(node);
- // ResourceManager resourceManager = RWT.getResourceManager();
- // if (!resourceManager.isRegistered(name)) {
- // InputStream inputStream = null;
- // Binary binary = getImageBinary(node);
- // if (binary == null)
- // return null;
- // try {
- // inputStream = binary.getStream();
- // resourceManager.register(name, inputStream);
- // } finally {
- // IOUtils.closeQuietly(inputStream);
- // JcrUtils.closeQuietly(binary);
- // }
- // if (log.isTraceEnabled())
- // log.trace("Registered image " + name);
- // }
- // return resourceManager.getLocation(name);
}
protected String getResourceName(Node node) throws RepositoryException {
}
@Override
- public String uploadImage(Node parentNode, String fileName, InputStream in) throws RepositoryException {
+ public String uploadImage(Node context, Node parentNode, String fileName, InputStream in, String contentType)
+ throws RepositoryException {
InputStream inputStream = null;
try {
String previousResourceName = null;
Node fileNode = JcrUtils.copyBytesAsFile(parentNode, fileName, arr);
inputStream = new ByteArrayInputStream(arr);
ImageData id = new ImageData(inputStream);
- processNewImageFile(fileNode, id);
+ processNewImageFile(context, fileNode, id);
- String mime = Files.probeContentType(Paths.get(fileName));
- fileNode.setProperty(Property.JCR_MIMETYPE, mime);
+ String mime = contentType != null ? contentType : Files.probeContentType(Paths.get(fileName));
+ if (mime != null) {
+ fileNode.getNode(JCR_CONTENT).setProperty(Property.JCR_MIMETYPE, mime);
+ }
fileNode.getSession().save();
// reset resource manager
}
}
- /** Does nothign by default. */
- protected void processNewImageFile(Node fileNode, ImageData id) throws RepositoryException, IOException {
+ /** Does nothing by default. */
+ protected void processNewImageFile(Node context, Node fileNode, ImageData id)
+ throws RepositoryException, IOException {
}
}