Hi XWiki developers,
I'm preparing a small plugin for thumbnails as explain in my previous mail.
The image is resized by adding a parameter heigth at this end of a download
URL (eg :xwiki/bin/download/Photos/Seychelles1999/DSC04010.JPG?height=550)
To call the plugin I need to add a piece of code in DownloadAction class.
Do you think :
- is it better to add the dependancy to the plugin in the DownloadAction class
such as :
// Sending the content of the attachment
- byte[] data = attachment.getContent(context);
+ byte[] data = null;
+
+ // Resize if imageplugin is on
+ ImagePlugin imageplugin = (ImagePlugin)
context.getWiki().getPlugin(
+ "image", context);
+ if ((request.getParameter("height") != null) &&
(imageplugin != null)) {
+ try {
+ int height =
Integer.parseInt(request.getParameter("height"));
+ data = imageplugin.createThumbnail(attachment,
height, context);
+ response.setContentType("image/png");
+ } catch (NumberFormatException e) {
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ if (data == null) data = attachment.getContent(context);
+
- or is it better to add a generic method in the plugin Interface class
(XWikiPluginInterface) with a method : startDownloading(byte[] data,
XWikiContext context) and to call it after in DownloadAction ?
Regards
--
Xavier MOGHRABI - Consortium ObjectWeb